1 //===-- muloti4_test.c - Test __muloti4 -----------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file tests __muloti3 for the compiler_rt library.
12 //===----------------------------------------------------------------------===//
21 // Effects: sets overflow if a * b overflows
23 ti_int
__muloti4(ti_int a
, ti_int b
, int *overflow
);
25 int test__muloti4(ti_int a
, ti_int b
, ti_int expected
, int expected_overflow
)
28 ti_int x
= __muloti4(a
, b
, &ov
);
29 if (ov
!= expected_overflow
) {
37 expectedt
.all
= expected
;
39 printf("error in __muloti4: overflow=%d expected=%d\n",
40 ov
, expected_overflow
);
41 printf("error in __muloti4: 0x%.16llX%.16llX * 0x%.16llX%.16llX = "
42 "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
43 at
.s
.high
, at
.s
.low
, bt
.s
.high
, bt
.s
.low
, xt
.s
.high
, xt
.s
.low
,
44 expectedt
.s
.high
, expectedt
.s
.low
);
47 else if (!expected_overflow
&& x
!= expected
)
56 expectedt
.all
= expected
;
57 printf("error in __muloti4: 0x%.16llX%.16llX * 0x%.16llX%.16llX = "
58 "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
59 at
.s
.high
, at
.s
.low
, bt
.s
.high
, bt
.s
.low
, xt
.s
.high
, xt
.s
.low
,
60 expectedt
.s
.high
, expectedt
.s
.low
);
71 if (test__muloti4(0, 0, 0, 0))
73 if (test__muloti4(0, 1, 0, 0))
75 if (test__muloti4(1, 0, 0, 0))
77 if (test__muloti4(0, 10, 0, 0))
79 if (test__muloti4(10, 0, 0, 0))
81 if (test__muloti4(0, 81985529216486895LL, 0, 0))
83 if (test__muloti4(81985529216486895LL, 0, 0, 0))
86 if (test__muloti4(0, -1, 0, 0))
88 if (test__muloti4(-1, 0, 0, 0))
90 if (test__muloti4(0, -10, 0, 0))
92 if (test__muloti4(-10, 0, 0, 0))
94 if (test__muloti4(0, -81985529216486895LL, 0, 0))
96 if (test__muloti4(-81985529216486895LL, 0, 0, 0))
99 if (test__muloti4(1, 1, 1, 0))
101 if (test__muloti4(1, 10, 10, 0))
103 if (test__muloti4(10, 1, 10, 0))
105 if (test__muloti4(1, 81985529216486895LL, 81985529216486895LL, 0))
107 if (test__muloti4(81985529216486895LL, 1, 81985529216486895LL, 0))
110 if (test__muloti4(1, -1, -1, 0))
112 if (test__muloti4(1, -10, -10, 0))
114 if (test__muloti4(-10, 1, -10, 0))
116 if (test__muloti4(1, -81985529216486895LL, -81985529216486895LL, 0))
118 if (test__muloti4(-81985529216486895LL, 1, -81985529216486895LL, 0))
121 if (test__muloti4(3037000499LL, 3037000499LL, 9223372030926249001LL, 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))
130 if (test__muloti4(4398046511103LL, 2097152LL, 9223372036852678656LL, 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))
139 if (test__muloti4(2097152LL, 4398046511103LL, 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))
148 if (test__muloti4(make_ti(0x00000000000000B5LL
, 0x04F333F9DE5BE000LL
),
149 make_ti(0x0000000000000000LL
, 0x00B504F333F9DE5BLL
),
150 make_ti(0x7FFFFFFFFFFFF328LL
, 0xDF915DA296E8A000LL
), 0))
153 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
155 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 1))
157 if (test__muloti4(-2,
158 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
159 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 1))
161 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
163 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 0))
165 if (test__muloti4(-1,
166 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
167 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 0))
169 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
174 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
177 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
179 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
), 0))
182 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
183 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
), 0))
185 if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
187 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 1))
190 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
191 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 1))
194 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
196 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
198 if (test__muloti4(-2,
199 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
200 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
202 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
204 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
206 if (test__muloti4(-1,
207 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
208 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
210 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
215 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
218 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
220 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 0))
223 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
224 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 0))
226 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
228 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
231 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
232 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
235 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
237 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 1))
239 if (test__muloti4(-2,
240 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
241 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 1))
243 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
245 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
), 0))
247 if (test__muloti4(-1,
248 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
249 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
), 0))
251 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
256 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
259 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
261 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 0))
264 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
265 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
), 0))
267 if (test__muloti4(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
269 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))
272 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
273 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
), 1))