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
test__cmpti2(ti_int a,ti_int b,si_int expected)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("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
main()35 int main()
36 {
37 #ifdef CRT_HAS_128BIT
38 if (test__cmpti2(0, 0, 1))
39 return 1;
40 if (test__cmpti2(1, 1, 1))
41 return 1;
42 if (test__cmpti2(2, 2, 1))
43 return 1;
44 if (test__cmpti2(0x7FFFFFFF, 0x7FFFFFFF, 1))
45 return 1;
46 if (test__cmpti2(0x80000000, 0x80000000, 1))
47 return 1;
48 if (test__cmpti2(0x80000001, 0x80000001, 1))
49 return 1;
50 if (test__cmpti2(0xFFFFFFFF, 0xFFFFFFFF, 1))
51 return 1;
52 if (test__cmpti2(0x000000010000000LL, 0x000000010000000LL, 1))
53 return 1;
54 if (test__cmpti2(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL, 1))
55 return 1;
56
57 if (test__cmpti2(0x0000000200000002LL, 0x0000000300000001LL, 0))
58 return 1;
59 if (test__cmpti2(0x0000000200000002LL, 0x0000000300000002LL, 0))
60 return 1;
61 if (test__cmpti2(0x0000000200000002LL, 0x0000000300000003LL, 0))
62 return 1;
63
64 if (test__cmpti2(0x0000000200000002LL, 0x0000000100000001LL, 2))
65 return 1;
66 if (test__cmpti2(0x0000000200000002LL, 0x0000000100000002LL, 2))
67 return 1;
68 if (test__cmpti2(0x0000000200000002LL, 0x0000000100000003LL, 2))
69 return 1;
70
71 if (test__cmpti2(0x0000000200000002LL, 0x0000000200000001LL, 2))
72 return 1;
73 if (test__cmpti2(0x0000000200000002LL, 0x0000000200000002LL, 1))
74 return 1;
75 if (test__cmpti2(0x0000000200000002LL, 0x0000000200000003LL, 0))
76 return 1;
77
78 if (test__cmpti2(make_ti(2, 2), make_ti(3, 1), 0))
79 return 1;
80 if (test__cmpti2(make_ti(2, 2), make_ti(3, 2), 0))
81 return 1;
82 if (test__cmpti2(make_ti(2, 2), make_ti(3, 3), 0))
83 return 1;
84
85 if (test__cmpti2(make_ti(2, 2), make_ti(1, 1), 2))
86 return 1;
87 if (test__cmpti2(make_ti(2, 2), make_ti(1, 2), 2))
88 return 1;
89 if (test__cmpti2(make_ti(2, 2), make_ti(1, 3), 2))
90 return 1;
91
92 if (test__cmpti2(make_ti(2, 2), make_ti(2, 1), 2))
93 return 1;
94 if (test__cmpti2(make_ti(2, 2), make_ti(2, 2), 1))
95 return 1;
96 if (test__cmpti2(make_ti(2, 2), make_ti(2, 3), 0))
97 return 1;
98
99 #else
100 printf("skipped\n");
101 #endif
102 return 0;
103 }
104