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

source code of compiler-rt/test/builtins/Unit/negvti2_test.c