aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/tests/stdbit/stdc_trailing_zeros_test.c
blob: 81fe11c5c82ac198f7fdbf1b3cd689981e55fef5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
 * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#define FUNCSTEM stdc_trailing_zeros
#define MKREFFUNC(name, type)						\
	static unsigned							\
	name(type value) 						\
	{ 								\
		type bit = 1;						\
		unsigned count = 0;					\
									\
		while (bit != 0 && (bit & value) == 0) {		\
			bit <<= 1;					\
			count++;					\
		}							\
									\
		return (count);						\
	}

#include "stdbit-test-framework.c"