1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_mulvti3
4 //===-- mulvti3_test.c - Test __mulvti3 -----------------------------------===//
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 __mulvti3 for the compiler_rt library.
14 //===----------------------------------------------------------------------===//
23 // Effects: aborts if a * b overflows
25 COMPILER_RT_ABI ti_int
__mulvti3(ti_int a
, ti_int b
);
27 int test__mulvti3(ti_int a
, ti_int b
, ti_int expected
)
29 ti_int x
= __mulvti3(a
, b
);
39 expectedt
.all
= expected
;
40 printf("error in __mulvti3: 0x%.16llX%.16llX * 0x%.16llX%.16llX = "
41 "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
42 at
.s
.high
, at
.s
.low
, bt
.s
.high
, bt
.s
.low
, xt
.s
.high
, xt
.s
.low
,
43 expectedt
.s
.high
, expectedt
.s
.low
);
53 if (test__mulvti3(0, 0, 0))
55 if (test__mulvti3(0, 1, 0))
57 if (test__mulvti3(1, 0, 0))
59 if (test__mulvti3(0, 10, 0))
61 if (test__mulvti3(10, 0, 0))
63 if (test__mulvti3(0, 81985529216486895LL, 0))
65 if (test__mulvti3(81985529216486895LL, 0, 0))
68 if (test__mulvti3(0, -1, 0))
70 if (test__mulvti3(-1, 0, 0))
72 if (test__mulvti3(0, -10, 0))
74 if (test__mulvti3(-10, 0, 0))
76 if (test__mulvti3(0, -81985529216486895LL, 0))
78 if (test__mulvti3(-81985529216486895LL, 0, 0))
81 if (test__mulvti3(1, 1, 1))
83 if (test__mulvti3(1, 10, 10))
85 if (test__mulvti3(10, 1, 10))
87 if (test__mulvti3(1, 81985529216486895LL, 81985529216486895LL))
89 if (test__mulvti3(81985529216486895LL, 1, 81985529216486895LL))
92 if (test__mulvti3(1, -1, -1))
94 if (test__mulvti3(1, -10, -10))
96 if (test__mulvti3(-10, 1, -10))
98 if (test__mulvti3(1, -81985529216486895LL, -81985529216486895LL))
100 if (test__mulvti3(-81985529216486895LL, 1, -81985529216486895LL))
103 if (test__mulvti3(3037000499LL, 3037000499LL, 9223372030926249001ULL))
105 if (test__mulvti3(-3037000499LL, 3037000499LL, -9223372030926249001LL))
107 if (test__mulvti3(3037000499LL, -3037000499LL, -9223372030926249001LL))
109 if (test__mulvti3(-3037000499LL, -3037000499LL, 9223372030926249001ULL))
112 if (test__mulvti3(4398046511103LL, 2097152LL, 9223372036852678656LL))
114 if (test__mulvti3(-4398046511103LL, 2097152LL, -9223372036852678656LL))
116 if (test__mulvti3(4398046511103LL, -2097152LL, -9223372036852678656LL))
118 if (test__mulvti3(-4398046511103LL, -2097152LL, 9223372036852678656LL))
121 if (test__mulvti3(2097152LL, 4398046511103LL, 9223372036852678656ULL))
123 if (test__mulvti3(-2097152LL, 4398046511103LL, -9223372036852678656LL))
125 if (test__mulvti3(2097152LL, -4398046511103LL, -9223372036852678656LL))
127 if (test__mulvti3(-2097152LL, -4398046511103LL, 9223372036852678656LL))
130 if (test__mulvti3(make_ti(0x00000000000000B5LL
, 0x04F333F9DE5BE000LL
),
131 make_ti(0x0000000000000000LL
, 0x00B504F333F9DE5BLL
),
132 make_ti(0x7FFFFFFFFFFFF328LL
, 0xDF915DA296E8A000LL
)))
135 // if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
137 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
139 // if (test__mulvti3(-2,
140 // make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
141 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
143 if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
145 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
)))
147 if (test__mulvti3(-1,
148 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
149 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
)))
151 if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
156 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
159 if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
161 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
)))
164 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
),
165 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
)))
167 // if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
169 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
171 // if (test__mulvti3(2,
172 // make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
173 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
176 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
178 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
180 // if (test__mulvti3(-2,
181 // make_ti(0x8000000000000000LL, 0x0000000000000000LL),
182 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
184 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
186 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
188 // if (test__mulvti3(-1,
189 // make_ti(0x8000000000000000LL, 0x0000000000000000LL),
190 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
192 if (test__mulvti3(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
197 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
200 if (test__mulvti3(make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
202 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
)))
205 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
),
206 make_ti(0x8000000000000000LL
, 0x0000000000000000LL
)))
208 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
210 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
212 // if (test__mulvti3(2,
213 // make_ti(0x8000000000000000LL, 0x0000000000000000LL),
214 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
217 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
219 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
221 // if (test__mulvti3(-2,
222 // make_ti(0x8000000000000000LL, 0x0000000000000001LL),
223 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
225 if (test__mulvti3(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
227 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
)))
229 if (test__mulvti3(-1,
230 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
231 make_ti(0x7FFFFFFFFFFFFFFFLL
, 0xFFFFFFFFFFFFFFFFLL
)))
233 if (test__mulvti3(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
238 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
241 if (test__mulvti3(make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
243 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
)))
246 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
),
247 make_ti(0x8000000000000000LL
, 0x0000000000000001LL
)))
249 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
251 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
253 // if (test__mulvti3(2,
254 // make_ti(0x8000000000000000LL, 0x0000000000000001LL),
255 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort