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