From 45105ae28dcce494eb1ab6a02f1e1f24b82e2ec7 Mon Sep 17 00:00:00 2001 From: vries Date: Tue, 17 Jul 2012 12:48:36 +0000 Subject: 2012-07-17 Tom de Vries * 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 --- gcc/hwint.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'gcc/hwint.c') diff --git a/gcc/hwint.c b/gcc/hwint.c index bfc5e3dedcd..024fb7e36e3 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. */ -- cgit v1.2.1