1*4684ddb6SLionel Sambuc //===-- cmpdi2_test.c - Test __cmpdi2 -------------------------------------===//
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 __cmpdi2 for the compiler_rt library.
11*4684ddb6SLionel Sambuc //
12*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
13*4684ddb6SLionel Sambuc
14*4684ddb6SLionel Sambuc #include "int_lib.h"
15*4684ddb6SLionel Sambuc #include <stdio.h>
16*4684ddb6SLionel Sambuc
17*4684ddb6SLionel Sambuc // Returns: if (a < b) returns 0
18*4684ddb6SLionel Sambuc // if (a == b) returns 1
19*4684ddb6SLionel Sambuc // if (a > b) returns 2
20*4684ddb6SLionel Sambuc
21*4684ddb6SLionel Sambuc si_int __cmpdi2(di_int a, di_int b);
22*4684ddb6SLionel Sambuc
test__cmpdi2(di_int a,di_int b,si_int expected)23*4684ddb6SLionel Sambuc int test__cmpdi2(di_int a, di_int b, si_int expected)
24*4684ddb6SLionel Sambuc {
25*4684ddb6SLionel Sambuc si_int x = __cmpdi2(a, b);
26*4684ddb6SLionel Sambuc if (x != expected)
27*4684ddb6SLionel Sambuc printf("error in __cmpdi2(0x%llX, 0x%llX) = %d, expected %d\n",
28*4684ddb6SLionel Sambuc a, b, x, expected);
29*4684ddb6SLionel Sambuc return x != expected;
30*4684ddb6SLionel Sambuc }
31*4684ddb6SLionel Sambuc
32*4684ddb6SLionel Sambuc char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
33*4684ddb6SLionel Sambuc
main()34*4684ddb6SLionel Sambuc int main()
35*4684ddb6SLionel Sambuc {
36*4684ddb6SLionel Sambuc if (test__cmpdi2(0, 0, 1))
37*4684ddb6SLionel Sambuc return 1;
38*4684ddb6SLionel Sambuc if (test__cmpdi2(1, 1, 1))
39*4684ddb6SLionel Sambuc return 1;
40*4684ddb6SLionel Sambuc if (test__cmpdi2(2, 2, 1))
41*4684ddb6SLionel Sambuc return 1;
42*4684ddb6SLionel Sambuc if (test__cmpdi2(0x7FFFFFFF, 0x7FFFFFFF, 1))
43*4684ddb6SLionel Sambuc return 1;
44*4684ddb6SLionel Sambuc if (test__cmpdi2(0x80000000, 0x80000000, 1))
45*4684ddb6SLionel Sambuc return 1;
46*4684ddb6SLionel Sambuc if (test__cmpdi2(0x80000001, 0x80000001, 1))
47*4684ddb6SLionel Sambuc return 1;
48*4684ddb6SLionel Sambuc if (test__cmpdi2(0xFFFFFFFF, 0xFFFFFFFF, 1))
49*4684ddb6SLionel Sambuc return 1;
50*4684ddb6SLionel Sambuc if (test__cmpdi2(0x000000010000000LL, 0x000000010000000LL, 1))
51*4684ddb6SLionel Sambuc return 1;
52*4684ddb6SLionel Sambuc if (test__cmpdi2(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL, 1))
53*4684ddb6SLionel Sambuc return 1;
54*4684ddb6SLionel Sambuc
55*4684ddb6SLionel Sambuc if (test__cmpdi2(0x0000000200000002LL, 0x0000000300000001LL, 0))
56*4684ddb6SLionel Sambuc return 1;
57*4684ddb6SLionel Sambuc if (test__cmpdi2(0x0000000200000002LL, 0x0000000300000002LL, 0))
58*4684ddb6SLionel Sambuc return 1;
59*4684ddb6SLionel Sambuc if (test__cmpdi2(0x0000000200000002LL, 0x0000000300000003LL, 0))
60*4684ddb6SLionel Sambuc return 1;
61*4684ddb6SLionel Sambuc
62*4684ddb6SLionel Sambuc if (test__cmpdi2(0x0000000200000002LL, 0x0000000100000001LL, 2))
63*4684ddb6SLionel Sambuc return 1;
64*4684ddb6SLionel Sambuc if (test__cmpdi2(0x0000000200000002LL, 0x0000000100000002LL, 2))
65*4684ddb6SLionel Sambuc return 1;
66*4684ddb6SLionel Sambuc if (test__cmpdi2(0x0000000200000002LL, 0x0000000100000003LL, 2))
67*4684ddb6SLionel Sambuc return 1;
68*4684ddb6SLionel Sambuc
69*4684ddb6SLionel Sambuc if (test__cmpdi2(0x0000000200000002LL, 0x0000000200000001LL, 2))
70*4684ddb6SLionel Sambuc return 1;
71*4684ddb6SLionel Sambuc if (test__cmpdi2(0x0000000200000002LL, 0x0000000200000002LL, 1))
72*4684ddb6SLionel Sambuc return 1;
73*4684ddb6SLionel Sambuc if (test__cmpdi2(0x0000000200000002LL, 0x0000000200000003LL, 0))
74*4684ddb6SLionel Sambuc return 1;
75*4684ddb6SLionel Sambuc
76*4684ddb6SLionel Sambuc return 0;
77*4684ddb6SLionel Sambuc }
78