aboutsummaryrefslogtreecommitdiff
path: root/gcc/hwint.h
diff options
context:
space:
mode:
authorTom de Vries <tom@codesourcery.com>2012-07-17 12:48:36 +0000
committerTom de Vries <vries@gcc.gnu.org>2012-07-17 12:48:36 +0000
commit440b6d590a8565358b3d603e27af8bd7db3fa27a (patch)
tree95b0113f480da4289ca38b07f1d29157bae7e038 /gcc/hwint.h
parenta86ec59783d1630f46d758b27faf5c5fe061ecfe (diff)
downloadgcc-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/hwint.h')
-rw-r--r--gcc/hwint.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/gcc/hwint.h b/gcc/hwint.h
index 00c9538..ca471486 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);