summaryrefslogtreecommitdiff
path: root/src/utils.h
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2016-02-27 22:29:57 +0200
committerRan Benita <ran234@gmail.com>2016-10-22 20:13:46 +0300
commit90611719572fbac04ddf3329f5683feb3b71e681 (patch)
treee08b852a53feaa704b2b1ba0068e495551837aba /src/utils.h
parent914c060a1dacb5b42b4bb9ded036c5c6951d842a (diff)
downloadxorg-lib-libxkbcommon-90611719572fbac04ddf3329f5683feb3b71e681.tar.gz
utils: add popcount function
Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/utils.h')
-rw-r--r--src/utils.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/utils.h b/src/utils.h
index 4b7e81c..11ef735 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -178,6 +178,19 @@ msb_pos(uint32_t mask)
return pos;
}
+static inline int
+popcount(uint32_t x)
+{
+ int count;
+#if defined(HAVE___BUILTIN_POPCOUNT)
+ count = __builtin_popcount(x);
+#else
+ for (count = 0; x; count++)
+ x &= x - 1;
+#endif
+ return count;
+}
+
bool
map_file(FILE *file, char **string_out, size_t *size_out);