]> git.sesse.net Git - vlc/commitdiff
Add parity() helper
authorRémi Denis-Courmont <remi@remlab.net>
Sun, 18 Mar 2012 09:36:55 +0000 (11:36 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Sun, 18 Mar 2012 09:36:55 +0000 (11:36 +0200)
include/vlc_common.h

index 5cb0adf12b62e9ea59942a19d0cde5c697f769c2..92c36c4b5a158e555afdc993915aef73b6c0b22c 100644 (file)
@@ -616,6 +616,18 @@ static inline unsigned popcount (unsigned x)
 #endif
 }
 
+VLC_USED
+static inline unsigned parity (unsigned x)
+{
+#if VLC_GCC_VERSION(3,4)
+    return __builtin_parity (x);
+#else
+    for (unsigned i = 4 * sizeof (x); i > 0; i /= 2)
+        x ^= x >> i;
+    return x & 1;
+#endif
+}
+
 #ifdef __OS2__
 #   undef bswap16
 #   undef bswap32