1 //===-- mulosi4_test.c - Test __mulosi4 -----------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file tests __mulosi4 for the compiler_rt library.
12 //===----------------------------------------------------------------------===//
19 // Effects: aborts if a * b overflows
21 si_int
__mulosi4(si_int a
, si_int b
, int *overflow
);
23 int test__mulosi4(si_int a
, si_int b
, si_int expected
, int expected_overflow
)
26 si_int x
= __mulosi4(a
, b
, &ov
);
27 if (ov
!= expected_overflow
)
28 printf("error in __mulosi4: overflow=%d expected=%d\n",
29 ov
, expected_overflow
);
30 else if (!expected_overflow
&& x
!= expected
) {
31 printf("error in __mulosi4: 0x%X * 0x%X = 0x%X (overflow=%d), "
32 "expected 0x%X (overflow=%d)\n",
33 a
, b
, x
, ov
, expected
, expected_overflow
);
42 if (test__mulosi4(0, 0, 0, 0))
44 if (test__mulosi4(0, 1, 0, 0))
46 if (test__mulosi4(1, 0, 0, 0))
48 if (test__mulosi4(0, 10, 0, 0))
50 if (test__mulosi4(10, 0, 0, 0))
52 if (test__mulosi4(0, 0x1234567, 0, 0))
54 if (test__mulosi4(0x1234567, 0, 0, 0))
57 if (test__mulosi4(0, -1, 0, 0))
59 if (test__mulosi4(-1, 0, 0, 0))
61 if (test__mulosi4(0, -10, 0, 0))
63 if (test__mulosi4(-10, 0, 0, 0))
65 if (test__mulosi4(0, -0x1234567, 0, 0))
67 if (test__mulosi4(-0x1234567, 0, 0, 0))
70 if (test__mulosi4(1, 1, 1, 0))
72 if (test__mulosi4(1, 10, 10, 0))
74 if (test__mulosi4(10, 1, 10, 0))
76 if (test__mulosi4(1, 0x1234567, 0x1234567, 0))
78 if (test__mulosi4(0x1234567, 1, 0x1234567, 0))
81 if (test__mulosi4(1, -1, -1, 0))
83 if (test__mulosi4(1, -10, -10, 0))
85 if (test__mulosi4(-10, 1, -10, 0))
87 if (test__mulosi4(1, -0x1234567, -0x1234567, 0))
89 if (test__mulosi4(-0x1234567, 1, -0x1234567, 0))
92 if (test__mulosi4(0x7FFFFFFF, -2, 0x80000001, 1))
94 if (test__mulosi4(-2, 0x7FFFFFFF, 0x80000001, 1))
96 if (test__mulosi4(0x7FFFFFFF, -1, 0x80000001, 0))
98 if (test__mulosi4(-1, 0x7FFFFFFF, 0x80000001, 0))
100 if (test__mulosi4(0x7FFFFFFF, 0, 0, 0))
102 if (test__mulosi4(0, 0x7FFFFFFF, 0, 0))
104 if (test__mulosi4(0x7FFFFFFF, 1, 0x7FFFFFFF, 0))
106 if (test__mulosi4(1, 0x7FFFFFFF, 0x7FFFFFFF, 0))
108 if (test__mulosi4(0x7FFFFFFF, 2, 0x80000001, 1))
110 if (test__mulosi4(2, 0x7FFFFFFF, 0x80000001, 1))
113 if (test__mulosi4(0x80000000, -2, 0x80000000, 1))
115 if (test__mulosi4(-2, 0x80000000, 0x80000000, 1))
117 if (test__mulosi4(0x80000000, -1, 0x80000000, 1))
119 if (test__mulosi4(-1, 0x80000000, 0x80000000, 1))
121 if (test__mulosi4(0x80000000, 0, 0, 0))
123 if (test__mulosi4(0, 0x80000000, 0, 0))
125 if (test__mulosi4(0x80000000, 1, 0x80000000, 0))
127 if (test__mulosi4(1, 0x80000000, 0x80000000, 0))
129 if (test__mulosi4(0x80000000, 2, 0x80000000, 1))
131 if (test__mulosi4(2, 0x80000000, 0x80000000, 1))
134 if (test__mulosi4(0x80000001, -2, 0x80000001, 1))
136 if (test__mulosi4(-2, 0x80000001, 0x80000001, 1))
138 if (test__mulosi4(0x80000001, -1, 0x7FFFFFFF, 0))
140 if (test__mulosi4(-1, 0x80000001, 0x7FFFFFFF, 0))
142 if (test__mulosi4(0x80000001, 0, 0, 0))
144 if (test__mulosi4(0, 0x80000001, 0, 0))
146 if (test__mulosi4(0x80000001, 1, 0x80000001, 0))
148 if (test__mulosi4(1, 0x80000001, 0x80000001, 0))
150 if (test__mulosi4(0x80000001, 2, 0x80000000, 1))
152 if (test__mulosi4(2, 0x80000001, 0x80000000, 1))