xref: /freebsd/lib/libc/tests/stdbit/stdc_trailing_ones_test.c (revision bd16bac27e7e0d31bccf88feca95cd98f0ef0fd4)
1 /*
2  * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
3  *
4  * SPDX-License-Identifier: BSD-2-Clause
5  */
6 
7 #define FUNCSTEM stdc_trailing_ones
8 #define MKREFFUNC(name, type)						\
9 	static unsigned							\
10 	name(type value) 						\
11 	{ 								\
12 		type bit = 1;						\
13 		unsigned count = 0;					\
14 									\
15 		while (bit != 0 && (bit & value) != 0) {		\
16 			bit <<= 1;					\
17 			count++;					\
18 		}							\
19 									\
20 		return (count);						\
21 	}
22 
23 #include "stdbit-test-framework.c"
24