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

#define FUNCSTEM stdc_first_trailing_zero
#define MKREFFUNC(name, type)						\
	static unsigned							\
	name(type value) 						\
	{ 								\
		type bit = 1;						\
		unsigned pos = 1;					\
									\
		value = ~value;						\
		if (value == 0)						\
			return (0);					\
									\
		while ((bit & value) == 0) {				\
			bit <<= 1;					\
			pos++;						\
		}							\
									\
		return (pos);						\
	}

#include "stdbit-test-framework.c"