As we all know and love .NET does throw an IntegerOverflow
exception every time an integer overflows. I think this is a very good thing.
But I wonder how they make this fast. x86 does not trap on integer overflows and I would be surprised if other architectures would allow one to do that. The best solution I have found for x86 is to put an "INTO" instruction after every single arithmetic operation. But I assume that would result in a noticeable slowdown.
They could do some static checking in the compiler to avoid this in cases when it can be proofed that the operation can not overflow. But what about performance critical inner loops when the compiler can't determine the outcome of the operations?
I tried to look at the Mono source but I couldn't find the spot where they do these checks.
So does anyone have a clue what they really do? I really would like to know.
On a side note: Is there a way to see the x86 code the .NET JITC emits?