blob: 3c4ff872e0d1f6addd6c93d8fe9c8423c3b5c968 (
plain) (
blame)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST
extern inline unsigned libj2_ctz_j2u(const struct libj2_j2u *a);
/* TODO Add man page */
#else
static uintmax_t
random_ju(void)
{
size_t n = LIBJ2_JU_BIT;
uintmax_t r = 0;
while (n--)
if (rand() < rand())
r |= (uintmax_t)1 << n;
return r;
}
int
main(void)
{
struct libj2_j2u a, a_saved;
unsigned i, j;
srand((unsigned)time(NULL));
for (i = 0; i <= LIBJ2_J2U_BIT; i++) {
for (j = 0; j < 64; j++) {
a.high = random_ju();
a.low = random_ju();
libj2_j2u_or_bit(&a, 0);
libj2_j2u_lsh(&a, i);
a_saved = a;
EXPECT(libj2_ctz_j2u(&a) == i);
EXPECT(libj2_j2u_eq_j2u(&a, &a_saved));
if (i <= LIBJ2_JU_BIT) {
a.high = UINTMAX_MAX;
a_saved.high = UINTMAX_MAX;
EXPECT(libj2_ctz_j2u(&a) == i);
EXPECT(libj2_j2u_eq_j2u(&a, &a_saved));
}
if (i < LIBJ2_JU_BIT) {
a.high = 0;
a_saved.high = 0;
EXPECT(libj2_ctz_j2u(&a) == i);
EXPECT(libj2_j2u_eq_j2u(&a, &a_saved));
}
}
}
return 0;
}
#endif
|