1 //===-- mulvti3_test.c - Test __mulvti3 -----------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file tests __mulvti3 for the compiler_rt library.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #if __x86_64
15
16 #include "int_lib.h"
17 #include <stdio.h>
18
19 // Returns: a * b
20
21 // Effects: aborts if a * b overflows
22
23 ti_int __mulvti3(ti_int a, ti_int b);
24
test__mulvti3(ti_int a,ti_int b,ti_int expected)25 int test__mulvti3(ti_int a, ti_int b, ti_int expected)
26 {
27 ti_int x = __mulvti3(a, b);
28 if (x != expected)
29 {
30 twords at;
31 at.all = a;
32 twords bt;
33 bt.all = b;
34 twords xt;
35 xt.all = x;
36 twords expectedt;
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);
42 }
43 return x != expected;
44 }
45
46 #endif
47
main()48 int main()
49 {
50 #if __x86_64
51 if (test__mulvti3(0, 0, 0))
52 return 1;
53 if (test__mulvti3(0, 1, 0))
54 return 1;
55 if (test__mulvti3(1, 0, 0))
56 return 1;
57 if (test__mulvti3(0, 10, 0))
58 return 1;
59 if (test__mulvti3(10, 0, 0))
60 return 1;
61 if (test__mulvti3(0, 81985529216486895LL, 0))
62 return 1;
63 if (test__mulvti3(81985529216486895LL, 0, 0))
64 return 1;
65
66 if (test__mulvti3(0, -1, 0))
67 return 1;
68 if (test__mulvti3(-1, 0, 0))
69 return 1;
70 if (test__mulvti3(0, -10, 0))
71 return 1;
72 if (test__mulvti3(-10, 0, 0))
73 return 1;
74 if (test__mulvti3(0, -81985529216486895LL, 0))
75 return 1;
76 if (test__mulvti3(-81985529216486895LL, 0, 0))
77 return 1;
78
79 if (test__mulvti3(1, 1, 1))
80 return 1;
81 if (test__mulvti3(1, 10, 10))
82 return 1;
83 if (test__mulvti3(10, 1, 10))
84 return 1;
85 if (test__mulvti3(1, 81985529216486895LL, 81985529216486895LL))
86 return 1;
87 if (test__mulvti3(81985529216486895LL, 1, 81985529216486895LL))
88 return 1;
89
90 if (test__mulvti3(1, -1, -1))
91 return 1;
92 if (test__mulvti3(1, -10, -10))
93 return 1;
94 if (test__mulvti3(-10, 1, -10))
95 return 1;
96 if (test__mulvti3(1, -81985529216486895LL, -81985529216486895LL))
97 return 1;
98 if (test__mulvti3(-81985529216486895LL, 1, -81985529216486895LL))
99 return 1;
100
101 if (test__mulvti3(3037000499LL, 3037000499LL, 9223372030926249001LL))
102 return 1;
103 if (test__mulvti3(-3037000499LL, 3037000499LL, -9223372030926249001LL))
104 return 1;
105 if (test__mulvti3(3037000499LL, -3037000499LL, -9223372030926249001LL))
106 return 1;
107 if (test__mulvti3(-3037000499LL, -3037000499LL, 9223372030926249001LL))
108 return 1;
109
110 if (test__mulvti3(4398046511103LL, 2097152LL, 9223372036852678656LL))
111 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
119 if (test__mulvti3(2097152LL, 4398046511103LL, 9223372036852678656LL))
120 return 1;
121 if (test__mulvti3(-2097152LL, 4398046511103LL, -9223372036852678656LL))
122 return 1;
123 if (test__mulvti3(2097152LL, -4398046511103LL, -9223372036852678656LL))
124 return 1;
125 if (test__mulvti3(-2097152LL, -4398046511103LL, 9223372036852678656LL))
126 return 1;
127
128 if (test__mulvti3(make_ti(0x00000000000000B5LL, 0x04F333F9DE5BE000LL),
129 make_ti(0x0000000000000000LL, 0x00B504F333F9DE5BLL),
130 make_ti(0x7FFFFFFFFFFFF328LL, 0xDF915DA296E8A000LL)))
131 return 1;
132
133 // if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
134 // -2,
135 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
136 // return 1;
137 // if (test__mulvti3(-2,
138 // make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
139 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
140 // return 1;
141 if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
142 -1,
143 make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
144 return 1;
145 if (test__mulvti3(-1,
146 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
147 make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
148 return 1;
149 if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
150 0,
151 0))
152 return 1;
153 if (test__mulvti3(0,
154 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
155 0))
156 return 1;
157 if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
158 1,
159 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
160 return 1;
161 if (test__mulvti3(1,
162 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
163 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
164 return 1;
165 // if (test__mulvti3(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
166 // 2,
167 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
168 // return 1;
169 // if (test__mulvti3(2,
170 // make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
171 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
172 // return 1;
173
174 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
175 // -2,
176 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
177 // return 1;
178 // if (test__mulvti3(-2,
179 // make_ti(0x8000000000000000LL, 0x0000000000000000LL),
180 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
181 // return 1;
182 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
183 // -1,
184 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
185 // return 1;
186 // if (test__mulvti3(-1,
187 // make_ti(0x8000000000000000LL, 0x0000000000000000LL),
188 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
189 // return 1;
190 if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
191 0,
192 0))
193 return 1;
194 if (test__mulvti3(0,
195 make_ti(0x8000000000000000LL, 0x0000000000000000LL),
196 0))
197 return 1;
198 if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
199 1,
200 make_ti(0x8000000000000000LL, 0x0000000000000000LL)))
201 return 1;
202 if (test__mulvti3(1,
203 make_ti(0x8000000000000000LL, 0x0000000000000000LL),
204 make_ti(0x8000000000000000LL, 0x0000000000000000LL)))
205 return 1;
206 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
207 // 2,
208 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
209 // return 1;
210 // if (test__mulvti3(2,
211 // make_ti(0x8000000000000000LL, 0x0000000000000000LL),
212 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
213 // return 1;
214
215 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
216 // -2,
217 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
218 // return 1;
219 // if (test__mulvti3(-2,
220 // make_ti(0x8000000000000000LL, 0x0000000000000001LL),
221 // make_ti(0x8000000000000000LL, 0x0000000000000001LL))) // abort
222 // return 1;
223 if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
224 -1,
225 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
226 return 1;
227 if (test__mulvti3(-1,
228 make_ti(0x8000000000000000LL, 0x0000000000000001LL),
229 make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
230 return 1;
231 if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
232 0,
233 0))
234 return 1;
235 if (test__mulvti3(0,
236 make_ti(0x8000000000000000LL, 0x0000000000000001LL),
237 0))
238 return 1;
239 if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
240 1,
241 make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
242 return 1;
243 if (test__mulvti3(1,
244 make_ti(0x8000000000000000LL, 0x0000000000000001LL),
245 make_ti(0x8000000000000000LL, 0x0000000000000001LL)))
246 return 1;
247 // if (test__mulvti3(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
248 // 2,
249 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
250 // return 1;
251 // if (test__mulvti3(2,
252 // make_ti(0x8000000000000000LL, 0x0000000000000001LL),
253 // make_ti(0x8000000000000000LL, 0x0000000000000000LL))) // abort
254 // return 1;
255
256 #else
257 printf("skipped\n");
258 #endif
259 return 0;
260 }
261