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