1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_mulodi4
3 //===-- mulodi4_test.c - Test __mulodi4 -----------------------------------===//
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //===----------------------------------------------------------------------===//
11 // This file tests __mulodi4 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
18 extern COMPILER_RT_ABI di_int
__mulodi4(di_int a
, di_int b
, int* overflow
);
20 int test__mulodi4(di_int a
, di_int b
, di_int expected
, int expected_overflow
)
23 di_int x
= __mulodi4(a
, b
, &ov
);
24 if (ov
!= expected_overflow
)
25 printf("error in __mulodi4: overflow=%d expected=%d\n",
26 ov
, expected_overflow
);
27 else if (!expected_overflow
&& x
!= expected
) {
28 printf("error in __mulodi4: 0x%llX * 0x%llX = 0x%llX (overflow=%d), "
29 "expected 0x%llX (overflow=%d)\n",
30 a
, b
, x
, ov
, expected
, expected_overflow
);
38 if (test__mulodi4(0, 0, 0, 0))
40 if (test__mulodi4(0, 1, 0, 0))
42 if (test__mulodi4(1, 0, 0, 0))
44 if (test__mulodi4(0, 10, 0, 0))
46 if (test__mulodi4(10, 0, 0, 0))
48 if (test__mulodi4(0, 81985529216486895LL, 0, 0))
50 if (test__mulodi4(81985529216486895LL, 0, 0, 0))
53 if (test__mulodi4(0, -1, 0, 0))
55 if (test__mulodi4(-1, 0, 0, 0))
57 if (test__mulodi4(0, -10, 0, 0))
59 if (test__mulodi4(-10, 0, 0, 0))
61 if (test__mulodi4(0, -81985529216486895LL, 0, 0))
63 if (test__mulodi4(-81985529216486895LL, 0, 0, 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(1, -1, -1, 0))
79 if (test__mulodi4(1, -10, -10, 0))
81 if (test__mulodi4(-10, 1, -10, 0))
83 if (test__mulodi4(1, -81985529216486895LL, -81985529216486895LL, 0))
85 if (test__mulodi4(-81985529216486895LL, 1, -81985529216486895LL, 0))
88 if (test__mulodi4(3037000499LL, 3037000499LL, 9223372030926249001LL, 0))
90 if (test__mulodi4(-3037000499LL, 3037000499LL, -9223372030926249001LL, 0))
92 if (test__mulodi4(3037000499LL, -3037000499LL, -9223372030926249001LL, 0))
94 if (test__mulodi4(-3037000499LL, -3037000499LL, 9223372030926249001LL, 0))
97 if (test__mulodi4(4398046511103LL, 2097152LL, 9223372036852678656LL, 0))
99 if (test__mulodi4(-4398046511103LL, 2097152LL, -9223372036852678656LL, 0))
101 if (test__mulodi4(4398046511103LL, -2097152LL, -9223372036852678656LL, 0))
103 if (test__mulodi4(-4398046511103LL, -2097152LL, 9223372036852678656LL, 0))
106 if (test__mulodi4(2097152LL, 4398046511103LL, 9223372036852678656LL, 0))
108 if (test__mulodi4(-2097152LL, 4398046511103LL, -9223372036852678656LL, 0))
110 if (test__mulodi4(2097152LL, -4398046511103LL, -9223372036852678656LL, 0))
112 if (test__mulodi4(-2097152LL, -4398046511103LL, 9223372036852678656LL, 0))
115 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL
, -2, 2, 1))
117 if (test__mulodi4(-2, 0x7FFFFFFFFFFFFFFFLL
, 2, 1))
119 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL
, -1, 0x8000000000000001LL
, 0))
121 if (test__mulodi4(-1, 0x7FFFFFFFFFFFFFFFLL
, 0x8000000000000001LL
, 0))
123 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL
, 0, 0, 0))
125 if (test__mulodi4(0, 0x7FFFFFFFFFFFFFFFLL
, 0, 0))
127 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL
, 1, 0x7FFFFFFFFFFFFFFFLL
, 0))
129 if (test__mulodi4(1, 0x7FFFFFFFFFFFFFFFLL
, 0x7FFFFFFFFFFFFFFFLL
, 0))
131 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL
, 2, 0x8000000000000001LL
, 1))
133 if (test__mulodi4(2, 0x7FFFFFFFFFFFFFFFLL
, 0x8000000000000001LL
, 1))
136 if (test__mulodi4(0x8000000000000000LL
, -2, 0x8000000000000000LL
, 1))
138 if (test__mulodi4(-2, 0x8000000000000000LL
, 0x8000000000000000LL
, 1))
140 if (test__mulodi4(0x8000000000000000LL
, -1, 0x8000000000000000LL
, 1))
142 if (test__mulodi4(-1, 0x8000000000000000LL
, 0x8000000000000000LL
, 1))
144 if (test__mulodi4(0x8000000000000000LL
, 0, 0, 0))
146 if (test__mulodi4(0, 0x8000000000000000LL
, 0, 0))
148 if (test__mulodi4(0x8000000000000000LL
, 1, 0x8000000000000000LL
, 0))
150 if (test__mulodi4(1, 0x8000000000000000LL
, 0x8000000000000000LL
, 0))
152 if (test__mulodi4(0x8000000000000000LL
, 2, 0x8000000000000000LL
, 1))
154 if (test__mulodi4(2, 0x8000000000000000LL
, 0x8000000000000000LL
, 1))
157 if (test__mulodi4(0x8000000000000001LL
, -2, 0x8000000000000001LL
, 1))
159 if (test__mulodi4(-2, 0x8000000000000001LL
, 0x8000000000000001LL
, 1))
161 if (test__mulodi4(0x8000000000000001LL
, -1, 0x7FFFFFFFFFFFFFFFLL
, 0))
163 if (test__mulodi4(-1, 0x8000000000000001LL
, 0x7FFFFFFFFFFFFFFFLL
, 0))
165 if (test__mulodi4(0x8000000000000001LL
, 0, 0, 0))
167 if (test__mulodi4(0, 0x8000000000000001LL
, 0, 0))
169 if (test__mulodi4(0x8000000000000001LL
, 1, 0x8000000000000001LL
, 0))
171 if (test__mulodi4(1, 0x8000000000000001LL
, 0x8000000000000001LL
, 0))
173 if (test__mulodi4(0x8000000000000001LL
, 2, 0x8000000000000000LL
, 1))
175 if (test__mulodi4(2, 0x8000000000000001LL
, 0x8000000000000000LL
, 1))