1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_muloti4
4 //===-- muloti4_test.c - Test __muloti4 -----------------------------------===//
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
10 //===----------------------------------------------------------------------===//
12 // This file tests __muloti3 for the compiler_rt library.
14 //===----------------------------------------------------------------------===//
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
)
30 ti_int x
= __muloti4(a
, b
, &ov
);
31 if (ov
!= expected_overflow
) {
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
);
49 else if (!expected_overflow
&& x
!= expected
)
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
);
73 if (test__muloti4(0, 0, 0, 0))
75 if (test__muloti4(0, 1, 0, 0))
77 if (test__muloti4(1, 0, 0, 0))
79 if (test__muloti4(0, 10, 0, 0))
81 if (test__muloti4(10, 0, 0, 0))
83 if (test__muloti4(0, 81985529216486895LL, 0, 0))
85 if (test__muloti4(81985529216486895LL, 0, 0, 0))
88 if (test__muloti4(0, -1, 0, 0))
90 if (test__muloti4(-1, 0, 0, 0))
92 if (test__muloti4(0, -10, 0, 0))
94 if (test__muloti4(-10, 0, 0, 0))
96 if (test__muloti4(0, -81985529216486895LL, 0, 0))
98 if (test__muloti4(-81985529216486895LL, 0, 0, 0))
101 if (test__muloti4(1, 1, 1, 0))
103 if (test__muloti4(1, 10, 10, 0))
105 if (test__muloti4(10, 1, 10, 0))
107 if (test__muloti4(1, 81985529216486895LL, 81985529216486895LL, 0))
109 if (test__muloti4(81985529216486895LL, 1, 81985529216486895LL, 0))
112 if (test__muloti4(1, -1, -1, 0))
114 if (test__muloti4(1, -10, -10, 0))
116 if (test__muloti4(-10, 1, -10, 0))
118 if (test__muloti4(1, -81985529216486895LL, -81985529216486895LL, 0))
120 if (test__muloti4(-81985529216486895LL, 1, -81985529216486895LL, 0))
123 if (test__muloti4(3037000499LL, 3037000499LL, 9223372030926249001LL, 0))
125 if (test__muloti4(-3037000499LL, 3037000499LL, -9223372030926249001LL, 0))
127 if (test__muloti4(3037000499LL, -3037000499LL, -9223372030926249001LL, 0))
129 if (test__muloti4(-3037000499LL, -3037000499LL, 9223372030926249001LL, 0))
132 if (test__muloti4(4398046511103LL, 2097152LL, 9223372036852678656LL, 0))
134 if (test__muloti4(-4398046511103LL, 2097152LL, -9223372036852678656LL, 0))
136 if (test__muloti4(4398046511103LL, -2097152LL, -9223372036852678656LL, 0))
138 if (test__muloti4(-4398046511103LL, -2097152LL, 9223372036852678656LL, 0))
141 if (test__muloti4(2097152LL, 4398046511103LL, 9223372036852678656LL, 0))
143 if (test__muloti4(-2097152LL, 4398046511103LL, -9223372036852678656LL, 0))
145 if (test__muloti4(2097152LL, -4398046511103LL, -9223372036852678656LL, 0))
147 if (test__muloti4(-2097152LL, -4398046511103LL, 9223372036852678656LL, 0))
150 if (test__muloti4(make_ti(0x00000000000000B5LL
, 0x04F333F9DE5BE000LL
),
151 make_ti(0x0000000000000000LL
, 0x00B504F333F9DE5BLL
),
152 make_ti(0x7FFFFFFFFFFFF328LL
, 0xDF915DA296E8A000LL
), 0))
155 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
157 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 1))
159 if (test__muloti4(-2,
160 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
161 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 1))
163 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
165 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 0))
167 if (test__muloti4(-1,
168 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
169 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 0))
171 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
176 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
179 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
181 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
), 0))
184 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
185 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
), 0))
187 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
189 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 1))
192 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
193 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 1))
196 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
198 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
200 if (test__muloti4(-2,
201 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
202 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
204 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
206 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
208 if (test__muloti4(-1,
209 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
210 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
212 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
217 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
220 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
222 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 0))
225 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
226 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 0))
228 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
230 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
233 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
234 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
237 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
239 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 1))
241 if (test__muloti4(-2,
242 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
243 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 1))
245 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
247 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
), 0))
249 if (test__muloti4(-1,
250 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
251 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
), 0))
253 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
258 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
261 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
263 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 0))
266 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
267 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 0))
269 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
271 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
274 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
275 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))