summaryrefslogtreecommitdiff
path: root/support/regression/tests/bitcount.c.in
blob: 13242e6234fc7a0feabfd2036585e6085364c1ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* Test count operations from stdbit.h

   type: unsigned short, unsigned int, unsigned long, unsigned long long
 */

#include <testfwk.h>

#if __STDC_VERSION_STDBIT_H__ >= 202311L
#pragma std_c23
#include <stdbit.h>
#endif

volatile {type} i, j;

void
testCount(void)
{
#if __STDC_VERSION_STDBIT_H__ >= 202311L
	i = 0x10;
	j = ~i;
	ASSERT (stdc_count_ones(i) == 1);
	ASSERT (stdc_count_zeros(j) == 1);
	ASSERT (stdc_has_single_bit(i));
	ASSERT (!stdc_has_single_bit(j));

	i = 0xff;
	j = ~i;
	ASSERT (stdc_count_ones(i) == 8);
	ASSERT (stdc_count_zeros(j) == 8);
	ASSERT (!stdc_has_single_bit(i));
	ASSERT (!stdc_has_single_bit(j));
#endif
}