From a27d788de5ead5b5623d06f7eaa7fce89c5e64c0 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 16 Mar 2017 01:04:22 -0700 Subject: [PATCH] limits-h: work around HP-UX 11.31 cc bug Problem reported by Bruno Haible in: http://lists.gnu.org/archive/html/bug-gnulib/2017-03/msg00062.html * lib/limits.in.h (_GL_INTEGER_WIDTH) [__HP_cc]: Use a simpler expression that works on all __HP_cc platforms. --- ChangeLog | 8 ++++++++ lib/limits.in.h | 30 +++++++++++++++++++----------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index a4fa592..69d2b7c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2017-03-16 Paul Eggert + + limits-h: work around HP-UX 11.31 cc bug + Problem reported by Bruno Haible in: + http://lists.gnu.org/archive/html/bug-gnulib/2017-03/msg00062.html + * lib/limits.in.h (_GL_INTEGER_WIDTH) [__HP_cc]: + Use a simpler expression that works on all __HP_cc platforms. + 2017-03-14 Bruno Haible gnulib-tool: Don't produce a tests directory with only snippet .h files. diff --git a/lib/limits.in.h b/lib/limits.in.h index 1846704..6b6a028 100644 --- a/lib/limits.in.h +++ b/lib/limits.in.h @@ -41,17 +41,25 @@ /* The number of usable bits in an unsigned or signed integer type with minimum value MIN and maximum value MAX, as an int expression - suitable in #if. Cover all known practical hosts. This - implementation exploits the fact that MAX is 1 less than a power of - 2, and merely counts the number of 1 bits in MAX; "COBn" means - "count the number of 1 bits in the low-order n bits"). */ -#define _GL_INTEGER_WIDTH(min, max) (((min) < 0) + _GL_COB128 (max)) -#define _GL_COB128(n) (_GL_COB64 ((n) >> 31 >> 31 >> 2) + _GL_COB64 (n)) -#define _GL_COB64(n) (_GL_COB32 ((n) >> 31 >> 1) + _GL_COB32 (n)) -#define _GL_COB32(n) (_GL_COB16 ((n) >> 16) + _GL_COB16 (n)) -#define _GL_COB16(n) (_GL_COB8 ((n) >> 8) + _GL_COB8 (n)) -#define _GL_COB8(n) (_GL_COB4 ((n) >> 4) + _GL_COB4 (n)) -#define _GL_COB4(n) (!!((n) & 8) + !!((n) & 4) + !!((n) & 2) + !!((n) & 1)) + suitable in #if. */ +#ifdef __HP_cc +/* Work around a bug in HP-UX 11.31 cc. See: + http://lists.gnu.org/archive/html/bug-gnulib/2017-03/msg00062.html */ +# define _GL_INTEGER_WIDTH(min, max) \ + ((max) >> 31 >> 1 ? 64 : (max) >> 16 ? 32 : (max) >> 8 ? 16 : 8) +#else +/* This implementation covers all known practical, non-buggy hosts. + It exploits the fact that MAX is 1 less than a power of 2, and + merely counts the number of 1 bits in MAX; "COBn" means "count the + number of 1 bits in the low-order n bits". */ +# define _GL_INTEGER_WIDTH(min, max) (((min) < 0) + _GL_COB128 (max)) +# define _GL_COB128(n) (_GL_COB64 ((n) >> 31 >> 31 >> 2) + _GL_COB64 (n)) +# define _GL_COB64(n) (_GL_COB32 ((n) >> 31 >> 1) + _GL_COB32 (n)) +# define _GL_COB32(n) (_GL_COB16 ((n) >> 16) + _GL_COB16 (n)) +# define _GL_COB16(n) (_GL_COB8 ((n) >> 8) + _GL_COB8 (n)) +# define _GL_COB8(n) (_GL_COB4 ((n) >> 4) + _GL_COB4 (n)) +# define _GL_COB4(n) (!!((n) & 8) + !!((n) & 4) + !!((n) & 2) + !!((n) & 1)) +#endif /* Macros specified by ISO/IEC TS 18661-1:2014. */ -- 2.7.4