summaryrefslogtreecommitdiff
path: root/gcc/hwint.h
diff options
context:
space:
mode:
authorvries <vries@138bc75d-0d04-0410-961f-82ee72b054a4>2012-07-17 12:48:36 +0000
committervries <vries@138bc75d-0d04-0410-961f-82ee72b054a4>2012-07-17 12:48:36 +0000
commit45105ae28dcce494eb1ab6a02f1e1f24b82e2ec7 (patch)
tree95b0113f480da4289ca38b07f1d29157bae7e038 /gcc/hwint.h
parent087dde2d35142ee19a522164cf3267ef73fb71c7 (diff)
downloadgcc-45105ae28dcce494eb1ab6a02f1e1f24b82e2ec7.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@189575 138bc75d-0d04-0410-961f-82ee72b054a4
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 00c9538fb11..ca471486c63 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);