1 //===-- cmpti2_test.c - Test __cmpti2 -------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file tests __cmpti2 for the compiler_rt library.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #if __x86_64
15
16 #include "int_lib.h"
17 #include <stdio.h>
18
19 // Returns: if (a < b) returns 0
20 // if (a == b) returns 1
21 // if (a > b) returns 2
22
23 si_int __cmpti2(ti_int a, ti_int b);
24
test__cmpti2(ti_int a,ti_int b,si_int expected)25 int test__cmpti2(ti_int a, ti_int b, si_int expected)
26 {
27 si_int x = __cmpti2(a, b);
28 if (x != expected)
29 {
30 twords at;
31 at.all = a;
32 twords bt;
33 bt.all = b;
34 printf("error in __cmpti2(0x%llX%.16llX, 0x%llX%.16llX) = %d, expected %d\n",
35 at.s.high, at.s.low, bt.s.high, bt.s.low, x, expected);
36 }
37 return x != expected;
38 }
39
40 char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
41
42 #endif
43
main()44 int main()
45 {
46 #if __x86_64
47 if (test__cmpti2(0, 0, 1))
48 return 1;
49 if (test__cmpti2(1, 1, 1))
50 return 1;
51 if (test__cmpti2(2, 2, 1))
52 return 1;
53 if (test__cmpti2(0x7FFFFFFF, 0x7FFFFFFF, 1))
54 return 1;
55 if (test__cmpti2(0x80000000, 0x80000000, 1))
56 return 1;
57 if (test__cmpti2(0x80000001, 0x80000001, 1))
58 return 1;
59 if (test__cmpti2(0xFFFFFFFF, 0xFFFFFFFF, 1))
60 return 1;
61 if (test__cmpti2(0x000000010000000LL, 0x000000010000000LL, 1))
62 return 1;
63 if (test__cmpti2(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL, 1))
64 return 1;
65
66 if (test__cmpti2(0x0000000200000002LL, 0x0000000300000001LL, 0))
67 return 1;
68 if (test__cmpti2(0x0000000200000002LL, 0x0000000300000002LL, 0))
69 return 1;
70 if (test__cmpti2(0x0000000200000002LL, 0x0000000300000003LL, 0))
71 return 1;
72
73 if (test__cmpti2(0x0000000200000002LL, 0x0000000100000001LL, 2))
74 return 1;
75 if (test__cmpti2(0x0000000200000002LL, 0x0000000100000002LL, 2))
76 return 1;
77 if (test__cmpti2(0x0000000200000002LL, 0x0000000100000003LL, 2))
78 return 1;
79
80 if (test__cmpti2(0x0000000200000002LL, 0x0000000200000001LL, 2))
81 return 1;
82 if (test__cmpti2(0x0000000200000002LL, 0x0000000200000002LL, 1))
83 return 1;
84 if (test__cmpti2(0x0000000200000002LL, 0x0000000200000003LL, 0))
85 return 1;
86
87 if (test__cmpti2(make_ti(2, 2), make_ti(3, 1), 0))
88 return 1;
89 if (test__cmpti2(make_ti(2, 2), make_ti(3, 2), 0))
90 return 1;
91 if (test__cmpti2(make_ti(2, 2), make_ti(3, 3), 0))
92 return 1;
93
94 if (test__cmpti2(make_ti(2, 2), make_ti(1, 1), 2))
95 return 1;
96 if (test__cmpti2(make_ti(2, 2), make_ti(1, 2), 2))
97 return 1;
98 if (test__cmpti2(make_ti(2, 2), make_ti(1, 3), 2))
99 return 1;
100
101 if (test__cmpti2(make_ti(2, 2), make_ti(2, 1), 2))
102 return 1;
103 if (test__cmpti2(make_ti(2, 2), make_ti(2, 2), 1))
104 return 1;
105 if (test__cmpti2(make_ti(2, 2), make_ti(2, 3), 0))
106 return 1;
107
108 #else
109 printf("skipped\n");
110 #endif
111 return 0;
112 }
113