[vlc-commits] [Git][videolan/vlc][master] 4 commits: stdbit: fix stdc_first_leading_*()

Rémi Denis-Courmont (@Courmisch) gitlab at videolan.org
Thu Jan 18 20:52:50 UTC 2024



Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC


Commits:
585c4f85 by Rémi Denis-Courmont at 2024-01-18T20:34:12+00:00
stdbit: fix stdc_first_leading_*()

- - - - -
1931ecd6 by Rémi Denis-Courmont at 2024-01-18T20:34:12+00:00
stdbit: factor stdc_first_trailing_zero*()

No functional changes.

- - - - -
623ee542 by Rémi Denis-Courmont at 2024-01-18T20:34:12+00:00
stdbit: factor stdc_count_zeros*()

No functional changes.

- - - - -
7a970a33 by Rémi Denis-Courmont at 2024-01-18T20:34:12+00:00
stdbit: fix std_bit_width*()

- - - - -


1 changed file:

- compat/stdbit/stdbit.h


Changes:

=====================================
compat/stdbit/stdbit.h
=====================================
@@ -243,116 +243,61 @@ static inline unsigned int stdc_trailing_ones_uc(unsigned char value)
 #define stdc_trailing_ones(value) \
         __stdbit_generic_type_func(trailing_ones, value)
 
-static inline unsigned int stdc_first_leading_zero_ull(unsigned long long value)
-{
-    return (CHAR_BIT * sizeof (value)) - stdc_leading_zeros_ull(value);
-}
-
-static inline unsigned int stdc_first_leading_zero_ul(unsigned long value)
-{
-    return (CHAR_BIT * sizeof (value)) - stdc_leading_zeros_ul(value);
-}
-
-static inline unsigned int stdc_first_leading_zero_ui(unsigned int value)
-{
-    return (CHAR_BIT * sizeof (value)) - stdc_leading_zeros_ui(value);
-}
-
-static inline unsigned int stdc_first_leading_zero_us(unsigned short value)
-{
-    return (CHAR_BIT * sizeof (value)) - stdc_leading_zeros_us(value);
-}
-
-static inline unsigned int stdc_first_leading_zero_uc(unsigned char value)
-{
-    return (CHAR_BIT * sizeof (value)) - stdc_leading_zeros_uc(value);
-}
-
-#define stdc_first_leading_zero(value) \
-        __stdbit_generic_type_func(first_leading_zero, value)
-
 static inline unsigned int stdc_first_leading_one_ull(unsigned long long value)
 {
-    return stdc_first_leading_zero_ull(~value);
+    return value ? (stdc_leading_zeros_ull(value) + 1) : 0;
 }
 
 static inline unsigned int stdc_first_leading_one_ul(unsigned long value)
 {
-    return stdc_first_leading_zero_ul(~value);
+    return value ? (stdc_leading_zeros_ul(value) + 1) : 0;
 }
 
 static inline unsigned int stdc_first_leading_one_ui(unsigned int value)
 {
-    return stdc_first_leading_zero_ui(~value);
+    return value ? (stdc_leading_zeros_ui(value) + 1) : 0;
 }
 
 static inline unsigned int stdc_first_leading_one_us(unsigned short value)
 {
-    return stdc_first_leading_zero_us(~value);
+    return value ? (stdc_leading_zeros_us(value) + 1) : 0;
 }
 
 static inline unsigned int stdc_first_leading_one_uc(unsigned char value)
 {
-    return stdc_first_leading_zero_uc(~value);
+    return value ? (stdc_leading_zeros_uc(value) + 1) : 0;
 }
 
 #define stdc_first_leading_one(value) \
         __stdbit_generic_type_func(first_leading_one, value)
 
-#if defined (__GNUC__) || defined (__clang__)
-static inline unsigned int stdc_first_trailing_zero_ull(unsigned long long value)
-{
-    return __builtin_ffsll(~value);
-}
-
-static inline unsigned int stdc_first_trailing_zero_ul(unsigned long value)
-{
-    return __builtin_ffsl(~value);
-}
-
-static inline unsigned int stdc_first_trailing_zero_ui(unsigned int value)
-{
-    return __builtin_ffs(~value);
-}
-
-static inline unsigned int stdc_first_trailing_zero_us(unsigned short value)
-{
-    return __builtin_ffs((unsigned short)~value);
-}
-
-static inline unsigned int stdc_first_trailing_zero_uc(unsigned char value)
-{
-    return __builtin_ffs((unsigned char)~value);
-}
-#else
-static inline unsigned int stdc_first_trailing_zero_ull(unsigned long long value)
+static inline unsigned int stdc_first_leading_zero_ull(unsigned long long value)
 {
-    return (~value) ? (1 + stdc_trailing_ones_ull(value)) : 0;
+    return stdc_leading_ones_ull(~value);
 }
 
