[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[7728] gnulib update
From: |
gavinsmith0123 |
Subject: |
[7728] gnulib update |
Date: |
Sat, 15 Apr 2017 04:08:47 -0400 (EDT) |
Revision: 7728
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7728
Author: gavin
Date: 2017-04-15 04:08:47 -0400 (Sat, 15 Apr 2017)
Log Message:
-----------
gnulib update
Modified Paths:
--------------
trunk/gnulib/lib/intprops.h
Modified: trunk/gnulib/lib/intprops.h
===================================================================
--- trunk/gnulib/lib/intprops.h 2017-04-14 17:53:38 UTC (rev 7727)
+++ trunk/gnulib/lib/intprops.h 2017-04-15 08:08:47 UTC (rev 7728)
@@ -389,10 +389,10 @@
(_Generic \
(*(r), \
signed char: \
- _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned char, \
+ _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
signed char, SCHAR_MIN, SCHAR_MAX), \
short int: \
- _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned short int, \
+ _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
short int, SHRT_MIN, SHRT_MAX), \
int: \
_GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
@@ -406,10 +406,10 @@
#else
# define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) \
(sizeof *(r) == sizeof (signed char) \
- ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned char, \
+ ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
signed char, SCHAR_MIN, SCHAR_MAX) \
: sizeof *(r) == sizeof (short int) \
- ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned short int, \
+ ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
short int, SHRT_MIN, SHRT_MAX) \
: sizeof *(r) == sizeof (int) \
? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
@@ -431,9 +431,8 @@
/* Store the low-order bits of A <op> B into *R, where the operation
is given by OP. Use the unsigned type UT for calculation to avoid
- overflow problems. *R's type is T, with extremal values TMIN and
- TMAX. T must be a signed integer type. Return 1 if the result
- overflows. */
+ overflow problems. *R's type is T, with extrema TMIN and TMAX.
+ T must be a signed integer type. Return 1 if the result overflows. */
#define _GL_INT_OP_CALC(a, b, r, op, overflow, ut, t, tmin, tmax) \
(sizeof ((a) op (b)) < sizeof (t) \
? _GL_INT_OP_CALC1 ((t) (a), (t) (b), r, op, overflow, ut, t, tmin, tmax) \
@@ -442,17 +441,34 @@
((overflow (a, b) \
|| (EXPR_SIGNED ((a) op (b)) && ((a) op (b)) < (tmin)) \
|| (tmax) < ((a) op (b))) \
- ? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t, tmin, tmax), 1) \
- : (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t, tmin, tmax), 0))
+ ? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 1) \
+ : (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 0))
-/* Return A <op> B, where the operation is given by OP. Use the
- unsigned type UT for calculation to avoid overflow problems.
- Convert the result to type T without overflow by subtracting TMIN
- from large values before converting, and adding it afterwards.
- Compilers can optimize all the operations except OP. */
-#define _GL_INT_OP_WRAPV_VIA_UNSIGNED(a, b, op, ut, t, tmin, tmax) \
- (((ut) (a) op (ut) (b)) <= (tmax) \
- ? (t) ((ut) (a) op (ut) (b)) \
- : ((t) (((ut) (a) op (ut) (b)) - (tmin)) + (tmin)))
+/* Return A <op> B, where the operation is given by OP. Return the
+ low-order bits of the mathematically-correct answer. Use the
+ unsigned type UT for calculation to avoid undefined behavior on
+ signed integer overflow. Assume that conversion to the result type
+ T yields the low-order bits in the usual way. UT is at least as
+ wide as T and is no narrower than unsigned int, T is two's
+ complement, and there is no padding or trap representations.
+ According to the C standard, converting UT to T yields an
+ implementation-defined result or signal for values outside T's range.
+ So, the standard way to convert UT to T is to subtract TMIN from
+ greater-than-TMAX values before converting them to T, and to add
+ TMIN afterwards, where TMIN and TMAX are T's extrema.
+ However, in practice there is no need to subtract and add TMIN.
+ E.g., GCC converts to signed integers in the usual way; see:
+ https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html
+ All other known C compilers are similar to GCC in this respect.
+ Furthermore, Oracle Studio 12.3 x86 has a bug when implementing the
+ standard way; see:
+ http://lists.gnu.org/archive/html/bug-gnulib/2017-04/msg00049.html
+
+ So, implement this operation in the usual way rather than in
+ the standard way. */
+
+#define _GL_INT_OP_WRAPV_VIA_UNSIGNED(a, b, op, ut, t) \
+ ((t) ((ut) (a) op (ut) (b)))
+
#endif /* _GL_INTPROPS_H */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [7728] gnulib update,
gavinsmith0123 <=