[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / mulodi4_test.c
blobe8654e1c3b5b55eef86a09780550b4a1711d3fc4
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_mulodi4
3 //===-- mulodi4_test.c - Test __mulodi4 -----------------------------------===//
4 //
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
8 //
9 //===----------------------------------------------------------------------===//
11 // This file tests __mulodi4 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
15 #include "int_lib.h"
16 #include <stdio.h>
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)
22 int ov;
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);
31 return 1;
33 return 0;
36 int main()
38 if (test__mulodi4(0, 0, 0, 0))
39 return 1;
40 if (test__mulodi4(0, 1, 0, 0))
41 return 1;
42 if (test__mulodi4(1, 0, 0, 0))
43 return 1;
44 if (test__mulodi4(0, 10, 0, 0))
45 return 1;
46 if (test__mulodi4(10, 0, 0, 0))
47 return 1;
48 if (test__mulodi4(0, 81985529216486895LL, 0, 0))
49 return 1;
50 if (test__mulodi4(81985529216486895LL, 0, 0, 0))
51 return 1;
53 if (test__mulodi4(0, -1, 0, 0))
54 return 1;
55 if (test__mulodi4(-1, 0, 0, 0))
56 return 1;
57 if (test__mulodi4(0, -10, 0, 0))
58 return 1;
59 if (test__mulodi4(-10, 0, 0, 0))
60 return 1;
61 if (test__mulodi4(0, -81985529216486895LL, 0, 0))
62 return 1;
63 if (test__mulodi4(-81985529216486895LL, 0, 0, 0))
64 return 1;
66 if (test__mulodi4(1, 1, 1, 0))
67 return 1;
68 if (test__mulodi4(1, 10, 10, 0))
69 return 1;
70 if (test__mulodi4(10, 1, 10, 0))
71 return 1;
72 if (test__mulodi4(1, 81985529216486895LL, 81985529216486895LL, 0))
73 return 1;
74 if (test__mulodi4(81985529216486895LL, 1, 81985529216486895LL, 0))
75 return 1;
77 if (test__mulodi4(1, -1, -1, 0))
78 return 1;
79 if (test__mulodi4(1, -10, -10, 0))
80 return 1;
81 if (test__mulodi4(-10, 1, -10, 0))
82 return 1;
83 if (test__mulodi4(1, -81985529216486895LL, -81985529216486895LL, 0))
84 return 1;
85 if (test__mulodi4(-81985529216486895LL, 1, -81985529216486895LL, 0))
86 return 1;
88 if (test__mulodi4(3037000499LL, 3037000499LL, 9223372030926249001LL, 0))
89 return 1;
90 if (test__mulodi4(-3037000499LL, 3037000499LL, -9223372030926249001LL, 0))
91 return 1;
92 if (test__mulodi4(3037000499LL, -3037000499LL, -9223372030926249001LL, 0))
93 return 1;
94 if (test__mulodi4(-3037000499LL, -3037000499LL, 9223372030926249001LL, 0))
95 return 1;
97 if (test__mulodi4(4398046511103LL, 2097152LL, 9223372036852678656LL, 0))
98 return 1;
99 if (test__mulodi4(-4398046511103LL, 2097152LL, -9223372036852678656LL, 0))
100 return 1;
101 if (test__mulodi4(4398046511103LL, -2097152LL, -9223372036852678656LL, 0))
102 return 1;
103 if (test__mulodi4(-4398046511103LL, -2097152LL, 9223372036852678656LL, 0))
104 return 1;
106 if (test__mulodi4(2097152LL, 4398046511103LL, 9223372036852678656LL, 0))
107 return 1;
108 if (test__mulodi4(-2097152LL, 4398046511103LL, -9223372036852678656LL, 0))
109 return 1;
110 if (test__mulodi4(2097152LL, -4398046511103LL, -9223372036852678656LL, 0))
111 return 1;
112 if (test__mulodi4(-2097152LL, -4398046511103LL, 9223372036852678656LL, 0))
113 return 1;
115 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, -2, 2, 1))
116 return 1;
117 if (test__mulodi4(-2, 0x7FFFFFFFFFFFFFFFLL, 2, 1))
118 return 1;
119 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, -1, 0x8000000000000001LL, 0))
120 return 1;
121 if (test__mulodi4(-1, 0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL, 0))
122 return 1;
123 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, 0, 0, 0))
124 return 1;
125 if (test__mulodi4(0, 0x7FFFFFFFFFFFFFFFLL, 0, 0))
126 return 1;
127 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, 1, 0x7FFFFFFFFFFFFFFFLL, 0))
128 return 1;
129 if (test__mulodi4(1, 0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFFLL, 0))
130 return 1;
131 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, 2, 0x8000000000000001LL, 1))
132 return 1;
133 if (test__mulodi4(2, 0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL, 1))
134 return 1;
136 if (test__mulodi4(0x8000000000000000LL, -2, 0x8000000000000000LL, 1))
137 return 1;
138 if (test__mulodi4(-2, 0x8000000000000000LL, 0x8000000000000000LL, 1))
139 return 1;
140 if (test__mulodi4(0x8000000000000000LL, -1, 0x8000000000000000LL, 1))
141 return 1;
142 if (test__mulodi4(-1, 0x8000000000000000LL, 0x8000000000000000LL, 1))
143 return 1;
144 if (test__mulodi4(0x8000000000000000LL, 0, 0, 0))
145 return 1;
146 if (test__mulodi4(0, 0x8000000000000000LL, 0, 0))
147 return 1;
148 if (test__mulodi4(0x8000000000000000LL, 1, 0x8000000000000000LL, 0))
149 return 1;
150 if (test__mulodi4(1, 0x8000000000000000LL, 0x8000000000000000LL, 0))
151 return 1;
152 if (test__mulodi4(0x8000000000000000LL, 2, 0x8000000000000000LL, 1))
153 return 1;
154 if (test__mulodi4(2, 0x8000000000000000LL, 0x8000000000000000LL, 1))
155 return 1;
157 if (test__mulodi4(0x8000000000000001LL, -2, 0x8000000000000001LL, 1))
158 return 1;
159 if (test__mulodi4(-2, 0x8000000000000001LL, 0x8000000000000001LL, 1))
160 return 1;
161 if (test__mulodi4(0x8000000000000001LL, -1, 0x7FFFFFFFFFFFFFFFLL, 0))
162 return 1;
163 if (test__mulodi4(-1, 0x8000000000000001LL, 0x7FFFFFFFFFFFFFFFLL, 0))
164 return 1;
165 if (test__mulodi4(0x8000000000000001LL, 0, 0, 0))
166 return 1;
167 if (test__mulodi4(0, 0x8000000000000001LL, 0, 0))
168 return 1;
169 if (test__mulodi4(0x8000000000000001LL, 1, 0x8000000000000001LL, 0))
170 return 1;
171 if (test__mulodi4(1, 0x8000000000000001LL, 0x8000000000000001LL, 0))
172 return 1;
173 if (test__mulodi4(0x8000000000000001LL, 2, 0x8000000000000000LL, 1))
174 return 1;
175 if (test__mulodi4(2, 0x8000000000000001LL, 0x8000000000000000LL, 1))
176 return 1;
178 return 0;