1 //===-- mulvti3_test.c - Test __mulvti3 -----------------------------------===//
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 __mulvti3 for the compiler_rt library.
12 //===----------------------------------------------------------------------===//
21 // Effects: aborts if a * b overflows
23 ti_int
__mulvti3(ti_int a
, ti_int b
);
25 int test__mulvti3(ti_int a
, ti_int b
, ti_int expected
)
27 ti_int x
= __mulvti3(a
, b
);
37 expectedt
.all
= expected
;
38 printf("error in __mulvti3: 0x%.16llX%.16llX * 0x%.16llX%.16llX = "
39 "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
40 at
.s
.high
, at
.s
.low
, bt
.s
.high
, bt
.s
.low
, xt
.s
.high
, xt
.s
.low
,
41 expectedt
.s
.high
, expectedt
.s
.low
);
51 if (test__mulvti3(0, 0, 0))
53 if (test__mulvti3(0, 1, 0))
55 if (test__mulvti3(1, 0, 0))
57 if (test__mulvti3(0, 10, 0))
59 if (test__mulvti3(10, 0, 0))
61 if (test__mulvti3(0, 81985529216486895LL, 0))
63 if (test__mulvti3(81985529216486895LL, 0, 0))
66 if (test__mulvti3(0, -1, 0))
68 if (test__mulvti3(-1, 0, 0))
70 if (test__mulvti3(0, -10, 0))
72 if (test__mulvti3(-10, 0, 0))
74 if (test__mulvti3(0, -81985529216486895LL, 0))
76 if (test__mulvti3(-81985529216486895LL, 0, 0))
79 if (test__mulvti3(1, 1, 1))
81 if (test__mulvti3(1, 10, 10))
83 if (test__mulvti3(10, 1, 10))
85 if (test__mulvti3(1, 81985529216486895LL, 81985529216486895LL))
87 if (test__mulvti3(81985529216486895LL, 1, 81985529216486895LL))
90 if (test__mulvti3(1, -1, -1))
92 if (test__mulvti3(1, -10, -10))
94 if (test__mulvti3(-10, 1, -10))
96 if (test__mulvti3(1, -81985529216486895LL, -81985529216486895LL))
98 if (test__mulvti3(-81985529216486895LL, 1, -81985529216486895LL))
101 if (test__mulvti3(3037000499LL, 3037000499LL, 9223372030926249001LL))
103 if (test__mulvti3(-3037000499LL, 3037000499LL, -9223372030926249001LL))
105 if (test__mulvti3(3037000499LL, -3037000499LL, -9223372030926249001LL))
107 if (test__mulvti3(-3037000499LL, -3037000499LL, 9223372030926249001LL))
110 if (test__mulvti3(4398046511103LL, 2097152LL, 9223372036852678656LL))
112 if (test__mulvti3(-4398046511103LL, 2097152LL, -9223372036852678656LL))
114 if (test__mulvti3(4398046511103LL, -2097152LL, -9223372036852678656LL))
116 if (test__mulvti3(-4398046511103LL, -2097152LL, 9223372036852678656LL))
119 if (test__mulvti3(2097152LL, 4398046511103LL, 9223372036852678656LL))
121 if (test__mulvti3(-2097152LL, 4398046511103LL, -9223372036852678656LL))
123 if (test__mulvti3(2097152LL, -4398046511103LL, -9223372036852678656LL))
125 if (test__mulvti3(-2097152LL, -4398046511103LL, 9223372036852678656LL))
128 if (test__mulvti3(make_ti(0x00000000000000B5LL
, 0x04F333F9DE5BE000LL
),
129 make_ti(0x0000000000000000LL
, 0x00B504F333F9DE5BLL
),
130 make_ti(0x7FFFFFFFFFFFF328LL
, 0xDF915DA296E8A000LL
)))
133 // if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
135 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
137 // if (test__mulvti3(-2,
138 // make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
139 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
141 if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
143 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
)))
145 if (test__mulvti3(-1,
146 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
147 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
)))
149 if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
154 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
157 if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
159 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
)))
162 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
163 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
)))
165 // if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
167 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
169 // if (test__mulvti3(2,
170 // make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
171 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
174 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
176 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
178 // if (test__mulvti3(-2,
179 // make_ti(0x8000000000000000LL, 0x0000000000000000LL),
180 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
182 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
184 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
186 // if (test__mulvti3(-1,
187 // make_ti(0x8000000000000000LL, 0x0000000000000000LL),
188 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
190 if (test__mulvti3(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
195 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
198 if (test__mulvti3(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
200 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
)))
203 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
204 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
)))
206 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
208 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
210 // if (test__mulvti3(2,
211 // make_ti(0x8000000000000000LL, 0x0000000000000000LL),
212 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
215 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
217 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
219 // if (test__mulvti3(-2,
220 // make_ti(0x8000000000000000LL, 0x0000000000000001LL),
221 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
223 if (test__mulvti3(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
225 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
)))
227 if (test__mulvti3(-1,
228 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
229 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
)))
231 if (test__mulvti3(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
236 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
239 if (test__mulvti3(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
241 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
)))
244 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
245 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
)))
247 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
249 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
251 // if (test__mulvti3(2,
252 // make_ti(0x8000000000000000LL, 0x0000000000000001LL),
253 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort