1 //===-- mulvdi3_test.c - Test __mulvdi3 -----------------------------------===//
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 __mulvdi3 for the compiler_rt library.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "int_lib.h"
15 #include <stdio.h>
16
17 // Returns: a * b
18
19 // Effects: aborts if a * b overflows
20
21 COMPILER_RT_ABI di_int __mulvdi3(di_int a, di_int b);
22
test__mulvdi3(di_int a,di_int b,di_int expected)23 int test__mulvdi3(di_int a, di_int b, di_int expected)
24 {
25 di_int x = __mulvdi3(a, b);
26 if (x != expected)
27 printf("error in __mulvdi3: %lld * %lld = %lld, expected %lld\n",
28 a, b, x, expected);
29 return x != expected;
30 }
31
main()32 int main()
33 {
34 if (test__mulvdi3(0, 0, 0))
35 return 1;
36 if (test__mulvdi3(0, 1, 0))
37 return 1;
38 if (test__mulvdi3(1, 0, 0))
39 return 1;
40 if (test__mulvdi3(0, 10, 0))
41 return 1;
42 if (test__mulvdi3(10, 0, 0))
43 return 1;
44 if (test__mulvdi3(0, 81985529216486895LL, 0))
45 return 1;
46 if (test__mulvdi3(81985529216486895LL, 0, 0))
47 return 1;
48
49 if (test__mulvdi3(0, -1, 0))
50 return 1;
51 if (test__mulvdi3(-1, 0, 0))
52 return 1;
53 if (test__mulvdi3(0, -10, 0))
54 return 1;
55 if (test__mulvdi3(-10, 0, 0))
56 return 1;
57 if (test__mulvdi3(0, -81985529216486895LL, 0))
58 return 1;
59 if (test__mulvdi3(-81985529216486895LL, 0, 0))
60 return 1;
61
62 if (test__mulvdi3(1, 1, 1))
63 return 1;
64 if (test__mulvdi3(1, 10, 10))
65 return 1;
66 if (test__mulvdi3(10, 1, 10))
67 return 1;
68 if (test__mulvdi3(1, 81985529216486895LL, 81985529216486895LL))
69 return 1;
70 if (test__mulvdi3(81985529216486895LL, 1, 81985529216486895LL))
71 return 1;
72
73 if (test__mulvdi3(1, -1, -1))
74 return 1;
75 if (test__mulvdi3(1, -10, -10))
76 return 1;
77 if (test__mulvdi3(-10, 1, -10))
78 return 1;
79 if (test__mulvdi3(1, -81985529216486895LL, -81985529216486895LL))
80 return 1;
81 if (test__mulvdi3(-81985529216486895LL, 1, -81985529216486895LL))
82 return 1;
83
84 if (test__mulvdi3(3037000499LL, 3037000499LL, 9223372030926249001LL))
85 return 1;
86 if (test__mulvdi3(-3037000499LL, 3037000499LL, -9223372030926249001LL))
87 return 1;
88 if (test__mulvdi3(3037000499LL, -3037000499LL, -9223372030926249001LL))
89 return 1;
90 if (test__mulvdi3(-3037000499LL, -3037000499LL, 9223372030926249001LL))
91 return 1;
92
93 if (test__mulvdi3(4398046511103LL, 2097152LL, 9223372036852678656LL))
94 return 1;
95 if (test__mulvdi3(-4398046511103LL, 2097152LL, -9223372036852678656LL))
96 return 1;
97 if (test__mulvdi3(4398046511103LL, -2097152LL, -9223372036852678656LL))
98 return 1;
99 if (test__mulvdi3(-4398046511103LL, -2097152LL, 9223372036852678656LL))
100 return 1;
101
102 if (test__mulvdi3(2097152LL, 4398046511103LL, 9223372036852678656LL))
103 return 1;
104 if (test__mulvdi3(-2097152LL, 4398046511103LL, -9223372036852678656LL))
105 return 1;
106 if (test__mulvdi3(2097152LL, -4398046511103LL, -9223372036852678656LL))
107 return 1;
108 if (test__mulvdi3(-2097152LL, -4398046511103LL, 9223372036852678656LL))
109 return 1;
110
111 // if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL, -2, 0x8000000000000001LL)) // abort
112 // return 1;
113 // if (test__mulvdi3(-2, 0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL)) // abort
114 // return 1;
115 if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL, -1, 0x8000000000000001LL))
116 return 1;
117 if (test__mulvdi3(-1, 0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL))
118 return 1;
119 if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL, 0, 0))
120 return 1;
121 if (test__mulvdi3(0, 0x7FFFFFFFFFFFFFFFLL, 0))
122 return 1;
123 if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL, 1, 0x7FFFFFFFFFFFFFFFLL))
124 return 1;
125 if (test__mulvdi3(1, 0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFFLL))
126 return 1;
127 // if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL, 2, 0x8000000000000001LL)) // abort
128 // return 1;
129 // if (test__mulvdi3(2, 0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL)) // abort
130 // return 1;
131
132 // if (test__mulvdi3(0x8000000000000000LL, -2, 0x8000000000000000LL)) // abort
133 // return 1;
134 // if (test__mulvdi3(-2, 0x8000000000000000LL, 0x8000000000000000LL)) // abort
135 // return 1;
136 // if (test__mulvdi3(0x8000000000000000LL, -1, 0x8000000000000000LL)) // abort
137 // return 1;
138 // if (test__mulvdi3(-1, 0x8000000000000000LL, 0x8000000000000000LL)) // abort
139 // return 1;
140 if (test__mulvdi3(0x8000000000000000LL, 0, 0))
141 return 1;
142 if (test__mulvdi3(0, 0x8000000000000000LL, 0))
143 return 1;
144 if (test__mulvdi3(0x8000000000000000LL, 1, 0x8000000000000000LL))
145 return 1;
146 if (test__mulvdi3(1, 0x8000000000000000LL, 0x8000000000000000LL))
147 return 1;
148 // if (test__mulvdi3(0x8000000000000000LL, 2, 0x8000000000000000LL)) // abort
149 // return 1;
150 // if (test__mulvdi3(2, 0x8000000000000000LL, 0x8000000000000000LL)) // abort
151 // return 1;
152
153 // if (test__mulvdi3(0x8000000000000001LL, -2, 0x8000000000000001LL)) // abort
154 // return 1;
155 // if (test__mulvdi3(-2, 0x8000000000000001LL, 0x8000000000000001LL)) // abort
156 // return 1;
157 if (test__mulvdi3(0x8000000000000001LL, -1, 0x7FFFFFFFFFFFFFFFLL))
158 return 1;
159 if (test__mulvdi3(-1, 0x8000000000000001LL, 0x7FFFFFFFFFFFFFFFLL))
160 return 1;
161 if (test__mulvdi3(0x8000000000000001LL, 0, 0))
162 return 1;
163 if (test__mulvdi3(0, 0x8000000000000001LL, 0))
164 return 1;
165 if (test__mulvdi3(0x8000000000000001LL, 1, 0x8000000000000001LL))
166 return 1;
167 if (test__mulvdi3(1, 0x8000000000000001LL, 0x8000000000000001LL))
168 return 1;
169 // if (test__mulvdi3(0x8000000000000001LL, 2, 0x8000000000000000LL)) // abort
170 // return 1;
171 // if (test__mulvdi3(2, 0x8000000000000001LL, 0x8000000000000000LL)) // abort
172 // return 1;
173
174 return 0;
175 }
176