[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / mulvti3_test.c
blob9cb86d75681cb16b43a7f68608de7cd895a75d3b
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_mulvti3
3 // REQUIRES: int128
4 //===-- mulvti3_test.c - Test __mulvti3 -----------------------------------===//
5 //
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
9 //
10 //===----------------------------------------------------------------------===//
12 // This file tests __mulvti3 for the compiler_rt library.
14 //===----------------------------------------------------------------------===//
16 #include "int_lib.h"
17 #include <stdio.h>
19 #ifdef CRT_HAS_128BIT
21 // Returns: a * b
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);
30 if (x != expected)
32 twords at;
33 at.all = a;
34 twords bt;
35 bt.all = b;
36 twords xt;
37 xt.all = x;
38 twords expectedt;
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);
45 return x != expected;
48 #endif
50 int main()
52 #ifdef CRT_HAS_128BIT
53 if (test__mulvti3(0, 0, 0))
54 return 1;
55 if (test__mulvti3(0, 1, 0))
56 return 1;
57 if (test__mulvti3(1, 0, 0))
58 return 1;
59 if (test__mulvti3(0, 10, 0))
60 return 1;
61 if (test__mulvti3(10, 0, 0))
62 return 1;
63 if (test__mulvti3(0, 81985529216486895LL, 0))
64 return 1;
65 if (test__mulvti3(81985529216486895LL, 0, 0))
66 return 1;
68 if (test__mulvti3(0, -1, 0))
69 return 1;
70 if (test__mulvti3(-1, 0, 0))
71 return 1;
72 if (test__mulvti3(0, -10, 0))
73 return 1;
74 if (test__mulvti3(-10, 0, 0))
75 return 1;
76 if (test__mulvti3(0, -81985529216486895LL, 0))
77 return 1;
78 if (test__mulvti3(-81985529216486895LL, 0, 0))
79 return 1;
81 if (test__mulvti3(1, 1, 1))
82 return 1;
83 if (test__mulvti3(1, 10, 10))
84 return 1;
85 if (test__mulvti3(10, 1, 10))
86 return 1;
87 if (test__mulvti3(1, 81985529216486895LL, 81985529216486895LL))
88 return 1;
89 if (test__mulvti3(81985529216486895LL, 1, 81985529216486895LL))
90 return 1;
92 if (test__mulvti3(1, -1, -1))
93 return 1;
94 if (test__mulvti3(1, -10, -10))
95 return 1;
96 if (test__mulvti3(-10, 1, -10))
97 return 1;
98 if (test__mulvti3(1, -81985529216486895LL, -81985529216486895LL))
99 return 1;
100 if (test__mulvti3(-81985529216486895LL, 1, -81985529216486895LL))
101 return 1;
103 if (test__mulvti3(3037000499LL, 3037000499LL, 9223372030926249001ULL))
104 return 1;
105 if (test__mulvti3(-3037000499LL, 3037000499LL, -9223372030926249001LL))
106 return 1;
107 if (test__mulvti3(3037000499LL, -3037000499LL, -9223372030926249001LL))
108 return 1;
109 if (test__mulvti3(-3037000499LL, -3037000499LL, 9223372030926249001ULL))
110 return 1;
112 if (test__mulvti3(4398046511103LL, 2097152LL, 9223372036852678656LL))
113 return 1;
114 if (test__mulvti3(-4398046511103LL, 2097152LL, -9223372036852678656LL))
115 return 1;
116 if (test__mulvti3(4398046511103LL, -2097152LL, -9223372036852678656LL))
117 return 1;
118 if (test__mulvti3(-4398046511103LL, -2097152LL, 9223372036852678656LL))
119 return 1;
121 if (test__mulvti3(2097152LL, 4398046511103LL, 9223372036852678656ULL))
122 return 1;
123 if (test__mulvti3(-2097152LL, 4398046511103LL, -9223372036852678656LL))
124 return 1;
125 if (test__mulvti3(2097152LL, -4398046511103LL, -9223372036852678656LL))
126 return 1;
127 if (test__mulvti3(-2097152LL, -4398046511103LL, 9223372036852678656LL))
128 return 1;
130 if (test__mulvti3(make_ti(0x00000000000000B5LL, 0x04F333F9DE5BE000LL),
131 make_ti(0x0000000000000000LL, 0x00B504F333F9DE5BLL),
132 make_ti(0x7FFFFFFFFFFFF328LL, 0xDF915DA296E8A000LL)))
133 return 1;
135 // if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
136 // -2,
137 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
138 // return 1;
139 // if (test__mulvti3(-2,
140 // make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
141 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
142 // return 1;
143 if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
145 make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
146 return 1;
147 if (test__mulvti3(-1,
148 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
149 make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
150 return 1;
151 if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
154 return 1;
155 if (test__mulvti3(0,
156 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
158 return 1;
159 if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
161 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
162 return 1;
163 if (test__mulvti3(1,
164 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
165 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
166 return 1;
167 // if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
168 // 2,
169 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
170 // return 1;
171 // if (test__mulvti3(2,
172 // make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
173 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
174 // return 1;
176 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
177 // -2,
178 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
179 // return 1;
180 // if (test__mulvti3(-2,
181 // make_ti(0x8000000000000000LL, 0x0000000000000000LL),
182 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
183 // return 1;
184 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
185 // -1,
186 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
187 // return 1;
188 // if (test__mulvti3(-1,
189 // make_ti(0x8000000000000000LL, 0x0000000000000000LL),
190 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
191 // return 1;
192 if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
195 return 1;
196 if (test__mulvti3(0,
197 make_ti(0x8000000000000000LL, 0x0000000000000000LL),
199 return 1;
200 if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
202 make_ti(0x8000000000000000LL, 0x0000000000000000LL)))
203 return 1;
204 if (test__mulvti3(1,
205 make_ti(0x8000000000000000LL, 0x0000000000000000LL),
206 make_ti(0x8000000000000000LL, 0x0000000000000000LL)))
207 return 1;
208 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
209 // 2,
210 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
211 // return 1;
212 // if (test__mulvti3(2,
213 // make_ti(0x8000000000000000LL, 0x0000000000000000LL),
214 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
215 // return 1;
217 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
218 // -2,
219 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
220 // return 1;
221 // if (test__mulvti3(-2,
222 // make_ti(0x8000000000000000LL, 0x0000000000000001LL),
223 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
224 // return 1;
225 if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
227 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
228 return 1;
229 if (test__mulvti3(-1,
230 make_ti(0x8000000000000000LL, 0x0000000000000001LL),
231 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
232 return 1;
233 if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
236 return 1;
237 if (test__mulvti3(0,
238 make_ti(0x8000000000000000LL, 0x0000000000000001LL),
240 return 1;
241 if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
243 make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
244 return 1;
245 if (test__mulvti3(1,
246 make_ti(0x8000000000000000LL, 0x0000000000000001LL),
247 make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
248 return 1;
249 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
250 // 2,
251 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
252 // return 1;
253 // if (test__mulvti3(2,
254 // make_ti(0x8000000000000000LL, 0x0000000000000001LL),
255 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
256 // return 1;
258 #else
259 printf("skipped\n");
260 #endif
261 return 0;