Go to the documentation of this file.
19 #ifndef __STDC_VERSION_STDBIT_H__
20 #define __STDC_VERSION_STDBIT_H__ 202311L
25 #define __STDC_ENDIAN_LITTLE__ 1234
26 #define __STDC_ENDIAN_BIG__ 4321
29 # if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
30 # define __STDC_ENDIAN_NATIVE__ __STDC_ENDIAN_LITTLE__
31 # elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
32 # define __STDC_ENDIAN_NATIVE__ __STDC_ENDIAN_BIG__
34 # define __STDC_ENDIAN_NATIVE__ 3412
36 #elif defined(_MSC_VER)
37 # define __STDC_ENDIAN_NATIVE__ __STDC_ENDIAN_LITTLE__
39 # error Not implemented.
42 #define __stdbit_generic_type_func(func, value) \
44 unsigned long long: stdc_##func##_ull((unsigned long long)(value)), \
45 unsigned long: stdc_##func##_ul((unsigned long)(value)), \
46 unsigned int: stdc_##func##_ui((unsigned int)(value)), \
47 unsigned short: stdc_##func##_us((unsigned short)(value)), \
48 unsigned char: stdc_##func##_uc((unsigned char)(value)))
50 #if defined (__GNUC__) || defined (__clang__)
69 - CHAR_BIT * (
sizeof (int) -
sizeof (
value));
77 static inline unsigned int __stdc_leading_zeros(
unsigned long long value,
80 unsigned int zeros =
size * CHAR_BIT;
92 return __stdc_leading_zeros(
value,
sizeof (
value));
97 return __stdc_leading_zeros(
value,
sizeof (
value));
102 return __stdc_leading_zeros(
value,
sizeof (
value));
107 return __stdc_leading_zeros(
value,
sizeof (
value));
112 return __stdc_leading_zeros(
value,
sizeof (
value));
116 #define stdc_leading_zeros(value) \
117 __stdbit_generic_type_func(leading_zeros, value)
144 #define stdc_leading_ones(value) \
145 __stdbit_generic_type_func(leading_ones, value)
147 #if defined (__GNUC__) || defined (__clang__)
150 return value ? (
unsigned int)__builtin_ctzll(
value)
151 : (CHAR_BIT *
sizeof (
value));
156 return value ? (
unsigned int)__builtin_ctzl(
value)
157 : (CHAR_BIT *
sizeof (
value));
162 return value ? (
unsigned int)__builtin_ctz(
value)
163 : (CHAR_BIT *
sizeof (
value));
168 return value ? (
unsigned int)__builtin_ctz(
value)
169 : (CHAR_BIT *
sizeof (
value));
174 return value ? (
unsigned int)__builtin_ctz(
value)
175 : (CHAR_BIT *
sizeof (
value));
178 static inline unsigned int __stdc_trailing_zeros(
unsigned long long value,
181 unsigned int zeros = 0;
184 return size * CHAR_BIT;
186 while ((
value & 1) == 0) {
196 return __stdc_trailing_zeros(
value,
sizeof (
value));
201 return __stdc_trailing_zeros(
value,
sizeof (
value));
206 return __stdc_trailing_zeros(
value,
sizeof (
value));
211 return __stdc_trailing_zeros(
value,
sizeof (
value));
216 return __stdc_trailing_zeros(
value,
sizeof (
value));
220 #define stdc_trailing_zeros(value) \
221 __stdbit_generic_type_func(trailing_zeros, value)
248 #define stdc_trailing_ones(value) \
249 __stdbit_generic_type_func(trailing_ones, value)
276 #define stdc_first_leading_one(value) \
277 __stdbit_generic_type_func(first_leading_one, value)
304 #define stdc_first_leading_zero(value) \
305 __stdbit_generic_type_func(first_leading_zero, value)
307 #if defined (__GNUC__) || defined (__clang__)
310 return __builtin_ffsll(
value);
315 return __builtin_ffsl(
value);
320 return __builtin_ffs(
value);
325 return __builtin_ffs(
value);
330 return __builtin_ffs(
value);
359 #define stdc_first_trailing_one(value) \
360 __stdbit_generic_type_func(first_trailing_one, value)
387 #define stdc_first_trailing_zero(value) \
388 __stdbit_generic_type_func(first_trailing_zero, value)
390 #if defined (__GNUC__) || defined (__clang__)
393 return __builtin_popcountll(
value);
398 return __builtin_popcountl(
value);
403 return __builtin_popcount(
value);
408 return __builtin_popcount(
value);
413 return __builtin_popcount(
value);
416 static inline unsigned int __stdc_count_ones(
unsigned long long value,
419 unsigned int ones = 0;
421 for (
unsigned int c = 0;
c < (
size * CHAR_BIT);
c++) {
431 return __stdc_count_ones(
value,
sizeof (
value));
436 return __stdc_count_ones(
value,
sizeof (
value));
441 return __stdc_count_ones(
value,
sizeof (
value));
446 return __stdc_count_ones(
value,
sizeof (
value));
451 return __stdc_count_ones(
value,
sizeof (
value));
455 #define stdc_count_ones(value) \
456 __stdbit_generic_type_func(count_ones, value)
483 #define stdc_count_zeros(value) \
484 __stdbit_generic_type_func(count_zeros, value)
511 #define stdc_has_single_bit(value) \
512 __stdbit_generic_type_func(has_single_bit, value)
539 #define stdc_bit_width(value) \
540 __stdbit_generic_type_func(bit_width, value)
567 #define stdc_bit_floor(value) \
568 __stdbit_generic_type_func(bit_floor, value)
596 #define stdc_bit_ceil(value) \
597 __stdbit_generic_type_func(bit_ceil, value)
static unsigned int stdc_first_leading_one_us(unsigned short value)
static unsigned int stdc_first_trailing_one_ull(unsigned long long value)
static bool stdc_has_single_bit_us(unsigned short value)
static unsigned int stdc_count_zeros_uc(unsigned char value)
static unsigned int stdc_bit_width_ul(unsigned long value)
static unsigned int stdc_bit_floor_uc(unsigned char value)
static unsigned int stdc_leading_zeros_ull(unsigned long long value)
static unsigned short stdc_bit_ceil_us(unsigned short value)
static unsigned int stdc_leading_ones_us(unsigned short value)
static unsigned int stdc_count_ones_ul(unsigned long value)
static unsigned int stdc_first_leading_zero_ui(unsigned int value)
static unsigned int stdc_count_zeros_ul(unsigned long value)
static unsigned int stdc_leading_zeros_ul(unsigned long value)
static unsigned int stdc_trailing_zeros_us(unsigned short value)
static unsigned long long stdc_bit_ceil_ull(unsigned long long value)
static unsigned int stdc_count_ones_us(unsigned short value)
static unsigned int stdc_count_ones_ui(unsigned int value)
static unsigned int stdc_trailing_zeros_ui(unsigned int value)
static unsigned int stdc_first_trailing_zero_ul(unsigned long value)
static unsigned int stdc_trailing_zeros_ul(unsigned long value)
static unsigned int stdc_first_trailing_zero_us(unsigned short value)
static unsigned int stdc_trailing_ones_ui(unsigned int value)
static unsigned int stdc_leading_zeros_us(unsigned short value)
static unsigned int stdc_count_ones_uc(unsigned char value)
static unsigned int stdc_trailing_zeros_ull(unsigned long long value)
static bool stdc_has_single_bit_uc(unsigned char value)
static bool stdc_has_single_bit_ui(unsigned int value)
static unsigned int stdc_trailing_ones_ul(unsigned long value)
static unsigned int stdc_leading_ones_ull(unsigned long long value)
static unsigned long stdc_bit_floor_ul(unsigned long value)
static unsigned long stdc_bit_ceil_ul(unsigned long value)
static unsigned int stdc_bit_floor_ui(unsigned int value)
static unsigned int stdc_first_leading_one_ul(unsigned long value)
static unsigned int stdc_trailing_ones_uc(unsigned char value)
static unsigned int stdc_bit_width_uc(unsigned char value)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static unsigned int stdc_bit_width_us(unsigned short value)
static bool stdc_has_single_bit_ul(unsigned long value)
static unsigned int stdc_first_trailing_one_us(unsigned short value)
static unsigned int stdc_trailing_zeros_uc(unsigned char value)
static unsigned int stdc_count_zeros_ui(unsigned int value)
static unsigned int stdc_leading_ones_ul(unsigned long value)
static unsigned int stdc_first_trailing_zero_ull(unsigned long long value)
static unsigned int stdc_first_leading_one_uc(unsigned char value)
static unsigned long long stdc_bit_floor_ull(unsigned long long value)
static unsigned int stdc_leading_ones_ui(unsigned int value)
static unsigned int stdc_first_leading_one_ui(unsigned int value)
static unsigned int stdc_leading_zeros_ui(unsigned int value)
static unsigned int stdc_first_trailing_one_uc(unsigned char value)
static unsigned int stdc_first_leading_one_ull(unsigned long long value)
static unsigned int stdc_count_ones_ull(unsigned long long value)
static unsigned int stdc_first_trailing_zero_ui(unsigned int value)
static unsigned int stdc_leading_ones_uc(unsigned char value)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
static unsigned int stdc_first_trailing_one_ul(unsigned long value)
static unsigned int stdc_first_trailing_zero_uc(unsigned char value)
static unsigned int stdc_trailing_ones_ull(unsigned long long value)
static unsigned int stdc_bit_width_ull(unsigned long long value)
static bool stdc_has_single_bit_ull(unsigned long long value)
static unsigned int stdc_leading_zeros_uc(unsigned char value)
static unsigned int stdc_first_leading_zero_ul(unsigned long value)
static unsigned int stdc_count_zeros_ull(unsigned long long value)
static unsigned int stdc_trailing_ones_us(unsigned short value)
static unsigned int stdc_bit_ceil_uc(unsigned char value)
static unsigned int stdc_count_zeros_us(unsigned short value)
static unsigned int stdc_bit_ceil_ui(unsigned int value)
static unsigned int stdc_bit_width_ui(unsigned int value)
static unsigned int stdc_first_trailing_one_ui(unsigned int value)
static unsigned int stdc_first_leading_zero_ull(unsigned long long value)
static unsigned int stdc_first_leading_zero_us(unsigned short value)
static unsigned int stdc_first_leading_zero_uc(unsigned char value)
static unsigned short stdc_bit_floor_us(unsigned short value)