1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
2 | // REQUIRES: librt_has_cmpti2 |
3 | // REQUIRES: int128 |
4 | |
5 | #include "int_lib.h" |
6 | #include <stdio.h> |
7 | |
8 | #ifdef CRT_HAS_128BIT |
9 | |
10 | // Returns: if (a < b) returns 0 |
11 | // if (a == b) returns 1 |
12 | // if (a > b) returns 2 |
13 | |
14 | COMPILER_RT_ABI si_int __cmpti2(ti_int a, ti_int b); |
15 | |
16 | int test__cmpti2(ti_int a, ti_int b, si_int expected) |
17 | { |
18 | si_int x = __cmpti2(a, b); |
19 | if (x != expected) |
20 | { |
21 | twords at; |
22 | at.all = a; |
23 | twords bt; |
24 | bt.all = b; |
25 | printf(format: "error in __cmpti2(0x%llX%.16llX, 0x%llX%.16llX) = %d, expected %d\n" , |
26 | at.s.high, at.s.low, bt.s.high, bt.s.low, x, expected); |
27 | } |
28 | return x != expected; |
29 | } |
30 | |
31 | char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0}; |
32 | |
33 | #endif |
34 | |
35 | int main() |
36 | { |
37 | #ifdef CRT_HAS_128BIT |
38 | if (test__cmpti2(a: 0, b: 0, expected: 1)) |
39 | return 1; |
40 | if (test__cmpti2(a: 1, b: 1, expected: 1)) |
41 | return 1; |
42 | if (test__cmpti2(a: 2, b: 2, expected: 1)) |
43 | return 1; |
44 | if (test__cmpti2(a: 0x7FFFFFFF, b: 0x7FFFFFFF, expected: 1)) |
45 | return 1; |
46 | if (test__cmpti2(a: 0x80000000, b: 0x80000000, expected: 1)) |
47 | return 1; |
48 | if (test__cmpti2(a: 0x80000001, b: 0x80000001, expected: 1)) |
49 | return 1; |
50 | if (test__cmpti2(a: 0xFFFFFFFF, b: 0xFFFFFFFF, expected: 1)) |
51 | return 1; |
52 | if (test__cmpti2(a: 0x000000010000000LL, b: 0x000000010000000LL, expected: 1)) |
53 | return 1; |
54 | if (test__cmpti2(a: 0xFFFFFFFFFFFFFFFFLL, b: 0xFFFFFFFFFFFFFFFFLL, expected: 1)) |
55 | return 1; |
56 | |
57 | if (test__cmpti2(a: 0x0000000200000002LL, b: 0x0000000300000001LL, expected: 0)) |
58 | return 1; |
59 | if (test__cmpti2(a: 0x0000000200000002LL, b: 0x0000000300000002LL, expected: 0)) |
60 | return 1; |
61 | if (test__cmpti2(a: 0x0000000200000002LL, b: 0x0000000300000003LL, expected: 0)) |
62 | return 1; |
63 | |
64 | if (test__cmpti2(a: 0x0000000200000002LL, b: 0x0000000100000001LL, expected: 2)) |
65 | return 1; |
66 | if (test__cmpti2(a: 0x0000000200000002LL, b: 0x0000000100000002LL, expected: 2)) |
67 | return 1; |
68 | if (test__cmpti2(a: 0x0000000200000002LL, b: 0x0000000100000003LL, expected: 2)) |
69 | return 1; |
70 | |
71 | if (test__cmpti2(a: 0x0000000200000002LL, b: 0x0000000200000001LL, expected: 2)) |
72 | return 1; |
73 | if (test__cmpti2(a: 0x0000000200000002LL, b: 0x0000000200000002LL, expected: 1)) |
74 | return 1; |
75 | if (test__cmpti2(a: 0x0000000200000002LL, b: 0x0000000200000003LL, expected: 0)) |
76 | return 1; |
77 | |
78 | if (test__cmpti2(a: make_ti(h: 2, l: 2), b: make_ti(h: 3, l: 1), expected: 0)) |
79 | return 1; |
80 | if (test__cmpti2(a: make_ti(h: 2, l: 2), b: make_ti(h: 3, l: 2), expected: 0)) |
81 | return 1; |
82 | if (test__cmpti2(a: make_ti(h: 2, l: 2), b: make_ti(h: 3, l: 3), expected: 0)) |
83 | return 1; |
84 | |
85 | if (test__cmpti2(a: make_ti(h: 2, l: 2), b: make_ti(h: 1, l: 1), expected: 2)) |
86 | return 1; |
87 | if (test__cmpti2(a: make_ti(h: 2, l: 2), b: make_ti(h: 1, l: 2), expected: 2)) |
88 | return 1; |
89 | if (test__cmpti2(a: make_ti(h: 2, l: 2), b: make_ti(h: 1, l: 3), expected: 2)) |
90 | return 1; |
91 | |
92 | if (test__cmpti2(a: make_ti(h: 2, l: 2), b: make_ti(h: 2, l: 1), expected: 2)) |
93 | return 1; |
94 | if (test__cmpti2(a: make_ti(h: 2, l: 2), b: make_ti(h: 2, l: 2), expected: 1)) |
95 | return 1; |
96 | if (test__cmpti2(a: make_ti(h: 2, l: 2), b: make_ti(h: 2, l: 3), expected: 0)) |
97 | return 1; |
98 | |
99 | #else |
100 | printf("skipped\n" ); |
101 | #endif |
102 | return 0; |
103 | } |
104 | |