Questions tagged [no-op]

No-op (also spelled as "noop" and "nop") is an abbreviation for "no-operation". It is code that does nothing and has no effect. It is used for filling space (adding padding) and/or wasting time. "nop" is a common instruction in assembly language.

The great art of doing nothing

What is it, and how did it come to be?

No-OPeration (nop, no-op) is the proper instruction to instruct a processor to do nothing (but waste time).
Just about every has at least some s which have no effect at all. They naturally occur because it pays to build a regular IS, which leads to curiosities like exchange A for A, assign A to A, bitwise-and/or A and A.

While some of those may be redefined for better instruction density, one will be chosen as intended nop.

Purpose/Uses

There are a great many uses for doing nothing. Some examples:

  • Reserving space for adding patches

    Some Windows system binariesreserve space to allow live-patching.

  • Neutralizing code

    An example is an implementation of a seldom changed flag in high-performance-code: Either there's an unconditional jump to additional code, or there's a single, efficient nop

  • Aligning code for better caching

    If a function begins at the start of a cache-line (or even memory-page), there will often be fewer cache-misses

  • Wasting time

    Counting instructions and busy-Loops for delaying are getting less common in high-end systems, though they are still alive and well on slower machines.

  • (Attacking) Making a bigger target for a (semi-)blind jump by building a nop-slide.

References

115 questions
4
votes
1 answer

Is a typedef to self allowed over template parameters

I was reading someone else's code when I came across this piece (stripped to MWE): template class Test { public: typedef R R; }; Here there is a typedef of the template parameter to itself, and it made GCC and clang (with or…
M. Zhang
  • 750
  • 8
  • 18
4
votes
1 answer

Multiple nop instructions do not consistently take longer than a single nop instruction

I am timing multiple NOP instructions and a single NOP instruction in C++, using rdtsc. However, I don't get an increase in the number of cycles it takes to execute NOPs in proportion to the number of NOPs executed. I'm confused as to why this is…
fraiser
  • 929
  • 12
  • 28
4
votes
4 answers

GCC inline asm NOP loop not being unrolled at compile time

Venturing out of my usual VC++ realm into the world of GCC (via MINGW32). Trying to create a Windows PE that consists largely of NOPs, ala: for(i = 0; i < 1000; i++) { asm("nop"); } But either I'm using the wrong syntax or the compiler is…
Rushyo
  • 7,495
  • 4
  • 35
  • 42
4
votes
2 answers

javascript - what is the purpose of declaring a variable a function first? (declaring variable twice)

Here is the code I have encountered: var c = function() {}, c = { autoSelectFirst: !1, appendTo: "body", serviceUrl: null, lookup: null, .. etc.. lookupFilter:…
Oliver Williams
  • 5,966
  • 7
  • 36
  • 78
4
votes
2 answers

How to handle zero jobs in sendRequestXML in quickbooks web connector

I have a scenario where there are a set of tasks and i am using quickbooks web connector for executing them. The user may want to run all tasks or some of them depending on need. Tasks which are for querying data always send static XML and parse…
Raghav
  • 552
  • 1
  • 9
  • 34
4
votes
1 answer

ftplib python: NOOP command works in ASCII not Binary

I have a threaded FTP script. While the data socket is receiving the data, a threaded loop sends NOOP commands to the control socket to keep control connection alive during large transfers. I am prevented from using the FTP.retrbinary() command as,…
hammus
  • 2,602
  • 2
  • 19
  • 37
4
votes
4 answers

How to explicitly comment empty methods?

public void destroy() { } I have written above empty method in my filter class which is required as per the interface. But when my code goes to PMD check it mentions Uncommented Empty Method finds instances where a method does not contain…
Madhu Sudhan Reddy
  • 607
  • 5
  • 15
  • 22
4
votes
8 answers

What are a good No OP operation for vb.net?

Something we can just put break point on while making sure it doesn't do anything else. In c, that would be while(false); What to do in vb.net?
user4951
  • 32,206
  • 53
  • 172
  • 282
3
votes
1 answer

How are the bytecodes for MIPS nop and sll differentiated?

As far as I'm aware both instructions have opcode and function code of 0, so how does the computer know which one it's doing?
3
votes
1 answer

What is NoOp in TensorFlow when Profiling?

I'm profiling ops on a GPU. What is going on behind the long NoOp? It seems like NoOp might represent the time between transferring data from GPU to CPU, since the final operation, TopKV2, executes on the CPU (does not have a GPU kernel) in TF…
user2827214
  • 1,191
  • 1
  • 13
  • 32
3
votes
1 answer

Meaning of weird side-effectless statement inside if

I was browsing through a project and came across this: if(!StaticAnimatedEntities) int esko = esko = 2; (The type of StaticAnimatedEntities here is a plain unsigned short.) It struck me as very odd so I grepped the project for esko and found…
Emil Laine
  • 41,598
  • 9
  • 101
  • 157
3
votes
2 answers

Should a "no op" function be implemented in Lua or in C?

I have the following function that simply returns its string argument: function N_(s) return s end You may recognize this function name from gettext. It's a marking for the benefit of the .pot extractor only. Would it be more efficient to…
Niccolo M.
  • 3,363
  • 2
  • 22
  • 39
3
votes
2 answers

Why invoke ThreadStart with empty Delegate?

While doing some forensics archeological survey in an old apps I have to maintain I came across this : It is a WPF application that was recently converted to .NET 4.0 and this code runs inside a background worker if(bgWorker1.IsBusy ||…
Newtopian
  • 7,543
  • 4
  • 48
  • 71
2
votes
0 answers

Why do I find some never called instructions nopl, nopw after ret or jmp in GCC compiled code?

When I compile code with gcc - (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 - I find in the compiled code some unused code lines at the end of some/all functions or after some absolute jmp. It seems the result is to align the code, but: Why don't use…
Sir Jo Black
  • 2,024
  • 2
  • 15
  • 22
2
votes
1 answer

Is new(&*p) double; a no-op. Does therefore uninitialized_default_construct becomes no-op as well?

The STL documentation says that the (1) uninitialized_default_construct calls ::new (static_cast(std::addressof(*p))) Value;. The only difference with (2) uninitialized_value_construct is that the later calls, ::new…
alfC
  • 14,261
  • 4
  • 67
  • 118