[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / muloti4_test.c
blob987e0af39e02de44e6af7cf4d3423c3b60472660
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_muloti4
3 // REQUIRES: int128
4 //===-- muloti4_test.c - Test __muloti4 -----------------------------------===//
5 //
6 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7 // See https://llvm.org/LICENSE.txt for license information.
8 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //
10 //===----------------------------------------------------------------------===//
12 // This file tests __muloti3 for the compiler_rt library.
14 //===----------------------------------------------------------------------===//
16 #include "int_lib.h"
17 #include <stdio.h>
19 #ifdef CRT_HAS_128BIT
21 // Returns: a * b
23 // Effects: sets overflow if a * b overflows
25 COMPILER_RT_ABI ti_int __muloti4(ti_int a, ti_int b, int *overflow);
27 int test__muloti4(ti_int a, ti_int b, ti_int expected, int expected_overflow)
29 int ov;
30 ti_int x = __muloti4(a, b, &ov);
31 if (ov != expected_overflow) {
32 twords at;
33 at.all = a;
34 twords bt;
35 bt.all = b;
36 twords xt;
37 xt.all = x;
38 twords expectedt;
39 expectedt.all = expected;
41 printf("error in __muloti4: overflow=%d expected=%d\n",
42 ov, expected_overflow);
43 printf("error in __muloti4: 0x%.16llX%.16llX * 0x%.16llX%.16llX = "
44 "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
45 at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low,
46 expectedt.s.high, expectedt.s.low);
47 return 1;
49 else if (!expected_overflow && x != expected)
51 twords at;
52 at.all = a;
53 twords bt;
54 bt.all = b;
55 twords xt;
56 xt.all = x;
57 twords expectedt;
58 expectedt.all = expected;
59 printf("error in __muloti4: 0x%.16llX%.16llX * 0x%.16llX%.16llX = "
60 "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
61 at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low,
62 expectedt.s.high, expectedt.s.low);
63 return 1;
65 return 0;
68 #endif
70 int main()
72 #ifdef CRT_HAS_128BIT
73 if (test__muloti4(0, 0, 0, 0))
74 return 1;
75 if (test__muloti4(0, 1, 0, 0))
76 return 1;
77 if (test__muloti4(1, 0, 0, 0))
78 return 1;
79 if (test__muloti4(0, 10, 0, 0))
80 return 1;
81 if (test__muloti4(10, 0, 0, 0))
82 return 1;
83 if (test__muloti4(0, 81985529216486895LL, 0, 0))
84 return 1;
85 if (test__muloti4(81985529216486895LL, 0, 0, 0))
86 return 1;
88 if (test__muloti4(0, -1, 0, 0))
89 return 1;
90 if (test__muloti4(-1, 0, 0, 0))
91 return 1;
92 if (test__muloti4(0, -10, 0, 0))
93 return 1;
94 if (test__muloti4(-10, 0, 0, 0))
95 return 1;
96 if (test__muloti4(0, -81985529216486895LL, 0, 0))
97 return 1;
98 if (test__muloti4(-81985529216486895LL, 0, 0, 0))
99 return 1;
101 if (test__muloti4(1, 1, 1, 0))
102 return 1;
103 if (test__muloti4(1, 10, 10, 0))
104 return 1;
105 if (test__muloti4(10, 1, 10, 0))
106 return 1;
107 if (test__muloti4(1, 81985529216486895LL, 81985529216486895LL, 0))
108 return 1;
109 if (test__muloti4(81985529216486895LL, 1, 81985529216486895LL, 0))
110 return 1;
112 if (test__muloti4(1, -1, -1, 0))
113 return 1;
114 if (test__muloti4(1, -10, -10, 0))
115 return 1;
116 if (test__muloti4(-10, 1, -10, 0))
117 return 1;
118 if (test__muloti4(1, -81985529216486895LL, -81985529216486895LL, 0))
119 return 1;
120 if (test__muloti4(-81985529216486895LL, 1, -81985529216486895LL, 0))
121 return 1;
123 if (test__muloti4(3037000499LL, 3037000499LL, 9223372030926249001LL, 0))
124 return 1;
125 if (test__muloti4(-3037000499LL, 3037000499LL, -9223372030926249001LL, 0))
126 return 1;
127 if (test__muloti4(3037000499LL, -3037000499LL, -9223372030926249001LL, 0))
128 return 1;
129 if (test__muloti4(-3037000499LL, -3037000499LL, 9223372030926249001LL, 0))
130 return 1;
132 if (test__muloti4(4398046511103LL, 2097152LL, 9223372036852678656LL, 0))
133 return 1;
134 if (test__muloti4(-4398046511103LL, 2097152LL, -9223372036852678656LL, 0))
135 return 1;
136 if (test__muloti4(4398046511103LL, -2097152LL, -9223372036852678656LL, 0))
137 return 1;
138 if (test__muloti4(-4398046511103LL, -2097152LL, 9223372036852678656LL, 0))
139 return 1;
141 if (test__muloti4(2097152LL, 4398046511103LL, 9223372036852678656LL, 0))
142 return 1;
143 if (test__muloti4(-2097152LL, 4398046511103LL, -9223372036852678656LL, 0))
144 return 1;
145 if (test__muloti4(2097152LL, -4398046511103LL, -9223372036852678656LL, 0))
146 return 1;
147 if (test__muloti4(-2097152LL, -4398046511103LL, 9223372036852678656LL, 0))
148 return 1;
150 if (test__muloti4(make_ti(0x00000000000000B5LL, 0x04F333F9DE5BE000LL),
151 make_ti(0x0000000000000000LL, 0x00B504F333F9DE5BLL),
152 make_ti(0x7FFFFFFFFFFFF328LL, 0xDF915DA296E8A000LL), 0))
153 return 1;
155 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
157 make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1))
158 return 1;
159 if (test__muloti4(-2,
160 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
161 make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1))
162 return 1;
163 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
165 make_ti(0x8000000000000000LL, 0x0000000000000001LL), 0))
166 return 1;
167 if (test__muloti4(-1,
168 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
169 make_ti(0x8000000000000000LL, 0x0000000000000001LL), 0))
170 return 1;
171 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
173 0, 0))
174 return 1;
175 if (test__muloti4(0,
176 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
177 0, 0))
178 return 1;
179 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
181 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 0))
182 return 1;
183 if (test__muloti4(1,
184 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
185 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 0))
186 return 1;
187 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
189 make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1))
190 return 1;
191 if (test__muloti4(2,
192 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
193 make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1))
194 return 1;
196 if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
198 make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
199 return 1;
200 if (test__muloti4(-2,
201 make_ti(0x8000000000000000LL, 0x0000000000000000LL),
202 make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
203 return 1;
204 if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
206 make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
207 return 1;
208 if (test__muloti4(-1,
209 make_ti(0x8000000000000000LL, 0x0000000000000000LL),
210 make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
211 return 1;
212 if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
214 0, 0))
215 return 1;
216 if (test__muloti4(0,
217 make_ti(0x8000000000000000LL, 0x0000000000000000LL),
218 0, 0))
219 return 1;
220 if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
222 make_ti(0x8000000000000000LL, 0x0000000000000000LL), 0))
223 return 1;
224 if (test__muloti4(1,
225 make_ti(0x8000000000000000LL, 0x0000000000000000LL),
226 make_ti(0x8000000000000000LL, 0x0000000000000000LL), 0))
227 return 1;
228 if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
230 make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
231 return 1;
232 if (test__muloti4(2,
233 make_ti(0x8000000000000000LL, 0x0000000000000000LL),
234 make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
235 return 1;
237 if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
239 make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1))
240 return 1;
241 if (test__muloti4(-2,
242 make_ti(0x8000000000000000LL, 0x0000000000000001LL),
243 make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1))
244 return 1;
245 if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
247 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 0))
248 return 1;
249 if (test__muloti4(-1,
250 make_ti(0x8000000000000000LL, 0x0000000000000001LL),
251 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 0))
252 return 1;
253 if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
255 0, 0))
256 return 1;
257 if (test__muloti4(0,
258 make_ti(0x8000000000000000LL, 0x0000000000000001LL),
259 0, 0))
260 return 1;
261 if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
263 make_ti(0x8000000000000000LL, 0x0000000000000001LL), 0))
264 return 1;
265 if (test__muloti4(1,
266 make_ti(0x8000000000000000LL, 0x0000000000000001LL),
267 make_ti(0x8000000000000000LL, 0x0000000000000001LL), 0))
268 return 1;
269 if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
271 make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
272 return 1;
273 if (test__muloti4(2,
274 make_ti(0x8000000000000000LL, 0x0000000000000001LL),
275 make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
276 return 1;
278 #else
279 printf("skipped\n");
280 #endif
281 return 0;