/* 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<