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