diff options
author | Tom de Vries <tom@codesourcery.com> | 2012-07-17 12:48:36 +0000 |
---|---|---|
committer | Tom de Vries <vries@gcc.gnu.org> | 2012-07-17 12:48:36 +0000 |
commit | 440b6d590a8565358b3d603e27af8bd7db3fa27a (patch) | |
tree | 95b0113f480da4289ca38b07f1d29157bae7e038 /gcc | |
parent | a86ec59783d1630f46d758b27faf5c5fe061ecfe (diff) | |
download | gcc-440b6d590a8565358b3d603e27af8bd7db3fa27a.zip gcc-440b6d590a8565358b3d603e27af8bd7db3fa27a.tar.gz gcc-440b6d590a8565358b3d603e27af8bd7db3fa27a.tar.bz2 |
double-int.h (double_int_popcount): New inline function.
2012-07-17 Tom de Vries <tom@codesourcery.com>
* double-int.h (double_int_popcount): New inline function.
* hwint.c (popcount_hwi): New function.
* hwint.h (popcount_hwi): Declare function. New inline function.
From-SVN: r189575
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/double-int.h | 8 | ||||
-rw-r--r-- | gcc/hwint.c | 16 | ||||
-rw-r--r-- | gcc/hwint.h | 15 |
4 files changed, 45 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3744447..f9f3f5f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2012-07-17 Tom de Vries <tom@codesourcery.com> + + * double-int.h (double_int_popcount): New inline function. + * hwint.c (popcount_hwi): New function. + * hwint.h (popcount_hwi): Declare function. New inline function. + 2012-07-17 Richard Henderson <rth@redhat.com> * tree-vect-stmts.c (supportable_widening_operation): Remove decl diff --git a/gcc/double-int.h b/gcc/double-int.h index 50a9bda..eab9c3c 100644 --- a/gcc/double-int.h +++ b/gcc/double-int.h @@ -284,6 +284,14 @@ double_int_equal_p (double_int cst1, double_int cst2) return cst1.low == cst2.low && cst1.high == cst2.high; } +/* Return number of set bits of CST. */ + +static inline int +double_int_popcount (double_int cst) +{ + return popcount_hwi (cst.high) + popcount_hwi (cst.low); +} + /* Legacy interface with decomposed high/low parts. */ diff --git a/gcc/hwint.c b/gcc/hwint.c index bfc5e3d..024fb7e 100644 --- a/gcc/hwint.c +++ b/gcc/hwint.c @@ -107,6 +107,22 @@ ffs_hwi (unsigned HOST_WIDE_INT x) return 1 + floor_log2 (x & -x); } +/* Return the number of set bits in X. */ + +int +popcount_hwi (unsigned HOST_WIDE_INT x) +{ + int i, ret = 0; + + for (i = 0; i < sizeof (x); i += 1) + { + ret += x & 1; + x >>= 1; + } + + return ret; +} + #endif /* GCC_VERSION < 3004 */ /* Compute the absolute value of X. */ diff --git a/gcc/hwint.h b/gcc/hwint.h index 00c9538..ca47148 100644 --- a/gcc/hwint.h +++ b/gcc/hwint.h @@ -179,6 +179,9 @@ extern int clz_hwi (unsigned HOST_WIDE_INT x); extern int ctz_hwi (unsigned HOST_WIDE_INT x); extern int ffs_hwi (unsigned HOST_WIDE_INT x); +/* Return the number of set bits in X. */ +extern int popcount_hwi (unsigned HOST_WIDE_INT x); + /* Return log2, or -1 if not exact. */ extern int exact_log2 (unsigned HOST_WIDE_INT); @@ -232,6 +235,18 @@ ffs_hwi (unsigned HOST_WIDE_INT x) } static inline int +popcount_hwi (unsigned HOST_WIDE_INT x) +{ +# if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG + return __builtin_popcountl (x); +# elif HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG + return __builtin_popcountll (x); +# else + return __builtin_popcount (x); +# endif +} + +static inline int floor_log2 (unsigned HOST_WIDE_INT x) { return HOST_BITS_PER_WIDE_INT - 1 - clz_hwi (x); |