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