1*4684ddb6SLionel Sambuc //===-- mulosi4_test.c - Test __mulosi4 -----------------------------------===//
2*4684ddb6SLionel Sambuc //
3*4684ddb6SLionel Sambuc // The LLVM Compiler Infrastructure
4*4684ddb6SLionel Sambuc //
5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*4684ddb6SLionel Sambuc //
8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
9*4684ddb6SLionel Sambuc //
10*4684ddb6SLionel Sambuc // This file tests __mulosi4 for the compiler_rt library.
11*4684ddb6SLionel Sambuc //
12*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
13*4684ddb6SLionel Sambuc
14*4684ddb6SLionel Sambuc #include "int_lib.h"
15*4684ddb6SLionel Sambuc #include <stdio.h>
16*4684ddb6SLionel Sambuc
17*4684ddb6SLionel Sambuc // Returns: a * b
18*4684ddb6SLionel Sambuc
19*4684ddb6SLionel Sambuc // Effects: aborts if a * b overflows
20*4684ddb6SLionel Sambuc
21*4684ddb6SLionel Sambuc si_int __mulosi4(si_int a, si_int b, int *overflow);
22*4684ddb6SLionel Sambuc
test__mulosi4(si_int a,si_int b,si_int expected,int expected_overflow)23*4684ddb6SLionel Sambuc int test__mulosi4(si_int a, si_int b, si_int expected, int expected_overflow)
24*4684ddb6SLionel Sambuc {
25*4684ddb6SLionel Sambuc int ov;
26*4684ddb6SLionel Sambuc si_int x = __mulosi4(a, b, &ov);
27*4684ddb6SLionel Sambuc if (ov != expected_overflow)
28*4684ddb6SLionel Sambuc printf("error in __mulosi4: overflow=%d expected=%d\n",
29*4684ddb6SLionel Sambuc ov, expected_overflow);
30*4684ddb6SLionel Sambuc else if (!expected_overflow && x != expected) {
31*4684ddb6SLionel Sambuc printf("error in __mulosi4: 0x%X * 0x%X = 0x%X (overflow=%d), "
32*4684ddb6SLionel Sambuc "expected 0x%X (overflow=%d)\n",
33*4684ddb6SLionel Sambuc a, b, x, ov, expected, expected_overflow);
34*4684ddb6SLionel Sambuc return 1;
35*4684ddb6SLionel Sambuc }
36*4684ddb6SLionel Sambuc return 0;
37*4684ddb6SLionel Sambuc }
38*4684ddb6SLionel Sambuc
39*4684ddb6SLionel Sambuc
main()40*4684ddb6SLionel Sambuc int main()
41*4684ddb6SLionel Sambuc {
42*4684ddb6SLionel Sambuc if (test__mulosi4(0, 0, 0, 0))
43*4684ddb6SLionel Sambuc return 1;
44*4684ddb6SLionel Sambuc if (test__mulosi4(0, 1, 0, 0))
45*4684ddb6SLionel Sambuc return 1;
46*4684ddb6SLionel Sambuc if (test__mulosi4(1, 0, 0, 0))
47*4684ddb6SLionel Sambuc return 1;
48*4684ddb6SLionel Sambuc if (test__mulosi4(0, 10, 0, 0))
49*4684ddb6SLionel Sambuc return 1;
50*4684ddb6SLionel Sambuc if (test__mulosi4(10, 0, 0, 0))
51*4684ddb6SLionel Sambuc return 1;
52*4684ddb6SLionel Sambuc if (test__mulosi4(0, 0x1234567, 0, 0))
53*4684ddb6SLionel Sambuc return 1;
54*4684ddb6SLionel Sambuc if (test__mulosi4(0x1234567, 0, 0, 0))
55*4684ddb6SLionel Sambuc return 1;
56*4684ddb6SLionel Sambuc
57*4684ddb6SLionel Sambuc if (test__mulosi4(0, -1, 0, 0))
58*4684ddb6SLionel Sambuc return 1;
59*4684ddb6SLionel Sambuc if (test__mulosi4(-1, 0, 0, 0))
60*4684ddb6SLionel Sambuc return 1;
61*4684ddb6SLionel Sambuc if (test__mulosi4(0, -10, 0, 0))
62*4684ddb6SLionel Sambuc return 1;
63*4684ddb6SLionel Sambuc if (test__mulosi4(-10, 0, 0, 0))
64*4684ddb6SLionel Sambuc return 1;
65*4684ddb6SLionel Sambuc if (test__mulosi4(0, -0x1234567, 0, 0))
66*4684ddb6SLionel Sambuc return 1;
67*4684ddb6SLionel Sambuc if (test__mulosi4(-0x1234567, 0, 0, 0))
68*4684ddb6SLionel Sambuc return 1;
69*4684ddb6SLionel Sambuc
70*4684ddb6SLionel Sambuc if (test__mulosi4(1, 1, 1, 0))
71*4684ddb6SLionel Sambuc return 1;
72*4684ddb6SLionel Sambuc if (test__mulosi4(1, 10, 10, 0))
73*4684ddb6SLionel Sambuc return 1;
74*4684ddb6SLionel Sambuc if (test__mulosi4(10, 1, 10, 0))
75*4684ddb6SLionel Sambuc return 1;
76*4684ddb6SLionel Sambuc if (test__mulosi4(1, 0x1234567, 0x1234567, 0))
77*4684ddb6SLionel Sambuc return 1;
78*4684ddb6SLionel Sambuc if (test__mulosi4(0x1234567, 1, 0x1234567, 0))
79*4684ddb6SLionel Sambuc return 1;
80*4684ddb6SLionel Sambuc
81*4684ddb6SLionel Sambuc if (test__mulosi4(1, -1, -1, 0))
82*4684ddb6SLionel Sambuc return 1;
83*4684ddb6SLionel Sambuc if (test__mulosi4(1, -10, -10, 0))
84*4684ddb6SLionel Sambuc return 1;
85*4684ddb6SLionel Sambuc if (test__mulosi4(-10, 1, -10, 0))
86*4684ddb6SLionel Sambuc return 1;
87*4684ddb6SLionel Sambuc if (test__mulosi4(1, -0x1234567, -0x1234567, 0))
88*4684ddb6SLionel Sambuc return 1;
89*4684ddb6SLionel Sambuc if (test__mulosi4(-0x1234567, 1, -0x1234567, 0))
90*4684ddb6SLionel Sambuc return 1;
91*4684ddb6SLionel Sambuc
92*4684ddb6SLionel Sambuc if (test__mulosi4(0x7FFFFFFF, -2, 0x80000001, 1))
93*4684ddb6SLionel Sambuc return 1;
94*4684ddb6SLionel Sambuc if (test__mulosi4(-2, 0x7FFFFFFF, 0x80000001, 1))
95*4684ddb6SLionel Sambuc return 1;
96*4684ddb6SLionel Sambuc if (test__mulosi4(0x7FFFFFFF, -1, 0x80000001, 0))
97*4684ddb6SLionel Sambuc return 1;
98*4684ddb6SLionel Sambuc if (test__mulosi4(-1, 0x7FFFFFFF, 0x80000001, 0))
99*4684ddb6SLionel Sambuc return 1;
100*4684ddb6SLionel Sambuc if (test__mulosi4(0x7FFFFFFF, 0, 0, 0))
101*4684ddb6SLionel Sambuc return 1;
102*4684ddb6SLionel Sambuc if (test__mulosi4(0, 0x7FFFFFFF, 0, 0))
103*4684ddb6SLionel Sambuc return 1;
104*4684ddb6SLionel Sambuc if (test__mulosi4(0x7FFFFFFF, 1, 0x7FFFFFFF, 0))
105*4684ddb6SLionel Sambuc return 1;
106*4684ddb6SLionel Sambuc if (test__mulosi4(1, 0x7FFFFFFF, 0x7FFFFFFF, 0))
107*4684ddb6SLionel Sambuc return 1;
108*4684ddb6SLionel Sambuc if (test__mulosi4(0x7FFFFFFF, 2, 0x80000001, 1))
109*4684ddb6SLionel Sambuc return 1;
110*4684ddb6SLionel Sambuc if (test__mulosi4(2, 0x7FFFFFFF, 0x80000001, 1))
111*4684ddb6SLionel Sambuc return 1;
112*4684ddb6SLionel Sambuc
113*4684ddb6SLionel Sambuc if (test__mulosi4(0x80000000, -2, 0x80000000, 1))
114*4684ddb6SLionel Sambuc return 1;
115*4684ddb6SLionel Sambuc if (test__mulosi4(-2, 0x80000000, 0x80000000, 1))
116*4684ddb6SLionel Sambuc return 1;
117*4684ddb6SLionel Sambuc if (test__mulosi4(0x80000000, -1, 0x80000000, 1))
118*4684ddb6SLionel Sambuc return 1;
119*4684ddb6SLionel Sambuc if (test__mulosi4(-1, 0x80000000, 0x80000000, 1))
120*4684ddb6SLionel Sambuc return 1;
121*4684ddb6SLionel Sambuc if (test__mulosi4(0x80000000, 0, 0, 0))
122*4684ddb6SLionel Sambuc return 1;
123*4684ddb6SLionel Sambuc if (test__mulosi4(0, 0x80000000, 0, 0))
124*4684ddb6SLionel Sambuc return 1;
125*4684ddb6SLionel Sambuc if (test__mulosi4(0x80000000, 1, 0x80000000, 0))
126*4684ddb6SLionel Sambuc return 1;
127*4684ddb6SLionel Sambuc if (test__mulosi4(1, 0x80000000, 0x80000000, 0))
128*4684ddb6SLionel Sambuc return 1;
129*4684ddb6SLionel Sambuc if (test__mulosi4(0x80000000, 2, 0x80000000, 1))
130*4684ddb6SLionel Sambuc return 1;
131*4684ddb6SLionel Sambuc if (test__mulosi4(2, 0x80000000, 0x80000000, 1))
132*4684ddb6SLionel Sambuc return 1;
133*4684ddb6SLionel Sambuc
134*4684ddb6SLionel Sambuc if (test__mulosi4(0x80000001, -2, 0x80000001, 1))
135*4684ddb6SLionel Sambuc return 1;
136*4684ddb6SLionel Sambuc if (test__mulosi4(-2, 0x80000001, 0x80000001, 1))
137*4684ddb6SLionel Sambuc return 1;
138*4684ddb6SLionel Sambuc if (test__mulosi4(0x80000001, -1, 0x7FFFFFFF, 0))
139*4684ddb6SLionel Sambuc return 1;
140*4684ddb6SLionel Sambuc if (test__mulosi4(-1, 0x80000001, 0x7FFFFFFF, 0))
141*4684ddb6SLionel Sambuc return 1;
142*4684ddb6SLionel Sambuc if (test__mulosi4(0x80000001, 0, 0, 0))
143*4684ddb6SLionel Sambuc return 1;
144*4684ddb6SLionel Sambuc if (test__mulosi4(0, 0x80000001, 0, 0))
145*4684ddb6SLionel Sambuc return 1;
146*4684ddb6SLionel Sambuc if (test__mulosi4(0x80000001, 1, 0x80000001, 0))
147*4684ddb6SLionel Sambuc return 1;
148*4684ddb6SLionel Sambuc if (test__mulosi4(1, 0x80000001, 0x80000001, 0))
149*4684ddb6SLionel Sambuc return 1;
150*4684ddb6SLionel Sambuc if (test__mulosi4(0x80000001, 2, 0x80000000, 1))
151*4684ddb6SLionel Sambuc return 1;
152*4684ddb6SLionel Sambuc if (test__mulosi4(2, 0x80000001, 0x80000000, 1))
153*4684ddb6SLionel Sambuc return 1;
154*4684ddb6SLionel Sambuc
155*4684ddb6SLionel Sambuc return 0;
156*4684ddb6SLionel Sambuc }
157