1 //===-- mulodi4_test.c - Test __mulodi4 -----------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file tests __mulodi4 for the compiler_rt library.
12 //===----------------------------------------------------------------------===//
17 extern di_int
__mulodi4(di_int a
, di_int b
, int* overflow
);
19 int test__mulodi4(di_int a
, di_int b
, di_int expected
, int expected_overflow
)
22 di_int x
= __mulodi4(a
, b
, &ov
);
23 if (ov
!= expected_overflow
)
24 printf("error in __mulodi4: overflow=%d expected=%d\n",
25 ov
, expected_overflow
);
26 else if (!expected_overflow
&& x
!= expected
) {
27 printf("error in __mulodi4: 0x%llX * 0x%llX = 0x%llX (overflow=%d), "
28 "expected 0x%llX (overflow=%d)\n",
29 a
, b
, x
, ov
, expected
, expected_overflow
);
37 if (test__mulodi4(0, 0, 0, 0))
39 if (test__mulodi4(0, 1, 0, 0))
41 if (test__mulodi4(1, 0, 0, 0))
43 if (test__mulodi4(0, 10, 0, 0))
45 if (test__mulodi4(10, 0, 0, 0))
47 if (test__mulodi4(0, 81985529216486895LL, 0, 0))
49 if (test__mulodi4(81985529216486895LL, 0, 0, 0))
52 if (test__mulodi4(0, -1, 0, 0))
54 if (test__mulodi4(-1, 0, 0, 0))
56 if (test__mulodi4(0, -10, 0, 0))
58 if (test__mulodi4(-10, 0, 0, 0))
60 if (test__mulodi4(0, -81985529216486895LL, 0, 0))
62 if (test__mulodi4(-81985529216486895LL, 0, 0, 0))
65 if (test__mulodi4(1, 1, 1, 0))
67 if (test__mulodi4(1, 10, 10, 0))
69 if (test__mulodi4(10, 1, 10, 0))
71 if (test__mulodi4(1, 81985529216486895LL, 81985529216486895LL, 0))
73 if (test__mulodi4(81985529216486895LL, 1, 81985529216486895LL, 0))
76 if (test__mulodi4(1, -1, -1, 0))
78 if (test__mulodi4(1, -10, -10, 0))
80 if (test__mulodi4(-10, 1, -10, 0))
82 if (test__mulodi4(1, -81985529216486895LL, -81985529216486895LL, 0))
84 if (test__mulodi4(-81985529216486895LL, 1, -81985529216486895LL, 0))
87 if (test__mulodi4(3037000499LL, 3037000499LL, 9223372030926249001LL, 0))
89 if (test__mulodi4(-3037000499LL, 3037000499LL, -9223372030926249001LL, 0))
91 if (test__mulodi4(3037000499LL, -3037000499LL, -9223372030926249001LL, 0))
93 if (test__mulodi4(-3037000499LL, -3037000499LL, 9223372030926249001LL, 0))
96 if (test__mulodi4(4398046511103LL, 2097152LL, 9223372036852678656LL, 0))
98 if (test__mulodi4(-4398046511103LL, 2097152LL, -9223372036852678656LL, 0))
100 if (test__mulodi4(4398046511103LL, -2097152LL, -9223372036852678656LL, 0))
102 if (test__mulodi4(-4398046511103LL, -2097152LL, 9223372036852678656LL, 0))
105 if (test__mulodi4(2097152LL, 4398046511103LL, 9223372036852678656LL, 0))
107 if (test__mulodi4(-2097152LL, 4398046511103LL, -9223372036852678656LL, 0))
109 if (test__mulodi4(2097152LL, -4398046511103LL, -9223372036852678656LL, 0))
111 if (test__mulodi4(-2097152LL, -4398046511103LL, 9223372036852678656LL, 0))
114 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL
, -2, 2, 1))
116 if (test__mulodi4(-2, 0x7FFFFFFFFFFFFFFFLL
, 2, 1))
118 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL
, -1, 0x8000000000000001LL
, 0))
120 if (test__mulodi4(-1, 0x7FFFFFFFFFFFFFFFLL
, 0x8000000000000001LL
, 0))
122 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL
, 0, 0, 0))
124 if (test__mulodi4(0, 0x7FFFFFFFFFFFFFFFLL
, 0, 0))
126 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL
, 1, 0x7FFFFFFFFFFFFFFFLL
, 0))
128 if (test__mulodi4(1, 0x7FFFFFFFFFFFFFFFLL
, 0x7FFFFFFFFFFFFFFFLL
, 0))
130 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL
, 2, 0x8000000000000001LL
, 1))
132 if (test__mulodi4(2, 0x7FFFFFFFFFFFFFFFLL
, 0x8000000000000001LL
, 1))
135 if (test__mulodi4(0x8000000000000000LL
, -2, 0x8000000000000000LL
, 1))
137 if (test__mulodi4(-2, 0x8000000000000000LL
, 0x8000000000000000LL
, 1))
139 if (test__mulodi4(0x8000000000000000LL
, -1, 0x8000000000000000LL
, 1))
141 if (test__mulodi4(-1, 0x8000000000000000LL
, 0x8000000000000000LL
, 1))
143 if (test__mulodi4(0x8000000000000000LL
, 0, 0, 0))
145 if (test__mulodi4(0, 0x8000000000000000LL
, 0, 0))
147 if (test__mulodi4(0x8000000000000000LL
, 1, 0x8000000000000000LL
, 0))
149 if (test__mulodi4(1, 0x8000000000000000LL
, 0x8000000000000000LL
, 0))
151 if (test__mulodi4(0x8000000000000000LL
, 2, 0x8000000000000000LL
, 1))
153 if (test__mulodi4(2, 0x8000000000000000LL
, 0x8000000000000000LL
, 1))
156 if (test__mulodi4(0x8000000000000001LL
, -2, 0x8000000000000001LL
, 1))
158 if (test__mulodi4(-2, 0x8000000000000001LL
, 0x8000000000000001LL
, 1))
160 if (test__mulodi4(0x8000000000000001LL
, -1, 0x7FFFFFFFFFFFFFFFLL
, 0))
162 if (test__mulodi4(-1, 0x8000000000000001LL
, 0x7FFFFFFFFFFFFFFFLL
, 0))
164 if (test__mulodi4(0x8000000000000001LL
, 0, 0, 0))
166 if (test__mulodi4(0, 0x8000000000000001LL
, 0, 0))
168 if (test__mulodi4(0x8000000000000001LL
, 1, 0x8000000000000001LL
, 0))
170 if (test__mulodi4(1, 0x8000000000000001LL
, 0x8000000000000001LL
, 0))
172 if (test__mulodi4(0x8000000000000001LL
, 2, 0x8000000000000000LL
, 1))
174 if (test__mulodi4(2, 0x8000000000000001LL
, 0x8000000000000000LL
, 1))