struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bitfirstleading.c.in
blob2838699413aca2308e11d684b2d9fdb9066bbdab
1 /* Test find first leading bit operations from stdbit.h
3 type: unsigned short, unsigned int, unsigned long, unsigned long long
4 */
6 #include <testfwk.h>
8 #ifdef __SDCC // Todo: Enable for all C23 implementations
9 #pragma std_c23
10 #include <stdbit.h>
11 #endif
13 #include <limits.h>
15 volatile {type} i;
17 #define OTHERBYTEBITS(x) (sizeof(x) - 1) * CHAR_BIT
19 void
20 testTrailing(void)
22 #ifdef __SDCC // Todo: Enable for all C23 implementations
24 i = 0x0;
25 ASSERT (stdc_first_leading_one(i) == 0);
26 ASSERT (stdc_first_leading_zero(i) == 1);
28 i = 0x1;
29 ASSERT (stdc_first_leading_one(i) == OTHERBYTEBITS(i) + 8);
30 ASSERT (stdc_first_leading_zero(i) == 1);
32 i = 0x2;
33 ASSERT (stdc_first_leading_one(i) == OTHERBYTEBITS(i) + 7);
34 ASSERT (stdc_first_leading_zero(i) == 1);
36 i = 0x3;
37 ASSERT (stdc_first_leading_one(i) == OTHERBYTEBITS(i) + 7);
38 ASSERT (stdc_first_leading_zero(i) == 1);
40 i = 0x7;
41 ASSERT (stdc_first_leading_one(i) == OTHERBYTEBITS(i) + 6);
42 ASSERT (stdc_first_leading_zero(i) == 1);
44 i = 0x8;
45 ASSERT (stdc_first_leading_one(i) == OTHERBYTEBITS(i) + 5);
46 ASSERT (stdc_first_leading_zero(i) == 1);
48 i = 0x9;
49 ASSERT (stdc_first_leading_one(i) == OTHERBYTEBITS(i) + 5);
50 ASSERT (stdc_first_leading_zero(i) == 1);
51 #endif