Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/lib/libc/stdbit/stdc_bit_width.c
96290 views
1
/*
2
* Copyright (c) 2025 Robert Clausecker <[email protected]>
3
*
4
* SPDX-License-Identifier: BSD-2-Clause
5
*/
6
7
#include <limits.h>
8
#include <stdbit.h>
9
10
unsigned int
11
stdc_bit_width_uc(unsigned char x)
12
{
13
if (x == 0)
14
return (0);
15
16
return (UINT_WIDTH - __builtin_clz(x));
17
}
18
19
unsigned int
20
stdc_bit_width_us(unsigned short x)
21
{
22
if (x == 0)
23
return (0);
24
25
return (UINT_WIDTH - __builtin_clz(x));
26
}
27
28
unsigned int
29
stdc_bit_width_ui(unsigned int x)
30
{
31
if (x == 0)
32
return (0);
33
34
return (UINT_WIDTH - __builtin_clz(x));
35
}
36
37
unsigned int
38
stdc_bit_width_ul(unsigned long x)
39
{
40
if (x == 0)
41
return (0);
42
43
return (ULONG_WIDTH - __builtin_clzl(x));
44
}
45
46
unsigned int
47
stdc_bit_width_ull(unsigned long long x)
48
{
49
if (x == 0)
50
return (0);
51
52
return (ULLONG_WIDTH - __builtin_clzll(x));
53
}
54
55