1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_mulodi4
7 extern COMPILER_RT_ABI di_int
__mulodi4(di_int a
, di_int b
, int* overflow
);
9 int test__mulodi4(di_int a
, di_int b
, di_int expected
, int expected_overflow
)
12 di_int x
= __mulodi4(a
, b
, &ov
);
13 if (ov
!= expected_overflow
)
14 printf("error in __mulodi4: overflow=%d expected=%d\n",
15 ov
, expected_overflow
);
16 else if (!expected_overflow
&& x
!= expected
) {
17 printf("error in __mulodi4: 0x%llX * 0x%llX = 0x%llX (overflow=%d), "
18 "expected 0x%llX (overflow=%d)\n",
19 a
, b
, x
, ov
, expected
, expected_overflow
);
27 if (test__mulodi4(0, 0, 0, 0))
29 if (test__mulodi4(0, 1, 0, 0))
31 if (test__mulodi4(1, 0, 0, 0))
33 if (test__mulodi4(0, 10, 0, 0))
35 if (test__mulodi4(10, 0, 0, 0))
37 if (test__mulodi4(0, 81985529216486895LL, 0, 0))
39 if (test__mulodi4(81985529216486895LL, 0, 0, 0))
42 if (test__mulodi4(0, -1, 0, 0))
44 if (test__mulodi4(-1, 0, 0, 0))
46 if (test__mulodi4(0, -10, 0, 0))
48 if (test__mulodi4(-10, 0, 0, 0))
50 if (test__mulodi4(0, -81985529216486895LL, 0, 0))
52 if (test__mulodi4(-81985529216486895LL, 0, 0, 0))
55 if (test__mulodi4(1, 1, 1, 0))
57 if (test__mulodi4(1, 10, 10, 0))
59 if (test__mulodi4(10, 1, 10, 0))
61 if (test__mulodi4(1, 81985529216486895LL, 81985529216486895LL, 0))
63 if (test__mulodi4(81985529216486895LL, 1, 81985529216486895LL, 0))
66 if (test__mulodi4(1, -1, -1, 0))
68 if (test__mulodi4(1, -10, -10, 0))
70 if (test__mulodi4(-10, 1, -10, 0))
72 if (test__mulodi4(1, -81985529216486895LL, -81985529216486895LL, 0))
74 if (test__mulodi4(-81985529216486895LL, 1, -81985529216486895LL, 0))
77 if (test__mulodi4(3037000499LL, 3037000499LL, 9223372030926249001LL, 0))
79 if (test__mulodi4(-3037000499LL, 3037000499LL, -9223372030926249001LL, 0))
81 if (test__mulodi4(3037000499LL, -3037000499LL, -9223372030926249001LL, 0))
83 if (test__mulodi4(-3037000499LL, -3037000499LL, 9223372030926249001LL, 0))
86 if (test__mulodi4(4398046511103LL, 2097152LL, 9223372036852678656LL, 0))
88 if (test__mulodi4(-4398046511103LL, 2097152LL, -9223372036852678656LL, 0))
90 if (test__mulodi4(4398046511103LL, -2097152LL, -9223372036852678656LL, 0))
92 if (test__mulodi4(-4398046511103LL, -2097152LL, 9223372036852678656LL, 0))
95 if (test__mulodi4(2097152LL, 4398046511103LL, 9223372036852678656LL, 0))
97 if (test__mulodi4(-2097152LL, 4398046511103LL, -9223372036852678656LL, 0))
99 if (test__mulodi4(2097152LL, -4398046511103LL, -9223372036852678656LL, 0))
101 if (test__mulodi4(-2097152LL, -4398046511103LL, 9223372036852678656LL, 0))
104 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL
, -2, 2, 1))
106 if (test__mulodi4(-2, 0x7FFFFFFFFFFFFFFFLL
, 2, 1))
108 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL
, -1, 0x8000000000000001LL
, 0))
110 if (test__mulodi4(-1, 0x7FFFFFFFFFFFFFFFLL
, 0x8000000000000001LL
, 0))
112 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL
, 0, 0, 0))
114 if (test__mulodi4(0, 0x7FFFFFFFFFFFFFFFLL
, 0, 0))
116 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL
, 1, 0x7FFFFFFFFFFFFFFFLL
, 0))
118 if (test__mulodi4(1, 0x7FFFFFFFFFFFFFFFLL
, 0x7FFFFFFFFFFFFFFFLL
, 0))
120 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL
, 2, 0x8000000000000001LL
, 1))
122 if (test__mulodi4(2, 0x7FFFFFFFFFFFFFFFLL
, 0x8000000000000001LL
, 1))
125 if (test__mulodi4(0x8000000000000000LL
, -2, 0x8000000000000000LL
, 1))
127 if (test__mulodi4(-2, 0x8000000000000000LL
, 0x8000000000000000LL
, 1))
129 if (test__mulodi4(0x8000000000000000LL
, -1, 0x8000000000000000LL
, 1))
131 if (test__mulodi4(-1, 0x8000000000000000LL
, 0x8000000000000000LL
, 1))
133 if (test__mulodi4(0x8000000000000000LL
, 0, 0, 0))
135 if (test__mulodi4(0, 0x8000000000000000LL
, 0, 0))
137 if (test__mulodi4(0x8000000000000000LL
, 1, 0x8000000000000000LL
, 0))
139 if (test__mulodi4(1, 0x8000000000000000LL
, 0x8000000000000000LL
, 0))
141 if (test__mulodi4(0x8000000000000000LL
, 2, 0x8000000000000000LL
, 1))
143 if (test__mulodi4(2, 0x8000000000000000LL
, 0x8000000000000000LL
, 1))
146 if (test__mulodi4(0x8000000000000001LL
, -2, 0x8000000000000001LL
, 1))
148 if (test__mulodi4(-2, 0x8000000000000001LL
, 0x8000000000000001LL
, 1))
150 if (test__mulodi4(0x8000000000000001LL
, -1, 0x7FFFFFFFFFFFFFFFLL
, 0))
152 if (test__mulodi4(-1, 0x8000000000000001LL
, 0x7FFFFFFFFFFFFFFFLL
, 0))
154 if (test__mulodi4(0x8000000000000001LL
, 0, 0, 0))
156 if (test__mulodi4(0, 0x8000000000000001LL
, 0, 0))
158 if (test__mulodi4(0x8000000000000001LL
, 1, 0x8000000000000001LL
, 0))
160 if (test__mulodi4(1, 0x8000000000000001LL
, 0x8000000000000001LL
, 0))
162 if (test__mulodi4(0x8000000000000001LL
, 2, 0x8000000000000000LL
, 1))
164 if (test__mulodi4(2, 0x8000000000000001LL
, 0x8000000000000000LL
, 1))