]> Savannah Git Hosting - gnulib.git/commitdiff
intprops: refactor _GL_HAS_BUILTIN_OVERFLOW_P
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 10 Aug 2022 06:20:49 +0000 (23:20 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 10 Aug 2022 07:22:08 +0000 (00:22 -0700)
* lib/intprops.h (_GL_HAS_BUILTIN_OVERFLOW_P)
[_GL_HAS_BUILTIN_OVERFLOW_P]: Use __builtin_sub_overflow_p
directly rather than indirectly via INT_SUBTRACT_OVERFLOW.
This simplifies future changes, and doesn’t change the generated code.

ChangeLog
lib/intprops.h

index dcf5ae826622b2700e71dec1ef4192e17de41e12..18e0f7f4f43da82586844fb268d2736648e6db60 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2022-08-09  Paul Eggert  <eggert@cs.ucla.edu>
 
+       intprops: refactor _GL_HAS_BUILTIN_OVERFLOW_P
+       * lib/intprops.h (_GL_HAS_BUILTIN_OVERFLOW_P)
+       [_GL_HAS_BUILTIN_OVERFLOW_P]: Use __builtin_sub_overflow_p
+       directly rather than indirectly via INT_SUBTRACT_OVERFLOW.
+       This simplifies future changes, and doesn’t change the generated code.
+
        verify: port ‘assume’ to C23 non-GCC
        * lib/verify.h (assume): Use C23's unreachable if available
        and if GCC and/or MSC primitives are not available.
index d4a917f72a0689d528f3df586d0710c0e602fc58..40c60fc4a8d1f502ce541d07406070fd948c7993 100644 (file)
 /* Range overflow checks.
 
    The INT_<op>_RANGE_OVERFLOW macros return 1 if the corresponding C
-   operators might not yield numerically correct answers due to
-   arithmetic overflow.  They do not rely on undefined or
-   implementation-defined behavior.  Their implementations are simple
-   and straightforward, but they are harder to use and may be less
-   efficient than the INT_<op>_WRAPV, INT_<op>_OK, and
-   INT_<op>_OVERFLOW macros described below.
+   operators overflow arithmetically when given the same arguments.
+   These macros do not rely on undefined or implementation-defined behavior.
+   Although their implementations are simple and straightforward,
+   they are harder to use and may be less efficient than the
+   INT_<op>_WRAPV, INT_<op>_OK, and INT_<op>_OVERFLOW macros described below.
 
    Example usage:
 
 #define INT_SUBTRACT_OVERFLOW(a, b) \
   _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW)
 #if _GL_HAS_BUILTIN_OVERFLOW_P
-# define INT_NEGATE_OVERFLOW(a) INT_SUBTRACT_OVERFLOW (0, a)
+# define INT_NEGATE_OVERFLOW(a) \
+   __builtin_sub_overflow_p (0, a, (__typeof__ (- (a))) 0)
 #else
 # define INT_NEGATE_OVERFLOW(a) \
    INT_NEGATE_RANGE_OVERFLOW (a, _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))