Talk:NOP (code)

message: I recently added the following text to the NOP code section:
:Note that in code which is compiled using an optimizing compiler, it is likely that any such redundant statements will be removed before they get a chance to be executed.
It was removed with the edit comment "There are no redundant statements in the example given".  Perhaps the intent of this sentence was not clear, so I'll explain it here and perhaps we can work out a better way of putting it.  My point is that in a non-optimising compiler, the given instructions may well be compiled into the binary (e.g. the source code i + 1; might result in machine code that performs an ADD and discards the results), but in an optimising compiler the whole instruction will be recognised as redundant and removed.  Therefore in an optimising compiler, main() { } and main { int i; i+1; } should produce exactly the same binary code. --HappyDog 08:54, 23 May 2007 (UTC)
replies: text: *Firstly compiler optimization is a continuum, all that can be said is optimizing compilers do more optimizations than non-optimizing compilers.  In the context of the code fragment it was not clear that that optimization of dead code was being discussed.  But my main point is that this article is about NOP, not compilers removing unnecessary code.  Ok, unnecessary code may be regarded as effectively a nop, but that is a rather indirect connection for an article like this to make.  Derek farn 10:59, 23 May 2007 (UTC)
replies: text:  That's all true, but reading that section, the implication is that the example code will compile into NOP instructions.  The paragraph begins An example of a single C statement that would also produce a NOP:, which is not true in optimising compilers that (as you rightly qualified) detect this kind of redundancy.  However, as this is such a basic optimisation to make, I would suspect (based on no actual research :-)) that most such compilers would manage this.  Perhaps the introduction to this section needs rewording, because it is unclear whether you are saying that this kind of instruction is called a NOP by C programmers (which in my experience it never is - 'void' is a more common term, if anything) or whether it compiles to a NOP, in which case a note about optimising compilers is required, imho. --HappyDog 11:30, 24 May 2007 (UTC)
replies: text:  I recently added something to this effect, which was reverted. Two points. There is no compiler I'm aware of, which at any optimisation level, ever, added in NOPs for empty lines of C code. That just isn't how compilers work. Why would they want to put in the extra work to output a NOP, when instead they could simply output nothing? Just because a compiler doesn't optimise well, doesn't mean it goes around purposefully spending extra work slowing things down. I think we do need a line which says that the NOPs of code are not directly related to NOPs of assembler itself, as too many people (including some people here, no offense), think that C compilers might output NOPs for empty instructions which isn't true at any optimisation level Mrjeff 09:55, 7 June 2007 (UTC)
replies: text: For some architectures, a compiler will generate a NOP for some occurrences of a null statement.  For instance, it may be necessary to fill the delay slot of a branch instruction on a MIPS processor.  This is a rather unusual edge case and mentioning it will only complicate the issue.  Do people actually think that in normal operation, a compiler goes round purposely generating NOPs when it detects redundant code?. Derek farn 10:40, 7 June 2007 (UTC)
replies: text:  In this instance the compiler is inserting its own NOPs where necessary.  It still won't convert null statements into NOPs. --HappyDog 14:19, 7 June 2007 (UTC)
thread_title:  Optimising compilers 

message: The word 'behaviour' was changed to 'output' in this edit with the edit summary Behavior can include things other than output.  However, surely the point of NOP is that it has no effect, whether to behaviour or output, so I am unsure why the change was made.  Perhaps I misunderstand the purpose of the sentence.  Can you explain what you are trying to say with it? --HappyDog 17:06, 27 May 2007 (UTC)
replies: text: A construct considered to be a NOP can exhibit behavior if actual instructions are generated/executed.  Time and power (electrical) will be consumed.  Yes, this behavior will require sensitive equipment to detect, but it is still behavior.  You are right in that it is a rather picky point.  But in many cases the essence of a NOP is that it is often something that happens (in other cases nothing at all happens) that has no consequences at the human level (I use the term program output when perhaps "no external effect noticeable human level" might be technically more accurate, if somewhat long winded). Derek farn 19:33, 27 May 2007 (UTC)
thread_title:  Behaviour/output. 

message: Another use of a null statement in C is for a goto label at the end of a block, e.g.:
 if (a_condition)
 {
     for (;;)
     {
         if (some_condition)
             goto endloop;
         ...
     }
 endloop: ;
 }
I should point out that using the continue statement is a better way to write empty loop bodies in C:
 while (ReadChar() != '\n')
     continue;
Except for a few rare exceptions, the use of null statements is generally considered bad programming style, especially in languages like C where a single ";" character can be easily misplaced or overlooked. A more visible approach is to use an empty block:
 if (condition_1)
 { }    // Do nothing
 else if (condition_2)
     do_something();
 else
     do_something_else();
