VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTBitOperations.cpp@ 85546

Last change on this file since 85546 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 17.1 KB
Line 
1/* $Id: tstRTBitOperations.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Inlined Bit Operations.
4 */
5
6/*
7 * Copyright (C) 2006-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include <iprt/asm.h>
32
33#include <iprt/initterm.h>
34#include <iprt/stream.h>
35#include <iprt/string.h>
36#include <iprt/test.h>
37
38
39/*
40 * Test 2 - ID allocation using a bitmap.
41 */
42
43#define NIL_TEST2_ID 0
44#define TEST2_ID_LAST ((RT_BIT_32(28) - 1) >> 8)
45
46struct TestMap2
47{
48 uint32_t idNil;
49 uint32_t idLast;
50 uint32_t idChunkPrev;
51 uint32_t bmChunkId[(TEST2_ID_LAST + 1 + 31) / 32];
52};
53
54static uint32_t test2AllocId(struct TestMap2 *p2)
55{
56 /*
57 * Scan sequentially from the last one + 1.
58 */
59 int32_t idChunk = ++p2->idChunkPrev;
60 if ( (uint32_t)idChunk < TEST2_ID_LAST
61 && idChunk > NIL_TEST2_ID)
62 {
63 idChunk = ASMBitNextClear(&p2->bmChunkId[0], TEST2_ID_LAST + 1, idChunk);
64 if (idChunk > NIL_TEST2_ID)
65 {
66 if (ASMAtomicBitTestAndSet(&p2->bmChunkId[0], idChunk))
67 {
68 RTTestFailed(NIL_RTTEST, "line %d: idChunk=%#x", __LINE__, idChunk);
69 return NIL_TEST2_ID;
70 }
71 return p2->idChunkPrev = idChunk;
72 }
73 }
74
75 /*
76 * Ok, scan from the start.
77 */
78 idChunk = ASMBitFirstClear(&p2->bmChunkId[0], TEST2_ID_LAST + 1);
79 if (idChunk <= NIL_TEST2_ID)
80 {
81 RTTestFailed(NIL_RTTEST, "line %d: idChunk=%#x", __LINE__, idChunk);
82 return NIL_TEST2_ID;
83 }
84 if (ASMAtomicBitTestAndSet(&p2->bmChunkId[0], idChunk))
85 {
86 RTTestFailed(NIL_RTTEST, "line %d: idChunk=%#x", __LINE__, idChunk);
87 return NIL_TEST2_ID;
88 }
89
90 return p2->idChunkPrev = idChunk;
91}
92
93
94static void test2(RTTEST hTest)
95{
96 struct TestMap2 *p2 = (struct TestMap2 *)RTTestGuardedAllocTail(hTest, sizeof(TestMap2));
97 p2->idNil = NIL_TEST2_ID;
98 p2->idLast = TEST2_ID_LAST;
99
100 /* Some simple tests first. */
101 RT_ZERO(p2->bmChunkId);
102 RTTEST_CHECK(hTest, ASMBitFirstSet(&p2->bmChunkId[0], TEST2_ID_LAST + 1) == -1);
103 for (uint32_t iBit = 0; iBit <= TEST2_ID_LAST; iBit++)
104 RTTEST_CHECK(hTest, !ASMBitTest(&p2->bmChunkId[0], iBit));
105
106 memset(&p2->bmChunkId[0], 0xff, sizeof(p2->bmChunkId));
107 RTTEST_CHECK(hTest, ASMBitFirstClear(&p2->bmChunkId[0], TEST2_ID_LAST + 1) == -1);
108 for (uint32_t iBit = 0; iBit <= TEST2_ID_LAST; iBit++)
109 RTTEST_CHECK(hTest, ASMBitTest(&p2->bmChunkId[0], iBit));
110
111 /* The real test. */
112 p2->idChunkPrev = 0;
113 RT_ZERO(p2->bmChunkId);
114 ASMBitSet(p2->bmChunkId, NIL_TEST2_ID);
115 uint32_t cLeft = TEST2_ID_LAST;
116 while (cLeft-- > 0)
117 test2AllocId(p2);
118
119 RTTEST_CHECK(hTest, ASMBitFirstClear(&p2->bmChunkId[0], TEST2_ID_LAST + 1) == -1);
120}
121
122
123int main()
124{
125 /*
126 * Init the runtime and stuff.
127 */
128 RTTEST hTest;
129 int rc = RTTestInitAndCreate("tstRTBitOperations", &hTest);
130 if (rc)
131 return rc;
132 RTTestBanner(hTest);
133
134 int i;
135 int j;
136 int k;
137
138 /*
139 * Tests
140 */
141 struct TestMap
142 {
143 uint32_t au32[4];
144 };
145#if 0
146 struct TestMap sTest;
147 struct TestMap *p = &sTest;
148#else
149 struct TestMap *p = (struct TestMap *)RTTestGuardedAllocTail(hTest, sizeof(*p));
150#endif
151#define DUMP() RTTestPrintf(hTest, RTTESTLVL_INFO, "au32={%08x,%08x,%08x,%08x}", p->au32[0], p->au32[1], p->au32[2], p->au32[3])
152#define CHECK(expr) do { if (!(expr)) { RTTestFailed(hTest, "line %d: %s", __LINE__, #expr); DUMP(); } CHECK_GUARD(s); } while (0)
153#define CHECK_BIT(expr, b1) do { if (!(expr)) { RTTestFailed(hTest, "line %d, b1=%d: %s", __LINE__, b1, #expr); } CHECK_GUARD(s); } while (0)
154#define CHECK_BIT2(expr, b1, b2) do { if (!(expr)) { RTTestFailed(hTest, "line %d, b1=%d b2=%d: %s", __LINE__, b1, b2, #expr); } CHECK_GUARD(s); } while (0)
155#define CHECK_BIT3(expr, b1, b2, b3) do { if (!(expr)) { RTTestFailed(hTest, "line %d, b1=%d b2=%d b3=%d: %s", __LINE__, b1, b2, b3, #expr); } CHECK_GUARD(s); } while (0)
156
157#define GUARD_MAP(p) do { } while (0)
158#define CHECK_GUARD(p) do { } while (0)
159#define MAP_CLEAR(p) do { RT_ZERO(*(p)); GUARD_MAP(p); } while (0)
160#define MAP_SET(p) do { memset(p, 0xff, sizeof(*(p))); GUARD_MAP(p); } while (0)
161
162 /* self check. */
163 MAP_CLEAR(p);
164 CHECK_GUARD(p);
165
166 /* bit set */
167 MAP_CLEAR(p);
168 ASMBitSet(&p->au32[0], 0);
169 ASMBitSet(&p->au32[0], 31);
170 ASMBitSet(&p->au32[0], 65);
171 CHECK(p->au32[0] == 0x80000001U);
172 CHECK(p->au32[2] == 0x00000002U);
173 CHECK(ASMBitTestAndSet(&p->au32[0], 0) && p->au32[0] == 0x80000001U);
174 CHECK(!ASMBitTestAndSet(&p->au32[0], 16) && p->au32[0] == 0x80010001U);
175 CHECK(ASMBitTestAndSet(&p->au32[0], 16) && p->au32[0] == 0x80010001U);
176 CHECK(!ASMBitTestAndSet(&p->au32[0], 80) && p->au32[2] == 0x00010002U);
177
178 MAP_CLEAR(p);
179 ASMAtomicBitSet(&p->au32[0], 0);
180 ASMAtomicBitSet(&p->au32[0], 30);
181 ASMAtomicBitSet(&p->au32[0], 64);
182 CHECK(p->au32[0] == 0x40000001U);
183 CHECK(p->au32[2] == 0x00000001U);
184 CHECK(ASMAtomicBitTestAndSet(&p->au32[0], 0) && p->au32[0] == 0x40000001U);
185 CHECK(!ASMAtomicBitTestAndSet(&p->au32[0], 16) && p->au32[0] == 0x40010001U);
186 CHECK(ASMAtomicBitTestAndSet(&p->au32[0], 16) && p->au32[0] == 0x40010001U);
187 CHECK(!ASMAtomicBitTestAndSet(&p->au32[0], 80) && p->au32[2] == 0x00010001U);
188
189 /* bit clear */
190 MAP_SET(p);
191 ASMBitClear(&p->au32[0], 0);
192 ASMBitClear(&p->au32[0], 31);
193 ASMBitClear(&p->au32[0], 65);
194 CHECK(p->au32[0] == ~0x80000001U);
195 CHECK(p->au32[2] == ~0x00000002U);
196 CHECK(!ASMBitTestAndClear(&p->au32[0], 0) && p->au32[0] == ~0x80000001U);
197 CHECK(ASMBitTestAndClear(&p->au32[0], 16) && p->au32[0] == ~0x80010001U);
198 CHECK(!ASMBitTestAndClear(&p->au32[0], 16) && p->au32[0] == ~0x80010001U);
199 CHECK(ASMBitTestAndClear(&p->au32[0], 80) && p->au32[2] == ~0x00010002U);
200
201 MAP_SET(p);
202 ASMAtomicBitClear(&p->au32[0], 0);
203 ASMAtomicBitClear(&p->au32[0], 30);
204 ASMAtomicBitClear(&p->au32[0], 64);
205 CHECK(p->au32[0] == ~0x40000001U);
206 CHECK(p->au32[2] == ~0x00000001U);
207 CHECK(!ASMAtomicBitTestAndClear(&p->au32[0], 0) && p->au32[0] == ~0x40000001U);
208 CHECK(ASMAtomicBitTestAndClear(&p->au32[0], 16) && p->au32[0] == ~0x40010001U);
209 CHECK(!ASMAtomicBitTestAndClear(&p->au32[0], 16) && p->au32[0] == ~0x40010001U);
210 CHECK(ASMAtomicBitTestAndClear(&p->au32[0], 80) && p->au32[2] == ~0x00010001U);
211
212 /* toggle */
213 MAP_SET(p);
214 ASMBitToggle(&p->au32[0], 0);
215 ASMBitToggle(&p->au32[0], 31);
216 ASMBitToggle(&p->au32[0], 65);
217 ASMBitToggle(&p->au32[0], 47);
218 ASMBitToggle(&p->au32[0], 47);
219 CHECK(p->au32[0] == ~0x80000001U);
220 CHECK(p->au32[2] == ~0x00000002U);
221 CHECK(!ASMBitTestAndToggle(&p->au32[0], 0) && p->au32[0] == ~0x80000000U);
222 CHECK(ASMBitTestAndToggle(&p->au32[0], 0) && p->au32[0] == ~0x80000001U);
223 CHECK(ASMBitTestAndToggle(&p->au32[0], 16) && p->au32[0] == ~0x80010001U);
224 CHECK(!ASMBitTestAndToggle(&p->au32[0], 16) && p->au32[0] == ~0x80000001U);
225 CHECK(ASMBitTestAndToggle(&p->au32[0], 80) && p->au32[2] == ~0x00010002U);
226
227 MAP_SET(p);
228 ASMAtomicBitToggle(&p->au32[0], 0);
229 ASMAtomicBitToggle(&p->au32[0], 30);
230 ASMAtomicBitToggle(&p->au32[0], 64);
231 ASMAtomicBitToggle(&p->au32[0], 47);
232 ASMAtomicBitToggle(&p->au32[0], 47);
233 CHECK(p->au32[0] == ~0x40000001U);
234 CHECK(p->au32[2] == ~0x00000001U);
235 CHECK(!ASMAtomicBitTestAndToggle(&p->au32[0], 0) && p->au32[0] == ~0x40000000U);
236 CHECK(ASMAtomicBitTestAndToggle(&p->au32[0], 0) && p->au32[0] == ~0x40000001U);
237 CHECK(ASMAtomicBitTestAndToggle(&p->au32[0], 16) && p->au32[0] == ~0x40010001U);
238 CHECK(!ASMAtomicBitTestAndToggle(&p->au32[0], 16) && p->au32[0] == ~0x40000001U);
239 CHECK(ASMAtomicBitTestAndToggle(&p->au32[0], 80) && p->au32[2] == ~0x00010001U);
240
241 /* test bit. */
242 for (i = 0; i < 128; i++)
243 {
244 MAP_SET(p);
245 CHECK_BIT(ASMBitTest(&p->au32[0], i), i);
246 ASMBitToggle(&p->au32[0], i);
247 CHECK_BIT(!ASMBitTest(&p->au32[0], i), i);
248 CHECK_BIT(!ASMBitTestAndToggle(&p->au32[0], i), i);
249 CHECK_BIT(ASMBitTest(&p->au32[0], i), i);
250 CHECK_BIT(ASMBitTestAndToggle(&p->au32[0], i), i);
251 CHECK_BIT(!ASMBitTest(&p->au32[0], i), i);
252
253 MAP_SET(p);
254 CHECK_BIT(ASMBitTest(&p->au32[0], i), i);
255 ASMAtomicBitToggle(&p->au32[0], i);
256 CHECK_BIT(!ASMBitTest(&p->au32[0], i), i);
257 CHECK_BIT(!ASMAtomicBitTestAndToggle(&p->au32[0], i), i);
258 CHECK_BIT(ASMBitTest(&p->au32[0], i), i);
259 CHECK_BIT(ASMAtomicBitTestAndToggle(&p->au32[0], i), i);
260 CHECK_BIT(!ASMBitTest(&p->au32[0], i), i);
261 }
262
263 /* bit searching */
264 MAP_SET(p);
265 CHECK(ASMBitFirstClear(&p->au32[0], sizeof(p->au32) * 8) == -1);
266 CHECK(ASMBitFirstSet(&p->au32[0], sizeof(p->au32) * 8) == 0);
267
268 ASMBitClear(&p->au32[0], 1);
269 CHECK(ASMBitFirstClear(&p->au32[0], sizeof(p->au32) * 8) == 1);
270 CHECK(ASMBitFirstSet(&p->au32[0], sizeof(p->au32) * 8) == 0);
271
272 MAP_SET(p);
273 ASMBitClear(&p->au32[0], 95);
274 CHECK(ASMBitFirstClear(&p->au32[0], sizeof(p->au32) * 8) == 95);
275 CHECK(ASMBitFirstSet(&p->au32[0], sizeof(p->au32) * 8) == 0);
276
277 MAP_SET(p);
278 ASMBitClear(&p->au32[0], 127);
279 CHECK(ASMBitFirstClear(&p->au32[0], sizeof(p->au32) * 8) == 127);
280 CHECK(ASMBitFirstSet(&p->au32[0], sizeof(p->au32) * 8) == 0);
281 CHECK(ASMBitNextSet(&p->au32[0], sizeof(p->au32) * 8, 0) == 1);
282 CHECK(ASMBitNextSet(&p->au32[0], sizeof(p->au32) * 8, 1) == 2);
283 CHECK(ASMBitNextSet(&p->au32[0], sizeof(p->au32) * 8, 2) == 3);
284
285
286 MAP_SET(p);
287 CHECK(ASMBitNextClear(&p->au32[0], sizeof(p->au32) * 8, 0) == -1);
288 ASMBitClear(&p->au32[0], 32);
289 CHECK(ASMBitNextClear(&p->au32[0], sizeof(p->au32) * 8, 32) == -1);
290 ASMBitClear(&p->au32[0], 88);
291 CHECK(ASMBitNextClear(&p->au32[0], sizeof(p->au32) * 8, 57) == 88);
292
293 MAP_SET(p);
294 ASMBitClear(&p->au32[0], 31);
295 ASMBitClear(&p->au32[0], 57);
296 ASMBitClear(&p->au32[0], 88);
297 ASMBitClear(&p->au32[0], 101);
298 ASMBitClear(&p->au32[0], 126);
299 ASMBitClear(&p->au32[0], 127);
300 CHECK(ASMBitFirstClear(&p->au32[0], sizeof(p->au32) * 8) == 31);
301 CHECK(ASMBitNextClear(&p->au32[0], sizeof(p->au32) * 8, 31) == 57);
302 CHECK(ASMBitNextClear(&p->au32[0], sizeof(p->au32) * 8, 57) == 88);
303 CHECK(ASMBitNextClear(&p->au32[0], sizeof(p->au32) * 8, 88) == 101);
304 CHECK(ASMBitNextClear(&p->au32[0], sizeof(p->au32) * 8, 101) == 126);
305 CHECK(ASMBitNextClear(&p->au32[0], sizeof(p->au32) * 8, 126) == 127);
306 CHECK(ASMBitNextClear(&p->au32[0], sizeof(p->au32) * 8, 127) == -1);
307
308 CHECK(ASMBitNextSet(&p->au32[0], sizeof(p->au32) * 8, 29) == 30);
309 CHECK(ASMBitNextSet(&p->au32[0], sizeof(p->au32) * 8, 30) == 32);
310
311 MAP_CLEAR(p);
312 for (i = 1; i < 128; i++)
313 CHECK_BIT(ASMBitNextClear(&p->au32[0], sizeof(p->au32) * 8, i - 1) == i, i);
314 for (i = 0; i < 128; i++)
315 {
316 MAP_SET(p);
317 ASMBitClear(&p->au32[0], i);
318 CHECK_BIT(ASMBitFirstClear(&p->au32[0], sizeof(p->au32) * 8) == i, i);
319 for (j = 0; j < i; j++)
320 CHECK_BIT(ASMBitNextClear(&p->au32[0], sizeof(p->au32) * 8, j) == i, i);
321 for (j = i; j < 128; j++)
322 CHECK_BIT(ASMBitNextClear(&p->au32[0], sizeof(p->au32) * 8, j) == -1, i);
323 }
324
325 /* clear range. */
326 MAP_SET(p);
327 ASMBitClearRange(&p->au32, 0, 128);
328 CHECK(!p->au32[0] && !p->au32[1] && !p->au32[2] && !p->au32[3]);
329 for (i = 0; i < 128; i++)
330 {
331 for (j = i + 1; j <= 128; j++)
332 {
333 MAP_SET(p);
334 ASMBitClearRange(&p->au32, i, j);
335 for (k = 0; k < i; k++)
336 CHECK_BIT3(ASMBitTest(&p->au32[0], k), i, j, k);
337 for (k = i; k < j; k++)
338 CHECK_BIT3(!ASMBitTest(&p->au32[0], k), i, j, k);
339 for (k = j; k < 128; k++)
340 CHECK_BIT3(ASMBitTest(&p->au32[0], k), i, j, k);
341 }
342 }
343
344 /* set range. */
345 MAP_CLEAR(p);
346 ASMBitSetRange(&p->au32[0], 0, 5);
347 ASMBitSetRange(&p->au32[0], 6, 44);
348 ASMBitSetRange(&p->au32[0], 64, 65);
349 CHECK(p->au32[0] == UINT32_C(0xFFFFFFDF));
350 CHECK(p->au32[1] == UINT32_C(0x00000FFF));
351 CHECK(p->au32[2] == UINT32_C(0x00000001));
352
353 MAP_CLEAR(p);
354 ASMBitSetRange(&p->au32[0], 0, 1);
355 ASMBitSetRange(&p->au32[0], 62, 63);
356 ASMBitSetRange(&p->au32[0], 63, 64);
357 ASMBitSetRange(&p->au32[0], 127, 128);
358 CHECK(p->au32[0] == UINT32_C(0x00000001) && p->au32[1] == UINT32_C(0xC0000000));
359 CHECK(p->au32[2] == UINT32_C(0x00000000) && p->au32[3] == UINT32_C(0x80000000));
360
361 MAP_CLEAR(p);
362 ASMBitSetRange(&p->au32, 0, 128);
363 CHECK(!~p->au32[0] && !~p->au32[1] && !~p->au32[2] && !~p->au32[3]);
364 for (i = 0; i < 128; i++)
365 {
366 for (j = i + 1; j <= 128; j++)
367 {
368 MAP_CLEAR(p);
369 ASMBitSetRange(&p->au32, i, j);
370 for (k = 0; k < i; k++)
371 CHECK_BIT3(!ASMBitTest(&p->au32[0], k), i, j, k);
372 for (k = i; k < j; k++)
373 CHECK_BIT3(ASMBitTest(&p->au32[0], k), i, j, k);
374 for (k = j; k < 128; k++)
375 CHECK_BIT3(!ASMBitTest(&p->au32[0], k), i, j, k);
376 }
377 }
378
379 /* searching for set bits. */
380 MAP_CLEAR(p);
381 CHECK(ASMBitFirstSet(&p->au32[0], sizeof(p->au32) * 8) == -1);
382
383 ASMBitSet(&p->au32[0], 65);
384 CHECK(ASMBitFirstSet(&p->au32[0], sizeof(p->au32) * 8) == 65);
385 CHECK(ASMBitNextSet(&p->au32[0], sizeof(p->au32) * 8, 65) == -1);
386 for (i = 0; i < 65; i++)
387 CHECK(ASMBitNextSet(&p->au32[0], sizeof(p->au32) * 8, i) == 65);
388 for (i = 65; i < 128; i++)
389 CHECK(ASMBitNextSet(&p->au32[0], sizeof(p->au32) * 8, i) == -1);
390
391 ASMBitSet(&p->au32[0], 17);
392 CHECK(ASMBitFirstSet(&p->au32[0], sizeof(p->au32) * 8) == 17);
393 CHECK(ASMBitNextSet(&p->au32[0], sizeof(p->au32) * 8, 17) == 65);
394 for (i = 0; i < 16; i++)
395 CHECK(ASMBitNextSet(&p->au32[0], sizeof(p->au32) * 8, i) == 17);
396 for (i = 17; i < 65; i++)
397 CHECK(ASMBitNextSet(&p->au32[0], sizeof(p->au32) * 8, i) == 65);
398
399 MAP_SET(p);
400 for (i = 1; i < 128; i++)
401 CHECK_BIT(ASMBitNextSet(&p->au32[0], sizeof(p->au32) * 8, i - 1) == i, i);
402 for (i = 0; i < 128; i++)
403 {
404 MAP_CLEAR(p);
405 ASMBitSet(&p->au32[0], i);
406 CHECK_BIT(ASMBitFirstSet(&p->au32[0], sizeof(p->au32) * 8) == i, i);
407 for (j = 0; j < i; j++)
408 CHECK_BIT(ASMBitNextSet(&p->au32[0], sizeof(p->au32) * 8, j) == i, i);
409 for (j = i; j < 128; j++)
410 CHECK_BIT(ASMBitNextSet(&p->au32[0], sizeof(p->au32) * 8, j) == -1, i);
411 }
412
413
414 CHECK(ASMBitLastSetU32(0) == 0);
415 CHECK(ASMBitLastSetU32(1) == 1);
416 CHECK(ASMBitLastSetU32(0x80000000) == 32);
417 CHECK(ASMBitLastSetU32(0xffffffff) == 32);
418 CHECK(ASMBitLastSetU32(RT_BIT(23) | RT_BIT(11)) == 24);
419 for (i = 0; i < 32; i++)
420 CHECK(ASMBitLastSetU32(1 << i) == (unsigned)i + 1);
421
422 CHECK(ASMBitFirstSetU32(0) == 0);
423 CHECK(ASMBitFirstSetU32(1) == 1);
424 CHECK(ASMBitFirstSetU32(0x80000000) == 32);
425 CHECK(ASMBitFirstSetU32(0xffffffff) == 1);
426 CHECK(ASMBitFirstSetU32(RT_BIT(23) | RT_BIT(11)) == 12);
427 for (i = 0; i < 32; i++)
428 CHECK(ASMBitFirstSetU32(1 << i) == (unsigned)i + 1);
429
430 CHECK(ASMBitLastSetU64(UINT64_C(0)) == 0);
431 CHECK(ASMBitLastSetU64(UINT64_C(1)) == 1);
432 CHECK(ASMBitLastSetU64(UINT64_C(0x80000000)) == 32);
433 CHECK(ASMBitLastSetU64(UINT64_C(0xffffffff)) == 32);
434 CHECK(ASMBitLastSetU64(RT_BIT_64(33) | RT_BIT_64(11)) == 34);
435 for (i = 0; i < 64; i++)
436 CHECK(ASMBitLastSetU64(UINT64_C(1) << i) == (unsigned)i + 1);
437
438 CHECK(ASMBitFirstSetU64(UINT64_C(0)) == 0);
439 CHECK(ASMBitFirstSetU64(UINT64_C(1)) == 1);
440 CHECK(ASMBitFirstSetU64(UINT64_C(0x80000000)) == 32);
441 CHECK(ASMBitFirstSetU64(UINT64_C(0xffffffff)) == 1);
442 CHECK(ASMBitFirstSetU64(RT_BIT_64(33) | RT_BIT_64(11)) == 12);
443 for (i = 0; i < 64; i++)
444 CHECK(ASMBitFirstSetU64(UINT64_C(1) << i) == (unsigned)i + 1);
445
446 /*
447 * Special tests.
448 */
449 test2(hTest);
450
451 /*
452 * Summary
453 */
454 return RTTestSummaryAndDestroy(hTest);
455}
456
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette