News for hackers. Stuff that matters.
Re:Fast integer overflow detection (2012) by acqq on Sunday December 14, 2014 @08:45PM (#8750333)
It's not the feature that anybody would use as is, when you'd use it you'd prefer to call the function. But then what's behind the function is irrelevant for the users of the function. We don't force compiler authors to put in the compiler what can be nicely put in the libraries.

It's: write one header with a few #if's once, everybody use it, whenever she needs it.

You'd just call

    is_safe_to_add_ints( s, t[i] ) 
and be sure that on the common platform it's optimal thanks to the #if's in the header, and not write

    bool bsafe = (t[i] < 0) ? s >= INT_MIN - t[i] : s <= INT_MAX - t[i];
every time you'd want to check if the addition would be safe.
Re:Fast integer overflow detection (2012) by Someone on Monday December 15, 2014 @03:23AM (#8751094)
But you want

   if( !canSafelyAdd(a,b)) return ERROR;
   c = a + b;
To compile down to an add and a check of the overflow bit. For that, you need help from the compiler.

There are many examples where compilers special-case what is in a library. For example, compilers know they do not have to call strlen every time through this loop:

    for(int i = 0; i < strlen(s); ++i)
Re:Fast integer overflow detection (2012) by acqq on Monday December 15, 2014 @04:05AM (#8751185)
The enough help you need is, in the implementation of the library function #if X86 #if GCC etc and then the assembly for each case, otherwise the slow but standard implementation. And that's one file, the code never to be directly used but by function name. It's already done this way in the current libraries for a lot processor specific stuff.