1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_mulosi4
9 // Effects: aborts if a * b overflows
11 COMPILER_RT_ABI si_int
__mulosi4(si_int a
, si_int b
, int *overflow
);
13 int test__mulosi4(si_int a
, si_int b
, si_int expected
, int expected_overflow
)
16 si_int x
= __mulosi4(a
, b
, &ov
);
17 if (ov
!= expected_overflow
)
18 printf("error in __mulosi4: overflow=%d expected=%d\n",
19 ov
, expected_overflow
);
20 else if (!expected_overflow
&& x
!= expected
) {
21 printf("error in __mulosi4: 0x%X * 0x%X = 0x%X (overflow=%d), "
22 "expected 0x%X (overflow=%d)\n",
23 a
, b
, x
, ov
, expected
, expected_overflow
);
32 if (test__mulosi4(0, 0, 0, 0))
34 if (test__mulosi4(0, 1, 0, 0))
36 if (test__mulosi4(1, 0, 0, 0))
38 if (test__mulosi4(0, 10, 0, 0))
40 if (test__mulosi4(10, 0, 0, 0))
42 if (test__mulosi4(0, 0x1234567, 0, 0))
44 if (test__mulosi4(0x1234567, 0, 0, 0))
47 if (test__mulosi4(0, -1, 0, 0))
49 if (test__mulosi4(-1, 0, 0, 0))
51 if (test__mulosi4(0, -10, 0, 0))
53 if (test__mulosi4(-10, 0, 0, 0))
55 if (test__mulosi4(0, -0x1234567, 0, 0))
57 if (test__mulosi4(-0x1234567, 0, 0, 0))
60 if (test__mulosi4(1, 1, 1, 0))
62 if (test__mulosi4(1, 10, 10, 0))
64 if (test__mulosi4(10, 1, 10, 0))
66 if (test__mulosi4(1, 0x1234567, 0x1234567, 0))
68 if (test__mulosi4(0x1234567, 1, 0x1234567, 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(0x7FFFFFFF, -2, 0x80000001, 1))
84 if (test__mulosi4(-2, 0x7FFFFFFF, 0x80000001, 1))
86 if (test__mulosi4(0x7FFFFFFF, -1, 0x80000001, 0))
88 if (test__mulosi4(-1, 0x7FFFFFFF, 0x80000001, 0))
90 if (test__mulosi4(0x7FFFFFFF, 0, 0, 0))
92 if (test__mulosi4(0, 0x7FFFFFFF, 0, 0))
94 if (test__mulosi4(0x7FFFFFFF, 1, 0x7FFFFFFF, 0))
96 if (test__mulosi4(1, 0x7FFFFFFF, 0x7FFFFFFF, 0))
98 if (test__mulosi4(0x7FFFFFFF, 2, 0x80000001, 1))
100 if (test__mulosi4(2, 0x7FFFFFFF, 0x80000001, 1))
103 if (test__mulosi4(0x80000000, -2, 0x80000000, 1))
105 if (test__mulosi4(-2, 0x80000000, 0x80000000, 1))
107 if (test__mulosi4(0x80000000, -1, 0x80000000, 1))
109 if (test__mulosi4(-1, 0x80000000, 0x80000000, 1))
111 if (test__mulosi4(0x80000000, 0, 0, 0))
113 if (test__mulosi4(0, 0x80000000, 0, 0))
115 if (test__mulosi4(0x80000000, 1, 0x80000000, 0))
117 if (test__mulosi4(1, 0x80000000, 0x80000000, 0))
119 if (test__mulosi4(0x80000000, 2, 0x80000000, 1))
121 if (test__mulosi4(2, 0x80000000, 0x80000000, 1))
124 if (test__mulosi4(0x80000001, -2, 0x80000001, 1))
126 if (test__mulosi4(-2, 0x80000001, 0x80000001, 1))
128 if (test__mulosi4(0x80000001, -1, 0x7FFFFFFF, 0))
130 if (test__mulosi4(-1, 0x80000001, 0x7FFFFFFF, 0))
132 if (test__mulosi4(0x80000001, 0, 0, 0))
134 if (test__mulosi4(0, 0x80000001, 0, 0))
136 if (test__mulosi4(0x80000001, 1, 0x80000001, 0))
138 if (test__mulosi4(1, 0x80000001, 0x80000001, 0))
140 if (test__mulosi4(0x80000001, 2, 0x80000000, 1))
142 if (test__mulosi4(2, 0x80000001, 0x80000000, 1))