diff options
author | vries <vries@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-07-17 12:48:36 +0000 |
---|---|---|
committer | vries <vries@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-07-17 12:48:36 +0000 |
commit | 45105ae28dcce494eb1ab6a02f1e1f24b82e2ec7 (patch) | |
tree | 95b0113f480da4289ca38b07f1d29157bae7e038 /gcc/hwint.c | |
parent | 087dde2d35142ee19a522164cf3267ef73fb71c7 (diff) | |
download | gcc-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.c')
-rw-r--r-- | gcc/hwint.c | 16 |
1 files changed, 16 insertions, 0 deletions
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. */ |