1*4684ddb6SLionel Sambuc //===-- negvti2_test.c - Test __negvti2 -----------------------------------===//
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 __negvti2 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: -a
20*4684ddb6SLionel Sambuc
21*4684ddb6SLionel Sambuc // Effects: aborts if -a overflows
22*4684ddb6SLionel Sambuc
23*4684ddb6SLionel Sambuc ti_int __negvti2(ti_int a);
24*4684ddb6SLionel Sambuc ti_int __negti2(ti_int a);
25*4684ddb6SLionel Sambuc
test__negvti2(ti_int a)26*4684ddb6SLionel Sambuc int test__negvti2(ti_int a)
27*4684ddb6SLionel Sambuc {
28*4684ddb6SLionel Sambuc ti_int x = __negvti2(a);
29*4684ddb6SLionel Sambuc ti_int expected = __negti2(a);
30*4684ddb6SLionel Sambuc if (x != expected)
31*4684ddb6SLionel Sambuc {
32*4684ddb6SLionel Sambuc twords at;
33*4684ddb6SLionel Sambuc at.all = a;
34*4684ddb6SLionel Sambuc twords xt;
35*4684ddb6SLionel Sambuc xt.all = x;
36*4684ddb6SLionel Sambuc twords expectedt;
37*4684ddb6SLionel Sambuc expectedt.all = expected;
38*4684ddb6SLionel Sambuc printf("error in __negvti2(0x%.16llX%.16llX) = 0x%.16llX%.16llX, "
39*4684ddb6SLionel Sambuc "expected 0x%.16llX%.16llX\n",
40*4684ddb6SLionel Sambuc at.s.high, at.s.low, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
41*4684ddb6SLionel Sambuc }
42*4684ddb6SLionel Sambuc return x != expected;
43*4684ddb6SLionel Sambuc }
44*4684ddb6SLionel Sambuc
45*4684ddb6SLionel Sambuc #endif
46*4684ddb6SLionel Sambuc
main()47*4684ddb6SLionel Sambuc int main()
48*4684ddb6SLionel Sambuc {
49*4684ddb6SLionel Sambuc #if __x86_64
50*4684ddb6SLionel Sambuc if (test__negvti2(0))
51*4684ddb6SLionel Sambuc return 1;
52*4684ddb6SLionel Sambuc if (test__negvti2(1))
53*4684ddb6SLionel Sambuc return 1;
54*4684ddb6SLionel Sambuc if (test__negvti2(-1))
55*4684ddb6SLionel Sambuc return 1;
56*4684ddb6SLionel Sambuc if (test__negvti2(2))
57*4684ddb6SLionel Sambuc return 1;
58*4684ddb6SLionel Sambuc if (test__negvti2(-2))
59*4684ddb6SLionel Sambuc return 1;
60*4684ddb6SLionel Sambuc if (test__negvti2(3))
61*4684ddb6SLionel Sambuc return 1;
62*4684ddb6SLionel Sambuc if (test__negvti2(-3))
63*4684ddb6SLionel Sambuc return 1;
64*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0x0000000000000000LL, 0x00000000FFFFFFFELL)))
65*4684ddb6SLionel Sambuc return 1;
66*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000002LL)))
67*4684ddb6SLionel Sambuc return 1;
68*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0x0000000000000000LL, 0x00000000FFFFFFFFLL)))
69*4684ddb6SLionel Sambuc return 1;
70*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000001LL)))
71*4684ddb6SLionel Sambuc return 1;
72*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0x0000000000000000LL, 0x0000000100000000LL)))
73*4684ddb6SLionel Sambuc return 1;
74*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000000LL)))
75*4684ddb6SLionel Sambuc return 1;
76*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0x0000000000000000LL, 0x0000000200000000LL)))
77*4684ddb6SLionel Sambuc return 1;
78*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFE00000000LL)))
79*4684ddb6SLionel Sambuc return 1;
80*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0x0000000000000000LL, 0x0000000300000000LL)))
81*4684ddb6SLionel Sambuc return 1;
82*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFD00000000LL)))
83*4684ddb6SLionel Sambuc return 1;
84*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0x0000000000000000LL, 0x7FFFFFFFFFFFFFFFLL)))
85*4684ddb6SLionel Sambuc return 1;
86*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0x8000000000000001LL)))
87*4684ddb6SLionel Sambuc return 1;
88*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0x0000000000000000LL, 0x7FFFFFFFFFFFFFFFLL)))
89*4684ddb6SLionel Sambuc return 1;
90*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFE00000000LL)))
91*4684ddb6SLionel Sambuc return 1;
92*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0x0000000000000000LL, 0x0000000200000000LL)))
93*4684ddb6SLionel Sambuc return 1;
94*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000000LL)))
95*4684ddb6SLionel Sambuc return 1;
96*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0x0000000000000000LL, 0x0000000100000000LL)))
97*4684ddb6SLionel Sambuc return 1;
98*4684ddb6SLionel Sambuc // if (test__negvti2(make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
99*4684ddb6SLionel Sambuc // return 1;
100*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
101*4684ddb6SLionel Sambuc return 1;
102*4684ddb6SLionel Sambuc if (test__negvti2(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
103*4684ddb6SLionel Sambuc return 1;
104*4684ddb6SLionel Sambuc
105*4684ddb6SLionel Sambuc #else
106*4684ddb6SLionel Sambuc printf("skipped\n");
107*4684ddb6SLionel Sambuc #endif
108*4684ddb6SLionel Sambuc return 0;
109*4684ddb6SLionel Sambuc }
110