xref: /minix3/tests/include/sys/t_bitops.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: t_bitops.c,v 1.19 2015/03/21 05:50:19 isaki Exp $ */
211be35a1SLionel Sambuc 
311be35a1SLionel Sambuc /*-
411be35a1SLionel Sambuc  * Copyright (c) 2011, 2012 The NetBSD Foundation, Inc.
511be35a1SLionel Sambuc  * All rights reserved.
611be35a1SLionel Sambuc  *
711be35a1SLionel Sambuc  * This code is derived from software contributed to The NetBSD Foundation
811be35a1SLionel Sambuc  * by Christos Zoulas and Jukka Ruohonen.
911be35a1SLionel Sambuc  *
1011be35a1SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
1111be35a1SLionel Sambuc  * modification, are permitted provided that the following conditions
1211be35a1SLionel Sambuc  * are met:
1311be35a1SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
1411be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
1511be35a1SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
1611be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
1711be35a1SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
1811be35a1SLionel Sambuc  *
1911be35a1SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2011be35a1SLionel Sambuc  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2111be35a1SLionel Sambuc  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2211be35a1SLionel Sambuc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2311be35a1SLionel Sambuc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2411be35a1SLionel Sambuc  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2511be35a1SLionel Sambuc  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2611be35a1SLionel Sambuc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2711be35a1SLionel Sambuc  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2811be35a1SLionel Sambuc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2911be35a1SLionel Sambuc  * POSSIBILITY OF SUCH DAMAGE.
3011be35a1SLionel Sambuc  */
3111be35a1SLionel Sambuc #include <sys/cdefs.h>
32*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: t_bitops.c,v 1.19 2015/03/21 05:50:19 isaki Exp $");
3311be35a1SLionel Sambuc 
3411be35a1SLionel Sambuc #include <atf-c.h>
3511be35a1SLionel Sambuc 
3611be35a1SLionel Sambuc #include <sys/cdefs.h>
3711be35a1SLionel Sambuc #include <sys/bitops.h>
3811be35a1SLionel Sambuc 
3911be35a1SLionel Sambuc #include <math.h>
4011be35a1SLionel Sambuc #include <inttypes.h>
4111be35a1SLionel Sambuc #include <stdlib.h>
4211be35a1SLionel Sambuc #include <string.h>
4311be35a1SLionel Sambuc 
4411be35a1SLionel Sambuc static const struct {
4511be35a1SLionel Sambuc 	uint32_t	val;
4611be35a1SLionel Sambuc 	int		ffs;
4711be35a1SLionel Sambuc 	int		fls;
4811be35a1SLionel Sambuc } bits[] = {
4911be35a1SLionel Sambuc 
5011be35a1SLionel Sambuc 	{ 0x00, 0, 0 }, { 0x01, 1, 1 },	{ 0x02, 2, 2 },	{ 0x03, 1, 2 },
5111be35a1SLionel Sambuc 	{ 0x04, 3, 3 }, { 0x05, 1, 3 },	{ 0x06, 2, 3 },	{ 0x07, 1, 3 },
5211be35a1SLionel Sambuc 	{ 0x08, 4, 4 }, { 0x09, 1, 4 },	{ 0x0A, 2, 4 },	{ 0x0B, 1, 4 },
5311be35a1SLionel Sambuc 	{ 0x0C, 3, 4 }, { 0x0D, 1, 4 },	{ 0x0E, 2, 4 },	{ 0x0F, 1, 4 },
5411be35a1SLionel Sambuc 
5511be35a1SLionel Sambuc 	{ 0x10, 5, 5 },	{ 0x11, 1, 5 },	{ 0x12, 2, 5 },	{ 0x13, 1, 5 },
5611be35a1SLionel Sambuc 	{ 0x14, 3, 5 },	{ 0x15, 1, 5 },	{ 0x16, 2, 5 },	{ 0x17, 1, 5 },
5711be35a1SLionel Sambuc 	{ 0x18, 4, 5 },	{ 0x19, 1, 5 },	{ 0x1A, 2, 5 },	{ 0x1B, 1, 5 },
5811be35a1SLionel Sambuc 	{ 0x1C, 3, 5 },	{ 0x1D, 1, 5 },	{ 0x1E, 2, 5 },	{ 0x1F, 1, 5 },
5911be35a1SLionel Sambuc 
6011be35a1SLionel Sambuc 	{ 0xF0, 5, 8 },	{ 0xF1, 1, 8 },	{ 0xF2, 2, 8 },	{ 0xF3, 1, 8 },
6111be35a1SLionel Sambuc 	{ 0xF4, 3, 8 },	{ 0xF5, 1, 8 },	{ 0xF6, 2, 8 },	{ 0xF7, 1, 8 },
6211be35a1SLionel Sambuc 	{ 0xF8, 4, 8 },	{ 0xF9, 1, 8 },	{ 0xFA, 2, 8 },	{ 0xFB, 1, 8 },
6311be35a1SLionel Sambuc 	{ 0xFC, 3, 8 },	{ 0xFD, 1, 8 },	{ 0xFE, 2, 8 },	{ 0xFF, 1, 8 },
6411be35a1SLionel Sambuc 
6511be35a1SLionel Sambuc };
6611be35a1SLionel Sambuc 
6711be35a1SLionel Sambuc ATF_TC(bitmap_basic);
ATF_TC_HEAD(bitmap_basic,tc)6811be35a1SLionel Sambuc ATF_TC_HEAD(bitmap_basic, tc)
6911be35a1SLionel Sambuc {
7011be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "A basic test of __BITMAP_*");
7111be35a1SLionel Sambuc }
7211be35a1SLionel Sambuc 
ATF_TC_BODY(bitmap_basic,tc)7311be35a1SLionel Sambuc ATF_TC_BODY(bitmap_basic, tc)
7411be35a1SLionel Sambuc {
7511be35a1SLionel Sambuc 	__BITMAP_TYPE(, uint32_t, 65536) bm;
7611be35a1SLionel Sambuc 	__BITMAP_ZERO(&bm);
7711be35a1SLionel Sambuc 
7811be35a1SLionel Sambuc 	ATF_REQUIRE(__BITMAP_SIZE(uint32_t, 65536) == 2048);
7911be35a1SLionel Sambuc 
8011be35a1SLionel Sambuc 	ATF_REQUIRE(__BITMAP_SHIFT(uint32_t) == 5);
8111be35a1SLionel Sambuc 
8211be35a1SLionel Sambuc 	ATF_REQUIRE(__BITMAP_MASK(uint32_t) == 31);
8311be35a1SLionel Sambuc 
8411be35a1SLionel Sambuc 	for (size_t i = 0; i < 65536; i += 2)
8511be35a1SLionel Sambuc 		__BITMAP_SET(i, &bm);
8611be35a1SLionel Sambuc 
8711be35a1SLionel Sambuc 	for (size_t i = 0; i < 2048; i++)
8811be35a1SLionel Sambuc 		ATF_REQUIRE(bm._b[i] == 0x55555555);
8911be35a1SLionel Sambuc 
9011be35a1SLionel Sambuc 	for (size_t i = 0; i < 65536; i++)
9111be35a1SLionel Sambuc 		if (i & 1)
9211be35a1SLionel Sambuc 			ATF_REQUIRE(!__BITMAP_ISSET(i, &bm));
9311be35a1SLionel Sambuc 		else {
9411be35a1SLionel Sambuc 			ATF_REQUIRE(__BITMAP_ISSET(i, &bm));
9511be35a1SLionel Sambuc 			__BITMAP_CLR(i, &bm);
9611be35a1SLionel Sambuc 		}
9711be35a1SLionel Sambuc 
9811be35a1SLionel Sambuc 	for (size_t i = 0; i < 65536; i += 2)
9911be35a1SLionel Sambuc 		ATF_REQUIRE(!__BITMAP_ISSET(i, &bm));
10011be35a1SLionel Sambuc }
10111be35a1SLionel Sambuc 
10211be35a1SLionel Sambuc ATF_TC(fast_divide32);
ATF_TC_HEAD(fast_divide32,tc)10311be35a1SLionel Sambuc ATF_TC_HEAD(fast_divide32, tc)
10411be35a1SLionel Sambuc {
10511be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "A basic test of fast_divide32(3)");
10611be35a1SLionel Sambuc }
10711be35a1SLionel Sambuc 
ATF_TC_BODY(fast_divide32,tc)10811be35a1SLionel Sambuc ATF_TC_BODY(fast_divide32, tc)
10911be35a1SLionel Sambuc {
11011be35a1SLionel Sambuc 	uint32_t a, b, q, r, m;
11111be35a1SLionel Sambuc 	uint8_t i, s1, s2;
11211be35a1SLionel Sambuc 
11311be35a1SLionel Sambuc 	a = 0xFFFF;
11411be35a1SLionel Sambuc 	b = 0x000F;
11511be35a1SLionel Sambuc 
11611be35a1SLionel Sambuc 	fast_divide32_prepare(b, &m, &s1, &s2);
11711be35a1SLionel Sambuc 
11811be35a1SLionel Sambuc 	q = fast_divide32(a, b, m, s1, s2);
11911be35a1SLionel Sambuc 	r = fast_remainder32(a, b, m, s1, s2);
12011be35a1SLionel Sambuc 
12111be35a1SLionel Sambuc 	ATF_REQUIRE(q == 0x1111 && r == 0);
12211be35a1SLionel Sambuc 
12311be35a1SLionel Sambuc 	for (i = 1; i < __arraycount(bits); i++) {
12411be35a1SLionel Sambuc 
12511be35a1SLionel Sambuc 		a = bits[i].val;
12611be35a1SLionel Sambuc 		b = bits[i].ffs;
12711be35a1SLionel Sambuc 
12811be35a1SLionel Sambuc 		fast_divide32_prepare(b, &m, &s1, &s2);
12911be35a1SLionel Sambuc 
13011be35a1SLionel Sambuc 		q = fast_divide32(a, b, m, s1, s2);
13111be35a1SLionel Sambuc 		r = fast_remainder32(a, b, m, s1, s2);
13211be35a1SLionel Sambuc 
13311be35a1SLionel Sambuc 		ATF_REQUIRE(q == a / b);
13411be35a1SLionel Sambuc 		ATF_REQUIRE(r == a % b);
13511be35a1SLionel Sambuc 	}
13611be35a1SLionel Sambuc }
13711be35a1SLionel Sambuc 
13811be35a1SLionel Sambuc ATF_TC(ffsfls);
ATF_TC_HEAD(ffsfls,tc)13911be35a1SLionel Sambuc ATF_TC_HEAD(ffsfls, tc)
14011be35a1SLionel Sambuc {
14111be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test ffs32(3)-family for correctness");
14211be35a1SLionel Sambuc }
14311be35a1SLionel Sambuc 
ATF_TC_BODY(ffsfls,tc)14411be35a1SLionel Sambuc ATF_TC_BODY(ffsfls, tc)
14511be35a1SLionel Sambuc {
14611be35a1SLionel Sambuc 	uint8_t i;
14711be35a1SLionel Sambuc 
14811be35a1SLionel Sambuc 	ATF_REQUIRE(ffs32(0) == 0x00);
14911be35a1SLionel Sambuc 	ATF_REQUIRE(fls32(0) == 0x00);
15011be35a1SLionel Sambuc 	ATF_REQUIRE(ffs64(0) == 0x00);
15111be35a1SLionel Sambuc 	ATF_REQUIRE(fls64(0) == 0x00);
15211be35a1SLionel Sambuc 
15311be35a1SLionel Sambuc 	ATF_REQUIRE(ffs32(UINT32_MAX) == 0x01);
15411be35a1SLionel Sambuc 	ATF_REQUIRE(fls32(UINT32_MAX) == 0x20);
15511be35a1SLionel Sambuc 	ATF_REQUIRE(ffs64(UINT64_MAX) == 0x01);
15611be35a1SLionel Sambuc 	ATF_REQUIRE(fls64(UINT64_MAX) == 0x40);
15711be35a1SLionel Sambuc 
15811be35a1SLionel Sambuc 	for (i = 1; i < __arraycount(bits); i++) {
15911be35a1SLionel Sambuc 
16011be35a1SLionel Sambuc 		ATF_REQUIRE(ffs32(bits[i].val) == bits[i].ffs);
16111be35a1SLionel Sambuc 		ATF_REQUIRE(fls32(bits[i].val) == bits[i].fls);
16211be35a1SLionel Sambuc 		ATF_REQUIRE(ffs64(bits[i].val) == bits[i].ffs);
16311be35a1SLionel Sambuc 		ATF_REQUIRE(fls64(bits[i].val) == bits[i].fls);
16411be35a1SLionel Sambuc 
16511be35a1SLionel Sambuc 		ATF_REQUIRE(ffs32(bits[i].val << 1) == bits[i].ffs + 1);
16611be35a1SLionel Sambuc 		ATF_REQUIRE(fls32(bits[i].val << 1) == bits[i].fls + 1);
16711be35a1SLionel Sambuc 		ATF_REQUIRE(ffs64(bits[i].val << 1) == bits[i].ffs + 1);
16811be35a1SLionel Sambuc 		ATF_REQUIRE(fls64(bits[i].val << 1) == bits[i].fls + 1);
16911be35a1SLionel Sambuc 
17011be35a1SLionel Sambuc 		ATF_REQUIRE(ffs32(bits[i].val << 9) == bits[i].ffs + 9);
17111be35a1SLionel Sambuc 		ATF_REQUIRE(fls32(bits[i].val << 9) == bits[i].fls + 9);
17211be35a1SLionel Sambuc 		ATF_REQUIRE(ffs64(bits[i].val << 9) == bits[i].ffs + 9);
17311be35a1SLionel Sambuc 		ATF_REQUIRE(fls64(bits[i].val << 9) == bits[i].fls + 9);
17411be35a1SLionel Sambuc 	}
17511be35a1SLionel Sambuc }
17611be35a1SLionel Sambuc 
177*0a6a1f1dSLionel Sambuc ATF_TC(ilog2_32bit);
ATF_TC_HEAD(ilog2_32bit,tc)178*0a6a1f1dSLionel Sambuc ATF_TC_HEAD(ilog2_32bit, tc)
17911be35a1SLionel Sambuc {
180*0a6a1f1dSLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test ilog2(3) for 32bit variable");
18111be35a1SLionel Sambuc }
18211be35a1SLionel Sambuc 
ATF_TC_BODY(ilog2_32bit,tc)183*0a6a1f1dSLionel Sambuc ATF_TC_BODY(ilog2_32bit, tc)
18411be35a1SLionel Sambuc {
185*0a6a1f1dSLionel Sambuc 	int i;
186*0a6a1f1dSLionel Sambuc 	uint32_t x;
18711be35a1SLionel Sambuc 
188*0a6a1f1dSLionel Sambuc 	for (i = 0; i < 32; i++) {
189*0a6a1f1dSLionel Sambuc 		x = 1 << i;
190*0a6a1f1dSLionel Sambuc 		ATF_REQUIRE(ilog2(x) == i);
19111be35a1SLionel Sambuc 	}
19211be35a1SLionel Sambuc }
19311be35a1SLionel Sambuc 
194*0a6a1f1dSLionel Sambuc ATF_TC(ilog2_64bit);
ATF_TC_HEAD(ilog2_64bit,tc)195*0a6a1f1dSLionel Sambuc ATF_TC_HEAD(ilog2_64bit, tc)
19611be35a1SLionel Sambuc {
197*0a6a1f1dSLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test ilog2(3) for 64bit variable");
19811be35a1SLionel Sambuc }
19911be35a1SLionel Sambuc 
ATF_TC_BODY(ilog2_64bit,tc)200*0a6a1f1dSLionel Sambuc ATF_TC_BODY(ilog2_64bit, tc)
20111be35a1SLionel Sambuc {
202*0a6a1f1dSLionel Sambuc 	int i;
203*0a6a1f1dSLionel Sambuc 	uint64_t x;
20411be35a1SLionel Sambuc 
205*0a6a1f1dSLionel Sambuc 	for (i = 0; i < 64; i++) {
206*0a6a1f1dSLionel Sambuc 		x = ((uint64_t)1) << i;
207*0a6a1f1dSLionel Sambuc 		ATF_REQUIRE(ilog2(x) == i);
208*0a6a1f1dSLionel Sambuc 	}
209*0a6a1f1dSLionel Sambuc }
210*0a6a1f1dSLionel Sambuc 
211*0a6a1f1dSLionel Sambuc ATF_TC(ilog2_const);
ATF_TC_HEAD(ilog2_const,tc)212*0a6a1f1dSLionel Sambuc ATF_TC_HEAD(ilog2_const, tc)
213*0a6a1f1dSLionel Sambuc {
214*0a6a1f1dSLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test ilog2(3) for constant");
215*0a6a1f1dSLionel Sambuc }
216*0a6a1f1dSLionel Sambuc 
ATF_TC_BODY(ilog2_const,tc)217*0a6a1f1dSLionel Sambuc ATF_TC_BODY(ilog2_const, tc)
218*0a6a1f1dSLionel Sambuc {
21911be35a1SLionel Sambuc 	/*
220*0a6a1f1dSLionel Sambuc 	 * These inlines test __builtin_constant_p() part of ilog2()
221*0a6a1f1dSLionel Sambuc 	 * at compile time, so don't change it to loop.  PR lib/49745
22211be35a1SLionel Sambuc 	 */
223*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000000001ULL) == 0);
224*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000000002ULL) == 1);
225*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000000004ULL) == 2);
226*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000000008ULL) == 3);
227*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000000010ULL) == 4);
228*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000000020ULL) == 5);
229*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000000040ULL) == 6);
230*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000000080ULL) == 7);
231*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000000100ULL) == 8);
232*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000000200ULL) == 9);
233*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000000400ULL) == 10);
234*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000000800ULL) == 11);
235*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000001000ULL) == 12);
236*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000002000ULL) == 13);
237*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000004000ULL) == 14);
238*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000008000ULL) == 15);
239*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000010000ULL) == 16);
240*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000020000ULL) == 17);
241*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000040000ULL) == 18);
242*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000080000ULL) == 19);
243*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000100000ULL) == 20);
244*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000200000ULL) == 21);
245*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000400000ULL) == 22);
246*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000800000ULL) == 23);
247*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000001000000ULL) == 24);
248*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000002000000ULL) == 25);
249*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000004000000ULL) == 26);
250*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000008000000ULL) == 27);
251*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000010000000ULL) == 28);
252*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000020000000ULL) == 29);
253*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000040000000ULL) == 30);
254*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000080000000ULL) == 31);
255*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000100000000ULL) == 32);
256*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000200000000ULL) == 33);
257*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000400000000ULL) == 34);
258*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000800000000ULL) == 35);
259*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000001000000000ULL) == 36);
260*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000002000000000ULL) == 37);
261*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000004000000000ULL) == 38);
262*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000008000000000ULL) == 39);
263*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000010000000000ULL) == 40);
264*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000020000000000ULL) == 41);
265*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000040000000000ULL) == 42);
266*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000080000000000ULL) == 43);
267*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000100000000000ULL) == 44);
268*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000200000000000ULL) == 45);
269*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000400000000000ULL) == 46);
270*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000800000000000ULL) == 47);
271*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0001000000000000ULL) == 48);
272*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0002000000000000ULL) == 49);
273*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0004000000000000ULL) == 50);
274*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0008000000000000ULL) == 51);
275*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0010000000000000ULL) == 52);
276*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0020000000000000ULL) == 53);
277*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0040000000000000ULL) == 54);
278*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0080000000000000ULL) == 55);
279*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0100000000000000ULL) == 56);
280*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0200000000000000ULL) == 57);
281*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0400000000000000ULL) == 58);
282*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0800000000000000ULL) == 59);
283*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x1000000000000000ULL) == 60);
284*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x2000000000000000ULL) == 61);
285*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x4000000000000000ULL) == 62);
286*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x8000000000000000ULL) == 63);
28711be35a1SLionel Sambuc 
288*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000000003ULL) == 1);
289*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000000007ULL) == 2);
290*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x000000000000000fULL) == 3);
291*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x000000000000001fULL) == 4);
292*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x000000000000003fULL) == 5);
293*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x000000000000007fULL) == 6);
294*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x00000000000000ffULL) == 7);
295*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x00000000000001ffULL) == 8);
296*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x00000000000003ffULL) == 9);
297*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x00000000000007ffULL) == 10);
298*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000000fffULL) == 11);
299*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000001fffULL) == 12);
300*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000003fffULL) == 13);
301*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000007fffULL) == 14);
302*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x000000000000ffffULL) == 15);
303*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x000000000001ffffULL) == 16);
304*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x000000000003ffffULL) == 17);
305*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x000000000007ffffULL) == 18);
306*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x00000000000fffffULL) == 19);
307*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x00000000001fffffULL) == 20);
308*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x00000000003fffffULL) == 21);
309*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x00000000007fffffULL) == 22);
310*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000000ffffffULL) == 23);
311*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000001ffffffULL) == 24);
312*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000003ffffffULL) == 25);
313*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000007ffffffULL) == 26);
314*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x000000000fffffffULL) == 27);
315*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x000000001fffffffULL) == 28);
316*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x000000003fffffffULL) == 29);
317*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x000000007fffffffULL) == 30);
318*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x00000000ffffffffULL) == 31);
319*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x00000001ffffffffULL) == 32);
320*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x00000003ffffffffULL) == 33);
321*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x00000007ffffffffULL) == 34);
322*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000000fffffffffULL) == 35);
323*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000001fffffffffULL) == 36);
324*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000003fffffffffULL) == 37);
325*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000007fffffffffULL) == 38);
326*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x000000ffffffffffULL) == 39);
327*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x000001ffffffffffULL) == 40);
328*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x000003ffffffffffULL) == 41);
329*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x000007ffffffffffULL) == 42);
330*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x00000fffffffffffULL) == 43);
331*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x00001fffffffffffULL) == 44);
332*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x00003fffffffffffULL) == 45);
333*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x00007fffffffffffULL) == 46);
334*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0000ffffffffffffULL) == 47);
335*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0001ffffffffffffULL) == 48);
336*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0003ffffffffffffULL) == 49);
337*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0007ffffffffffffULL) == 50);
338*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x000fffffffffffffULL) == 51);
339*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x001fffffffffffffULL) == 52);
340*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x003fffffffffffffULL) == 53);
341*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x007fffffffffffffULL) == 54);
342*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x00ffffffffffffffULL) == 55);
343*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x01ffffffffffffffULL) == 56);
344*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x03ffffffffffffffULL) == 57);
345*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x07ffffffffffffffULL) == 58);
346*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x0fffffffffffffffULL) == 59);
347*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x1fffffffffffffffULL) == 60);
348*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x3fffffffffffffffULL) == 61);
349*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0x7fffffffffffffffULL) == 62);
350*0a6a1f1dSLionel Sambuc 	ATF_REQUIRE(ilog2(0xffffffffffffffffULL) == 63);
35111be35a1SLionel Sambuc }
35211be35a1SLionel Sambuc 
ATF_TP_ADD_TCS(tp)35311be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
35411be35a1SLionel Sambuc {
35511be35a1SLionel Sambuc 
35611be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, bitmap_basic);
35711be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, fast_divide32);
35811be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, ffsfls);
359*0a6a1f1dSLionel Sambuc 	ATF_TP_ADD_TC(tp, ilog2_32bit);
360*0a6a1f1dSLionel Sambuc 	ATF_TP_ADD_TC(tp, ilog2_64bit);
361*0a6a1f1dSLionel Sambuc 	ATF_TP_ADD_TC(tp, ilog2_const);
36211be35a1SLionel Sambuc 
36311be35a1SLionel Sambuc 	return atf_no_error();
36411be35a1SLionel Sambuc }
365