Hi.
Not too long I had to use Reflection.Emit to dynamically generate some
classes that were only to be dynamically generated based on runtime
conditions.
Before emitting the op codes, I created a class and compiled it, then
reviewed the op codes using Reflector.
Well, I noticed the compiler created, in some cases, a sequence of NOP
instructions. Why? Is there a reason that the compiler felt it necessary
to emit these? Are there timing sequences that requires NOP to exist?
Homer J Simpson - 05 Mar 2006 06:58 GMT
> Hi.
>
[quoted text clipped - 8 lines]
> instructions. Why? Is there a reason that the compiler felt it necessary
> to emit these? Are there timing sequences that requires NOP to exist?
It's not unknown for compilers. Sometimes after optimisation the compiler
replaces unneeded codes with NOPs - perhaps a jump only needs 3 bytes
instead of 4. It's easier to replace the opcode than to reassemble the whole
thing.
As for timing, it's possible but unlikely. That's the sort of thing you do
in hand assembly only.
Christoph Nahr - 05 Mar 2006 07:38 GMT
>Well, I noticed the compiler created, in some cases, a sequence of NOP
>instructions. Why? Is there a reason that the compiler felt it necessary
>to emit these? Are there timing sequences that requires NOP to exist?
Timing doesn't figure into IL code. The NOPs are there to facilitate
debugging -- they allow setting breakpoints on "non-statements" such
as the entry of a loop, and adding code during edit & continue. They
won't appear when you turn on optimization.

Signature
http://www.kynosarges.de