Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bitcounttrailing.c.in
blob215a0920e15ca558a50399a4fd1f5b55a1132da4
1 /* Test count trailing bits 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 void
18 testTrailing(void)
20 #ifdef __SDCC // Todo: Enable for all C23 implementations
21 i = 0x0;
22 ASSERT (stdc_count_trailing_ones(i) == 0);
23 ASSERT (stdc_count_trailing_zeros(i) == sizeof({type}) * CHAR_BIT);
25 i = 0x1;
26 ASSERT (stdc_count_trailing_ones(i) == 1);
27 ASSERT (stdc_count_trailing_zeros(i) == 0);
29 i = 0x2;
30 ASSERT (stdc_count_trailing_ones(i) == 0);
31 ASSERT (stdc_count_trailing_zeros(i) == 1);
33 i = 0x3;
34 ASSERT (stdc_count_trailing_ones(i) == 2);
35 ASSERT (stdc_count_trailing_zeros(i) == 0);
37 i = 0x7;
38 ASSERT (stdc_count_trailing_ones(i) == 3);
39 ASSERT (stdc_count_trailing_zeros(i) == 0);
41 i = 0x8;
42 ASSERT (stdc_count_trailing_ones(i) == 0);
43 ASSERT (stdc_count_trailing_zeros(i) == 3);
45 i = 0x9;
46 ASSERT (stdc_count_trailing_ones(i) == 1);
47 ASSERT (stdc_count_trailing_zeros(i) == 0);
48 #endif