master
c 57 lines 1.55 KB
Raw
1 #include <assert.h>
2 #include <inttypes.h>
3
4 #define ARRAY_SIZE(X) (sizeof(X) / sizeof(*(X)))
5
6 #define TEST(C, I) \
7 static uint64_t test_##C(uint64_t rj) \
8 { \
9 uint64_t rd; \
10 asm volatile(I " %0, %1\n\t" : "=r"(rd) : "r"(rj)); \
11 return rd; \
12 }
13
14 TEST(clo_w, "clo.w")
15 TEST(clo_d, "clo.d")
16 TEST(clz_w, "clz.w")
17 TEST(clz_d, "clz.d")
18 TEST(cto_w, "cto.w")
19 TEST(cto_d, "cto.d")
20 TEST(ctz_w, "ctz.w")
21 TEST(ctz_d, "ctz.d")
22 TEST(bitrev_4b, "bitrev.4b")
23 TEST(bitrev_8b, "bitrev.8b")
24 TEST(bitrev_w, "bitrev.w")
25 TEST(bitrev_d, "bitrev.d")
26
27 struct vector {
28 uint64_t (*func)(uint64_t);
29 uint64_t u;
30 uint64_t r;
31 };
32
33 static struct vector vectors[] = {
34 {test_clo_w, 0xfff11fff392476ab, 0},
35 {test_clo_d, 0xabd28a64000000, 0},
36 {test_clz_w, 0xfaffff42392476ab, 2},
37 {test_clz_d, 0xabd28a64000000, 8},
38 {test_cto_w, 0xfff11fff392476ab, 2},
39 {test_cto_d, 0xabd28a64000000, 0},
40 {test_ctz_w, 0xfaffff42392476ab, 0},
41 {test_ctz_d, 0xabd28a64000000, 26},
42 {test_bitrev_4b, 0xdeadbeef11223344, 0xffffffff8844cc22},
43 {test_bitrev_8b, 0x1122334455667788, 0x8844cc22aa66ee11},
44 {test_bitrev_w, 0xdeadbeef89abcdef, 0xfffffffff7b3d591},
45 {test_bitrev_d, 0x0123456789abcdef, 0xf7b3d591e6a2c480},
46 };
47
48 int main()
49 {
50 int i;
51
52 for (i = 0; i < ARRAY_SIZE(vectors); i++) {
53 assert((*vectors[i].func)(vectors[i].u) == vectors[i].r);
54 }
55
56 return 0;
57 }