xref: /freebsd/lib/libc/stdbit/stdc_count_ones.c (revision b1bebaaba9b9c0ddfe503c43ca8e9e3917ee2c57)
1 /*
2  * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
3  *
4  * SPDX-License-Identifier: BSD-2-Clause
5  */
6 
7 #include <limits.h>
8 #include <stdbit.h>
9 
10 unsigned int
11 stdc_count_ones_uc(unsigned char x)
12 {
13 	return (__builtin_popcount(x));
14 }
15 
16 unsigned int
17 stdc_count_ones_us(unsigned short x)
18 {
19 	return (__builtin_popcount(x));
20 }
21 
22 unsigned int
23 stdc_count_ones_ui(unsigned int x)
24 {
25 	return (__builtin_popcount(x));
26 }
27 
28 unsigned int
29 stdc_count_ones_ul(unsigned long x)
30 {
31 	return (__builtin_popcountl(x));
32 }
33 
34 unsigned int
35 stdc_count_ones_ull(unsigned long long x)
36 {
37 	return (__builtin_popcountll(x));
38 }
39