-static inline unsigned int stdc_first_trailing_zero_ul(unsigned long value)
+static inline unsigned int stdc_first_leading_zero_ul(unsigned long value)
 {
-    return (~value) ? (1 + stdc_trailing_ones_ul(value)) : 0;
+    return stdc_leading_ones_ul(~value);
 }
 
-static inline unsigned int stdc_first_trailing_zero_ui(unsigned int value)
+static inline unsigned int stdc_first_leading_zero_ui(unsigned int value)
 {
-    return (~value) ? (1 + stdc_trailing_ones_ui(value)) : 0;
+    return stdc_leading_ones_ui(~value);
 }
 
-static inline unsigned int stdc_first_trailing_zero_us(unsigned short value)
+static inline unsigned int stdc_first_leading_zero_us(unsigned short value)
 {
-    return ((unsigned short)~value) ? (1 + stdc_trailing_ones_us(value)) : 0;
+    return stdc_leading_ones_us(~value);
 }
 
-static inline unsigned int stdc_first_trailing_zero_uc(unsigned char value)
+static inline unsigned int stdc_first_leading_zero_uc(unsigned char value)
 {
-    return ((unsigned char)~value) ? (1 + stdc_trailing_ones_uc(value)) : 0;
+    return stdc_leading_ones_uc(~value);
 }
-#endif
 
-#define stdc_first_trailing_zero(value) \
-        __stdbit_generic_type_func(first_trailing_zero, value)
+#define stdc_first_leading_zero(value) \
+        __stdbit_generic_type_func(first_leading_zero, value)
 
 #if defined (__GNUC__) || defined (__clang__)
 static inline unsigned int stdc_first_trailing_one_ull(unsigned long long value)
@@ -409,79 +354,33 @@ static inline unsigned int stdc_first_trailing_one_uc(unsigned char value)
 #define stdc_first_trailing_one(value) \
         __stdbit_generic_type_func(first_trailing_one, value)
 
-#if defined (__GNUC__) || defined (__clang__)
-static inline unsigned int stdc_count_zeros_ull(unsigned long long value)
-{
-    return __builtin_popcountll(~value);
-}
-
-static inline unsigned int stdc_count_zeros_ul(unsigned long value)
-{
-    return __builtin_popcountl(~value);
-}
-
-static inline unsigned int stdc_count_zeros_ui(unsigned int value)
-{
-    return __builtin_popcount(~value);
-}
-
-static inline unsigned int stdc_count_zeros_us(unsigned short value)
-{
-    return __builtin_popcount((unsigned short)~value);
-}
-
-static inline unsigned int stdc_count_zeros_uc(unsigned char value)
-{
-    return __builtin_popcount((unsigned char)~value);
-}
-#else
-static inline unsigned int __stdc_count_ones(unsigned long long value,
-                                             unsigned int size)
-{
-    unsigned int ones = 0;
-
-    for (unsigned int c = 0; c < (size * CHAR_BIT); c++) {
-         ones += value & 1;
-         value >>= 1;
-    }
-
-    return ones;
-}
-
-static inline unsigned int __stdc_count_zeros(unsigned long long value,
-                                              unsigned int size)
-{
-    return __stdc_count_ones(~value, size);
-}
-
-static inline unsigned int stdc_count_zeros_ull(unsigned long long value)
+static inline unsigned int stdc_first_trailing_zero_ull(unsigned long long value)
 {
-    return __stdc_count_zeros(value, sizeof (value));
+    return stdc_first_trailing_one_ull(~value);
 }
 
-static inline unsigned int stdc_count_zeros_ul(unsigned long value)
+static inline unsigned int stdc_first_trailing_zero_ul(unsigned long value)
 {
-    return __stdc_count_zeros(value, sizeof (value));
+    return stdc_first_trailing_one_ul(~value);
 }
 
-static inline unsigned int stdc_count_zeros_ui(unsigned int value)
+static inline unsigned int stdc_first_trailing_zero_ui(unsigned int value)
 {
-    return __stdc_count_zeros(value, sizeof (value));
+    return stdc_first_trailing_one_ui(~value);
 }
 
