1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_mulosi4
3 //===-- mulosi4_test.c - Test __mulosi4 -----------------------------------===//
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 __mulosi4 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
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
)
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
);
43 if (test__mulosi4(0, 0, 0, 0))
45 if (test__mulosi4(0, 1, 0, 0))
47 if (test__mulosi4(1, 0, 0, 0))
49 if (test__mulosi4(0, 10, 0, 0))
51 if (test__mulosi4(10, 0, 0, 0))
53 if (test__mulosi4(0, 0x1234567, 0, 0))
55 if (test__mulosi4(0x1234567, 0, 0, 0))
58 if (test__mulosi4(0, -1, 0, 0))
60 if (test__mulosi4(-1, 0, 0, 0))
62 if (test__mulosi4(0, -10, 0, 0))
64 if (test__mulosi4(-10, 0, 0, 0))
66 if (test__mulosi4(0, -0x1234567, 0, 0))
68 if (test__mulosi4(-0x1234567, 0, 0, 0))
71 if (test__mulosi4(1, 1, 1, 0))
73 if (test__mulosi4(1, 10, 10, 0))
75 if (test__mulosi4(10, 1, 10, 0))
77 if (test__mulosi4(1, 0x1234567, 0x1234567, 0))
79 if (test__mulosi4(0x1234567, 1, 0x1234567, 0))
82 if (test__mulosi4(1, -1, -1, 0))
84 if (test__mulosi4(1, -10, -10, 0))
86 if (test__mulosi4(-10, 1, -10, 0))
88 if (test__mulosi4(1, -0x1234567, -0x1234567, 0))
90 if (test__mulosi4(-0x1234567, 1, -0x1234567, 0))
93 if (test__mulosi4(0x7FFFFFFF, -2, 0x80000001, 1))
95 if (test__mulosi4(-2, 0x7FFFFFFF, 0x80000001, 1))
97 if (test__mulosi4(0x7FFFFFFF, -1, 0x80000001, 0))
99 if (test__mulosi4(-1, 0x7FFFFFFF, 0x80000001, 0))
101 if (test__mulosi4(0x7FFFFFFF, 0, 0, 0))
103 if (test__mulosi4(0, 0x7FFFFFFF, 0, 0))
105 if (test__mulosi4(0x7FFFFFFF, 1, 0x7FFFFFFF, 0))
107 if (test__mulosi4(1, 0x7FFFFFFF, 0x7FFFFFFF, 0))
109 if (test__mulosi4(0x7FFFFFFF, 2, 0x80000001, 1))
111 if (test__mulosi4(2, 0x7FFFFFFF, 0x80000001, 1))
114 if (test__mulosi4(0x80000000, -2, 0x80000000, 1))
116 if (test__mulosi4(-2, 0x80000000, 0x80000000, 1))
118 if (test__mulosi4(0x80000000, -1, 0x80000000, 1))
120 if (test__mulosi4(-1, 0x80000000, 0x80000000, 1))
122 if (test__mulosi4(0x80000000, 0, 0, 0))
124 if (test__mulosi4(0, 0x80000000, 0, 0))
126 if (test__mulosi4(0x80000000, 1, 0x80000000, 0))
128 if (test__mulosi4(1, 0x80000000, 0x80000000, 0))
130 if (test__mulosi4(0x80000000, 2, 0x80000000, 1))
132 if (test__mulosi4(2, 0x80000000, 0x80000000, 1))
135 if (test__mulosi4(0x80000001, -2, 0x80000001, 1))
137 if (test__mulosi4(-2, 0x80000001, 0x80000001, 1))
139 if (test__mulosi4(0x80000001, -1, 0x7FFFFFFF, 0))
141 if (test__mulosi4(-1, 0x80000001, 0x7FFFFFFF, 0))
143 if (test__mulosi4(0x80000001, 0, 0, 0))
145 if (test__mulosi4(0, 0x80000001, 0, 0))
147 if (test__mulosi4(0x80000001, 1, 0x80000001, 0))
149 if (test__mulosi4(1, 0x80000001, 0x80000001, 0))
151 if (test__mulosi4(0x80000001, 2, 0x80000000, 1))
153 if (test__mulosi4(2, 0x80000001, 0x80000000, 1))