Bruno Haible wrote:
I would suggest to simplify _GL_INTEGER_WIDTH by assuming that its value MUST be one of 8, 16, 32, 64, 128.
We could do that as a special case if __HP_cc is defined, as we know that particular compiler doesn't work with other-width integers. Does the attached (untested) patch work for you?
I'd rather keep the generic code with non-buggy compilers. You're right that much of Gnulib fails to work on unusual machines, but when it's easy to support the weird ones I'd rather do so, partly because compilers do exist for machines with non-powers-of-two widths, partly because it's more fun to be portable.
From a27d788de5ead5b5623d06f7eaa7fce89c5e64c0 Mon Sep 17 00:00:00 2001 From: Paul Eggert <egg...@cs.ucla.edu> 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 <egg...@cs.ucla.edu> + + 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 <br...@clisp.org> 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