Re:How undefined signed overflow enables optimizations in GCC
by gpvos on Sunday February 21, 2016 @10:56PM
(#11148341)
These look very unknown to me. How portable are these? If only GCC has these, I am not going to use them at all.
Re:How undefined signed overflow enables optimizations in GCC
by frankzinger on Monday February 22, 2016 @12:49AM
(#11148794)
Clang also has them: http://clang.llvm.org/docs/LanguageExtensions.html#builtin-f..., under the heading "Checked Arithmetic Builtins".
Re:How undefined signed overflow enables optimizations in GCC
by cnvogel on Monday February 22, 2016 @06:08AM
(#11150002)
You could implement them as static/inline functions for compilers that lack the builtins (using a bunch of comparisons with SHORT_/INT_MAX, ...) , which would be slower but for things explicitly meant as security check, probably worth the cost.
I've used them to replace explicit checks for overflow in some DSP related code which tried to implement saturation. The gcc builtins also were much faster than tedious "manual" checks.
https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins...