Inside .NET - The mystery of conv.ovf..un…

I'm sure you've all read the ECMA-335 document; but for those of you who don't know, this is the document that specifies all the gory details of how .NET works.

When you got to Partition III, page 62 in your bedtime reading I expect you read it, thought nothing very much of it, but then went Hmmm? That's a little odd. Why is it needed exactly?

download atonement movie in dvd quality

Because it's a little strange, and I just can't figure out why it's really needed.

Of course, this could be because I'm being a bit slow. If so, please just leave a comment explaining what it's about to put me out of my confusion - I'm not losing sleep over it, but it's close...

hi-def quality the last exorcism download

The problem is all about conversion instructions. When you write something like this:

int i = ...
byte b = (byte)i;
where to watch the whole my neighbour totoro film

Then the CIL instruction generated for line 2 will be conv.u1, which tells the CIL runtime to convert whatever is at the top of the stack into a u1, which is the same as the C# byte type.

Simple.

neowolf aka the band from hell film download

Now, if you had this C#:

checked {
  int i = ...
  byte b = (byte)i;
}

Then the CIL instruction generated for line 3 will be conv.ovf.u1, which tells the CIL runtime to do the same conversion as last time, but do an overflow check as well, so if i doesn't fit in to a byte

then an OverflowException will be thrown.

watch the shooter film
the hangover ipod

Still simple.

And, futhermore, if you have this in C#:

pre buy the little rascals movie

watch roman holiday the film full version
checked {
  uint i = ...
  byte b = (byte)i;
}

Then the CIL for line 3 will be conv.ovf.u1.un, which tells the CIL runtime to do the another checked conversion, but this time it is told that the source type is unsigned (the .un part of the CIL instruction).

Which still looks well, good, obvious and still simple.

the tailor of panama the film high quality

But the thing is - it just isn't needed.

As part of the JIT, the runtime has to do a full stack analysis, and as part of that stack analysis the runtime will already know exactly what type is in the source stack entry. Therefore it can figure out whether it's a signed or unsigned int without any help from the CIL instruction.

And because there is a very small range of types that are allowed to be used as the operand to these conversion instructions, and the range of supported instructions is fixed (i.e. no extensibility is allowed), I cannot think of any situation where theses conv.ovf.<to type>.un instructions would actually be needed. The runtime could always just use the conv.ovf.<to type>

instruction and figure out if it's signed

or unsigned from the stack analysis.

One Response to “Inside .NET - The mystery of conv.ovf..un…”

  1. Achille says:

    Hi, your project looks nice.

    Regarding your question, note that the only integer types the CLI operates on are int32, int64, native int (III.1.1). I guess this helps reduce the number of possibilities in the subsequent tables (1.5).