-static inline unsigned int stdc_count_zeros_us(unsigned short value)
+static inline unsigned int stdc_first_trailing_zero_us(unsigned short value)
 {
-    return __stdc_count_zeros(value, sizeof (value));
+    return stdc_first_trailing_one_us(~value);
 }
 
-static inline unsigned int stdc_count_zeros_uc(unsigned char value)
+static inline unsigned int stdc_first_trailing_zero_uc(unsigned char value)
 {
-    return __stdc_count_zeros(value, sizeof (value));
+    return stdc_first_trailing_one_uc(~value);
 }
-#endif
 
-#define stdc_count_zeros(value) \
-        __stdbit_generic_type_func(count_zeros, value)
+#define stdc_first_trailing_zero(value) \
+        __stdbit_generic_type_func(first_trailing_zero, value)
 
 #if defined (__GNUC__) || defined (__clang__)
 static inline unsigned int stdc_count_ones_ull(unsigned long long value)
@@ -509,6 +408,19 @@ static inline unsigned int stdc_count_ones_uc(unsigned char value)
     return __builtin_popcount(value);
 }
 #else
+static inline unsigned int __stdc_count_ones(unsigned long long value,
+                                             unsigned int size)
+{
+    unsigned int ones = 0;
+
+    for (unsigned int c = 0; c < (size * CHAR_BIT); c++) {
+         ones += value & 1;
+         value >>= 1;
+    }
+
+    return ones;
+}
+
 static inline unsigned int stdc_count_ones_ull(unsigned long long value)
 {
     return __stdc_count_ones(value, sizeof (value));
@@ -538,6 +450,34 @@ static inline unsigned int stdc_count_ones_uc(unsigned char value)
 #define stdc_count_ones(value) \
         __stdbit_generic_type_func(count_ones, value)
 
+static inline unsigned int stdc_count_zeros_ull(unsigned long long value)
+{
+    return stdc_count_ones_ull(~value);
+}
+
+static inline unsigned int stdc_count_zeros_ul(unsigned long value)
+{
+    return stdc_count_ones_ul(~value);
+}
+
+static inline unsigned int stdc_count_zeros_ui(unsigned int value)
+{
+    return stdc_count_ones_ui(~value);
+}
+
+static inline unsigned int stdc_count_zeros_us(unsigned short value)
+{
+    return stdc_count_ones_us(~value);
+}
+
+static inline unsigned int stdc_count_zeros_uc(unsigned char value)
+{
+    return stdc_count_ones_uc(~value);
+}
+
+#define stdc_count_zeros(value) \
+        __stdbit_generic_type_func(count_zeros, value)
+
 static inline bool stdc_has_single_bit_ull(unsigned long long value)
 {
     return value && (value & (value - 1)) == 0;
@@ -568,27 +508,27 @@ static inline bool stdc_has_single_bit_uc(unsigned char value)
 
 static inline unsigned int stdc_bit_width_ull(unsigned long long value)
 {
-    return stdc_first_leading_one_ull(value);
+    return (CHAR_BIT * sizeof (value)) - stdc_leading_zeros_ull(value);
 }
 
 static inline unsigned int stdc_bit_width_ul(unsigned long value)
 {
-    return stdc_first_leading_one_ul(value);
+    return (CHAR_BIT * sizeof (value)) - stdc_leading_zeros_ul(value);
 }
 
 static inline unsigned int stdc_bit_width_ui(unsigned int value)
 {
-    return stdc_first_leading_one_ui(value);
+    return (CHAR_BIT * sizeof (value)) - stdc_leading_zeros_ui(value);
 }
 
 static inline unsigned int stdc_bit_width_us(unsigned short value)
 {
-    return stdc_first_leading_one_us(value);
+    return (CHAR_BIT * sizeof (value)) - stdc_leading_zeros_us(value);
 }
 
 static inline unsigned int stdc_bit_width_uc(unsigned char value)
 {
-    return stdc_first_leading_one_uc(value);
+    return (CHAR_BIT * sizeof (value)) - stdc_leading_zeros_uc(value);
 }
 
 #define stdc_bit_width(value) \



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/a8e83b1b69df3d500d52e5ddb9bd562723ee3b5e...7a970a33329c9836d169727ddbaf49a33240d587

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/a8e83b1b69df3d500d52e5ddb9bd562723ee3b5e...7a970a33329c9836d169727ddbaf49a33240d587
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list