• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- muloti4_test.c - Test __muloti4 -----------------------------------===//
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 __muloti3 for the compiler_rt library.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "int_lib.h"
15 #include <stdio.h>
16 
17 #ifdef CRT_HAS_128BIT
18 
19 // Returns: a * b
20 
21 // Effects: sets overflow if a * b overflows
22 
23 COMPILER_RT_ABI ti_int __muloti4(ti_int a, ti_int b, int *overflow);
24 
test__muloti4(ti_int a,ti_int b,ti_int expected,int expected_overflow)25 int test__muloti4(ti_int a, ti_int b, ti_int expected, int expected_overflow)
26 {
27     int ov;
28     ti_int x = __muloti4(a, b, &ov);
29     if (ov != expected_overflow) {
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 
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);
45       return 1;
46     }
47     else if (!expected_overflow && x != expected)
48     {
49         twords at;
50         at.all = a;
51         twords bt;
52         bt.all = b;
53         twords xt;
54         xt.all = x;
55         twords expectedt;
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);
61 	return 1;
62     }
63     return 0;
64 }
65 
66 #endif
67 
main()68 int main()
69 {
70 #ifdef CRT_HAS_128BIT
71     if (test__muloti4(0, 0, 0, 0))
72         return 1;
73     if (test__muloti4(0, 1, 0, 0))
74         return 1;
75     if (test__muloti4(1, 0, 0, 0))
76         return 1;
77     if (test__muloti4(0, 10, 0, 0))
78         return 1;
79     if (test__muloti4(10, 0, 0, 0))
80         return 1;
81     if (test__muloti4(0, 81985529216486895LL, 0, 0))
82         return 1;
83     if (test__muloti4(81985529216486895LL, 0, 0, 0))
84         return 1;
85 
86     if (test__muloti4(0, -1, 0, 0))
87         return 1;
88     if (test__muloti4(-1, 0, 0, 0))
89         return 1;
90     if (test__muloti4(0, -10, 0, 0))
91         return 1;
92     if (test__muloti4(-10, 0, 0, 0))
93         return 1;
94     if (test__muloti4(0, -81985529216486895LL, 0, 0))
95         return 1;
96     if (test__muloti4(-81985529216486895LL, 0, 0, 0))
97         return 1;
98 
99     if (test__muloti4(1, 1, 1, 0))
100         return 1;
101     if (test__muloti4(1, 10, 10, 0))
102         return 1;
103     if (test__muloti4(10, 1, 10, 0))
104         return 1;
105     if (test__muloti4(1, 81985529216486895LL, 81985529216486895LL, 0))
106         return 1;
107     if (test__muloti4(81985529216486895LL, 1, 81985529216486895LL, 0))
108         return 1;
109 
110     if (test__muloti4(1, -1, -1, 0))
111         return 1;
112     if (test__muloti4(1, -10, -10, 0))
113         return 1;
114     if (test__muloti4(-10, 1, -10, 0))
115         return 1;
116     if (test__muloti4(1, -81985529216486895LL, -81985529216486895LL, 0))
117         return 1;
118     if (test__muloti4(-81985529216486895LL, 1, -81985529216486895LL, 0))
119         return 1;
120 
121     if (test__muloti4(3037000499LL, 3037000499LL, 9223372030926249001LL, 0))
122         return 1;
123     if (test__muloti4(-3037000499LL, 3037000499LL, -9223372030926249001LL, 0))
124         return 1;
125     if (test__muloti4(3037000499LL, -3037000499LL, -9223372030926249001LL, 0))
126         return 1;
127     if (test__muloti4(-3037000499LL, -3037000499LL, 9223372030926249001LL, 0))
128         return 1;
129 
130     if (test__muloti4(4398046511103LL, 2097152LL, 9223372036852678656LL, 0))
131         return 1;
132     if (test__muloti4(-4398046511103LL, 2097152LL, -9223372036852678656LL, 0))
133         return 1;
134     if (test__muloti4(4398046511103LL, -2097152LL, -9223372036852678656LL, 0))
135         return 1;
136     if (test__muloti4(-4398046511103LL, -2097152LL, 9223372036852678656LL, 0))
137         return 1;
138 
139     if (test__muloti4(2097152LL, 4398046511103LL, 9223372036852678656LL, 0))
140         return 1;
141     if (test__muloti4(-2097152LL, 4398046511103LL, -9223372036852678656LL, 0))
142         return 1;
143     if (test__muloti4(2097152LL, -4398046511103LL, -9223372036852678656LL, 0))
144         return 1;
145     if (test__muloti4(-2097152LL, -4398046511103LL, 9223372036852678656LL, 0))
146         return 1;
147 
148     if (test__muloti4(make_ti(0x00000000000000B5LL, 0x04F333F9DE5BE000LL),
149                       make_ti(0x0000000000000000LL, 0x00B504F333F9DE5BLL),
150                       make_ti(0x7FFFFFFFFFFFF328LL, 0xDF915DA296E8A000LL), 0))
151         return 1;
152 
153      if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
154                        -2,
155                        make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1))
156        return 1;
157      if (test__muloti4(-2,
158                        make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
159                        make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1))
160          return 1;
161     if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
162                       -1,
163                       make_ti(0x8000000000000000LL, 0x0000000000000001LL), 0))
164         return 1;
165     if (test__muloti4(-1,
166                       make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
167                       make_ti(0x8000000000000000LL, 0x0000000000000001LL), 0))
168         return 1;
169     if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
170                       0,
171                       0, 0))
172         return 1;
173     if (test__muloti4(0,
174                       make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
175                       0, 0))
176         return 1;
177     if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
178                       1,
179                       make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 0))
180         return 1;
181     if (test__muloti4(1,
182                       make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
183                       make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 0))
184         return 1;
185      if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
186                        2,
187                        make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1))
188          return 1;
189      if (test__muloti4(2,
190                        make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL),
191                        make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1))
192          return 1;
193 
194      if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
195                        -2,
196                        make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
197          return 1;
198      if (test__muloti4(-2,
199                        make_ti(0x8000000000000000LL, 0x0000000000000000LL),
200                        make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
201          return 1;
202      if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
203                        -1,
204                        make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
205          return 1;
206      if (test__muloti4(-1,
207                        make_ti(0x8000000000000000LL, 0x0000000000000000LL),
208                        make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
209          return 1;
210     if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
211                       0,
212                       0, 0))
213         return 1;
214     if (test__muloti4(0,
215                       make_ti(0x8000000000000000LL, 0x0000000000000000LL),
216                       0, 0))
217         return 1;
218     if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
219                       1,
220                       make_ti(0x8000000000000000LL, 0x0000000000000000LL), 0))
221         return 1;
222     if (test__muloti4(1,
223                       make_ti(0x8000000000000000LL, 0x0000000000000000LL),
224                       make_ti(0x8000000000000000LL, 0x0000000000000000LL), 0))
225         return 1;
226      if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL),
227                        2,
228                        make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
229          return 1;
230      if (test__muloti4(2,
231                        make_ti(0x8000000000000000LL, 0x0000000000000000LL),
232                        make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
233          return 1;
234 
235      if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
236                        -2,
237                        make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1))
238          return 1;
239      if (test__muloti4(-2,
240                        make_ti(0x8000000000000000LL, 0x0000000000000001LL),
241                        make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1))
242          return 1;
243     if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
244                       -1,
245                       make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 0))
246         return 1;
247     if (test__muloti4(-1,
248                       make_ti(0x8000000000000000LL, 0x0000000000000001LL),
249                       make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 0))
250         return 1;
251     if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
252                       0,
253                       0, 0))
254         return 1;
255     if (test__muloti4(0,
256                       make_ti(0x8000000000000000LL, 0x0000000000000001LL),
257                       0, 0))
258         return 1;
259     if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
260                       1,
261                       make_ti(0x8000000000000000LL, 0x0000000000000001LL), 0))
262         return 1;
263     if (test__muloti4(1,
264                       make_ti(0x8000000000000000LL, 0x0000000000000001LL),
265                       make_ti(0x8000000000000000LL, 0x0000000000000001LL), 0))
266         return 1;
267      if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL),
268                        2,
269                        make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
270          return 1;
271      if (test__muloti4(2,
272                        make_ti(0x8000000000000000LL, 0x0000000000000001LL),
273                        make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1))
274          return 1;
275 
276 #else
277     printf("skipped\n");
278 #endif
279     return 0;
280 }
281