]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
2012-07-17 Tom de Vries <tom@codesourcery.com>
authorvries <vries@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 17 Jul 2012 12:48:36 +0000 (12:48 +0000)
committervries <vries@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 17 Jul 2012 12:48:36 +0000 (12:48 +0000)
* 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/ChangeLog
gcc/double-int.h
gcc/hwint.c
gcc/hwint.h

index 3744447a3407eff2fa357dd330ae9baaf68c59f3..f9f3f5f148b9321993a01fa7f050884017c29dc9 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2012-07-17  Richard Henderson  <rth@redhat.com>
 
        * tree-vect-stmts.c (supportable_widening_operation): Remove decl
index 50a9bda5d6ac3c7cff367e104d03b17a97ec7e6a..eab9c3c14a642e7dbe8f7e7a36f6ad8b1862ba23 100644 (file)
@@ -284,6 +284,14 @@ double_int_equal_p (double_int cst1, double_int cst2)
   return cst1.low == cst2.low && cst1.high == cst2.high;
 }
 
+/* Return number of set bits of CST.  */
+
+static inline int
+double_int_popcount (double_int cst)
+{
+  return popcount_hwi (cst.high) + popcount_hwi (cst.low);
+}
+
 
 /* Legacy interface with decomposed high/low parts.  */
 
index bfc5e3dedcdd84200ae4b5a29c99b3aecc4ee684..024fb7e36e3690f91849dab6b7775864977e880b 100644 (file)
@@ -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.  */
index 00c9538fb112a2cb0784aef36b48ea34c702d055..ca471486c63dfc7c00facda3c7642f4202597365 100644 (file)
@@ -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);
 
@@ -231,6 +234,18 @@ ffs_hwi (unsigned HOST_WIDE_INT x)
 # endif
 }
 
+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)
 {