4 ms·
Interesting post, as Regehr's posts tend to be. Presumably .Net goes to great lengths to optimise overflow-checking, as the checks are enabled for production u
by MaxBarraclough 6y ago
Interesting post, as Regehr's posts tend to be.
Presumably .Net goes to great lengths to optimise overflow-checking, as the checks are enabled for production use. I wonder if they manage to get the overhead to below the 8.7% mentioned in the article.
edit: I had put OpenJDK and .Net but tom_mellior is right to point out that Java has wrapping arithmetic
- tom_mellior 6y agoWhy would OpenJDK do integer overflow checking? Java integers have well-defined two's complement wrapping semantics. When you add two positive numbers and get a negative result, this might not be what the programmer wanted, but it is not undefined behavior like it is in C. Are you maybe mixing this up with array bounds checking?
- MaxBarraclough 6y agoOops, you're right! I forgot Java arithmetic wraps, offering (rarely used) methods for overflow-checked arithmetic. [0] I was right about .Net though. Assuming a checked context, .Net (and C#) throw on overflow, rather than wrapping. [1] [0] https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Math.html#addExact(int,int) https://docs.oracle.com/en/java/javase/11/docs/api/java.base... [1] https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/checked-and-unchecked https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...
- chrisseaton 6y agoOpenJDK only does overflow checking in a tiny number of cases.
- MaxBarraclough 6y agoCunningham's Law strikes again! You're right of course. Please see my response to tom_mellior.