| 1 |
/* Test stdc_leading_zeros functions and macros. |
| 2 |
Copyright (C) 2024-2025 Free Software Foundation, Inc. |
| 3 |
This file is part of the GNU C Library. |
| 4 |
|
| 5 |
The GNU C Library is free software; you can redistribute it and/or |
| 6 |
modify it under the terms of the GNU Lesser General Public |
| 7 |
License as published by the Free Software Foundation; either |
| 8 |
version 2.1 of the License, or (at your option) any later version. |
| 9 |
|
| 10 |
The GNU C Library is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
Lesser General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU Lesser General Public |
| 16 |
License along with the GNU C Library; if not, see |
| 17 |
<https://www.gnu.org/licenses/>. */ |
| 18 |
|
| 19 |
#include <tst-stdbit.h> |
| 20 |
|
| 21 |
static const struct stdbit_test inputs[] = |
| 22 |
{ |
| 23 |
{ 0ULL, 8, 16, 32, 64 }, |
| 24 |
{ 0x1ULL, 7, 15, 31, 63 }, |
| 25 |
{ 0x2ULL, 6, 14, 30, 62 }, |
| 26 |
{ 0x3ULL, 6, 14, 30, 62 }, |
| 27 |
{ 0x4ULL, 5, 13, 29, 61 }, |
| 28 |
{ 0x5ULL, 5, 13, 29, 61 }, |
| 29 |
{ 0x6ULL, 5, 13, 29, 61 }, |
| 30 |
{ 0x7ULL, 5, 13, 29, 61 }, |
| 31 |
{ 0x8ULL, 4, 12, 28, 60 }, |
| 32 |
{ 0x9ULL, 4, 12, 28, 60 }, |
| 33 |
{ 0xaULL, 4, 12, 28, 60 }, |
| 34 |
{ 0xbULL, 4, 12, 28, 60 }, |
| 35 |
{ 0xcULL, 4, 12, 28, 60 }, |
| 36 |
{ 0xdULL, 4, 12, 28, 60 }, |
| 37 |
{ 0xeULL, 4, 12, 28, 60 }, |
| 38 |
{ 0xfULL, 4, 12, 28, 60 }, |
| 39 |
{ 0x10ULL, 3, 11, 27, 59 }, |
| 40 |
{ 0x11ULL, 3, 11, 27, 59 }, |
| 41 |
{ 0x12ULL, 3, 11, 27, 59 }, |
| 42 |
{ 0x1fULL, 3, 11, 27, 59 }, |
| 43 |
{ 0x20ULL, 2, 10, 26, 58 }, |
| 44 |
{ 0x7fULL, 1, 9, 25, 57 }, |
| 45 |
{ 0x80ULL, 0, 8, 24, 56 }, |
| 46 |
{ 0x81ULL, 0, 8, 24, 56 }, |
| 47 |
{ 0x9aULL, 0, 8, 24, 56 }, |
| 48 |
{ 0xf3ULL, 0, 8, 24, 56 }, |
| 49 |
{ 0xffULL, 0, 8, 24, 56 }, |
| 50 |
{ 0x100ULL, 8, 7, 23, 55 }, |
| 51 |
{ 0x101ULL, 7, 7, 23, 55 }, |
| 52 |
{ 0x102ULL, 6, 7, 23, 55 }, |
| 53 |
{ 0x1feULL, 0, 7, 23, 55 }, |
| 54 |
{ 0x1ffULL, 0, 7, 23, 55 }, |
| 55 |
{ 0x200ULL, 8, 6, 22, 54 }, |
| 56 |
{ 0x234ULL, 2, 6, 22, 54 }, |
| 57 |
{ 0x4567ULL, 1, 1, 17, 49 }, |
| 58 |
{ 0x7fffULL, 0, 1, 17, 49 }, |
| 59 |
{ 0x8000ULL, 8, 0, 16, 48 }, |
| 60 |
{ 0x8001ULL, 7, 0, 16, 48 }, |
| 61 |
{ 0xfffeULL, 0, 0, 16, 48 }, |
| 62 |
{ 0xffffULL, 0, 0, 16, 48 }, |
| 63 |
{ 0x10000ULL, 8, 16, 15, 47 }, |
| 64 |
{ 0x10001ULL, 7, 15, 15, 47 }, |
| 65 |
{ 0xfedcba98ULL, 0, 0, 0, 32 }, |
| 66 |
{ 0xfffffefeULL, 0, 0, 0, 32 }, |
| 67 |
{ 0xffffffffULL, 0, 0, 0, 32 }, |
| 68 |
{ 0x100000000ULL, 8, 16, 32, 31 }, |
| 69 |
{ 0x100000001ULL, 7, 15, 31, 31 }, |
| 70 |
{ 0x123456789ULL, 0, 1, 2, 31 }, |
| 71 |
{ 0x123456789abcdefULL, 0, 0, 0, 7 }, |
| 72 |
{ 0x789abcdef0123456ULL, 1, 2, 0, 1 }, |
| 73 |
{ 0x8000000000000000ULL, 8, 16, 32, 0 }, |
| 74 |
{ 0x8000000000000001ULL, 7, 15, 31, 0 }, |
| 75 |
{ 0xfffffffffffffffeULL, 0, 0, 0, 0 }, |
| 76 |
{ 0xffffffffffffffffULL, 0, 0, 0, 0 }, |
| 77 |
}; |
| 78 |
|
| 79 |
TEST_STDBIT_UI_TOPLEVEL (stdc_leading_zeros); |
| 80 |
|
| 81 |
static int |
| 82 |
do_test (void) |
| 83 |
{ |
| 84 |
TEST_STDBIT_UI (stdc_leading_zeros, inputs); |
| 85 |
return 0; |
| 86 |
} |
| 87 |
|
| 88 |
#include <support/test-driver.c> |