* config/srclist.txt: Add files containing stdbit test cases shared with glibc. * modules/stdbit-tests: New file. * tests/support/test-driver.c, tests/tst-stdbit.h: New files, copied from glibc with changes. * tests/tst-stdc_bit_ceil.c: * tests/tst-stdc_bit_floor.c, tests/tst-stdc_bit_width.c: * tests/tst-stdc_count_ones.c, tests/tst-stdc_count_zeros.c: * tests/tst-stdc_first_leading_one.c: * tests/tst-stdc_first_leading_zero.c: * tests/tst-stdc_first_trailing_one.c: * tests/tst-stdc_first_trailing_zero.c: * tests/tst-stdc_has_single_bit.c, tests/tst-stdc_leading_ones.c: * tests/tst-stdc_leading_zeros.c, tests/tst-stdc_trailing_ones.c: * tests/tst-stdc_trailing_zeros.c: New files, copied verbatim from glibc. --- ChangeLog | 18 +++ config/srclist.txt | 15 ++ lib/stdbit.in.h | 115 +++++++------- modules/stdbit-tests | 42 +++++ tests/support/test-driver.c | 5 + tests/tst-stdbit.h | 225 +++++++++++++++++++++++++++ tests/tst-stdc_bit_ceil.c | 88 +++++++++++ tests/tst-stdc_bit_floor.c | 88 +++++++++++ tests/tst-stdc_bit_width.c | 88 +++++++++++ tests/tst-stdc_count_ones.c | 88 +++++++++++ tests/tst-stdc_count_zeros.c | 88 +++++++++++ tests/tst-stdc_first_leading_one.c | 88 +++++++++++ tests/tst-stdc_first_leading_zero.c | 88 +++++++++++ tests/tst-stdc_first_trailing_one.c | 88 +++++++++++ tests/tst-stdc_first_trailing_zero.c | 88 +++++++++++ tests/tst-stdc_has_single_bit.c | 88 +++++++++++ tests/tst-stdc_leading_ones.c | 88 +++++++++++ tests/tst-stdc_leading_zeros.c | 88 +++++++++++ tests/tst-stdc_trailing_ones.c | 88 +++++++++++ tests/tst-stdc_trailing_zeros.c | 88 +++++++++++ 20 files changed, 1592 insertions(+), 60 deletions(-) create mode 100644 modules/stdbit-tests create mode 100644 tests/support/test-driver.c create mode 100644 tests/tst-stdbit.h create mode 100644 tests/tst-stdc_bit_ceil.c create mode 100644 tests/tst-stdc_bit_floor.c create mode 100644 tests/tst-stdc_bit_width.c create mode 100644 tests/tst-stdc_count_ones.c create mode 100644 tests/tst-stdc_count_zeros.c create mode 100644 tests/tst-stdc_first_leading_one.c create mode 100644 tests/tst-stdc_first_leading_zero.c create mode 100644 tests/tst-stdc_first_trailing_one.c create mode 100644 tests/tst-stdc_first_trailing_zero.c create mode 100644 tests/tst-stdc_has_single_bit.c create mode 100644 tests/tst-stdc_leading_ones.c create mode 100644 tests/tst-stdc_leading_zeros.c create mode 100644 tests/tst-stdc_trailing_ones.c create mode 100644 tests/tst-stdc_trailing_zeros.c
diff --git a/ChangeLog b/ChangeLog index 1019917f36..083babb011 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,23 @@ 2024-05-11 Paul Eggert <egg...@cs.ucla.edu> + stdbit-tests: new module + * config/srclist.txt: Add files containing stdbit test cases + shared with glibc. + * modules/stdbit-tests: New file. + * tests/support/test-driver.c, tests/tst-stdbit.h: + New files, copied from glibc with changes. + * tests/tst-stdc_bit_ceil.c: + * tests/tst-stdc_bit_floor.c, tests/tst-stdc_bit_width.c: + * tests/tst-stdc_count_ones.c, tests/tst-stdc_count_zeros.c: + * tests/tst-stdc_first_leading_one.c: + * tests/tst-stdc_first_leading_zero.c: + * tests/tst-stdc_first_trailing_one.c: + * tests/tst-stdc_first_trailing_zero.c: + * tests/tst-stdc_has_single_bit.c, tests/tst-stdc_leading_ones.c: + * tests/tst-stdc_leading_zeros.c, tests/tst-stdc_trailing_ones.c: + * tests/tst-stdc_trailing_zeros.c: + New files, copied verbatim from glibc. + stdbit: new module * doc/gnulib-tool.texi, doc/gnulib.texi: Mention it. * doc/posix-headers/stdbit.texi, lib/stdbit.c, lib/stdbit.in.h: diff --git a/config/srclist.txt b/config/srclist.txt index 78f77aafd2..34ffd63aec 100644 --- a/config/srclist.txt +++ b/config/srclist.txt @@ -71,6 +71,21 @@ $LIBCSRC posix/regex.h lib #$LIBCSRC posix/regex_internal.h lib #$LIBCSRC posix/regexec.c lib #$LIBCSRC stdlib/canonicalize lib/canonicalize-lgpl.c +#$LIBCSRC stdlib/tst-stdbit.h tests +$LIBCSRC stdlib/tst-stdc_bit_ceil.c tests +$LIBCSRC stdlib/tst-stdc_bit_floor.c tests +$LIBCSRC stdlib/tst-stdc_bit_width.c tests +$LIBCSRC stdlib/tst-stdc_count_ones.c tests +$LIBCSRC stdlib/tst-stdc_count_zeros.c tests +$LIBCSRC stdlib/tst-stdc_first_leading_one.c tests +$LIBCSRC stdlib/tst-stdc_first_leading_zero.c tests +$LIBCSRC stdlib/tst-stdc_first_trailing_one.c tests +$LIBCSRC stdlib/tst-stdc_first_trailing_zero.c tests +$LIBCSRC stdlib/tst-stdc_has_single_bit.c tests +$LIBCSRC stdlib/tst-stdc_leading_ones.c tests +$LIBCSRC stdlib/tst-stdc_leading_zeros.c tests +$LIBCSRC stdlib/tst-stdc_trailing_ones.c tests +$LIBCSRC stdlib/tst-stdc_trailing_zeros.c tests #$LIBCSRC sysdeps/generic/eloop-threshold.h lib $LIBCSRC time/timegm.c lib #$LIBCSRC time/mktime.c lib diff --git a/lib/stdbit.in.h b/lib/stdbit.in.h index a2fff04772..3701344498 100644 --- a/lib/stdbit.in.h +++ b/lib/stdbit.in.h @@ -63,22 +63,23 @@ _GL_INLINE_HEADER_BEGIN extern "C" { #endif + _GL_STDBIT_INLINE unsigned int -stdc_leading_zeros_uc (unsigned char n) +stdc_leading_zeros_ui (unsigned int n) { - return count_leading_zeros (n) - 8 * (sizeof 0u - sizeof n); + return count_leading_zeros (n); } _GL_STDBIT_INLINE unsigned int -stdc_leading_zeros_us (unsigned short int n) +stdc_leading_zeros_uc (unsigned char n) { - return count_leading_zeros (n) - 8 * (sizeof 0u - sizeof n); + return stdc_leading_zeros_ui (n) - 8 * (sizeof 0u - sizeof n); } _GL_STDBIT_INLINE unsigned int -stdc_leading_zeros_ui (unsigned int n) +stdc_leading_zeros_us (unsigned short int n) { - return count_leading_zeros (n); + return stdc_leading_zeros_ui (n) - 8 * (sizeof 0u - sizeof n); } _GL_STDBIT_INLINE unsigned int @@ -104,33 +105,31 @@ stdc_leading_zeros_ull (unsigned long long int n) _GL_STDBIT_INLINE unsigned int stdc_leading_ones_uc (unsigned char n) { - unsigned int ui = n; - return count_leading_zeros (~(ui << 8 * (sizeof ui - sizeof n))); + return stdc_leading_zeros_uc (~n); } _GL_STDBIT_INLINE unsigned int stdc_leading_ones_us (unsigned short int n) { - unsigned int ui = n; - return count_leading_zeros (~(ui << 8 * (sizeof ui - sizeof n))); + return stdc_leading_zeros_us (~n); } _GL_STDBIT_INLINE unsigned int stdc_leading_ones_ui (unsigned int n) { - return count_leading_zeros (~n); + return stdc_leading_zeros_ui (~n); } _GL_STDBIT_INLINE unsigned int stdc_leading_ones_ul (unsigned long int n) { - return count_leading_zeros_l (~n); + return stdc_leading_zeros_ul (~n); } _GL_STDBIT_INLINE unsigned int stdc_leading_ones_ull (unsigned long long int n) { - return count_leading_zeros_ll (~n); + return stdc_leading_zeros_ull (~n); } #define stdc_leading_ones(n) \ @@ -142,21 +141,21 @@ stdc_leading_ones_ull (unsigned long long int n) _GL_STDBIT_INLINE unsigned int -stdc_trailing_zeros_uc (unsigned char n) +stdc_trailing_zeros_ui (unsigned int n) { - return count_trailing_zeros (n | (1 + (unsigned char) -1)); + return count_trailing_zeros (n); } _GL_STDBIT_INLINE unsigned int -stdc_trailing_zeros_us (unsigned short int n) +stdc_trailing_zeros_uc (unsigned char n) { - return count_trailing_zeros (n | (1 + (unsigned short int) -1)); + return stdc_trailing_zeros_ui (n | (1 + (unsigned char) -1)); } _GL_STDBIT_INLINE unsigned int -stdc_trailing_zeros_ui (unsigned int n) +stdc_trailing_zeros_us (unsigned short int n) { - return count_trailing_zeros (n); + return stdc_trailing_zeros_ui (n | (1 + (unsigned short int) -1)); } _GL_STDBIT_INLINE unsigned int @@ -182,33 +181,31 @@ stdc_trailing_zeros_ull (unsigned long long int n) _GL_STDBIT_INLINE unsigned int stdc_trailing_ones_uc (unsigned char n) { - unsigned int ui = n; - return count_trailing_zeros (~ui); + return stdc_trailing_zeros_uc (~n); } _GL_STDBIT_INLINE unsigned int stdc_trailing_ones_us (unsigned short int n) { - unsigned int ui = n; - return count_trailing_zeros (~ui); + return stdc_trailing_zeros_us (~n); } _GL_STDBIT_INLINE unsigned int stdc_trailing_ones_ui (unsigned int n) { - return count_trailing_zeros (~n); + return stdc_trailing_zeros_ui (~n); } _GL_STDBIT_INLINE unsigned int stdc_trailing_ones_ul (unsigned long int n) { - return count_trailing_zeros_l (~n); + return stdc_trailing_zeros_ul (~n); } _GL_STDBIT_INLINE unsigned int stdc_trailing_ones_ull (unsigned long long int n) { - return count_trailing_zeros_ll (~n); + return stdc_trailing_zeros_ull (~n); } #define stdc_trailing_ones(n) \ @@ -392,81 +389,79 @@ stdc_first_trailing_one_ull (unsigned long long int n) _GL_STDBIT_INLINE unsigned int -stdc_count_zeros_uc (unsigned char n) +stdc_count_ones_ui (unsigned int n) { - unsigned int ui = n; - return count_one_bits (~ui) - 8 * (sizeof ui - sizeof n); + return count_one_bits (n); } _GL_STDBIT_INLINE unsigned int -stdc_count_zeros_us (unsigned short int n) +stdc_count_ones_uc (unsigned char n) { - unsigned int ui = n; - return count_one_bits (~ui) - 8 * (sizeof ui - sizeof n); + return stdc_count_ones_ui (n); } _GL_STDBIT_INLINE unsigned int -stdc_count_zeros_ui (unsigned int n) +stdc_count_ones_us (unsigned short int n) { - return count_one_bits (~n); + return stdc_count_ones_ui (n); } _GL_STDBIT_INLINE unsigned int -stdc_count_zeros_ul (unsigned long int n) +stdc_count_ones_ul (unsigned long int n) { - return count_one_bits_l (~n); + return count_one_bits_l (n); } _GL_STDBIT_INLINE unsigned int -stdc_count_zeros_ull (unsigned long long int n) +stdc_count_ones_ull (unsigned long long int n) { - return count_one_bits_ll (~n); + return count_one_bits_ll (n); } -#define stdc_count_zeros(n) \ - (sizeof (n) == 1 ? stdc_count_zeros_uc (n) \ - : sizeof (n) == sizeof (unsigned short int) ? stdc_count_zeros_us (n) \ - : sizeof (n) == sizeof 0u ? stdc_count_zeros_ui (n) \ - : sizeof (n) == sizeof 0ul ? stdc_count_zeros_ul (n) \ - : stdc_count_zeros_ull (n)) +#define stdc_count_ones(n) \ + (sizeof (n) == 1 ? stdc_count_ones_uc (n) \ + : sizeof (n) == sizeof (unsigned short int) ? stdc_count_ones_us (n) \ + : sizeof (n) == sizeof 0u ? stdc_count_ones_ui (n) \ + : sizeof (n) == sizeof 0ul ? stdc_count_ones_ul (n) \ + : stdc_count_ones_ull (n)) _GL_STDBIT_INLINE unsigned int -stdc_count_ones_uc (unsigned char n) +stdc_count_zeros_uc (unsigned char n) { - return count_one_bits (n); + return stdc_count_ones_uc (~n); } _GL_STDBIT_INLINE unsigned int -stdc_count_ones_us (unsigned short int n) +stdc_count_zeros_us (unsigned short int n) { - return count_one_bits (n); + return stdc_count_ones_us (~n); } _GL_STDBIT_INLINE unsigned int -stdc_count_ones_ui (unsigned int n) +stdc_count_zeros_ui (unsigned int n) { - return count_one_bits (n); + return stdc_count_ones_ui (~n); } _GL_STDBIT_INLINE unsigned int -stdc_count_ones_ul (unsigned long int n) +stdc_count_zeros_ul (unsigned long int n) { - return count_one_bits_l (n); + return stdc_count_ones_ul (~n); } _GL_STDBIT_INLINE unsigned int -stdc_count_ones_ull (unsigned long long int n) +stdc_count_zeros_ull (unsigned long long int n) { - return count_one_bits_ll (n); + return stdc_count_ones_ull (~n); } -#define stdc_count_ones(n) \ - (sizeof (n) == 1 ? stdc_count_ones_uc (n) \ - : sizeof (n) == sizeof (unsigned short int) ? stdc_count_ones_us (n) \ - : sizeof (n) == sizeof 0u ? stdc_count_ones_ui (n) \ - : sizeof (n) == sizeof 0ul ? stdc_count_ones_ul (n) \ - : stdc_count_ones_ull (n)) +#define stdc_count_zeros(n) \ + (sizeof (n) == 1 ? stdc_count_zeros_uc (n) \ + : sizeof (n) == sizeof (unsigned short int) ? stdc_count_zeros_us (n) \ + : sizeof (n) == sizeof 0u ? stdc_count_zeros_ui (n) \ + : sizeof (n) == sizeof 0ul ? stdc_count_zeros_ul (n) \ + : stdc_count_zeros_ull (n)) _GL_STDBIT_INLINE bool diff --git a/modules/stdbit-tests b/modules/stdbit-tests new file mode 100644 index 0000000000..4ef358aca9 --- /dev/null +++ b/modules/stdbit-tests @@ -0,0 +1,42 @@ +Files: +tests/macros.h +tests/support/test-driver.c +tests/tst-stdbit.h +tests/tst-stdc_bit_ceil.c +tests/tst-stdc_bit_floor.c +tests/tst-stdc_bit_width.c +tests/tst-stdc_count_ones.c +tests/tst-stdc_count_zeros.c +tests/tst-stdc_first_leading_one.c +tests/tst-stdc_first_leading_zero.c +tests/tst-stdc_first_trailing_one.c +tests/tst-stdc_first_trailing_zero.c +tests/tst-stdc_has_single_bit.c +tests/tst-stdc_leading_ones.c +tests/tst-stdc_leading_zeros.c +tests/tst-stdc_trailing_ones.c +tests/tst-stdc_trailing_zeros.c + +Depends-on: +assert-h +libc-config +stdint + +configure.ac: + +Makefile.am: +TESTS += \ + tst-stdc_bit_ceil tst-stdc_bit_floor tst-stdc_bit_width \ + tst-stdc_count_ones tst-stdc_count_zeros tst-stdc_first_leading_one \ + tst-stdc_first_leading_zero tst-stdc_first_trailing_one \ + tst-stdc_first_trailing_zero tst-stdc_has_single_bit \ + tst-stdc_leading_ones tst-stdc_leading_zeros tst-stdc_trailing_ones \ + tst-stdc_trailing_zeros + +check_PROGRAMS += \ + tst-stdc_bit_ceil tst-stdc_bit_floor tst-stdc_bit_width \ + tst-stdc_count_ones tst-stdc_count_zeros tst-stdc_first_leading_one \ + tst-stdc_first_leading_zero tst-stdc_first_trailing_one \ + tst-stdc_first_trailing_zero tst-stdc_has_single_bit \ + tst-stdc_leading_ones tst-stdc_leading_zeros tst-stdc_trailing_ones \ + tst-stdc_trailing_zeros diff --git a/tests/support/test-driver.c b/tests/support/test-driver.c new file mode 100644 index 0000000000..84ac82ec24 --- /dev/null +++ b/tests/support/test-driver.c @@ -0,0 +1,5 @@ +int +main (void) +{ + return do_test (); +} diff --git a/tests/tst-stdbit.h b/tests/tst-stdbit.h new file mode 100644 index 0000000000..b40d7447bf --- /dev/null +++ b/tests/tst-stdbit.h @@ -0,0 +1,225 @@ +/* Common test support for <stdbit.h> tests. + 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/>. */ + +#ifndef _TST_STDBIT_H +#define _TST_STDBIT_H + +#if HAVE_CONFIG_H +# include <libc-config.h> +#endif + +#include <stdbit.h> +#include <stdbool.h> + +#if !HAVE_CONFIG_H +# include <array_length.h> +# include <support/check.h> +#else +# include <stdint.h> +# include <macros.h> +# define array_length(a) (sizeof (a) / sizeof *(a)) +# define TEST_COMPARE(a, b) ASSERT ((a) == (b)) +#endif + +struct stdbit_test +{ + /* The test input. */ + uint64_t x; + /* Expected results if that test input is converted to 8, 16, 32 or + 64 bits and then passed to the function under test for that + width. */ + uint64_t res_8, res_16, res_32, res_64; +}; + +#if !HAVE_CONFIG_H +# define TEST_TYPE(EXPR, TYPE) \ + _Static_assert (_Generic ((EXPR), TYPE: 1, default: 0), "bad type") +#elif ((defined __GNUC__ && 2 <= __GNUC__) \ + || (defined __clang_major__ && 4 <= __clang_major__) \ + || (defined __IBMC__ && 1210 <= __IBMC__ && defined __IBM__TYPEOF__) \ + || (defined __SUNPRO_C && 0x5110 <= __SUNPRO_C && !__STDC__) \ + || 202311 <= __STDC_VERSION__) +# if __HAVE_GENERIC_SELECTION +# define TEST_TYPE(EXPR, TYPE) \ + static_assert (_Generic (EXPR, TYPE: 1, default: 0)) +# else +# define TEST_TYPE(EXPR, TYPE) static_assert (sizeof (EXPR) == sizeof (TYPE)) +# endif +#else +/* A pre-C11 platform that lacks typeof. */ +# define TEST_TYPE(EXPR, TYPE) static_assert (sizeof (TYPE) <= sizeof (EXPR)) +#endif + +/* Test a <stdbit.h> function / macro. For each function family, and + each input type, we test both with and without macros from the + header being used, both with a possibly wider argument being passed + (that must be truncated by the prototype) and with the argument + truncated in the caller, as well as testing the type-generic macro + (with the argument truncated in the caller). Also test that the + results have the correct type; also test truncation from + floating-point arguments (valid for functions, including with macro + expansion, because the prototype must implicitly convert to integer + type; not valid for the type-generic macros). Also test that the + argument is evaluated exactly once. Also test the macros are + usable (e.g. in typeof) at top level (GCC doesn't allow ({}) + outside functions: bug 93239). */ + +#define TEST_STDBIT_T(FUNC, X, RES, TTYPE, TYPE, SUFFIX) \ + do \ + { \ + TEST_COMPARE (FUNC ## SUFFIX (X), (RES)); \ + TEST_TYPE (FUNC ## SUFFIX (X), TTYPE); \ + TEST_COMPARE ((FUNC ## SUFFIX) (X), (RES)); \ + TEST_TYPE ((FUNC ## SUFFIX) (X), TTYPE); \ + TEST_COMPARE (FUNC ## SUFFIX ((TYPE) (X)), (RES)); \ + TEST_TYPE (FUNC ## SUFFIX ((TYPE) (X)), TTYPE); \ + TEST_COMPARE ((FUNC ## SUFFIX) ((TYPE) (X)), (RES)); \ + TEST_TYPE ((FUNC ## SUFFIX) ((TYPE) (X)), TTYPE); \ + TEST_COMPARE (FUNC ((TYPE) (X)), (RES)); \ + TEST_TYPE (FUNC ((TYPE) (X)), TTYPE); \ + if (sizeof (TYPE) <= 2) \ + { \ + TEST_COMPARE (FUNC ## SUFFIX ((float) (TYPE) (X)), (RES)); \ + TEST_TYPE (FUNC ## SUFFIX ((float) (TYPE) (X)), TTYPE); \ + TEST_COMPARE ((FUNC ## SUFFIX) ((float) (TYPE) (X)), (RES)); \ + TEST_TYPE ((FUNC ## SUFFIX) ((float) (TYPE) (X)), TTYPE); \ + } \ + if (sizeof (TYPE) <= 4) \ + { \ + TEST_COMPARE (FUNC ## SUFFIX ((double) (TYPE) (X)), (RES)); \ + TEST_TYPE (FUNC ## SUFFIX ((double) (TYPE) (X)), TTYPE); \ + TEST_COMPARE ((FUNC ## SUFFIX) ((double) (TYPE) (X)), (RES)); \ + TEST_TYPE ((FUNC ## SUFFIX) ((double) (TYPE) (X)), TTYPE); \ + TEST_COMPARE (FUNC ## SUFFIX ((long double) (TYPE) (X)), (RES)); \ + TEST_TYPE (FUNC ## SUFFIX ((long double) (TYPE) (X)), TTYPE); \ + TEST_COMPARE ((FUNC ## SUFFIX) ((long double) (TYPE) (X)), (RES)); \ + TEST_TYPE ((FUNC ## SUFFIX) ((long double) (TYPE) (X)), TTYPE); \ + } \ + TYPE xt = (X); \ + TEST_COMPARE (FUNC ## SUFFIX (xt++), (RES)); \ + TEST_COMPARE (xt, (TYPE) ((X) + 1)); \ + xt = (X); \ + TEST_COMPARE (FUNC (xt++), (RES)); \ + TEST_COMPARE (xt, (TYPE) ((X) + 1)); \ + } \ + while (0) + +#define TEST_STDBIT_UI(FUNC, INPUTS) \ + do \ + for (int i = 0; i < array_length (INPUTS); i++) \ + { \ + uint64_t x = (INPUTS)[i].x; \ + unsigned int res_8 = (INPUTS)[i].res_8; \ + unsigned int res_16 = (INPUTS)[i].res_16; \ + unsigned int res_32 = (INPUTS)[i].res_32; \ + unsigned int res_64 = (INPUTS)[i].res_64; \ + unsigned int res_l = (sizeof (long int) == 4 \ + ? res_32 : res_64); \ + TEST_STDBIT_T (FUNC, x, res_8, unsigned int, \ + unsigned char, _uc); \ + TEST_STDBIT_T (FUNC, x, res_16, unsigned int, \ + unsigned short, _us); \ + TEST_STDBIT_T (FUNC, x, res_32, unsigned int, \ + unsigned int, _ui); \ + TEST_STDBIT_T (FUNC, x, res_l, unsigned int, \ + unsigned long int, _ul); \ + TEST_STDBIT_T (FUNC, x, res_64, unsigned int, \ + unsigned long long int, _ull); \ + } \ + while (0) + +#define TEST_STDBIT_BOOL(FUNC, INPUTS) \ + do \ + for (int i = 0; i < array_length (INPUTS); i++) \ + { \ + uint64_t x = (INPUTS)[i].x; \ + bool res_8 = (INPUTS)[i].res_8; \ + bool res_16 = (INPUTS)[i].res_16; \ + bool res_32 = (INPUTS)[i].res_32; \ + bool res_64 = (INPUTS)[i].res_64; \ + bool res_l = (sizeof (long int) == 4 ? res_32 : res_64); \ + TEST_STDBIT_T (FUNC, x, res_8, _Bool, unsigned char, _uc); \ + TEST_STDBIT_T (FUNC, x, res_16, _Bool, unsigned short, _us); \ + TEST_STDBIT_T (FUNC, x, res_32, _Bool, unsigned int, _ui); \ + TEST_STDBIT_T (FUNC, x, res_l, _Bool, unsigned long int, _ul); \ + TEST_STDBIT_T (FUNC, x, res_64, _Bool, \ + unsigned long long int, _ull); \ + } \ + while (0) + +#define TEST_STDBIT_SAME(FUNC, INPUTS) \ + do \ + for (int i = 0; i < array_length (INPUTS); i++) \ + { \ + uint64_t x = (INPUTS)[i].x; \ + unsigned char res_8 = (INPUTS)[i].res_8; \ + unsigned short res_16 = (INPUTS)[i].res_16; \ + unsigned int res_32 = (INPUTS)[i].res_32; \ + unsigned long long int res_64 = (INPUTS)[i].res_64; \ + unsigned long int res_l = (sizeof (long int) == 4 \ + ? res_32 : res_64); \ + TEST_STDBIT_T (FUNC, x, res_8, unsigned char, \ + unsigned char, _uc); \ + TEST_STDBIT_T (FUNC, x, res_16, unsigned short, \ + unsigned short, _us); \ + TEST_STDBIT_T (FUNC, x, res_32, unsigned int, \ + unsigned int, _ui); \ + TEST_STDBIT_T (FUNC, x, res_l, unsigned long int, \ + unsigned long int, _ul); \ + TEST_STDBIT_T (FUNC, x, res_64, unsigned long long int, \ + unsigned long long int, _ull); \ + } \ + while (0) + +#define TEST_STDBIT_UI_TOPLEVEL(FUNC) \ + TEST_TYPE (FUNC ## _uc ((unsigned char) 0), unsigned int); \ + TEST_TYPE (FUNC ((unsigned char) 0), unsigned int); \ + TEST_TYPE (FUNC ## _us ((unsigned short) 0), unsigned int); \ + TEST_TYPE (FUNC ((unsigned short) 0), unsigned int); \ + TEST_TYPE (FUNC ## _ui (0U), unsigned int); \ + TEST_TYPE (FUNC (0U), unsigned int); \ + TEST_TYPE (FUNC ## _ul (0UL), unsigned int); \ + TEST_TYPE (FUNC (0UL), unsigned int); \ + TEST_TYPE (FUNC ## _ull (0ULL), unsigned int); \ + TEST_TYPE (FUNC (0ULL), unsigned int) + +#define TEST_STDBIT_BOOL_TOPLEVEL(FUNC) \ + TEST_TYPE (FUNC ## _uc ((unsigned char) 0), _Bool); \ + TEST_TYPE (FUNC ((unsigned char) 0), _Bool); \ + TEST_TYPE (FUNC ## _us ((unsigned short) 0), _Bool); \ + TEST_TYPE (FUNC ((unsigned short) 0), _Bool); \ + TEST_TYPE (FUNC ## _ui (0U), _Bool); \ + TEST_TYPE (FUNC (0U), _Bool); \ + TEST_TYPE (FUNC ## _ul (0UL), _Bool); \ + TEST_TYPE (FUNC (0UL), _Bool); \ + TEST_TYPE (FUNC ## _ull (0ULL), _Bool); \ + TEST_TYPE (FUNC (0ULL), _Bool) + +#define TEST_STDBIT_SAME_TOPLEVEL(FUNC) \ + TEST_TYPE (FUNC ## _uc ((unsigned char) 0), unsigned char); \ + TEST_TYPE (FUNC ((unsigned char) 0), unsigned char); \ + TEST_TYPE (FUNC ## _us ((unsigned short) 0), unsigned short); \ + TEST_TYPE (FUNC ((unsigned short) 0), unsigned short); \ + TEST_TYPE (FUNC ## _ui (0U), unsigned int); \ + TEST_TYPE (FUNC (0U), unsigned int); \ + TEST_TYPE (FUNC ## _ul (0UL), unsigned long int); \ + TEST_TYPE (FUNC (0UL), unsigned long int); \ + TEST_TYPE (FUNC ## _ull (0ULL), unsigned long long int); \ + TEST_TYPE (FUNC (0ULL), unsigned long long int) + +#endif diff --git a/tests/tst-stdc_bit_ceil.c b/tests/tst-stdc_bit_ceil.c new file mode 100644 index 0000000000..9f2f327a3a --- /dev/null +++ b/tests/tst-stdc_bit_ceil.c @@ -0,0 +1,88 @@ +/* Test stdc_bit_ceil functions and macros. + 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 <tst-stdbit.h> + +static const struct stdbit_test inputs[] = + { + { 0ULL, 0x1, 0x1, 0x1, 0x1ULL }, + { 0x1ULL, 0x1, 0x1, 0x1, 0x1ULL }, + { 0x2ULL, 0x2, 0x2, 0x2, 0x2ULL }, + { 0x3ULL, 0x4, 0x4, 0x4, 0x4ULL }, + { 0x4ULL, 0x4, 0x4, 0x4, 0x4ULL }, + { 0x5ULL, 0x8, 0x8, 0x8, 0x8ULL }, + { 0x6ULL, 0x8, 0x8, 0x8, 0x8ULL }, + { 0x7ULL, 0x8, 0x8, 0x8, 0x8ULL }, + { 0x8ULL, 0x8, 0x8, 0x8, 0x8ULL }, + { 0x9ULL, 0x10, 0x10, 0x10, 0x10ULL }, + { 0xaULL, 0x10, 0x10, 0x10, 0x10ULL }, + { 0xbULL, 0x10, 0x10, 0x10, 0x10ULL }, + { 0xcULL, 0x10, 0x10, 0x10, 0x10ULL }, + { 0xdULL, 0x10, 0x10, 0x10, 0x10ULL }, + { 0xeULL, 0x10, 0x10, 0x10, 0x10ULL }, + { 0xfULL, 0x10, 0x10, 0x10, 0x10ULL }, + { 0x10ULL, 0x10, 0x10, 0x10, 0x10ULL }, + { 0x11ULL, 0x20, 0x20, 0x20, 0x20ULL }, + { 0x12ULL, 0x20, 0x20, 0x20, 0x20ULL }, + { 0x1fULL, 0x20, 0x20, 0x20, 0x20ULL }, + { 0x20ULL, 0x20, 0x20, 0x20, 0x20ULL }, + { 0x7fULL, 0x80, 0x80, 0x80, 0x80ULL }, + { 0x80ULL, 0x80, 0x80, 0x80, 0x80ULL }, + { 0x81ULL, 0, 0x100, 0x100, 0x100ULL }, + { 0x9aULL, 0, 0x100, 0x100, 0x100ULL }, + { 0xf3ULL, 0, 0x100, 0x100, 0x100ULL }, + { 0xffULL, 0, 0x100, 0x100, 0x100ULL }, + { 0x100ULL, 0x1, 0x100, 0x100, 0x100ULL }, + { 0x101ULL, 0x1, 0x200, 0x200, 0x200ULL }, + { 0x102ULL, 0x2, 0x200, 0x200, 0x200ULL }, + { 0x1feULL, 0, 0x200, 0x200, 0x200ULL }, + { 0x1ffULL, 0, 0x200, 0x200, 0x200ULL }, + { 0x200ULL, 0x1, 0x200, 0x200, 0x200ULL }, + { 0x234ULL, 0x40, 0x400, 0x400, 0x400ULL }, + { 0x4567ULL, 0x80, 0x8000, 0x8000, 0x8000ULL }, + { 0x7fffULL, 0, 0x8000, 0x8000, 0x8000ULL }, + { 0x8000ULL, 0x1, 0x8000, 0x8000, 0x8000ULL }, + { 0x8001ULL, 0x1, 0, 0x10000, 0x10000ULL }, + { 0xfffeULL, 0, 0, 0x10000, 0x10000ULL }, + { 0xffffULL, 0, 0, 0x10000, 0x10000ULL }, + { 0x10000ULL, 0x1, 0x1, 0x10000, 0x10000ULL }, + { 0x10001ULL, 0x1, 0x1, 0x20000, 0x20000ULL }, + { 0xfedcba98ULL, 0, 0, 0, 0x100000000ULL }, + { 0xfffffefeULL, 0, 0, 0, 0x100000000ULL }, + { 0xffffffffULL, 0, 0, 0, 0x100000000ULL }, + { 0x100000000ULL, 0x1, 0x1, 0x1, 0x100000000ULL }, + { 0x100000001ULL, 0x1, 0x1, 0x1, 0x200000000ULL }, + { 0x123456789ULL, 0, 0x8000, 0x40000000, 0x200000000ULL }, + { 0x123456789abcdefULL, 0, 0, 0, 0x200000000000000ULL }, + { 0x789abcdef0123456ULL, 0x80, 0x4000, 0, 0x8000000000000000ULL }, + { 0x8000000000000000ULL, 0x1, 0x1, 0x1, 0x8000000000000000ULL }, + { 0x8000000000000001ULL, 0x1, 0x1, 0x1, 0ULL }, + { 0xfffffffffffffffeULL, 0, 0, 0, 0ULL }, + { 0xffffffffffffffffULL, 0, 0, 0, 0ULL }, + }; + +TEST_STDBIT_SAME_TOPLEVEL (stdc_bit_ceil); + +static int +do_test (void) +{ + TEST_STDBIT_SAME (stdc_bit_ceil, inputs); + return 0; +} + +#include <support/test-driver.c> diff --git a/tests/tst-stdc_bit_floor.c b/tests/tst-stdc_bit_floor.c new file mode 100644 index 0000000000..3f1d0537fd --- /dev/null +++ b/tests/tst-stdc_bit_floor.c @@ -0,0 +1,88 @@ +/* Test stdc_bit_floor functions and macros. + 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 <tst-stdbit.h> + +static const struct stdbit_test inputs[] = + { + { 0ULL, 0, 0, 0, 0ULL }, + { 0x1ULL, 0x1, 0x1, 0x1, 0x1ULL }, + { 0x2ULL, 0x2, 0x2, 0x2, 0x2ULL }, + { 0x3ULL, 0x2, 0x2, 0x2, 0x2ULL }, + { 0x4ULL, 0x4, 0x4, 0x4, 0x4ULL }, + { 0x5ULL, 0x4, 0x4, 0x4, 0x4ULL }, + { 0x6ULL, 0x4, 0x4, 0x4, 0x4ULL }, + { 0x7ULL, 0x4, 0x4, 0x4, 0x4ULL }, + { 0x8ULL, 0x8, 0x8, 0x8, 0x8ULL }, + { 0x9ULL, 0x8, 0x8, 0x8, 0x8ULL }, + { 0xaULL, 0x8, 0x8, 0x8, 0x8ULL }, + { 0xbULL, 0x8, 0x8, 0x8, 0x8ULL }, + { 0xcULL, 0x8, 0x8, 0x8, 0x8ULL }, + { 0xdULL, 0x8, 0x8, 0x8, 0x8ULL }, + { 0xeULL, 0x8, 0x8, 0x8, 0x8ULL }, + { 0xfULL, 0x8, 0x8, 0x8, 0x8ULL }, + { 0x10ULL, 0x10, 0x10, 0x10, 0x10ULL }, + { 0x11ULL, 0x10, 0x10, 0x10, 0x10ULL }, + { 0x12ULL, 0x10, 0x10, 0x10, 0x10ULL }, + { 0x1fULL, 0x10, 0x10, 0x10, 0x10ULL }, + { 0x20ULL, 0x20, 0x20, 0x20, 0x20ULL }, + { 0x7fULL, 0x40, 0x40, 0x40, 0x40ULL }, + { 0x80ULL, 0x80, 0x80, 0x80, 0x80ULL }, + { 0x81ULL, 0x80, 0x80, 0x80, 0x80ULL }, + { 0x9aULL, 0x80, 0x80, 0x80, 0x80ULL }, + { 0xf3ULL, 0x80, 0x80, 0x80, 0x80ULL }, + { 0xffULL, 0x80, 0x80, 0x80, 0x80ULL }, + { 0x100ULL, 0, 0x100, 0x100, 0x100ULL }, + { 0x101ULL, 0x1, 0x100, 0x100, 0x100ULL }, + { 0x102ULL, 0x2, 0x100, 0x100, 0x100ULL }, + { 0x1feULL, 0x80, 0x100, 0x100, 0x100ULL }, + { 0x1ffULL, 0x80, 0x100, 0x100, 0x100ULL }, + { 0x200ULL, 0, 0x200, 0x200, 0x200ULL }, + { 0x234ULL, 0x20, 0x200, 0x200, 0x200ULL }, + { 0x4567ULL, 0x40, 0x4000, 0x4000, 0x4000ULL }, + { 0x7fffULL, 0x80, 0x4000, 0x4000, 0x4000ULL }, + { 0x8000ULL, 0, 0x8000, 0x8000, 0x8000ULL }, + { 0x8001ULL, 0x1, 0x8000, 0x8000, 0x8000ULL }, + { 0xfffeULL, 0x80, 0x8000, 0x8000, 0x8000ULL }, + { 0xffffULL, 0x80, 0x8000, 0x8000, 0x8000ULL }, + { 0x10000ULL, 0, 0, 0x10000, 0x10000ULL }, + { 0x10001ULL, 0x1, 0x1, 0x10000, 0x10000ULL }, + { 0xfedcba98ULL, 0x80, 0x8000, 0x80000000, 0x80000000ULL }, + { 0xfffffefeULL, 0x80, 0x8000, 0x80000000, 0x80000000ULL }, + { 0xffffffffULL, 0x80, 0x8000, 0x80000000, 0x80000000ULL }, + { 0x100000000ULL, 0, 0, 0, 0x100000000ULL }, + { 0x100000001ULL, 0x1, 0x1, 0x1, 0x100000000ULL }, + { 0x123456789ULL, 0x80, 0x4000, 0x20000000, 0x100000000ULL }, + { 0x123456789abcdefULL, 0x80, 0x8000, 0x80000000, 0x100000000000000ULL }, + { 0x789abcdef0123456ULL, 0x40, 0x2000, 0x80000000, 0x4000000000000000ULL }, + { 0x8000000000000000ULL, 0, 0, 0, 0x8000000000000000ULL }, + { 0x8000000000000001ULL, 0x1, 0x1, 0x1, 0x8000000000000000ULL }, + { 0xfffffffffffffffeULL, 0x80, 0x8000, 0x80000000, 0x8000000000000000ULL }, + { 0xffffffffffffffffULL, 0x80, 0x8000, 0x80000000, 0x8000000000000000ULL }, + }; + +TEST_STDBIT_SAME_TOPLEVEL (stdc_bit_floor); + +static int +do_test (void) +{ + TEST_STDBIT_SAME (stdc_bit_floor, inputs); + return 0; +} + +#include <support/test-driver.c> diff --git a/tests/tst-stdc_bit_width.c b/tests/tst-stdc_bit_width.c new file mode 100644 index 0000000000..b3bb6f6818 --- /dev/null +++ b/tests/tst-stdc_bit_width.c @@ -0,0 +1,88 @@ +/* Test stdc_bit_width functions and macros. + 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 <tst-stdbit.h> + +static const struct stdbit_test inputs[] = + { + { 0ULL, 0, 0, 0, 0 }, + { 0x1ULL, 1, 1, 1, 1 }, + { 0x2ULL, 2, 2, 2, 2 }, + { 0x3ULL, 2, 2, 2, 2 }, + { 0x4ULL, 3, 3, 3, 3 }, + { 0x5ULL, 3, 3, 3, 3 }, + { 0x6ULL, 3, 3, 3, 3 }, + { 0x7ULL, 3, 3, 3, 3 }, + { 0x8ULL, 4, 4, 4, 4 }, + { 0x9ULL, 4, 4, 4, 4 }, + { 0xaULL, 4, 4, 4, 4 }, + { 0xbULL, 4, 4, 4, 4 }, + { 0xcULL, 4, 4, 4, 4 }, + { 0xdULL, 4, 4, 4, 4 }, + { 0xeULL, 4, 4, 4, 4 }, + { 0xfULL, 4, 4, 4, 4 }, + { 0x10ULL, 5, 5, 5, 5 }, + { 0x11ULL, 5, 5, 5, 5 }, + { 0x12ULL, 5, 5, 5, 5 }, + { 0x1fULL, 5, 5, 5, 5 }, + { 0x20ULL, 6, 6, 6, 6 }, + { 0x7fULL, 7, 7, 7, 7 }, + { 0x80ULL, 8, 8, 8, 8 }, + { 0x81ULL, 8, 8, 8, 8 }, + { 0x9aULL, 8, 8, 8, 8 }, + { 0xf3ULL, 8, 8, 8, 8 }, + { 0xffULL, 8, 8, 8, 8 }, + { 0x100ULL, 0, 9, 9, 9 }, + { 0x101ULL, 1, 9, 9, 9 }, + { 0x102ULL, 2, 9, 9, 9 }, + { 0x1feULL, 8, 9, 9, 9 }, + { 0x1ffULL, 8, 9, 9, 9 }, + { 0x200ULL, 0, 10, 10, 10 }, + { 0x234ULL, 6, 10, 10, 10 }, + { 0x4567ULL, 7, 15, 15, 15 }, + { 0x7fffULL, 8, 15, 15, 15 }, + { 0x8000ULL, 0, 16, 16, 16 }, + { 0x8001ULL, 1, 16, 16, 16 }, + { 0xfffeULL, 8, 16, 16, 16 }, + { 0xffffULL, 8, 16, 16, 16 }, + { 0x10000ULL, 0, 0, 17, 17 }, + { 0x10001ULL, 1, 1, 17, 17 }, + { 0xfedcba98ULL, 8, 16, 32, 32 }, + { 0xfffffefeULL, 8, 16, 32, 32 }, + { 0xffffffffULL, 8, 16, 32, 32 }, + { 0x100000000ULL, 0, 0, 0, 33 }, + { 0x100000001ULL, 1, 1, 1, 33 }, + { 0x123456789ULL, 8, 15, 30, 33 }, + { 0x123456789abcdefULL, 8, 16, 32, 57 }, + { 0x789abcdef0123456ULL, 7, 14, 32, 63 }, + { 0x8000000000000000ULL, 0, 0, 0, 64 }, + { 0x8000000000000001ULL, 1, 1, 1, 64 }, + { 0xfffffffffffffffeULL, 8, 16, 32, 64 }, + { 0xffffffffffffffffULL, 8, 16, 32, 64 }, + }; + +TEST_STDBIT_UI_TOPLEVEL (stdc_bit_width); + +static int +do_test (void) +{ + TEST_STDBIT_UI (stdc_bit_width, inputs); + return 0; +} + +#include <support/test-driver.c> diff --git a/tests/tst-stdc_count_ones.c b/tests/tst-stdc_count_ones.c new file mode 100644 index 0000000000..8f8e3a7233 --- /dev/null +++ b/tests/tst-stdc_count_ones.c @@ -0,0 +1,88 @@ +/* Test stdc_count_ones functions and macros. + 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 <tst-stdbit.h> + +static const struct stdbit_test inputs[] = + { + { 0ULL, 0, 0, 0, 0 }, + { 0x1ULL, 1, 1, 1, 1 }, + { 0x2ULL, 1, 1, 1, 1 }, + { 0x3ULL, 2, 2, 2, 2 }, + { 0x4ULL, 1, 1, 1, 1 }, + { 0x5ULL, 2, 2, 2, 2 }, + { 0x6ULL, 2, 2, 2, 2 }, + { 0x7ULL, 3, 3, 3, 3 }, + { 0x8ULL, 1, 1, 1, 1 }, + { 0x9ULL, 2, 2, 2, 2 }, + { 0xaULL, 2, 2, 2, 2 }, + { 0xbULL, 3, 3, 3, 3 }, + { 0xcULL, 2, 2, 2, 2 }, + { 0xdULL, 3, 3, 3, 3 }, + { 0xeULL, 3, 3, 3, 3 }, + { 0xfULL, 4, 4, 4, 4 }, + { 0x10ULL, 1, 1, 1, 1 }, + { 0x11ULL, 2, 2, 2, 2 }, + { 0x12ULL, 2, 2, 2, 2 }, + { 0x1fULL, 5, 5, 5, 5 }, + { 0x20ULL, 1, 1, 1, 1 }, + { 0x7fULL, 7, 7, 7, 7 }, + { 0x80ULL, 1, 1, 1, 1 }, + { 0x81ULL, 2, 2, 2, 2 }, + { 0x9aULL, 4, 4, 4, 4 }, + { 0xf3ULL, 6, 6, 6, 6 }, + { 0xffULL, 8, 8, 8, 8 }, + { 0x100ULL, 0, 1, 1, 1 }, + { 0x101ULL, 1, 2, 2, 2 }, + { 0x102ULL, 1, 2, 2, 2 }, + { 0x1feULL, 7, 8, 8, 8 }, + { 0x1ffULL, 8, 9, 9, 9 }, + { 0x200ULL, 0, 1, 1, 1 }, + { 0x234ULL, 3, 4, 4, 4 }, + { 0x4567ULL, 5, 8, 8, 8 }, + { 0x7fffULL, 8, 15, 15, 15 }, + { 0x8000ULL, 0, 1, 1, 1 }, + { 0x8001ULL, 1, 2, 2, 2 }, + { 0xfffeULL, 7, 15, 15, 15 }, + { 0xffffULL, 8, 16, 16, 16 }, + { 0x10000ULL, 0, 0, 1, 1 }, + { 0x10001ULL, 1, 1, 2, 2 }, + { 0xfedcba98ULL, 3, 8, 20, 20 }, + { 0xfffffefeULL, 7, 14, 30, 30 }, + { 0xffffffffULL, 8, 16, 32, 32 }, + { 0x100000000ULL, 0, 0, 0, 1 }, + { 0x100000001ULL, 1, 1, 1, 2 }, + { 0x123456789ULL, 3, 8, 14, 15 }, + { 0x123456789abcdefULL, 7, 12, 20, 32 }, + { 0x789abcdef0123456ULL, 4, 7, 13, 32 }, + { 0x8000000000000000ULL, 0, 0, 0, 1 }, + { 0x8000000000000001ULL, 1, 1, 1, 2 }, + { 0xfffffffffffffffeULL, 7, 15, 31, 63 }, + { 0xffffffffffffffffULL, 8, 16, 32, 64 }, + }; + +TEST_STDBIT_UI_TOPLEVEL (stdc_count_ones); + +static int +do_test (void) +{ + TEST_STDBIT_UI (stdc_count_ones, inputs); + return 0; +} + +#include <support/test-driver.c> diff --git a/tests/tst-stdc_count_zeros.c b/tests/tst-stdc_count_zeros.c new file mode 100644 index 0000000000..cb72c83e1a --- /dev/null +++ b/tests/tst-stdc_count_zeros.c @@ -0,0 +1,88 @@ +/* Test stdc_count_zeros functions and macros. + 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 <tst-stdbit.h> + +static const struct stdbit_test inputs[] = + { + { 0ULL, 8, 16, 32, 64 }, + { 0x1ULL, 7, 15, 31, 63 }, + { 0x2ULL, 7, 15, 31, 63 }, + { 0x3ULL, 6, 14, 30, 62 }, + { 0x4ULL, 7, 15, 31, 63 }, + { 0x5ULL, 6, 14, 30, 62 }, + { 0x6ULL, 6, 14, 30, 62 }, + { 0x7ULL, 5, 13, 29, 61 }, + { 0x8ULL, 7, 15, 31, 63 }, + { 0x9ULL, 6, 14, 30, 62 }, + { 0xaULL, 6, 14, 30, 62 }, + { 0xbULL, 5, 13, 29, 61 }, + { 0xcULL, 6, 14, 30, 62 }, + { 0xdULL, 5, 13, 29, 61 }, + { 0xeULL, 5, 13, 29, 61 }, + { 0xfULL, 4, 12, 28, 60 }, + { 0x10ULL, 7, 15, 31, 63 }, + { 0x11ULL, 6, 14, 30, 62 }, + { 0x12ULL, 6, 14, 30, 62 }, + { 0x1fULL, 3, 11, 27, 59 }, + { 0x20ULL, 7, 15, 31, 63 }, + { 0x7fULL, 1, 9, 25, 57 }, + { 0x80ULL, 7, 15, 31, 63 }, + { 0x81ULL, 6, 14, 30, 62 }, + { 0x9aULL, 4, 12, 28, 60 }, + { 0xf3ULL, 2, 10, 26, 58 }, + { 0xffULL, 0, 8, 24, 56 }, + { 0x100ULL, 8, 15, 31, 63 }, + { 0x101ULL, 7, 14, 30, 62 }, + { 0x102ULL, 7, 14, 30, 62 }, + { 0x1feULL, 1, 8, 24, 56 }, + { 0x1ffULL, 0, 7, 23, 55 }, + { 0x200ULL, 8, 15, 31, 63 }, + { 0x234ULL, 5, 12, 28, 60 }, + { 0x4567ULL, 3, 8, 24, 56 }, + { 0x7fffULL, 0, 1, 17, 49 }, + { 0x8000ULL, 8, 15, 31, 63 }, + { 0x8001ULL, 7, 14, 30, 62 }, + { 0xfffeULL, 1, 1, 17, 49 }, + { 0xffffULL, 0, 0, 16, 48 }, + { 0x10000ULL, 8, 16, 31, 63 }, + { 0x10001ULL, 7, 15, 30, 62 }, + { 0xfedcba98ULL, 5, 8, 12, 44 }, + { 0xfffffefeULL, 1, 2, 2, 34 }, + { 0xffffffffULL, 0, 0, 0, 32 }, + { 0x100000000ULL, 8, 16, 32, 63 }, + { 0x100000001ULL, 7, 15, 31, 62 }, + { 0x123456789ULL, 5, 8, 18, 49 }, + { 0x123456789abcdefULL, 1, 4, 12, 32 }, + { 0x789abcdef0123456ULL, 4, 9, 19, 32 }, + { 0x8000000000000000ULL, 8, 16, 32, 63 }, + { 0x8000000000000001ULL, 7, 15, 31, 62 }, + { 0xfffffffffffffffeULL, 1, 1, 1, 1 }, + { 0xffffffffffffffffULL, 0, 0, 0, 0 }, + }; + +TEST_STDBIT_UI_TOPLEVEL (stdc_count_zeros); + +static int +do_test (void) +{ + TEST_STDBIT_UI (stdc_count_zeros, inputs); + return 0; +} + +#include <support/test-driver.c> diff --git a/tests/tst-stdc_first_leading_one.c b/tests/tst-stdc_first_leading_one.c new file mode 100644 index 0000000000..63f24bd5fe --- /dev/null +++ b/tests/tst-stdc_first_leading_one.c @@ -0,0 +1,88 @@ +/* Test stdc_first_leading_one functions and macros. + 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 <tst-stdbit.h> + +static const struct stdbit_test inputs[] = + { + { 0ULL, 0, 0, 0, 0 }, + { 0x1ULL, 8, 16, 32, 64 }, + { 0x2ULL, 7, 15, 31, 63 }, + { 0x3ULL, 7, 15, 31, 63 }, + { 0x4ULL, 6, 14, 30, 62 }, + { 0x5ULL, 6, 14, 30, 62 }, + { 0x6ULL, 6, 14, 30, 62 }, + { 0x7ULL, 6, 14, 30, 62 }, + { 0x8ULL, 5, 13, 29, 61 }, + { 0x9ULL, 5, 13, 29, 61 }, + { 0xaULL, 5, 13, 29, 61 }, + { 0xbULL, 5, 13, 29, 61 }, + { 0xcULL, 5, 13, 29, 61 }, + { 0xdULL, 5, 13, 29, 61 }, + { 0xeULL, 5, 13, 29, 61 }, + { 0xfULL, 5, 13, 29, 61 }, + { 0x10ULL, 4, 12, 28, 60 }, + { 0x11ULL, 4, 12, 28, 60 }, + { 0x12ULL, 4, 12, 28, 60 }, + { 0x1fULL, 4, 12, 28, 60 }, + { 0x20ULL, 3, 11, 27, 59 }, + { 0x7fULL, 2, 10, 26, 58 }, + { 0x80ULL, 1, 9, 25, 57 }, + { 0x81ULL, 1, 9, 25, 57 }, + { 0x9aULL, 1, 9, 25, 57 }, + { 0xf3ULL, 1, 9, 25, 57 }, + { 0xffULL, 1, 9, 25, 57 }, + { 0x100ULL, 0, 8, 24, 56 }, + { 0x101ULL, 8, 8, 24, 56 }, + { 0x102ULL, 7, 8, 24, 56 }, + { 0x1feULL, 1, 8, 24, 56 }, + { 0x1ffULL, 1, 8, 24, 56 }, + { 0x200ULL, 0, 7, 23, 55 }, + { 0x234ULL, 3, 7, 23, 55 }, + { 0x4567ULL, 2, 2, 18, 50 }, + { 0x7fffULL, 1, 2, 18, 50 }, + { 0x8000ULL, 0, 1, 17, 49 }, + { 0x8001ULL, 8, 1, 17, 49 }, + { 0xfffeULL, 1, 1, 17, 49 }, + { 0xffffULL, 1, 1, 17, 49 }, + { 0x10000ULL, 0, 0, 16, 48 }, + { 0x10001ULL, 8, 16, 16, 48 }, + { 0xfedcba98ULL, 1, 1, 1, 33 }, + { 0xfffffefeULL, 1, 1, 1, 33 }, + { 0xffffffffULL, 1, 1, 1, 33 }, + { 0x100000000ULL, 0, 0, 0, 32 }, + { 0x100000001ULL, 8, 16, 32, 32 }, + { 0x123456789ULL, 1, 2, 3, 32 }, + { 0x123456789abcdefULL, 1, 1, 1, 8 }, + { 0x789abcdef0123456ULL, 2, 3, 1, 2 }, + { 0x8000000000000000ULL, 0, 0, 0, 1 }, + { 0x8000000000000001ULL, 8, 16, 32, 1 }, + { 0xfffffffffffffffeULL, 1, 1, 1, 1 }, + { 0xffffffffffffffffULL, 1, 1, 1, 1 }, + }; + +TEST_STDBIT_UI_TOPLEVEL (stdc_first_leading_one); + +static int +do_test (void) +{ + TEST_STDBIT_UI (stdc_first_leading_one, inputs); + return 0; +} + +#include <support/test-driver.c> diff --git a/tests/tst-stdc_first_leading_zero.c b/tests/tst-stdc_first_leading_zero.c new file mode 100644 index 0000000000..b9d11677e3 --- /dev/null +++ b/tests/tst-stdc_first_leading_zero.c @@ -0,0 +1,88 @@ +/* Test stdc_first_leading_zero functions and macros. + 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 <tst-stdbit.h> + +static const struct stdbit_test inputs[] = + { + { 0ULL, 1, 1, 1, 1 }, + { 0x1ULL, 1, 1, 1, 1 }, + { 0x2ULL, 1, 1, 1, 1 }, + { 0x3ULL, 1, 1, 1, 1 }, + { 0x4ULL, 1, 1, 1, 1 }, + { 0x5ULL, 1, 1, 1, 1 }, + { 0x6ULL, 1, 1, 1, 1 }, + { 0x7ULL, 1, 1, 1, 1 }, + { 0x8ULL, 1, 1, 1, 1 }, + { 0x9ULL, 1, 1, 1, 1 }, + { 0xaULL, 1, 1, 1, 1 }, + { 0xbULL, 1, 1, 1, 1 }, + { 0xcULL, 1, 1, 1, 1 }, + { 0xdULL, 1, 1, 1, 1 }, + { 0xeULL, 1, 1, 1, 1 }, + { 0xfULL, 1, 1, 1, 1 }, + { 0x10ULL, 1, 1, 1, 1 }, + { 0x11ULL, 1, 1, 1, 1 }, + { 0x12ULL, 1, 1, 1, 1 }, + { 0x1fULL, 1, 1, 1, 1 }, + { 0x20ULL, 1, 1, 1, 1 }, + { 0x7fULL, 1, 1, 1, 1 }, + { 0x80ULL, 2, 1, 1, 1 }, + { 0x81ULL, 2, 1, 1, 1 }, + { 0x9aULL, 2, 1, 1, 1 }, + { 0xf3ULL, 5, 1, 1, 1 }, + { 0xffULL, 0, 1, 1, 1 }, + { 0x100ULL, 1, 1, 1, 1 }, + { 0x101ULL, 1, 1, 1, 1 }, + { 0x102ULL, 1, 1, 1, 1 }, + { 0x1feULL, 8, 1, 1, 1 }, + { 0x1ffULL, 0, 1, 1, 1 }, + { 0x200ULL, 1, 1, 1, 1 }, + { 0x234ULL, 1, 1, 1, 1 }, + { 0x4567ULL, 1, 1, 1, 1 }, + { 0x7fffULL, 0, 1, 1, 1 }, + { 0x8000ULL, 1, 2, 1, 1 }, + { 0x8001ULL, 1, 2, 1, 1 }, + { 0xfffeULL, 8, 16, 1, 1 }, + { 0xffffULL, 0, 0, 1, 1 }, + { 0x10000ULL, 1, 1, 1, 1 }, + { 0x10001ULL, 1, 1, 1, 1 }, + { 0xfedcba98ULL, 2, 2, 8, 1 }, + { 0xfffffefeULL, 8, 8, 24, 1 }, + { 0xffffffffULL, 0, 0, 0, 1 }, + { 0x100000000ULL, 1, 1, 1, 1 }, + { 0x100000001ULL, 1, 1, 1, 1 }, + { 0x123456789ULL, 2, 1, 1, 1 }, + { 0x123456789abcdefULL, 4, 3, 2, 1 }, + { 0x789abcdef0123456ULL, 1, 1, 5, 1 }, + { 0x8000000000000000ULL, 1, 1, 1, 2 }, + { 0x8000000000000001ULL, 1, 1, 1, 2 }, + { 0xfffffffffffffffeULL, 8, 16, 32, 64 }, + { 0xffffffffffffffffULL, 0, 0, 0, 0 }, + }; + +TEST_STDBIT_UI_TOPLEVEL (stdc_first_leading_zero); + +static int +do_test (void) +{ + TEST_STDBIT_UI (stdc_first_leading_zero, inputs); + return 0; +} + +#include <support/test-driver.c> diff --git a/tests/tst-stdc_first_trailing_one.c b/tests/tst-stdc_first_trailing_one.c new file mode 100644 index 0000000000..d4eeb22e0a --- /dev/null +++ b/tests/tst-stdc_first_trailing_one.c @@ -0,0 +1,88 @@ +/* Test stdc_first_trailing_one functions and macros. + 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 <tst-stdbit.h> + +static const struct stdbit_test inputs[] = + { + { 0ULL, 0, 0, 0, 0 }, + { 0x1ULL, 1, 1, 1, 1 }, + { 0x2ULL, 2, 2, 2, 2 }, + { 0x3ULL, 1, 1, 1, 1 }, + { 0x4ULL, 3, 3, 3, 3 }, + { 0x5ULL, 1, 1, 1, 1 }, + { 0x6ULL, 2, 2, 2, 2 }, + { 0x7ULL, 1, 1, 1, 1 }, + { 0x8ULL, 4, 4, 4, 4 }, + { 0x9ULL, 1, 1, 1, 1 }, + { 0xaULL, 2, 2, 2, 2 }, + { 0xbULL, 1, 1, 1, 1 }, + { 0xcULL, 3, 3, 3, 3 }, + { 0xdULL, 1, 1, 1, 1 }, + { 0xeULL, 2, 2, 2, 2 }, + { 0xfULL, 1, 1, 1, 1 }, + { 0x10ULL, 5, 5, 5, 5 }, + { 0x11ULL, 1, 1, 1, 1 }, + { 0x12ULL, 2, 2, 2, 2 }, + { 0x1fULL, 1, 1, 1, 1 }, + { 0x20ULL, 6, 6, 6, 6 }, + { 0x7fULL, 1, 1, 1, 1 }, + { 0x80ULL, 8, 8, 8, 8 }, + { 0x81ULL, 1, 1, 1, 1 }, + { 0x9aULL, 2, 2, 2, 2 }, + { 0xf3ULL, 1, 1, 1, 1 }, + { 0xffULL, 1, 1, 1, 1 }, + { 0x100ULL, 0, 9, 9, 9 }, + { 0x101ULL, 1, 1, 1, 1 }, + { 0x102ULL, 2, 2, 2, 2 }, + { 0x1feULL, 2, 2, 2, 2 }, + { 0x1ffULL, 1, 1, 1, 1 }, + { 0x200ULL, 0, 10, 10, 10 }, + { 0x234ULL, 3, 3, 3, 3 }, + { 0x4567ULL, 1, 1, 1, 1 }, + { 0x7fffULL, 1, 1, 1, 1 }, + { 0x8000ULL, 0, 16, 16, 16 }, + { 0x8001ULL, 1, 1, 1, 1 }, + { 0xfffeULL, 2, 2, 2, 2 }, + { 0xffffULL, 1, 1, 1, 1 }, + { 0x10000ULL, 0, 0, 17, 17 }, + { 0x10001ULL, 1, 1, 1, 1 }, + { 0xfedcba98ULL, 4, 4, 4, 4 }, + { 0xfffffefeULL, 2, 2, 2, 2 }, + { 0xffffffffULL, 1, 1, 1, 1 }, + { 0x100000000ULL, 0, 0, 0, 33 }, + { 0x100000001ULL, 1, 1, 1, 1 }, + { 0x123456789ULL, 1, 1, 1, 1 }, + { 0x123456789abcdefULL, 1, 1, 1, 1 }, + { 0x789abcdef0123456ULL, 2, 2, 2, 2 }, + { 0x8000000000000000ULL, 0, 0, 0, 64 }, + { 0x8000000000000001ULL, 1, 1, 1, 1 }, + { 0xfffffffffffffffeULL, 2, 2, 2, 2 }, + { 0xffffffffffffffffULL, 1, 1, 1, 1 }, + }; + +TEST_STDBIT_UI_TOPLEVEL (stdc_first_trailing_one); + +static int +do_test (void) +{ + TEST_STDBIT_UI (stdc_first_trailing_one, inputs); + return 0; +} + +#include <support/test-driver.c> diff --git a/tests/tst-stdc_first_trailing_zero.c b/tests/tst-stdc_first_trailing_zero.c new file mode 100644 index 0000000000..4a804e2d5f --- /dev/null +++ b/tests/tst-stdc_first_trailing_zero.c @@ -0,0 +1,88 @@ +/* Test stdc_first_trailing_zero functions and macros. + 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 <tst-stdbit.h> + +static const struct stdbit_test inputs[] = + { + { 0ULL, 1, 1, 1, 1 }, + { 0x1ULL, 2, 2, 2, 2 }, + { 0x2ULL, 1, 1, 1, 1 }, + { 0x3ULL, 3, 3, 3, 3 }, + { 0x4ULL, 1, 1, 1, 1 }, + { 0x5ULL, 2, 2, 2, 2 }, + { 0x6ULL, 1, 1, 1, 1 }, + { 0x7ULL, 4, 4, 4, 4 }, + { 0x8ULL, 1, 1, 1, 1 }, + { 0x9ULL, 2, 2, 2, 2 }, + { 0xaULL, 1, 1, 1, 1 }, + { 0xbULL, 3, 3, 3, 3 }, + { 0xcULL, 1, 1, 1, 1 }, + { 0xdULL, 2, 2, 2, 2 }, + { 0xeULL, 1, 1, 1, 1 }, + { 0xfULL, 5, 5, 5, 5 }, + { 0x10ULL, 1, 1, 1, 1 }, + { 0x11ULL, 2, 2, 2, 2 }, + { 0x12ULL, 1, 1, 1, 1 }, + { 0x1fULL, 6, 6, 6, 6 }, + { 0x20ULL, 1, 1, 1, 1 }, + { 0x7fULL, 8, 8, 8, 8 }, + { 0x80ULL, 1, 1, 1, 1 }, + { 0x81ULL, 2, 2, 2, 2 }, + { 0x9aULL, 1, 1, 1, 1 }, + { 0xf3ULL, 3, 3, 3, 3 }, + { 0xffULL, 0, 9, 9, 9 }, + { 0x100ULL, 1, 1, 1, 1 }, + { 0x101ULL, 2, 2, 2, 2 }, + { 0x102ULL, 1, 1, 1, 1 }, + { 0x1feULL, 1, 1, 1, 1 }, + { 0x1ffULL, 0, 10, 10, 10 }, + { 0x200ULL, 1, 1, 1, 1 }, + { 0x234ULL, 1, 1, 1, 1 }, + { 0x4567ULL, 4, 4, 4, 4 }, + { 0x7fffULL, 0, 16, 16, 16 }, + { 0x8000ULL, 1, 1, 1, 1 }, + { 0x8001ULL, 2, 2, 2, 2 }, + { 0xfffeULL, 1, 1, 1, 1 }, + { 0xffffULL, 0, 0, 17, 17 }, + { 0x10000ULL, 1, 1, 1, 1 }, + { 0x10001ULL, 2, 2, 2, 2 }, + { 0xfedcba98ULL, 1, 1, 1, 1 }, + { 0xfffffefeULL, 1, 1, 1, 1 }, + { 0xffffffffULL, 0, 0, 0, 33 }, + { 0x100000000ULL, 1, 1, 1, 1 }, + { 0x100000001ULL, 2, 2, 2, 2 }, + { 0x123456789ULL, 2, 2, 2, 2 }, + { 0x123456789abcdefULL, 5, 5, 5, 5 }, + { 0x789abcdef0123456ULL, 1, 1, 1, 1 }, + { 0x8000000000000000ULL, 1, 1, 1, 1 }, + { 0x8000000000000001ULL, 2, 2, 2, 2 }, + { 0xfffffffffffffffeULL, 1, 1, 1, 1 }, + { 0xffffffffffffffffULL, 0, 0, 0, 0 }, + }; + +TEST_STDBIT_UI_TOPLEVEL (stdc_first_trailing_zero); + +static int +do_test (void) +{ + TEST_STDBIT_UI (stdc_first_trailing_zero, inputs); + return 0; +} + +#include <support/test-driver.c> diff --git a/tests/tst-stdc_has_single_bit.c b/tests/tst-stdc_has_single_bit.c new file mode 100644 index 0000000000..2a2c855825 --- /dev/null +++ b/tests/tst-stdc_has_single_bit.c @@ -0,0 +1,88 @@ +/* Test stdc_has_single_bit functions and macros. + 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 <tst-stdbit.h> + +static const struct stdbit_test inputs[] = + { + { 0ULL, false, false, false, false }, + { 0x1ULL, true, true, true, true }, + { 0x2ULL, true, true, true, true }, + { 0x3ULL, false, false, false, false }, + { 0x4ULL, true, true, true, true }, + { 0x5ULL, false, false, false, false }, + { 0x6ULL, false, false, false, false }, + { 0x7ULL, false, false, false, false }, + { 0x8ULL, true, true, true, true }, + { 0x9ULL, false, false, false, false }, + { 0xaULL, false, false, false, false }, + { 0xbULL, false, false, false, false }, + { 0xcULL, false, false, false, false }, + { 0xdULL, false, false, false, false }, + { 0xeULL, false, false, false, false }, + { 0xfULL, false, false, false, false }, + { 0x10ULL, true, true, true, true }, + { 0x11ULL, false, false, false, false }, + { 0x12ULL, false, false, false, false }, + { 0x1fULL, false, false, false, false }, + { 0x20ULL, true, true, true, true }, + { 0x7fULL, false, false, false, false }, + { 0x80ULL, true, true, true, true }, + { 0x81ULL, false, false, false, false }, + { 0x9aULL, false, false, false, false }, + { 0xf3ULL, false, false, false, false }, + { 0xffULL, false, false, false, false }, + { 0x100ULL, false, true, true, true }, + { 0x101ULL, true, false, false, false }, + { 0x102ULL, true, false, false, false }, + { 0x1feULL, false, false, false, false }, + { 0x1ffULL, false, false, false, false }, + { 0x200ULL, false, true, true, true }, + { 0x234ULL, false, false, false, false }, + { 0x4567ULL, false, false, false, false }, + { 0x7fffULL, false, false, false, false }, + { 0x8000ULL, false, true, true, true }, + { 0x8001ULL, true, false, false, false }, + { 0xfffeULL, false, false, false, false }, + { 0xffffULL, false, false, false, false }, + { 0x10000ULL, false, false, true, true }, + { 0x10001ULL, true, true, false, false }, + { 0xfedcba98ULL, false, false, false, false }, + { 0xfffffefeULL, false, false, false, false }, + { 0xffffffffULL, false, false, false, false }, + { 0x100000000ULL, false, false, false, true }, + { 0x100000001ULL, true, true, true, false }, + { 0x123456789ULL, false, false, false, false }, + { 0x123456789abcdefULL, false, false, false, false }, + { 0x789abcdef0123456ULL, false, false, false, false }, + { 0x8000000000000000ULL, false, false, false, true }, + { 0x8000000000000001ULL, true, true, true, false }, + { 0xfffffffffffffffeULL, false, false, false, false }, + { 0xffffffffffffffffULL, false, false, false, false }, + }; + +TEST_STDBIT_BOOL_TOPLEVEL (stdc_has_single_bit); + +static int +do_test (void) +{ + TEST_STDBIT_BOOL (stdc_has_single_bit, inputs); + return 0; +} + +#include <support/test-driver.c> diff --git a/tests/tst-stdc_leading_ones.c b/tests/tst-stdc_leading_ones.c new file mode 100644 index 0000000000..8d8ccd5ecf --- /dev/null +++ b/tests/tst-stdc_leading_ones.c @@ -0,0 +1,88 @@ +/* Test stdc_leading_ones functions and macros. + 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 <tst-stdbit.h> + +static const struct stdbit_test inputs[] = + { + { 0ULL, 0, 0, 0, 0 }, + { 0x1ULL, 0, 0, 0, 0 }, + { 0x2ULL, 0, 0, 0, 0 }, + { 0x3ULL, 0, 0, 0, 0 }, + { 0x4ULL, 0, 0, 0, 0 }, + { 0x5ULL, 0, 0, 0, 0 }, + { 0x6ULL, 0, 0, 0, 0 }, + { 0x7ULL, 0, 0, 0, 0 }, + { 0x8ULL, 0, 0, 0, 0 }, + { 0x9ULL, 0, 0, 0, 0 }, + { 0xaULL, 0, 0, 0, 0 }, + { 0xbULL, 0, 0, 0, 0 }, + { 0xcULL, 0, 0, 0, 0 }, + { 0xdULL, 0, 0, 0, 0 }, + { 0xeULL, 0, 0, 0, 0 }, + { 0xfULL, 0, 0, 0, 0 }, + { 0x10ULL, 0, 0, 0, 0 }, + { 0x11ULL, 0, 0, 0, 0 }, + { 0x12ULL, 0, 0, 0, 0 }, + { 0x1fULL, 0, 0, 0, 0 }, + { 0x20ULL, 0, 0, 0, 0 }, + { 0x7fULL, 0, 0, 0, 0 }, + { 0x80ULL, 1, 0, 0, 0 }, + { 0x81ULL, 1, 0, 0, 0 }, + { 0x9aULL, 1, 0, 0, 0 }, + { 0xf3ULL, 4, 0, 0, 0 }, + { 0xffULL, 8, 0, 0, 0 }, + { 0x100ULL, 0, 0, 0, 0 }, + { 0x101ULL, 0, 0, 0, 0 }, + { 0x102ULL, 0, 0, 0, 0 }, + { 0x1feULL, 7, 0, 0, 0 }, + { 0x1ffULL, 8, 0, 0, 0 }, + { 0x200ULL, 0, 0, 0, 0 }, + { 0x234ULL, 0, 0, 0, 0 }, + { 0x4567ULL, 0, 0, 0, 0 }, + { 0x7fffULL, 8, 0, 0, 0 }, + { 0x8000ULL, 0, 1, 0, 0 }, + { 0x8001ULL, 0, 1, 0, 0 }, + { 0xfffeULL, 7, 15, 0, 0 }, + { 0xffffULL, 8, 16, 0, 0 }, + { 0x10000ULL, 0, 0, 0, 0 }, + { 0x10001ULL, 0, 0, 0, 0 }, + { 0xfedcba98ULL, 1, 1, 7, 0 }, + { 0xfffffefeULL, 7, 7, 23, 0 }, + { 0xffffffffULL, 8, 16, 32, 0 }, + { 0x100000000ULL, 0, 0, 0, 0 }, + { 0x100000001ULL, 0, 0, 0, 0 }, + { 0x123456789ULL, 1, 0, 0, 0 }, + { 0x123456789abcdefULL, 3, 2, 1, 0 }, + { 0x789abcdef0123456ULL, 0, 0, 4, 0 }, + { 0x8000000000000000ULL, 0, 0, 0, 1 }, + { 0x8000000000000001ULL, 0, 0, 0, 1 }, + { 0xfffffffffffffffeULL, 7, 15, 31, 63 }, + { 0xffffffffffffffffULL, 8, 16, 32, 64 }, + }; + +TEST_STDBIT_UI_TOPLEVEL (stdc_leading_ones); + +static int +do_test (void) +{ + TEST_STDBIT_UI (stdc_leading_ones, inputs); + return 0; +} + +#include <support/test-driver.c> diff --git a/tests/tst-stdc_leading_zeros.c b/tests/tst-stdc_leading_zeros.c new file mode 100644 index 0000000000..3452908d5b --- /dev/null +++ b/tests/tst-stdc_leading_zeros.c @@ -0,0 +1,88 @@ +/* Test stdc_leading_zeros functions and macros. + 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 <tst-stdbit.h> + +static const struct stdbit_test inputs[] = + { + { 0ULL, 8, 16, 32, 64 }, + { 0x1ULL, 7, 15, 31, 63 }, + { 0x2ULL, 6, 14, 30, 62 }, + { 0x3ULL, 6, 14, 30, 62 }, + { 0x4ULL, 5, 13, 29, 61 }, + { 0x5ULL, 5, 13, 29, 61 }, + { 0x6ULL, 5, 13, 29, 61 }, + { 0x7ULL, 5, 13, 29, 61 }, + { 0x8ULL, 4, 12, 28, 60 }, + { 0x9ULL, 4, 12, 28, 60 }, + { 0xaULL, 4, 12, 28, 60 }, + { 0xbULL, 4, 12, 28, 60 }, + { 0xcULL, 4, 12, 28, 60 }, + { 0xdULL, 4, 12, 28, 60 }, + { 0xeULL, 4, 12, 28, 60 }, + { 0xfULL, 4, 12, 28, 60 }, + { 0x10ULL, 3, 11, 27, 59 }, + { 0x11ULL, 3, 11, 27, 59 }, + { 0x12ULL, 3, 11, 27, 59 }, + { 0x1fULL, 3, 11, 27, 59 }, + { 0x20ULL, 2, 10, 26, 58 }, + { 0x7fULL, 1, 9, 25, 57 }, + { 0x80ULL, 0, 8, 24, 56 }, + { 0x81ULL, 0, 8, 24, 56 }, + { 0x9aULL, 0, 8, 24, 56 }, + { 0xf3ULL, 0, 8, 24, 56 }, + { 0xffULL, 0, 8, 24, 56 }, + { 0x100ULL, 8, 7, 23, 55 }, + { 0x101ULL, 7, 7, 23, 55 }, + { 0x102ULL, 6, 7, 23, 55 }, + { 0x1feULL, 0, 7, 23, 55 }, + { 0x1ffULL, 0, 7, 23, 55 }, + { 0x200ULL, 8, 6, 22, 54 }, + { 0x234ULL, 2, 6, 22, 54 }, + { 0x4567ULL, 1, 1, 17, 49 }, + { 0x7fffULL, 0, 1, 17, 49 }, + { 0x8000ULL, 8, 0, 16, 48 }, + { 0x8001ULL, 7, 0, 16, 48 }, + { 0xfffeULL, 0, 0, 16, 48 }, + { 0xffffULL, 0, 0, 16, 48 }, + { 0x10000ULL, 8, 16, 15, 47 }, + { 0x10001ULL, 7, 15, 15, 47 }, + { 0xfedcba98ULL, 0, 0, 0, 32 }, + { 0xfffffefeULL, 0, 0, 0, 32 }, + { 0xffffffffULL, 0, 0, 0, 32 }, + { 0x100000000ULL, 8, 16, 32, 31 }, + { 0x100000001ULL, 7, 15, 31, 31 }, + { 0x123456789ULL, 0, 1, 2, 31 }, + { 0x123456789abcdefULL, 0, 0, 0, 7 }, + { 0x789abcdef0123456ULL, 1, 2, 0, 1 }, + { 0x8000000000000000ULL, 8, 16, 32, 0 }, + { 0x8000000000000001ULL, 7, 15, 31, 0 }, + { 0xfffffffffffffffeULL, 0, 0, 0, 0 }, + { 0xffffffffffffffffULL, 0, 0, 0, 0 }, + }; + +TEST_STDBIT_UI_TOPLEVEL (stdc_leading_zeros); + +static int +do_test (void) +{ + TEST_STDBIT_UI (stdc_leading_zeros, inputs); + return 0; +} + +#include <support/test-driver.c> diff --git a/tests/tst-stdc_trailing_ones.c b/tests/tst-stdc_trailing_ones.c new file mode 100644 index 0000000000..6fcd9d8000 --- /dev/null +++ b/tests/tst-stdc_trailing_ones.c @@ -0,0 +1,88 @@ +/* Test stdc_trailing_ones functions and macros. + 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 <tst-stdbit.h> + +static const struct stdbit_test inputs[] = + { + { 0ULL, 0, 0, 0, 0 }, + { 0x1ULL, 1, 1, 1, 1 }, + { 0x2ULL, 0, 0, 0, 0 }, + { 0x3ULL, 2, 2, 2, 2 }, + { 0x4ULL, 0, 0, 0, 0 }, + { 0x5ULL, 1, 1, 1, 1 }, + { 0x6ULL, 0, 0, 0, 0 }, + { 0x7ULL, 3, 3, 3, 3 }, + { 0x8ULL, 0, 0, 0, 0 }, + { 0x9ULL, 1, 1, 1, 1 }, + { 0xaULL, 0, 0, 0, 0 }, + { 0xbULL, 2, 2, 2, 2 }, + { 0xcULL, 0, 0, 0, 0 }, + { 0xdULL, 1, 1, 1, 1 }, + { 0xeULL, 0, 0, 0, 0 }, + { 0xfULL, 4, 4, 4, 4 }, + { 0x10ULL, 0, 0, 0, 0 }, + { 0x11ULL, 1, 1, 1, 1 }, + { 0x12ULL, 0, 0, 0, 0 }, + { 0x1fULL, 5, 5, 5, 5 }, + { 0x20ULL, 0, 0, 0, 0 }, + { 0x7fULL, 7, 7, 7, 7 }, + { 0x80ULL, 0, 0, 0, 0 }, + { 0x81ULL, 1, 1, 1, 1 }, + { 0x9aULL, 0, 0, 0, 0 }, + { 0xf3ULL, 2, 2, 2, 2 }, + { 0xffULL, 8, 8, 8, 8 }, + { 0x100ULL, 0, 0, 0, 0 }, + { 0x101ULL, 1, 1, 1, 1 }, + { 0x102ULL, 0, 0, 0, 0 }, + { 0x1feULL, 0, 0, 0, 0 }, + { 0x1ffULL, 8, 9, 9, 9 }, + { 0x200ULL, 0, 0, 0, 0 }, + { 0x234ULL, 0, 0, 0, 0 }, + { 0x4567ULL, 3, 3, 3, 3 }, + { 0x7fffULL, 8, 15, 15, 15 }, + { 0x8000ULL, 0, 0, 0, 0 }, + { 0x8001ULL, 1, 1, 1, 1 }, + { 0xfffeULL, 0, 0, 0, 0 }, + { 0xffffULL, 8, 16, 16, 16 }, + { 0x10000ULL, 0, 0, 0, 0 }, + { 0x10001ULL, 1, 1, 1, 1 }, + { 0xfedcba98ULL, 0, 0, 0, 0 }, + { 0xfffffefeULL, 0, 0, 0, 0 }, + { 0xffffffffULL, 8, 16, 32, 32 }, + { 0x100000000ULL, 0, 0, 0, 0 }, + { 0x100000001ULL, 1, 1, 1, 1 }, + { 0x123456789ULL, 1, 1, 1, 1 }, + { 0x123456789abcdefULL, 4, 4, 4, 4 }, + { 0x789abcdef0123456ULL, 0, 0, 0, 0 }, + { 0x8000000000000000ULL, 0, 0, 0, 0 }, + { 0x8000000000000001ULL, 1, 1, 1, 1 }, + { 0xfffffffffffffffeULL, 0, 0, 0, 0 }, + { 0xffffffffffffffffULL, 8, 16, 32, 64 }, + }; + +TEST_STDBIT_UI_TOPLEVEL (stdc_trailing_ones); + +static int +do_test (void) +{ + TEST_STDBIT_UI (stdc_trailing_ones, inputs); + return 0; +} + +#include <support/test-driver.c> diff --git a/tests/tst-stdc_trailing_zeros.c b/tests/tst-stdc_trailing_zeros.c new file mode 100644 index 0000000000..a7664ee5bb --- /dev/null +++ b/tests/tst-stdc_trailing_zeros.c @@ -0,0 +1,88 @@ +/* Test stdc_trailing_zeros functions and macros. + 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 <tst-stdbit.h> + +static const struct stdbit_test inputs[] = + { + { 0ULL, 8, 16, 32, 64 }, + { 0x1ULL, 0, 0, 0, 0 }, + { 0x2ULL, 1, 1, 1, 1 }, + { 0x3ULL, 0, 0, 0, 0 }, + { 0x4ULL, 2, 2, 2, 2 }, + { 0x5ULL, 0, 0, 0, 0 }, + { 0x6ULL, 1, 1, 1, 1 }, + { 0x7ULL, 0, 0, 0, 0 }, + { 0x8ULL, 3, 3, 3, 3 }, + { 0x9ULL, 0, 0, 0, 0 }, + { 0xaULL, 1, 1, 1, 1 }, + { 0xbULL, 0, 0, 0, 0 }, + { 0xcULL, 2, 2, 2, 2 }, + { 0xdULL, 0, 0, 0, 0 }, + { 0xeULL, 1, 1, 1, 1 }, + { 0xfULL, 0, 0, 0, 0 }, + { 0x10ULL, 4, 4, 4, 4 }, + { 0x11ULL, 0, 0, 0, 0 }, + { 0x12ULL, 1, 1, 1, 1 }, + { 0x1fULL, 0, 0, 0, 0 }, + { 0x20ULL, 5, 5, 5, 5 }, + { 0x7fULL, 0, 0, 0, 0 }, + { 0x80ULL, 7, 7, 7, 7 }, + { 0x81ULL, 0, 0, 0, 0 }, + { 0x9aULL, 1, 1, 1, 1 }, + { 0xf3ULL, 0, 0, 0, 0 }, + { 0xffULL, 0, 0, 0, 0 }, + { 0x100ULL, 8, 8, 8, 8 }, + { 0x101ULL, 0, 0, 0, 0 }, + { 0x102ULL, 1, 1, 1, 1 }, + { 0x1feULL, 1, 1, 1, 1 }, + { 0x1ffULL, 0, 0, 0, 0 }, + { 0x200ULL, 8, 9, 9, 9 }, + { 0x234ULL, 2, 2, 2, 2 }, + { 0x4567ULL, 0, 0, 0, 0 }, + { 0x7fffULL, 0, 0, 0, 0 }, + { 0x8000ULL, 8, 15, 15, 15 }, + { 0x8001ULL, 0, 0, 0, 0 }, + { 0xfffeULL, 1, 1, 1, 1 }, + { 0xffffULL, 0, 0, 0, 0 }, + { 0x10000ULL, 8, 16, 16, 16 }, + { 0x10001ULL, 0, 0, 0, 0 }, + { 0xfedcba98ULL, 3, 3, 3, 3 }, + { 0xfffffefeULL, 1, 1, 1, 1 }, + { 0xffffffffULL, 0, 0, 0, 0 }, + { 0x100000000ULL, 8, 16, 32, 32 }, + { 0x100000001ULL, 0, 0, 0, 0 }, + { 0x123456789ULL, 0, 0, 0, 0 }, + { 0x123456789abcdefULL, 0, 0, 0, 0 }, + { 0x789abcdef0123456ULL, 1, 1, 1, 1 }, + { 0x8000000000000000ULL, 8, 16, 32, 63 }, + { 0x8000000000000001ULL, 0, 0, 0, 0 }, + { 0xfffffffffffffffeULL, 1, 1, 1, 1 }, + { 0xffffffffffffffffULL, 0, 0, 0, 0 }, + }; + +TEST_STDBIT_UI_TOPLEVEL (stdc_trailing_zeros); + +static int +do_test (void) +{ + TEST_STDBIT_UI (stdc_trailing_zeros, inputs); + return 0; +} + +#include <support/test-driver.c> -- 2.44.0