— Loadmaster 17:11, 30 May 2007 (UTC)
replies: text: Let's not be C specific.  Are there any kinds of NOP 'statements; that appear in other languages and perhaps are not found in C? Derek farn 17:30, 30 May 2007 (UTC)
thread_title:  Null statements and style 

message: Does a comment count as a NOP? --HappyDog 02:36, 31 May 2007 (UTC)
replies: text: A comment is not intended to be an operation.  A NOP is an instruction that looks like it might do something (of course it does, it wastes cpu time and takes up storage).  Derek farn 11:15, 31 May 2007 (UTC)
replies: text:  A C compiler will discard a null statement and a comment in the same way - neither will be converted into executable code.  Both are lines in the source code that do nothing.  I don't quite see the distinction. --HappyDog 12:05, 31 May 2007 (UTC)
replies: text: Perhaps I am being overly keen to create a distinction.  I guess one definition of NOP is something that is not an operation (or a vegetable, or a rock, or a etc...)  The usage I am familiar with is when a construct is normally an operation, but for some reason it is written in such a way that no operation actually takes place.  Now this may just be splitting hairs, but to me a comment is obviously not a NOP.  Perhaps somebody else can describe it better than me (or perhaps people do regard a comment as a NOP and I am just out of touch). Derek farn 15:38, 31 May 2007 (UTC)
replies: text:  I meant that a null statement in C is not something I would consider a NOP - I wasn't trying to imply that a comment was.  My point was that in a compiled language the whole concept of a NOP is somewhat nebulous, and that in C the relationship between a null statement or a comment and the resulting source code is the same - they are both discarded by the compiler.  Therefore defining a NOP in terms of the resulting machine code does not work. --HappyDog 23:37, 31 May 2007 (UTC)

text: Comments are known to execute very fast. ;-) — Loadmaster 23:35, 31 May 2007 (UTC)

text: I don't read the text as defining NOP in terms of the resulting machine code.  I think it reads as being in terms of intent. Derek farn 10:33, 7 June 2007 (UTC)
thread_title:  Comments 

message: I take issue with the statement at the top of the page that says NOP "effectively does nothing at all."
Some processors drop to a lower power state on NOPs (saving power while they have "nothing" to do). The 2nd section also talks about how NOP takes a specific number of clock cycles to execute, which means NOP could be used to synchronize code between multiple cores or CPUs, etc.
Call me a pedant, but these things matter in computer science
Fry-kun (talk) 22:42, 1 September 2010 (UTC)
thread_title:  Not "nothing at all" 

message: Usually NOPs do "nothing". Well, there is some discussion as what actually is something and what's nothing, but well, they usually don't change registers or memory or something like that.
Well, that's what I thought until I had to work on a TI TMS320C28x CPU. NOP has two optional parameters there:
nop *, ARP2 ; set arp pointer to xar2
So that's actually not a no-op. Source: http://www.ti.com/general/docs/lit/getliterature.tsp?baseLiteratureNumber=spru430&track=no
See page 407 for a description of NOP, and 135 for an example using it that way. --212.18.210.70 (talk) 16:40, 15 January 2013 (UTC)
thread_title:  NOPs with side-effect 

message: The Java language has a return; statement, which does nothing.
In the Java I learned, this exits from the function in which it appears, just as it does in C and other derived languages.  As such, I'm removing it. — Smjg (talk) 23:27, 22 September 2014 (UTC)
thread_title:  Java return? 

message: The PAUSE instruction is encoded as "F3 90", so it is like a "REP NOP" but is handled differently on CPUs that supports the special PAUSE command, but I do not know how "different". 
I think the PAUSE command should be mentioned here. What do you think? --RokerHRO (talk) 12:22, 30 April 2015 (UTC)
replies: text: The pause instruction has been encoded as rep nop because that combination—although technically invalid—had the same effect as a nop instruction on previous chips. pause behaves like a nop with a hint to the processor that this is a spin-lock and the processor should divert resources to other threads running on the same core (e.g. with hyperthreading) or slow down and safe energy. I think it might be a good idea to write something about hinting nops in general. --16:58, 30 April 2015 (UTC)
thread_title:  x86 PAUSE instruction 

message: Hello fellow Wikipedians,
I have just modified one external link on NOP. Please take a moment to review my edit. If you have any questions, or need the bot to ignore the links, or the page altogether, please visit this simple FaQ for additional information. I made the following changes:
*Added archive https://web.archive.org/web/20120118213535/http://www.sparc.org/standards/SPARCV9.pdf to http://www.sparc.org/standards/SPARCV9.pdf
When you have finished reviewing my changes, you may follow the instructions on the template below to fix any issues with the URLs.
Cheers.—InternetArchiveBot (Report bug) 23:46, 10 February 2018 (UTC)
thread_title:  External links modified (February 2018)