Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/lib/libc/stdbit/stdc_first_trailing_zero.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_first_trailing_zero_uc(unsigned char x)
12
{
13
if (x == UCHAR_MAX)
14
return (0);
15
16
return (__builtin_ctz(~x) + 1);
17
}
18
19
unsigned int
20
stdc_first_trailing_zero_us(unsigned short x)
21
{
22
if (x == USHRT_MAX)
23
return (0);
24
25
return (__builtin_ctz(~x) + 1);
26
}
27
28
unsigned int
29
stdc_first_trailing_zero_ui(unsigned int x)
30
{
31
if (x == ~0U)
32
return (0);
33
34
return (__builtin_ctz(~x) + 1);
35
}
36
37
unsigned int
38
stdc_first_trailing_zero_ul(unsigned long x)
39
{
40
if (x == ~0UL)
41
return (0);
42
43
return (__builtin_ctzl(~x) + 1);
44
}
45
46
unsigned int
47
stdc_first_trailing_zero_ull(unsigned long long x)
48
{
49
if (x == ~0ULL)
50
return (0);
51
52
return (__builtin_ctzll(~x) + 1);
53
}
54
55