/* ISO C23 Standard: 7.18 - Bit and byte utilities <stdbit.h>.
Copyright (C) 2024-2025 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 _STDBIT_H
#define _STDBIT_H 1
#include <features.h>
#include <bits/endian.h>
#include <bits/stdint-intn.h>
#include <bits/stdint-uintn.h>
#include <bits/stdint-least.h>
/* In C23, <stdbool.h> defines only an implementation-namespace macro,
so is OK to include here. Before C23, including <stdbool.h> allows
the header to use bool rather than _Bool unconditionally, and so to
compile as C++ (although the type-generic macros are not a good
form of type-generic interface for C++). */
#include <stdbool.h>
#define __need_size_t
#include <stddef.h>
#define __STDC_VERSION_STDBIT_H__ 202311L
#define __STDC_ENDIAN_LITTLE__ __LITTLE_ENDIAN
#define __STDC_ENDIAN_BIG__ __BIG_ENDIAN
#define __STDC_ENDIAN_NATIVE__ __BYTE_ORDER
__BEGIN_DECLS
/* Use __pacify_uint16 (N) instead of (uint16_t) (N) when the cast is helpful
only to pacify older GCC (e.g., GCC 10 -Wconversion) or non-GCC (e.g
clang -Wimplicit-int-conversion). */
#if __GNUC_PREREQ (11, 0)
# define __pacify_uint8(n) (n)
# define __pacify_uint16(n) (n)
#else
# define __pacify_uint8(n) ((uint8_t) (n))
# define __pacify_uint16(n) ((uint16_t) (n))
#endif
/* Count leading zeros. */
extern unsigned int stdc_leading_zeros_uc (unsigned char __x)
__THROW __attribute_const__;
extern unsigned int stdc_leading_zeros_us (unsigned short __x)
__THROW __attribute_const__;
extern unsigned int stdc_leading_zeros_ui (unsigned int __x)
__THROW __attribute_const__;
extern unsigned int stdc_leading_zeros_ul (unsigned long int __x)
__THROW __attribute_const__;
__extension__
extern unsigned int stdc_leading_zeros_ull (unsigned long long int __x)
__THROW __attribute_const__;
#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
__clz64_inline (uint64_t __x)
{
return __x == 0 ? 64U : (unsigned int) __builtin_clzll (__x);
}
static __always_inline unsigned int
__clz32_inline (uint32_t __x)
{
return __x == 0 ? 32U : (unsigned int) __builtin_clz