aboutsummaryrefslogtreecommitdiff
path: root/gcc/hwint.c
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.c
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.c')
-rw-r--r--gcc/hwint.c16
1 files changed, 16 insertions, 0 deletions
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. */