[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / mulosi4_test.c
blobf653fe4a95700ce2b8fc0fe6256bb35d0e67f545
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_mulosi4
3 //===-- mulosi4_test.c - Test __mulosi4 -----------------------------------===//
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 __mulosi4 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
15 #include "int_lib.h"
16 #include <stdio.h>
18 // Returns: a * b
20 // Effects: aborts if a * b overflows
22 COMPILER_RT_ABI si_int __mulosi4(si_int a, si_int b, int *overflow);
24 int test__mulosi4(si_int a, si_int b, si_int expected, int expected_overflow)
26 int ov;
27 si_int x = __mulosi4(a, b, &ov);
28 if (ov != expected_overflow)
29 printf("error in __mulosi4: overflow=%d expected=%d\n",
30 ov, expected_overflow);
31 else if (!expected_overflow && x != expected) {
32 printf("error in __mulosi4: 0x%X * 0x%X = 0x%X (overflow=%d), "
33 "expected 0x%X (overflow=%d)\n",
34 a, b, x, ov, expected, expected_overflow);
35 return 1;
37 return 0;
41 int main()
43 if (test__mulosi4(0, 0, 0, 0))
44 return 1;
45 if (test__mulosi4(0, 1, 0, 0))
46 return 1;
47 if (test__mulosi4(1, 0, 0, 0))
48 return 1;
49 if (test__mulosi4(0, 10, 0, 0))
50 return 1;
51 if (test__mulosi4(10, 0, 0, 0))
52 return 1;
53 if (test__mulosi4(0, 0x1234567, 0, 0))
54 return 1;
55 if (test__mulosi4(0x1234567, 0, 0, 0))
56 return 1;
58 if (test__mulosi4(0, -1, 0, 0))
59 return 1;
60 if (test__mulosi4(-1, 0, 0, 0))
61 return 1;
62 if (test__mulosi4(0, -10, 0, 0))
63 return 1;
64 if (test__mulosi4(-10, 0, 0, 0))
65 return 1;
66 if (test__mulosi4(0, -0x1234567, 0, 0))
67 return 1;
68 if (test__mulosi4(-0x1234567, 0, 0, 0))
69 return 1;
71 if (test__mulosi4(1, 1, 1, 0))
72 return 1;
73 if (test__mulosi4(1, 10, 10, 0))
74 return 1;
75 if (test__mulosi4(10, 1, 10, 0))
76 return 1;
77 if (test__mulosi4(1, 0x1234567, 0x1234567, 0))
78 return 1;
79 if (test__mulosi4(0x1234567, 1, 0x1234567, 0))
80 return 1;
82 if (test__mulosi4(1, -1, -1, 0))
83 return 1;
84 if (test__mulosi4(1, -10, -10, 0))
85 return 1;
86 if (test__mulosi4(-10, 1, -10, 0))
87 return 1;
88 if (test__mulosi4(1, -0x1234567, -0x1234567, 0))
89 return 1;
90 if (test__mulosi4(-0x1234567, 1, -0x1234567, 0))
91 return 1;
93 if (test__mulosi4(0x7FFFFFFF, -2, 0x80000001, 1))
94 return 1;
95 if (test__mulosi4(-2, 0x7FFFFFFF, 0x80000001, 1))
96 return 1;
97 if (test__mulosi4(0x7FFFFFFF, -1, 0x80000001, 0))
98 return 1;
99 if (test__mulosi4(-1, 0x7FFFFFFF, 0x80000001, 0))
100 return 1;
101 if (test__mulosi4(0x7FFFFFFF, 0, 0, 0))
102 return 1;
103 if (test__mulosi4(0, 0x7FFFFFFF, 0, 0))
104 return 1;
105 if (test__mulosi4(0x7FFFFFFF, 1, 0x7FFFFFFF, 0))
106 return 1;
107 if (test__mulosi4(1, 0x7FFFFFFF, 0x7FFFFFFF, 0))
108 return 1;
109 if (test__mulosi4(0x7FFFFFFF, 2, 0x80000001, 1))
110 return 1;
111 if (test__mulosi4(2, 0x7FFFFFFF, 0x80000001, 1))
112 return 1;
114 if (test__mulosi4(0x80000000, -2, 0x80000000, 1))
115 return 1;
116 if (test__mulosi4(-2, 0x80000000, 0x80000000, 1))
117 return 1;
118 if (test__mulosi4(0x80000000, -1, 0x80000000, 1))
119 return 1;
120 if (test__mulosi4(-1, 0x80000000, 0x80000000, 1))
121 return 1;
122 if (test__mulosi4(0x80000000, 0, 0, 0))
123 return 1;
124 if (test__mulosi4(0, 0x80000000, 0, 0))
125 return 1;
126 if (test__mulosi4(0x80000000, 1, 0x80000000, 0))
127 return 1;
128 if (test__mulosi4(1, 0x80000000, 0x80000000, 0))
129 return 1;
130 if (test__mulosi4(0x80000000, 2, 0x80000000, 1))
131 return 1;
132 if (test__mulosi4(2, 0x80000000, 0x80000000, 1))
133 return 1;
135 if (test__mulosi4(0x80000001, -2, 0x80000001, 1))
136 return 1;
137 if (test__mulosi4(-2, 0x80000001, 0x80000001, 1))
138 return 1;
139 if (test__mulosi4(0x80000001, -1, 0x7FFFFFFF, 0))
140 return 1;
141 if (test__mulosi4(-1, 0x80000001, 0x7FFFFFFF, 0))
142 return 1;
143 if (test__mulosi4(0x80000001, 0, 0, 0))
144 return 1;
145 if (test__mulosi4(0, 0x80000001, 0, 0))
146 return 1;
147 if (test__mulosi4(0x80000001, 1, 0x80000001, 0))
148 return 1;
149 if (test__mulosi4(1, 0x80000001, 0x80000001, 0))
150 return 1;
151 if (test__mulosi4(0x80000001, 2, 0x80000000, 1))
152 return 1;
153 if (test__mulosi4(2, 0x80000001, 0x80000000, 1))
154 return 1;
156 return 0;