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
12COMPILER_RT_ABI ti_int __negti2(ti_int a);
13
14int 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(format: "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
32char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
33
34#endif
35
36int main()
37{
38#ifdef CRT_HAS_128BIT
39 if (test__negti2(a: 0, expected: 0))
40 return 1;
41 if (test__negti2(a: 1, expected: -1))
42 return 1;
43 if (test__negti2(a: -1, expected: 1))
44 return 1;
45 if (test__negti2(a: 2, expected: -2))
46 return 1;
47 if (test__negti2(a: -2, expected: 2))
48 return 1;
49 if (test__negti2(a: 3, expected: -3))
50 return 1;
51 if (test__negti2(a: -3, expected: 3))
52 return 1;
53 if (test__negti2(a: make_ti(h: 0x0000000000000000LL, l: 0x00000000FFFFFFFELL),
54 expected: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0xFFFFFFFF00000002LL)))
55 return 1;
56 if (test__negti2(a: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0xFFFFFFFF00000002LL),
57 expected: make_ti(h: 0x0000000000000000LL, l: 0x00000000FFFFFFFELL)))
58 return 1;
59 if (test__negti2(a: make_ti(h: 0x0000000000000000LL, l: 0x00000000FFFFFFFFLL),
60 expected: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0xFFFFFFFF00000001LL)))
61 return 1;
62 if (test__negti2(a: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0xFFFFFFFF00000001LL),
63 expected: make_ti(h: 0x0000000000000000LL, l: 0x00000000FFFFFFFFLL)))
64 return 1;
65 if (test__negti2(a: make_ti(h: 0x0000000000000000LL, l: 0x0000000100000000LL),
66 expected: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0xFFFFFFFF00000000LL)))
67 return 1;
68 if (test__negti2(a: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0xFFFFFFFF00000000LL),
69 expected: make_ti(h: 0x0000000000000000LL, l: 0x0000000100000000LL)))
70 return 1;
71 if (test__negti2(a: make_ti(h: 0x0000000000000000LL, l: 0x0000000200000000LL),
72 expected: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0xFFFFFFFE00000000LL)))
73 return 1;
74 if (test__negti2(a: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0xFFFFFFFE00000000LL),
75 expected: make_ti(h: 0x0000000000000000LL, l: 0x0000000200000000LL)))
76 return 1;
77 if (test__negti2(a: make_ti(h: 0x0000000000000000LL, l: 0x0000000300000000LL),
78 expected: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0xFFFFFFFD00000000LL)))
79 return 1;
80 if (test__negti2(a: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0xFFFFFFFD00000000LL),
81 expected: make_ti(h: 0x0000000000000000LL, l: 0x0000000300000000LL)))
82 return 1;
83 if (test__negti2(a: make_ti(h: 0x0000000000000000LL, l: 0x7FFFFFFFFFFFFFFFLL),
84 expected: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0x8000000000000001LL)))
85 return 1;
86 if (test__negti2(a: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0x8000000000000001LL),
87 expected: make_ti(h: 0x0000000000000000LL, l: 0x7FFFFFFFFFFFFFFFLL)))
88 return 1;
89 if (test__negti2(a: make_ti(h: 0x0000000000000000LL, l: 0x7FFFFFFFFFFFFFFFLL),
90 expected: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0x8000000000000001LL)))
91 return 1;
92 if (test__negti2(a: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0xFFFFFFFE00000000LL),
93 expected: make_ti(h: 0x0000000000000000LL, l: 0x0000000200000000LL)))
94 return 1;
95 if (test__negti2(a: make_ti(h: 0x0000000000000000LL, l: 0x0000000200000000LL),
96 expected: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0xFFFFFFFE00000000LL)))
97 return 1;
98 if (test__negti2(a: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0xFFFFFFFF00000000LL),
99 expected: make_ti(h: 0x0000000000000000LL, l: 0x0000000100000000LL)))
100 return 1;
101 if (test__negti2(a: make_ti(h: 0x0000000000000000LL, l: 0x0000000100000000LL),
102 expected: make_ti(h: 0xFFFFFFFFFFFFFFFFLL, l: 0xFFFFFFFF00000000LL)))
103 return 1;
104 if (test__negti2(a: make_ti(h: 0x8000000000000000LL, l: 0x0000000000000000LL),
105 expected: make_ti(h: 0x8000000000000000LL, l: 0x0000000000000000LL)))
106 return 1;
107 if (test__negti2(a: make_ti(h: 0x8000000000000000LL, l: 0x0000000000000001LL),
108 expected: make_ti(h: 0x7FFFFFFFFFFFFFFFLL, l: 0xFFFFFFFFFFFFFFFFLL)))
109 return 1;
110 if (test__negti2(a: make_ti(h: 0x7FFFFFFFFFFFFFFFLL, l: 0xFFFFFFFFFFFFFFFFLL),
111 expected: make_ti(h: 0x8000000000000000LL, l: 0x0000000000000001LL)))
112 return 1;
113
114#else
115 printf("skipped\n");
116#endif
117 return 0;
118}
119

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