X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fcount-one-bits.h;h=fcbe7fda67b967e96f1045c955c083b2a468cdf4;hb=1a2869593e115e4a6c74aaa0b23ca612357403ce;hp=7553bec4ecbfc850f62901ac1fbcf0b96eb99453;hpb=e9cfd9f2d0d75d5d09d0acff6cb578a5c039c45c;p=gnulib.git diff --git a/lib/count-one-bits.h b/lib/count-one-bits.h index 7553bec4e..fcbe7fda6 100644 --- a/lib/count-one-bits.h +++ b/lib/count-one-bits.h @@ -1,10 +1,10 @@ /* count-one-bits.h -- counts the number of 1-bits in a word. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007-2008 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or modify + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -12,27 +12,30 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + along with this program. If not, see . */ /* Written by Ben Pfaff. */ #ifndef COUNT_ONE_BITS_H # define COUNT_ONE_BITS_H 1 -#include #include #include "verify.h" -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR >= 4) +/* Expand the code which computes the number of 1-bits of the local + variable 'x' of type TYPE (an unsigned integer type) and returns it + from the current function. */ +#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) #define COUNT_ONE_BITS(BUILTIN, TYPE) \ return BUILTIN (x); #else -#define COUNT_ONE_BITS(BUILTIN, TYPE) \ - int count = count_one_bits_32 (x); \ - if (CHAR_BIT * sizeof (TYPE) > 32) \ - count += count_one_bits_32 (x >> 31 >> 1); \ - (void) verify_true (CHAR_BIT * sizeof (TYPE) <= 64); \ +#define COUNT_ONE_BITS(BUILTIN, TYPE) \ + /* This condition is written so as to avoid shifting by more than \ + 31 bits at once, and also avoids a random HP-UX cc bug. */ \ + verify (((TYPE) -1 >> 31 >> 31 >> 2) == 0); /* TYPE has at most 64 bits */ \ + int count = count_one_bits_32 (x); \ + if (1 < (TYPE) -1 >> 31) /* TYPE has more than 32 bits? */ \ + count += count_one_bits_32 (x >> 31 >> 1); \ return count; /* Compute and return the the number of 1-bits set in the least