1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_muloti4
12 // Effects: sets overflow if a * b overflows
14 COMPILER_RT_ABI ti_int
__muloti4(ti_int a
, ti_int b
, int *overflow
);
16 int test__muloti4(ti_int a
, ti_int b
, ti_int expected
, int expected_overflow
)
19 ti_int x
= __muloti4(a
, b
, &ov
);
20 if (ov
!= expected_overflow
) {
28 expectedt
.all
= expected
;
30 printf("error in __muloti4: overflow=%d expected=%d\n",
31 ov
, expected_overflow
);
32 printf("error in __muloti4: 0x%.16llX%.16llX * 0x%.16llX%.16llX = "
33 "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
34 at
.s
.high
, at
.s
.low
, bt
.s
.high
, bt
.s
.low
, xt
.s
.high
, xt
.s
.low
,
35 expectedt
.s
.high
, expectedt
.s
.low
);
38 else if (!expected_overflow
&& x
!= expected
)
47 expectedt
.all
= expected
;
48 printf("error in __muloti4: 0x%.16llX%.16llX * 0x%.16llX%.16llX = "
49 "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
50 at
.s
.high
, at
.s
.low
, bt
.s
.high
, bt
.s
.low
, xt
.s
.high
, xt
.s
.low
,
51 expectedt
.s
.high
, expectedt
.s
.low
);
62 if (test__muloti4(0, 0, 0, 0))
64 if (test__muloti4(0, 1, 0, 0))
66 if (test__muloti4(1, 0, 0, 0))
68 if (test__muloti4(0, 10, 0, 0))
70 if (test__muloti4(10, 0, 0, 0))
72 if (test__muloti4(0, 81985529216486895LL, 0, 0))
74 if (test__muloti4(81985529216486895LL, 0, 0, 0))
77 if (test__muloti4(0, -1, 0, 0))
79 if (test__muloti4(-1, 0, 0, 0))
81 if (test__muloti4(0, -10, 0, 0))
83 if (test__muloti4(-10, 0, 0, 0))
85 if (test__muloti4(0, -81985529216486895LL, 0, 0))
87 if (test__muloti4(-81985529216486895LL, 0, 0, 0))
90 if (test__muloti4(1, 1, 1, 0))
92 if (test__muloti4(1, 10, 10, 0))
94 if (test__muloti4(10, 1, 10, 0))
96 if (test__muloti4(1, 81985529216486895LL, 81985529216486895LL, 0))
98 if (test__muloti4(81985529216486895LL, 1, 81985529216486895LL, 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(3037000499LL, 3037000499LL, 9223372030926249001LL, 0))
114 if (test__muloti4(-3037000499LL, 3037000499LL, -9223372030926249001LL, 0))
116 if (test__muloti4(3037000499LL, -3037000499LL, -9223372030926249001LL, 0))
118 if (test__muloti4(-3037000499LL, -3037000499LL, 9223372030926249001LL, 0))
121 if (test__muloti4(4398046511103LL, 2097152LL, 9223372036852678656LL, 0))
123 if (test__muloti4(-4398046511103LL, 2097152LL, -9223372036852678656LL, 0))
125 if (test__muloti4(4398046511103LL, -2097152LL, -9223372036852678656LL, 0))
127 if (test__muloti4(-4398046511103LL, -2097152LL, 9223372036852678656LL, 0))
130 if (test__muloti4(2097152LL, 4398046511103LL, 9223372036852678656LL, 0))
132 if (test__muloti4(-2097152LL, 4398046511103LL, -9223372036852678656LL, 0))
134 if (test__muloti4(2097152LL, -4398046511103LL, -9223372036852678656LL, 0))
136 if (test__muloti4(-2097152LL, -4398046511103LL, 9223372036852678656LL, 0))
139 if (test__muloti4(make_ti(0x00000000000000B5LL
, 0x04F333F9DE5BE000LL
),
140 make_ti(0x0000000000000000LL
, 0x00B504F333F9DE5BLL
),
141 make_ti(0x7FFFFFFFFFFFF328LL
, 0xDF915DA296E8A000LL
), 0))
144 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
146 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 1))
148 if (test__muloti4(-2,
149 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
150 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 1))
152 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
154 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 0))
156 if (test__muloti4(-1,
157 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
158 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 0))
160 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
165 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
168 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
170 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
), 0))
173 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
174 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
), 0))
176 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
178 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 1))
181 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
182 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 1))
185 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
187 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
189 if (test__muloti4(-2,
190 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
191 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
193 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
195 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
197 if (test__muloti4(-1,
198 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
199 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
201 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
206 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
209 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
211 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 0))
214 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
215 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 0))
217 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
219 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
222 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
223 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
226 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
228 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 1))
230 if (test__muloti4(-2,
231 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
232 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 1))
234 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
236 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
), 0))
238 if (test__muloti4(-1,
239 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
240 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
), 0))
242 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
247 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
250 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
252 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 0))
255 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
256 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 0))
258 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
260 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
263 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
264 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))