1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_negti2
3 // REQUIRES: int128
4
5 #include "int_lib.h"
6 #include <stdio.h>
7
8 #ifdef CRT_HAS_128BIT
9
10 // Returns: -a
11
12 COMPILER_RT_ABI ti_int __negti2(ti_int a);
13
test__negti2(ti_int a,ti_int expected)14 int test__negti2(ti_int a, ti_int expected)
15 {
16 ti_int x = __negti2(a);
17 if (x != expected)
18 {
19 twords at;
20 at.all = a;
21 twords xt;
22 xt.all = x;
23 twords expectedt;
24 expectedt.all = expected;
25 printf("error in __negti2: -0x%.16llX%.16llX = 0x%.16llX%.16llX, "
26 "expected 0x%.16llX%.16llX\n",
27 at.s.high, at.s.low, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
28 }
29 return x != expected;
30 }
31
32 char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
33
34 #endif
35
main()36 int main()
37 {
38 #ifdef CRT_HAS_128BIT
39 if (test__negti2(0, 0))
40 return 1;
41 if (test__negti2(1, -1))
42 return 1;
43 if (test__negti2(-1, 1))
44 return 1;
45 if (test__negti2(2, -2))
46 return 1;
47 if (test__negti2(-2, 2))
48 return 1;
49 if (test__negti2(3, -3))
50 return 1;
51 if (test__negti2(-3, 3))
52 return 1;
53 if (test__negti2(make_ti(0x0000000000000000LL, 0x00000000FFFFFFFELL),
54 make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000002LL)))
55 return 1;
56 if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000002LL),
57 make_ti(0x0000000000000000LL, 0x00000000FFFFFFFELL)))
58 return 1;
59 if (test__negti2(make_ti(0x0000000000000000LL, 0x00000000FFFFFFFFLL),
60 make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000001LL)))
61 return 1;
62 if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000001LL),
63 make_ti(0x0000000000000000LL, 0x00000000FFFFFFFFLL)))
64 return 1;
65 if (test__negti2(make_ti(0x0000000000000000LL, 0x0000000100000000LL),
66 make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000000LL)))
67 return 1;
68 if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000000LL),
69 make_ti(0x0000000000000000LL, 0x0000000100000000LL)))
70 return 1;
71 if (test__negti2(make_ti(0x0000000000000000LL, 0x0000000200000000LL),
72 make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFE00000000LL)))
73 return 1;
74 if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFE00000000LL),
75 make_ti(0x0000000000000000LL, 0x0000000200000000LL)))
76 return 1;
77 if (test__negti2(make_ti(0x0000000000000000LL, 0x0000000300000000LL),
78 make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFD00000000LL)))
79 return 1;
80 if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFD00000000LL),
81 make_ti(0x0000000000000000LL, 0x0000000300000000LL)))
82 return 1;
83 if (test__negti2(make_ti(0x0000000000000000LL, 0x7FFFFFFFFFFFFFFFLL),
84 make_ti(0xFFFFFFFFFFFFFFFFLL, 0x8000000000000001LL)))
85 return 1;
86 if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0x8000000000000001LL),
87 make_ti(0x0000000000000000LL, 0x7FFFFFFFFFFFFFFFLL)))
88 return 1;
89 if (test__negti2(make_ti(0x0000000000000000LL, 0x7FFFFFFFFFFFFFFFLL),
90 make_ti(0xFFFFFFFFFFFFFFFFLL, 0x8000000000000001LL)))
91 return 1;
92 if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFE00000000LL),
93 make_ti(0x0000000000000000LL, 0x0000000200000000LL)))
94 return 1;
95 if (test__negti2(make_ti(0x0000000000000000LL, 0x0000000200000000LL),
96 make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFE00000000LL)))
97 return 1;
98 if (test__negti2(make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000000LL),
99 make_ti(0x0000000000000000LL, 0x0000000100000000LL)))
100 return 1;
101 if (test__negti2(make_ti(0x0000000000000000LL, 0x0000000100000000LL),
102 make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFF00000000LL)))
103 return 1;
104 if (test__negti2(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
105 make_ti(0x8000000000000000LL, 0x0000000000000000LL)))
106 return 1;
107 if (test__negti2(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
108 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
109 return 1;
110 if (test__negti2(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
111 make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
112 return 1;
113
114 #else
115 printf("skipped\n");
116 #endif
117 return 0;
118 }
119