aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-01-31 19:17:27 +0100
committerJakub Jelinek <jakub@redhat.com>2024-01-31 19:17:27 +0100
commitda89496337b97e6a2aaf1e81d55cf998f6db1070 (patch)
tree387c162fccd66a88e5663ee69e0ee131f183615d /stdlib
parent903cd866060555c77abbf70d0d85994ec5a18193 (diff)
downloadglibc-da89496337b97e6a2aaf1e81d55cf998f6db1070.tar.xz
glibc-da89496337b97e6a2aaf1e81d55cf998f6db1070.zip
Use gcc __builtin_stdc_* builtins in stdbit.h if possible
The following patch uses the GCC 14 __builtin_stdc_* builtins in stdbit.h for the type-generic macros, so that when compiled with GCC 14 or later, it supports not just 8/16/32/64-bit unsigned integers, but also 128-bit (if target supports them) and unsigned _BitInt (any supported precision). And so that the macros don't expand arguments multiple times and can be evaluated in constant expressions. The new testcase is gcc's gcc/testsuite/gcc.dg/builtin-stdc-bit-1.c adjusted to test stdbit.h and the type-generic macros in there instead of the builtins and adjusted to use glibc test framework rather than gcc style tests with __builtin_abort (). Signed-off-by: Jakub Jelinek <jakub@redhat.com> Reviewed-by: Joseph Myers <josmyers@redhat.com>
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/Makefile1
-rw-r--r--stdlib/stdbit.h84
-rw-r--r--stdlib/tst-stdbit-builtins.c778
3 files changed, 849 insertions, 14 deletions
diff --git a/stdlib/Makefile b/stdlib/Makefile
index d587f054d1..9898cc5d8a 100644
--- a/stdlib/Makefile
+++ b/stdlib/Makefile
@@ -308,6 +308,7 @@ tests := \
tst-setcontext10 \
tst-setcontext11 \
tst-stdbit-Wconversion \
+ tst-stdbit-builtins \
tst-stdc_bit_ceil \
tst-stdc_bit_floor \
tst-stdc_bit_width \
diff --git a/stdlib/stdbit.h b/stdlib/stdbit.h
index f334eb174d..2801590c63 100644
--- a/stdlib/stdbit.h
+++ b/stdlib/stdbit.h
@@ -64,9 +64,13 @@ extern unsigned int stdc_leading_zeros_ul (unsigned long int __x)
__extension__
extern unsigned int stdc_leading_zeros_ull (unsigned long long int __x)
__THROW __attribute_const__;
-#define stdc_leading_zeros(x) \
+#if __glibc_has_builtin (__builtin_stdc_leading_zeros)
+# define stdc_leading_zeros(x) (__builtin_stdc_leading_zeros (x))
+#else
+# define stdc_leading_zeros(x) \
(stdc_leading_zeros_ull (x) \
- (unsigned int) (8 * (sizeof (0ULL) - sizeof (x))))
+#endif
#if __GNUC_PREREQ (3, 4) || __glibc_has_builtin (__builtin_clzll)
static __always_inline unsigned int
@@ -116,9 +120,13 @@ extern unsigned int stdc_leading_ones_ul (unsigned long int __x)
__extension__
extern unsigned int stdc_leading_ones_ull (unsigned long long int __x)
__THROW __attribute_const__;
-#define stdc_leading_ones(x) \
+#if __glibc_has_builtin (__builtin_stdc_leading_ones)
+# define stdc_leading_ones(x) (__builtin_stdc_leading_ones (x))
+#else
+# define stdc_leading_ones(x) \
(stdc_leading_ones_ull ((unsigned long long int) (x) \
<< 8 * (sizeof (0ULL) - sizeof (x))))
+#endif
#if __GNUC_PREREQ (3, 4) || __glibc_has_builtin (__builtin_clzll)
static __always_inline unsigned int
@@ -168,11 +176,15 @@ extern unsigned int stdc_trailing_zeros_ul (unsigned long int __x)
__extension__
extern unsigned int stdc_trailing_zeros_ull (unsigned long long int __x)
__THROW __attribute_const__;
-#define stdc_trailing_zeros(x) \
+#if __glibc_has_builtin (__builtin_stdc_trailing_zeros)
+# define stdc_trailing_zeros(x) (__builtin_stdc_trailing_zeros (x))
+#else
+# define stdc_trailing_zeros(x) \
(sizeof (x) == 8 ? stdc_trailing_zeros_ull (x) \
: sizeof (x) == 4 ? stdc_trailing_zeros_ui (x) \
: sizeof (x) == 2 ? stdc_trailing_zeros_us (__pacify_uint16 (x)) \
: stdc_trailing_zeros_uc (__pacify_uint8 (x)))
+#endif
#if __GNUC_PREREQ (3, 4) || __glibc_has_builtin (__builtin_ctzll)
static __always_inline unsigned int
@@ -222,7 +234,11 @@ extern unsigned int stdc_trailing_ones_ul (unsigned long int __x)
__extension__
extern unsigned int stdc_trailing_ones_ull (unsigned long long int __x)
__THROW __attribute_const__;
-#define stdc_trailing_ones(x) (stdc_trailing_ones_ull (x))
+#if __glibc_has_builtin (__builtin_stdc_trailing_ones)
+# define stdc_trailing_ones(x) (__builtin_stdc_trailing_ones (x))
+#else
+# define stdc_trailing_ones(x) (stdc_trailing_ones_ull (x))
+#endif
#if __GNUC_PREREQ (3, 4) || __glibc_has_builtin (__builtin_ctzll)
static __always_inline unsigned int
@@ -272,11 +288,15 @@ extern unsigned int stdc_first_leading_zero_ul (unsigned long int __x)
__extension__
extern unsigned int stdc_first_leading_zero_ull (unsigned long long int __x)
__THROW __attribute_const__;
-#define stdc_first_leading_zero(x) \
+#if __glibc_has_builtin (__builtin_stdc_first_leading_zero)
+# define stdc_first_leading_zero(x) (__builtin_stdc_first_leading_zero (x))
+#else
+# define stdc_first_leading_zero(x) \
(sizeof (x) == 8 ? stdc_first_leading_zero_ull (x) \
: sizeof (x) == 4 ? stdc_first_leading_zero_ui (x) \
: sizeof (x) == 2 ? stdc_first_leading_zero_us (__pacify_uint16 (x)) \
: stdc_first_leading_zero_uc (__pacify_uint8 (x)))
+#endif
#if __GNUC_PREREQ (3, 4) || __glibc_has_builtin (__builtin_clzll)
static __always_inline unsigned int
@@ -326,11 +346,15 @@ extern unsigned int stdc_first_leading_one_ul (unsigned long int __x)
__extension__
extern unsigned int stdc_first_leading_one_ull (unsigned long long int __x)
__THROW __attribute_const__;
-#define stdc_first_leading_one(x) \
+#if __glibc_has_builtin (__builtin_stdc_first_leading_one)
+# define stdc_first_leading_one(x) (__builtin_stdc_first_leading_one (x))
+#else
+# define stdc_first_leading_one(x) \
(sizeof (x) == 8 ? stdc_first_leading_one_ull (x) \
: sizeof (x) == 4 ? stdc_first_leading_one_ui (x) \
: sizeof (x) == 2 ? stdc_first_leading_one_us (__pacify_uint16 (x)) \
: stdc_first_leading_one_uc (__pacify_uint8 (x)))
+#endif
#if __GNUC_PREREQ (3, 4) || __glibc_has_builtin (__builtin_clzll)
static __always_inline unsigned int
@@ -380,11 +404,15 @@ extern unsigned int stdc_first_trailing_zero_ul (unsigned long int __x)
__extension__
extern unsigned int stdc_first_trailing_zero_ull (unsigned long long int __x)
__THROW __attribute_const__;
-#define stdc_first_trailing_zero(x) \
+#if __glibc_has_builtin (__builtin_stdc_first_trailing_zero)
+# define stdc_first_trailing_zero(x) (__builtin_stdc_first_trailing_zero (x))
+#else
+# define stdc_first_trailing_zero(x) \
(sizeof (x) == 8 ? stdc_first_trailing_zero_ull (x) \
: sizeof (x) == 4 ? stdc_first_trailing_zero_ui (x) \
: sizeof (x) == 2 ? stdc_first_trailing_zero_us (__pacify_uint16 (x)) \
: stdc_first_trailing_zero_uc (__pacify_uint8 (x)))
+#endif
#if __GNUC_PREREQ (3, 4) || __glibc_has_builtin (__builtin_ctzll)
static __always_inline unsigned int
@@ -434,11 +462,15 @@ extern unsigned int stdc_first_trailing_one_ul (unsigned long int __x)
__extension__
extern unsigned int stdc_first_trailing_one_ull (unsigned long long int __x)
__THROW __attribute_const__;
-#define stdc_first_trailing_one(x) \
+#if __glibc_has_builtin (__builtin_stdc_first_trailing_one)
+# define stdc_first_trailing_one(x) (__builtin_stdc_first_trailing_one (x))
+#else
+# define stdc_first_trailing_one(x) \
(sizeof (x) == 8 ? stdc_first_trailing_one_ull (x) \
: sizeof (x) == 4 ? stdc_first_trailing_one_ui (x) \
: sizeof (x) == 2 ? stdc_first_trailing_one_us (__pacify_uint16 (x)) \
: stdc_first_trailing_one_uc (__pacify_uint8 (x)))
+#endif
#if __GNUC_PREREQ (3, 4) || __glibc_has_builtin (__builtin_ctzll)
static __always_inline unsigned int
@@ -488,9 +520,13 @@ extern unsigned int stdc_count_zeros_ul (unsigned long int __x)
__extension__
extern unsigned int stdc_count_zeros_ull (unsigned long long int __x)
__THROW __attribute_const__;
-#define stdc_count_zeros(x) \
+#if __glibc_has_builtin (__builtin_stdc_count_zeros)
+# define stdc_count_zeros(x) (__builtin_stdc_count_zeros (x))
+#else
+# define stdc_count_zeros(x) \
(stdc_count_zeros_ull (x) \
- (unsigned int) (8 * (sizeof (0ULL) - sizeof (x))))
+#endif
#if __GNUC_PREREQ (3, 4) || __glibc_has_builtin (__builtin_popcountll)
static __always_inline unsigned int
@@ -540,7 +576,11 @@ extern unsigned int stdc_count_ones_ul (unsigned long int __x)
__extension__
extern unsigned int stdc_count_ones_ull (unsigned long long int __x)
__THROW __attribute_const__;
-#define stdc_count_ones(x) (stdc_count_ones_ull (x))
+#if __glibc_has_builtin (__builtin_stdc_count_ones)
+# define stdc_count_ones(x) (__builtin_stdc_count_ones (x))
+#else
+# define stdc_count_ones(x) (stdc_count_ones_ull (x))
+#endif
#if __GNUC_PREREQ (3, 4) || __glibc_has_builtin (__builtin_popcountll)
static __always_inline unsigned int
@@ -590,10 +630,14 @@ extern bool stdc_has_single_bit_ul (unsigned long int __x)
__extension__
extern bool stdc_has_single_bit_ull (unsigned long long int __x)
__THROW __attribute_const__;
-#define stdc_has_single_bit(x) \
+#if __glibc_has_builtin (__builtin_stdc_has_single_bit)
+# define stdc_has_single_bit(x) (__builtin_stdc_has_single_bit (x))
+#else
+# define stdc_has_single_bit(x) \
((bool) (sizeof (x) <= sizeof (unsigned int) \
? stdc_has_single_bit_ui (x) \
: stdc_has_single_bit_ull (x)))
+#endif
static __always_inline bool
__hsb64_inline (uint64_t __x)
@@ -641,7 +685,11 @@ extern unsigned int stdc_bit_width_ul (unsigned long int __x)
__extension__
extern unsigned int stdc_bit_width_ull (unsigned long long int __x)
__THROW __attribute_const__;
-#define stdc_bit_width(x) (stdc_bit_width_ull (x))
+#if __glibc_has_builtin (__builtin_stdc_bit_width)
+# define stdc_bit_width(x) (__builtin_stdc_bit_width (x))
+#else
+# define stdc_bit_width(x) (stdc_bit_width_ull (x))
+#endif
#if __GNUC_PREREQ (3, 4) || __glibc_has_builtin (__builtin_clzll)
static __always_inline unsigned int
@@ -691,7 +739,11 @@ extern unsigned long int stdc_bit_floor_ul (unsigned long int __x)
__extension__
extern unsigned long long int stdc_bit_floor_ull (unsigned long long int __x)
__THROW __attribute_const__;
-#define stdc_bit_floor(x) ((__typeof (x)) stdc_bit_floor_ull (x))
+#if __glibc_has_builtin (__builtin_stdc_bit_floor)
+# define stdc_bit_floor(x) (__builtin_stdc_bit_floor (x))
+#else
+# define stdc_bit_floor(x) ((__typeof (x)) stdc_bit_floor_ull (x))
+#endif
#if __GNUC_PREREQ (3, 4) || __glibc_has_builtin (__builtin_clzll)
static __always_inline uint64_t
@@ -743,7 +795,11 @@ extern unsigned long int stdc_bit_ceil_ul (unsigned long int __x)
__extension__
extern unsigned long long int stdc_bit_ceil_ull (unsigned long long int __x)
__THROW __attribute_const__;
-#define stdc_bit_ceil(x) ((__typeof (x)) stdc_bit_ceil_ull (x))
+#if __glibc_has_builtin (__builtin_stdc_bit_ceil)
+# define stdc_bit_ceil(x) (__builtin_stdc_bit_ceil (x))
+#else
+# define stdc_bit_ceil(x) ((__typeof (x)) stdc_bit_ceil_ull (x))
+#endif
#if __GNUC_PREREQ (3, 4) || __glibc_has_builtin (__builtin_clzll)
static __always_inline uint64_t
diff --git a/stdlib/tst-stdbit-builtins.c b/stdlib/tst-stdbit-builtins.c
new file mode 100644
index 0000000000..536841ca8a
--- /dev/null
+++ b/stdlib/tst-stdbit-builtins.c
@@ -0,0 +1,778 @@
+/* Test <stdbit.h> type-generic macros with compiler __builtin_stdc_* support.
+ Copyright (C) 2024 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <stdbit.h>
+#include <limits.h>
+#include <support/check.h>
+
+#if __glibc_has_builtin (__builtin_stdc_leading_zeros) \
+ && __glibc_has_builtin (__builtin_stdc_leading_ones) \
+ && __glibc_has_builtin (__builtin_stdc_trailing_zeros) \
+ && __glibc_has_builtin (__builtin_stdc_trailing_ones) \
+ && __glibc_has_builtin (__builtin_stdc_first_leading_zero) \
+ && __glibc_has_builtin (__builtin_stdc_first_leading_one) \
+ && __glibc_has_builtin (__builtin_stdc_first_trailing_zero) \
+ && __glibc_has_builtin (__builtin_stdc_first_trailing_one) \
+ && __glibc_has_builtin (__builtin_stdc_count_zeros) \
+ && __glibc_has_builtin (__builtin_stdc_count_ones) \
+ && __glibc_has_builtin (__builtin_stdc_has_single_bit) \
+ && __glibc_has_builtin (__builtin_stdc_bit_width) \
+ && __glibc_has_builtin (__builtin_stdc_bit_floor) \
+ && __glibc_has_builtin (__builtin_stdc_bit_ceil)
+
+# if !defined (BITINT_MAXWIDTH) && defined (__BITINT_MAXWIDTH__)
+# define BITINT_MAXWIDTH __BITINT_MAXWIDTH__
+# endif
+
+typedef unsigned char uc;
+typedef unsigned short us;
+typedef unsigned int ui;
+typedef unsigned long int ul;
+typedef unsigned long long int ull;
+
+# define expr_has_type(e, t) _Generic (e, default : 0, t : 1)
+
+static int
+do_test (void)
+{
+ TEST_COMPARE (stdc_leading_zeros ((uc) 0), CHAR_BIT);
+ TEST_COMPARE (expr_has_type (stdc_leading_zeros ((uc) 0), ui), 1);
+ TEST_COMPARE (stdc_leading_zeros ((us) 0), sizeof (short) * CHAR_BIT);
+ TEST_COMPARE (expr_has_type (stdc_leading_zeros ((us) 0), ui), 1);
+ TEST_COMPARE (stdc_leading_zeros (0U), sizeof (int) * CHAR_BIT);
+ TEST_COMPARE (expr_has_type (stdc_leading_zeros (0U), ui), 1);
+ TEST_COMPARE (stdc_leading_zeros (0UL), sizeof (long int) * CHAR_BIT);
+ TEST_COMPARE (expr_has_type (stdc_leading_zeros (0UL), ui), 1);
+ TEST_COMPARE (stdc_leading_zeros (0ULL), sizeof (long long int) * CHAR_BIT);
+ TEST_COMPARE (expr_has_type (stdc_leading_zeros (0ULL), ui), 1);
+ TEST_COMPARE (stdc_leading_zeros ((uc) ~0U), 0);
+ TEST_COMPARE (stdc_leading_zeros ((us) ~0U), 0);
+ TEST_COMPARE (stdc_leading_zeros (~0U), 0);
+ TEST_COMPARE (stdc_leading_zeros (~0UL), 0);
+ TEST_COMPARE (stdc_leading_zeros (~0ULL), 0);
+ TEST_COMPARE (stdc_leading_zeros ((uc) 3), CHAR_BIT - 2);
+ TEST_COMPARE (stdc_leading_zeros ((us) 9), sizeof (short) * CHAR_BIT - 4);
+ TEST_COMPARE (stdc_leading_zeros (34U), sizeof (int) * CHAR_BIT - 6);
+ TEST_COMPARE (stdc_leading_zeros (130UL), sizeof (long int) * CHAR_BIT - 8);
+ TEST_COMPARE (stdc_leading_zeros (512ULL),
+ sizeof (long long int) * CHAR_BIT - 10);
+ TEST_COMPARE (stdc_leading_ones ((uc) 0), 0);
+ TEST_COMPARE (expr_has_type (stdc_leading_ones ((uc) 0), ui), 1);
+ TEST_COMPARE (stdc_leading_ones ((us) 0), 0);
+ TEST_COMPARE (expr_has_type (stdc_leading_ones ((us) 0), ui), 1);
+ TEST_COMPARE (stdc_leading_ones (0U), 0);
+ TEST_COMPARE (expr_has_type (stdc_leading_ones (0U), ui), 1);
+ TEST_COMPARE (stdc_leading_ones (0UL), 0);
+ TEST_COMPARE (expr_has_type (stdc_leading_ones (0UL), ui), 1);
+ TEST_COMPARE (stdc_leading_ones (0ULL), 0);
+ TEST_COMPARE (expr_has_type (stdc_leading_ones (0ULL), ui), 1);
+ TEST_COMPARE (stdc_leading_ones ((uc) ~0U), CHAR_BIT);
+ TEST_COMPARE (stdc_leading_ones ((us) ~0U), sizeof (short) * CHAR_BIT);
+ TEST_COMPARE (stdc_leading_ones (~0U), sizeof (int) * CHAR_BIT);
+ TEST_COMPARE (stdc_leading_ones (~0UL), sizeof (long int) * CHAR_BIT);
+ TEST_COMPARE (stdc_leading_ones (~0ULL), sizeof (long long int) * CHAR_BIT);
+ TEST_COMPARE (stdc_leading_ones ((uc) ~3), CHAR_BIT - 2);
+ TEST_COMPARE (stdc_leading_ones ((us) ~9), sizeof (short) * CHAR_BIT - 4);
+ TEST_COMPARE (stdc_leading_ones (~34U), sizeof (int) * CHAR_BIT - 6);
+ TEST_COMPARE (stdc_leading_ones (~130UL), sizeof (long int) * CHAR_BIT - 8);
+ TEST_COMPARE (stdc_leading_ones (~512ULL),
+ sizeof (long long int) * CHAR_BIT - 10);
+ TEST_COMPARE (stdc_trailing_zeros ((uc) 0), CHAR_BIT);
+ TEST_COMPARE (expr_has_type (stdc_trailing_zeros ((uc) 0), ui), 1);
+ TEST_COMPARE (stdc_trailing_zeros ((us) 0), sizeof (short) * CHAR_BIT);
+ TEST_COMPARE (expr_has_type (stdc_trailing_zeros ((us) 0), ui), 1);
+ TEST_COMPARE (stdc_trailing_zeros (0U), sizeof (int) * CHAR_BIT);
+ TEST_COMPARE (expr_has_type (stdc_trailing_zeros (0U), ui), 1);
+ TEST_COMPARE (stdc_trailing_zeros (0UL), sizeof (long int) * CHAR_BIT);
+ TEST_COMPARE (expr_has_type (stdc_trailing_zeros (0UL), ui), 1);
+ TEST_COMPARE (stdc_trailing_zeros (0ULL), sizeof (long long int) * CHAR_BIT);
+ TEST_COMPARE (expr_has_type (stdc_trailing_zeros (0ULL), ui), 1);
+ TEST_COMPARE (stdc_trailing_zeros ((uc) ~0U), 0);
+ TEST_COMPARE (stdc_trailing_zeros ((us) ~0U), 0);
+ TEST_COMPARE (stdc_trailing_zeros (~0U), 0);
+ TEST_COMPARE (stdc_trailing_zeros (~0UL), 0);
+ TEST_COMPARE (stdc_trailing_zeros (~0ULL), 0);
+ TEST_COMPARE (stdc_trailing_zeros ((uc) 2), 1);
+ TEST_COMPARE (stdc_trailing_zeros ((us) 24), 3);
+ TEST_COMPARE (stdc_trailing_zeros (32U), 5);
+ TEST_COMPARE (stdc_trailing_zeros (128UL), 7);
+ TEST_COMPARE (stdc_trailing_zeros (512ULL), 9);
+ TEST_COMPARE (stdc_trailing_ones ((uc) 0), 0);
+ TEST_COMPARE (expr_has_type (stdc_trailing_ones ((uc) 0), ui), 1);
+ TEST_COMPARE (stdc_trailing_ones ((us) 0), 0);
+ TEST_COMPARE (expr_has_type (stdc_trailing_ones ((us) 0), ui), 1);
+ TEST_COMPARE (stdc_trailing_ones (0U), 0);
+ TEST_COMPARE (expr_has_type (stdc_trailing_ones (0U), ui), 1);
+ TEST_COMPARE (stdc_trailing_ones (0UL), 0);
+ TEST_COMPARE (expr_has_type (stdc_trailing_ones (0UL), ui), 1);
+ TEST_COMPARE (stdc_trailing_ones (0ULL), 0);
+ TEST_COMPARE (expr_has_type (stdc_trailing_ones (0ULL), ui), 1);
+ TEST_COMPARE (stdc_trailing_ones ((uc) ~0U), CHAR_BIT);
+ TEST_COMPARE (stdc_trailing_ones ((us) ~0U), sizeof (short) * CHAR_BIT);
+ TEST_COMPARE (stdc_trailing_ones (~0U), sizeof (int) * CHAR_BIT);
+ TEST_COMPARE (stdc_trailing_ones (~0UL), sizeof (long int) * CHAR_BIT);
+ TEST_COMPARE (stdc_trailing_ones (~0ULL), sizeof (long long int) * CHAR_BIT);
+ TEST_COMPARE (stdc_trailing_ones ((uc) 5), 1);
+ TEST_COMPARE (stdc_trailing_ones ((us) 15), 4);
+ TEST_COMPARE (stdc_trailing_ones (127U), 7);
+ TEST_COMPARE (stdc_trailing_ones (511UL), 9);
+ TEST_COMPARE (stdc_trailing_ones (~0ULL >> 2),
+ sizeof (long long int) * CHAR_BIT - 2);
+ TEST_COMPARE (stdc_first_leading_zero ((uc) 0), 1);
+ TEST_COMPARE (expr_has_type (stdc_first_leading_zero ((uc) 0), ui), 1);
+ TEST_COMPARE (stdc_first_leading_zero ((us) 0), 1);
+ TEST_COMPARE (expr_has_type (stdc_first_leading_zero ((us) 0), ui), 1);
+ TEST_COMPARE (stdc_first_leading_zero (0U), 1);
+ TEST_COMPARE (expr_has_type (stdc_first_leading_zero (0U), ui), 1);
+ TEST_COMPARE (stdc_first_leading_zero (0UL), 1);
+ TEST_COMPARE (expr_has_type (stdc_first_leading_zero (0UL), ui), 1);
+ TEST_COMPARE (stdc_first_leading_zero (0ULL), 1);
+ TEST_COMPARE (expr_has_type (stdc_first_leading_zero (0ULL), ui), 1);
+ TEST_COMPARE (stdc_first_leading_zero ((uc) ~0U), 0);
+ TEST_COMPARE (stdc_first_leading_zero ((us) ~0U), 0);
+ TEST_COMPARE (stdc_first_leading_zero (~0U), 0);
+ TEST_COMPARE (stdc_first_leading_zero (~0UL), 0);
+ TEST_COMPARE (stdc_first_leading_zero (~0ULL), 0);
+ TEST_COMPARE (stdc_first_leading_zero ((uc) ~3U), CHAR_BIT - 1);
+ TEST_COMPARE (stdc_first_leading_zero ((us) ~15U),
+ sizeof (short) * CHAR_BIT - 3);
+ TEST_COMPARE (stdc_first_leading_zero (~63U), sizeof (int) * CHAR_BIT - 5);
+ TEST_COMPARE (stdc_first_leading_zero (~255UL),
+ sizeof (long int) * CHAR_BIT - 7);
+ TEST_COMPARE (stdc_first_leading_zero (~1023ULL),
+ sizeof (long long int) * CHAR_BIT - 9);
+ TEST_COMPARE (stdc_first_leading_one ((uc) 0), 0);
+ TEST_COMPARE (expr_has_type (stdc_first_leading_one ((uc) 0), ui), 1);
+ TEST_COMPARE (stdc_first_leading_one ((us) 0), 0);
+ TEST_COMPARE (expr_has_type (stdc_first_leading_one ((us) 0), ui), 1);
+ TEST_COMPARE (stdc_first_leading_one (0U), 0);
+ TEST_COMPARE (expr_has_type (stdc_first_leading_one (0U), ui), 1);
+ TEST_COMPARE (stdc_first_leading_one (0UL), 0);
+ TEST_COMPARE (expr_has_type (stdc_first_leading_one (0UL), ui), 1);
+ TEST_COMPARE (stdc_first_leading_one (0ULL), 0);
+ TEST_COMPARE (expr_has_type (stdc_first_leading_one (0ULL), ui), 1);
+ TEST_COMPARE (stdc_first_leading_one ((uc) ~0U), 1);
+ TEST_COMPARE (stdc_first_leading_one ((us) ~0U), 1);
+ TEST_COMPARE (stdc_first_leading_one (~0U), 1);
+ TEST_COMPARE (stdc_first_leading_one (~0UL), 1);
+ TEST_COMPARE (stdc_first_leading_one (~0ULL), 1);
+ TEST_COMPARE (stdc_first_leading_one ((uc) 3), CHAR_BIT - 1);
+ TEST_COMPARE (stdc_first_leading_one ((us) 9),
+ sizeof (short) * CHAR_BIT - 3);
+ TEST_COMPARE (stdc_first_leading_one (34U), sizeof (int) * CHAR_BIT - 5);
+ TEST_COMPARE (stdc_first_leading_one (130UL),
+ sizeof (long int) * CHAR_BIT - 7);
+ TEST_COMPARE (stdc_first_leading_one (512ULL),
+ sizeof (long long int) * CHAR_BIT - 9);
+ TEST_COMPARE (stdc_first_trailing_zero ((uc) 0), 1);
+ TEST_COMPARE (expr_has_type (stdc_first_trailing_zero ((uc) 0), ui), 1);
+ TEST_COMPARE (stdc_first_trailing_zero ((us) 0), 1);
+ TEST_COMPARE (expr_has_type (stdc_first_trailing_zero ((us) 0), ui), 1);
+ TEST_COMPARE (stdc_first_trailing_zero (0U), 1);
+ TEST_COMPARE (expr_has_type (stdc_first_trailing_zero (0U), ui), 1);
+ TEST_COMPARE (stdc_first_trailing_zero (0UL), 1);
+ TEST_COMPARE (expr_has_type (stdc_first_trailing_zero (0UL), ui), 1);
+ TEST_COMPARE (stdc_first_trailing_zero (0ULL), 1);
+ TEST_COMPARE (expr_has_type (stdc_first_trailing_zero (0ULL), ui), 1);
+ TEST_COMPARE (stdc_first_trailing_zero ((uc) ~0U), 0);
+ TEST_COMPARE (stdc_first_trailing_zero ((us) ~0U), 0);
+ TEST_COMPARE (stdc_first_trailing_zero (~0U), 0);
+ TEST_COMPARE (stdc_first_trailing_zero (~0UL), 0);
+ TEST_COMPARE (stdc_first_trailing_zero (~0ULL), 0);
+ TEST_COMPARE (stdc_first_trailing_zero ((uc) 2), 1);
+ TEST_COMPARE (stdc_first_trailing_zero ((us) 15), 5);
+ TEST_COMPARE (stdc_first_trailing_zero (63U), 7);
+ TEST_COMPARE (stdc_first_trailing_zero (128UL), 1);
+ TEST_COMPARE (stdc_first_trailing_zero (511ULL), 10);
+ TEST_COMPARE (stdc_first_trailing_one ((uc) 0), 0);
+ TEST_COMPARE (expr_has_type (stdc_first_trailing_one ((uc) 0), ui), 1);
+ TEST_COMPARE (stdc_first_trailing_one ((us) 0), 0);
+ TEST_COMPARE (expr_has_type (stdc_first_trailing_one ((us) 0), ui), 1);
+ TEST_COMPARE (stdc_first_trailing_one (0U), 0);
+ TEST_COMPARE (expr_has_type (stdc_first_trailing_one (0U), ui), 1);
+ TEST_COMPARE (stdc_first_trailing_one (0UL), 0);
+ TEST_COMPARE (expr_has_type (stdc_first_trailing_one (0UL), ui), 1);
+ TEST_COMPARE (stdc_first_trailing_one (0ULL), 0);
+ TEST_COMPARE (expr_has_type (stdc_first_trailing_one (0ULL), ui), 1);
+ TEST_COMPARE (stdc_first_trailing_one ((uc) ~0U), 1);
+ TEST_COMPARE (stdc_first_trailing_one ((us) ~0U), 1);
+ TEST_COMPARE (stdc_first_trailing_one (~0U), 1);
+ TEST_COMPARE (stdc_first_trailing_one (~0UL), 1);
+ TEST_COMPARE (stdc_first_trailing_one (~0ULL), 1);
+ TEST_COMPARE (stdc_first_trailing_one ((uc) 4), 3);
+ TEST_COMPARE (stdc_first_trailing_one ((us) 96), 6);
+ TEST_COMPARE (stdc_first_trailing_one (127U), 1);
+ TEST_COMPARE (stdc_first_trailing_one (511UL), 1);
+ TEST_COMPARE (stdc_first_trailing_one (~0ULL << 12), 13);
+ TEST_COMPARE (stdc_count_zeros ((uc) 0), CHAR_BIT);
+ TEST_COMPARE (expr_has_type (stdc_count_zeros ((uc) 0), ui), 1);
+ TEST_COMPARE (stdc_count_zeros ((us) 0), sizeof (short) * CHAR_BIT);
+ TEST_COMPARE (expr_has_type (stdc_count_zeros ((us) 0), ui), 1);
+ TEST_COMPARE (stdc_count_zeros (0U), sizeof (int) * CHAR_BIT);
+ TEST_COMPARE (expr_has_type (stdc_count_zeros (0U), ui), 1);
+ TEST_COMPARE (stdc_count_zeros (0UL), sizeof (long int) * CHAR_BIT);
+ TEST_COMPARE (expr_has_type (stdc_count_zeros (0UL), ui), 1);
+ TEST_COMPARE (stdc_count_zeros (0ULL), sizeof (long long int) * CHAR_BIT);
+ TEST_COMPARE (expr_has_type (stdc_count_zeros (0ULL), ui), 1);
+ TEST_COMPARE (stdc_count_zeros ((uc) ~0U), 0);
+ TEST_COMPARE (stdc_count_zeros ((us) ~0U), 0);
+ TEST_COMPARE (stdc_count_zeros (~0U), 0);
+ TEST_COMPARE (stdc_count_zeros (~0UL), 0);
+ TEST_COMPARE (stdc_count_zeros (~0ULL), 0);
+ TEST_COMPARE (stdc_count_zeros ((uc) 1U), CHAR_BIT - 1);
+ TEST_COMPARE (stdc_count_zeros ((us) 42), sizeof (short) * CHAR_BIT - 3);
+ TEST_COMPARE (stdc_count_zeros (291U), sizeof (int) * CHAR_BIT - 4);
+ TEST_COMPARE (stdc_count_zeros (~1315UL), 5);
+ TEST_COMPARE (stdc_count_zeros (3363ULL),
+ sizeof (long long int) * CHAR_BIT - 6);
+ TEST_COMPARE (stdc_count_ones ((uc) 0), 0);
+ TEST_COMPARE (expr_has_type (stdc_count_ones ((uc) 0), ui), 1);
+ TEST_COMPARE (stdc_count_ones ((us) 0), 0);
+ TEST_COMPARE (expr_has_type (stdc_count_ones ((us) 0), ui), 1);
+ TEST_COMPARE (stdc_count_ones (0U), 0);
+ TEST_COMPARE (expr_has_type (stdc_count_ones (0U), ui), 1);
+ TEST_COMPARE (stdc_count_ones (0UL), 0);
+ TEST_COMPARE (expr_has_type (stdc_count_ones (0UL), ui), 1);
+ TEST_COMPARE (stdc_count_ones (0ULL), 0);
+ TEST_COMPARE (expr_has_type (stdc_count_ones (0ULL), ui), 1);
+ TEST_COMPARE (stdc_count_ones ((uc) ~0U), CHAR_BIT);
+ TEST_COMPARE (stdc_count_ones ((us) ~0U), sizeof (short) * CHAR_BIT);
+ TEST_COMPARE (stdc_count_ones (~0U), sizeof (int) * CHAR_BIT);
+ TEST_COMPARE (stdc_count_ones (~0UL), sizeof (long int) * CHAR_BIT);
+ TEST_COMPARE (stdc_count_ones (~0ULL), sizeof (long long int) * CHAR_BIT);
+ TEST_COMPARE (stdc_count_ones ((uc) ~1U), CHAR_BIT - 1);
+ TEST_COMPARE (stdc_count_ones ((us) ~42), sizeof (short) * CHAR_BIT - 3);
+ TEST_COMPARE (stdc_count_ones (~291U), sizeof (int) * CHAR_BIT - 4);
+ TEST_COMPARE (stdc_count_ones (1315UL), 5);
+ TEST_COMPARE (stdc_count_ones (~3363ULL),
+ sizeof (long long int) * CHAR_BIT - 6);
+ TEST_COMPARE (stdc_has_single_bit ((uc) 0), 0);
+ TEST_COMPARE (expr_has_type (stdc_has_single_bit ((uc) 0), _Bool), 1);
+ TEST_COMPARE (stdc_has_single_bit ((us) 0), 0);
+ TEST_COMPARE (expr_has_type (stdc_has_single_bit ((us) 0), _Bool), 1);
+ TEST_COMPARE (stdc_has_single_bit (0U), 0);
+ TEST_COMPARE (expr_has_type (stdc_has_single_bit (0U), _Bool), 1);
+ TEST_COMPARE (stdc_has_single_bit (0UL), 0);
+ TEST_COMPARE (expr_has_type (stdc_has_single_bit (0UL), _Bool), 1);
+ TEST_COMPARE (stdc_has_single_bit (0ULL), 0);
+ TEST_COMPARE (expr_has_type (stdc_has_single_bit (0ULL), _Bool), 1);
+ TEST_COMPARE (stdc_has_single_bit ((uc) 2), 1);
+ TEST_COMPARE (stdc_has_single_bit ((us) 8), 1);
+ TEST_COMPARE (stdc_has_single_bit (32U), 1);
+ TEST_COMPARE (stdc_has_single_bit (128UL), 1);
+ TEST_COMPARE (stdc_has_single_bit (512ULL), 1);
+ TEST_COMPARE (stdc_has_single_bit ((uc) 7), 0);
+ TEST_COMPARE (stdc_has_single_bit ((us) 96), 0);
+ TEST_COMPARE (stdc_has_single_bit (513U), 0);
+ TEST_COMPARE (stdc_has_single_bit (1022UL), 0);
+ TEST_COMPARE (stdc_has_single_bit (12ULL), 0);
+ TEST_COMPARE (stdc_bit_width ((uc) 0), 0);