1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_mulvdi3
9 // Effects: aborts if a * b overflows
11 COMPILER_RT_ABI di_int
__mulvdi3(di_int a
, di_int b
);
13 int test__mulvdi3(di_int a
, di_int b
, di_int expected
)
15 di_int x
= __mulvdi3(a
, b
);
17 printf("error in __mulvdi3: %lld * %lld = %lld, expected %lld\n",
24 if (test__mulvdi3(0, 0, 0))
26 if (test__mulvdi3(0, 1, 0))
28 if (test__mulvdi3(1, 0, 0))
30 if (test__mulvdi3(0, 10, 0))
32 if (test__mulvdi3(10, 0, 0))
34 if (test__mulvdi3(0, 81985529216486895LL, 0))
36 if (test__mulvdi3(81985529216486895LL, 0, 0))
39 if (test__mulvdi3(0, -1, 0))
41 if (test__mulvdi3(-1, 0, 0))
43 if (test__mulvdi3(0, -10, 0))
45 if (test__mulvdi3(-10, 0, 0))
47 if (test__mulvdi3(0, -81985529216486895LL, 0))
49 if (test__mulvdi3(-81985529216486895LL, 0, 0))
52 if (test__mulvdi3(1, 1, 1))
54 if (test__mulvdi3(1, 10, 10))
56 if (test__mulvdi3(10, 1, 10))
58 if (test__mulvdi3(1, 81985529216486895LL, 81985529216486895LL))
60 if (test__mulvdi3(81985529216486895LL, 1, 81985529216486895LL))
63 if (test__mulvdi3(1, -1, -1))
65 if (test__mulvdi3(1, -10, -10))
67 if (test__mulvdi3(-10, 1, -10))
69 if (test__mulvdi3(1, -81985529216486895LL, -81985529216486895LL))
71 if (test__mulvdi3(-81985529216486895LL, 1, -81985529216486895LL))
74 if (test__mulvdi3(3037000499LL, 3037000499LL, 9223372030926249001LL))
76 if (test__mulvdi3(-3037000499LL, 3037000499LL, -9223372030926249001LL))
78 if (test__mulvdi3(3037000499LL, -3037000499LL, -9223372030926249001LL))
80 if (test__mulvdi3(-3037000499LL, -3037000499LL, 9223372030926249001LL))
83 if (test__mulvdi3(4398046511103LL, 2097152LL, 9223372036852678656LL))
85 if (test__mulvdi3(-4398046511103LL, 2097152LL, -9223372036852678656LL))
87 if (test__mulvdi3(4398046511103LL, -2097152LL, -9223372036852678656LL))
89 if (test__mulvdi3(-4398046511103LL, -2097152LL, 9223372036852678656LL))
92 if (test__mulvdi3(2097152LL, 4398046511103LL, 9223372036852678656LL))
94 if (test__mulvdi3(-2097152LL, 4398046511103LL, -9223372036852678656LL))
96 if (test__mulvdi3(2097152LL, -4398046511103LL, -9223372036852678656LL))
98 if (test__mulvdi3(-2097152LL, -4398046511103LL, 9223372036852678656LL))
101 // if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL, -2, 0x8000000000000001LL)) // abort
103 // if (test__mulvdi3(-2, 0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL)) // abort
105 if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL
, -1, 0x8000000000000001LL
))
107 if (test__mulvdi3(-1, 0x7FFFFFFFFFFFFFFFLL
, 0x8000000000000001LL
))
109 if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL
, 0, 0))
111 if (test__mulvdi3(0, 0x7FFFFFFFFFFFFFFFLL
, 0))
113 if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL
, 1, 0x7FFFFFFFFFFFFFFFLL
))
115 if (test__mulvdi3(1, 0x7FFFFFFFFFFFFFFFLL
, 0x7FFFFFFFFFFFFFFFLL
))
117 // if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL, 2, 0x8000000000000001LL)) // abort
119 // if (test__mulvdi3(2, 0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL)) // abort
122 // if (test__mulvdi3(0x8000000000000000LL, -2, 0x8000000000000000LL)) // abort
124 // if (test__mulvdi3(-2, 0x8000000000000000LL, 0x8000000000000000LL)) // abort
126 // if (test__mulvdi3(0x8000000000000000LL, -1, 0x8000000000000000LL)) // abort
128 // if (test__mulvdi3(-1, 0x8000000000000000LL, 0x8000000000000000LL)) // abort
130 if (test__mulvdi3(0x8000000000000000LL
, 0, 0))
132 if (test__mulvdi3(0, 0x8000000000000000LL
, 0))
134 if (test__mulvdi3(0x8000000000000000LL
, 1, 0x8000000000000000LL
))
136 if (test__mulvdi3(1, 0x8000000000000000LL
, 0x8000000000000000LL
))
138 // if (test__mulvdi3(0x8000000000000000LL, 2, 0x8000000000000000LL)) // abort
140 // if (test__mulvdi3(2, 0x8000000000000000LL, 0x8000000000000000LL)) // abort
143 // if (test__mulvdi3(0x8000000000000001LL, -2, 0x8000000000000001LL)) // abort
145 // if (test__mulvdi3(-2, 0x8000000000000001LL, 0x8000000000000001LL)) // abort
147 if (test__mulvdi3(0x8000000000000001LL
, -1, 0x7FFFFFFFFFFFFFFFLL
))
149 if (test__mulvdi3(-1, 0x8000000000000001LL
, 0x7FFFFFFFFFFFFFFFLL
))
151 if (test__mulvdi3(0x8000000000000001LL
, 0, 0))
153 if (test__mulvdi3(0, 0x8000000000000001LL
, 0))
155 if (test__mulvdi3(0x8000000000000001LL
, 1, 0x8000000000000001LL
))
157 if (test__mulvdi3(1, 0x8000000000000001LL
, 0x8000000000000001LL
))
159 // if (test__mulvdi3(0x8000000000000001LL, 2, 0x8000000000000000LL)) // abort
161 // if (test__mulvdi3(2, 0x8000000000000001LL, 0x8000000000000000LL)) // abort