1 //===-- mulvdi3_test.c - Test __mulvdi3 -----------------------------------===//
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 __mulvdi3 for the compiler_rt library.
12 //===----------------------------------------------------------------------===//
19 // Effects: aborts if a * b overflows
21 di_int
__mulvdi3(di_int a
, di_int b
);
23 int test__mulvdi3(di_int a
, di_int b
, di_int expected
)
25 di_int x
= __mulvdi3(a
, b
);
27 printf("error in __mulvdi3: %lld * %lld = %lld, expected %lld\n",
34 if (test__mulvdi3(0, 0, 0))
36 if (test__mulvdi3(0, 1, 0))
38 if (test__mulvdi3(1, 0, 0))
40 if (test__mulvdi3(0, 10, 0))
42 if (test__mulvdi3(10, 0, 0))
44 if (test__mulvdi3(0, 81985529216486895LL, 0))
46 if (test__mulvdi3(81985529216486895LL, 0, 0))
49 if (test__mulvdi3(0, -1, 0))
51 if (test__mulvdi3(-1, 0, 0))
53 if (test__mulvdi3(0, -10, 0))
55 if (test__mulvdi3(-10, 0, 0))
57 if (test__mulvdi3(0, -81985529216486895LL, 0))
59 if (test__mulvdi3(-81985529216486895LL, 0, 0))
62 if (test__mulvdi3(1, 1, 1))
64 if (test__mulvdi3(1, 10, 10))
66 if (test__mulvdi3(10, 1, 10))
68 if (test__mulvdi3(1, 81985529216486895LL, 81985529216486895LL))
70 if (test__mulvdi3(81985529216486895LL, 1, 81985529216486895LL))
73 if (test__mulvdi3(1, -1, -1))
75 if (test__mulvdi3(1, -10, -10))
77 if (test__mulvdi3(-10, 1, -10))
79 if (test__mulvdi3(1, -81985529216486895LL, -81985529216486895LL))
81 if (test__mulvdi3(-81985529216486895LL, 1, -81985529216486895LL))
84 if (test__mulvdi3(3037000499LL, 3037000499LL, 9223372030926249001LL))
86 if (test__mulvdi3(-3037000499LL, 3037000499LL, -9223372030926249001LL))
88 if (test__mulvdi3(3037000499LL, -3037000499LL, -9223372030926249001LL))
90 if (test__mulvdi3(-3037000499LL, -3037000499LL, 9223372030926249001LL))
93 if (test__mulvdi3(4398046511103LL, 2097152LL, 9223372036852678656LL))
95 if (test__mulvdi3(-4398046511103LL, 2097152LL, -9223372036852678656LL))
97 if (test__mulvdi3(4398046511103LL, -2097152LL, -9223372036852678656LL))
99 if (test__mulvdi3(-4398046511103LL, -2097152LL, 9223372036852678656LL))
102 if (test__mulvdi3(2097152LL, 4398046511103LL, 9223372036852678656LL))
104 if (test__mulvdi3(-2097152LL, 4398046511103LL, -9223372036852678656LL))
106 if (test__mulvdi3(2097152LL, -4398046511103LL, -9223372036852678656LL))
108 if (test__mulvdi3(-2097152LL, -4398046511103LL, 9223372036852678656LL))
111 // if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL, -2, 0x8000000000000001LL)) // abort
113 // if (test__mulvdi3(-2, 0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL)) // abort
115 if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL
, -1, 0x8000000000000001LL
))
117 if (test__mulvdi3(-1, 0x7FFFFFFFFFFFFFFFLL
, 0x8000000000000001LL
))
119 if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL
, 0, 0))
121 if (test__mulvdi3(0, 0x7FFFFFFFFFFFFFFFLL
, 0))
123 if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL
, 1, 0x7FFFFFFFFFFFFFFFLL
))
125 if (test__mulvdi3(1, 0x7FFFFFFFFFFFFFFFLL
, 0x7FFFFFFFFFFFFFFFLL
))
127 // if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL, 2, 0x8000000000000001LL)) // abort
129 // if (test__mulvdi3(2, 0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL)) // abort
132 // if (test__mulvdi3(0x8000000000000000LL, -2, 0x8000000000000000LL)) // abort
134 // if (test__mulvdi3(-2, 0x8000000000000000LL, 0x8000000000000000LL)) // abort
136 // if (test__mulvdi3(0x8000000000000000LL, -1, 0x8000000000000000LL)) // abort
138 // if (test__mulvdi3(-1, 0x8000000000000000LL, 0x8000000000000000LL)) // abort
140 if (test__mulvdi3(0x8000000000000000LL
, 0, 0))
142 if (test__mulvdi3(0, 0x8000000000000000LL
, 0))
144 if (test__mulvdi3(0x8000000000000000LL
, 1, 0x8000000000000000LL
))
146 if (test__mulvdi3(1, 0x8000000000000000LL
, 0x8000000000000000LL
))
148 // if (test__mulvdi3(0x8000000000000000LL, 2, 0x8000000000000000LL)) // abort
150 // if (test__mulvdi3(2, 0x8000000000000000LL, 0x8000000000000000LL)) // abort
153 // if (test__mulvdi3(0x8000000000000001LL, -2, 0x8000000000000001LL)) // abort
155 // if (test__mulvdi3(-2, 0x8000000000000001LL, 0x8000000000000001LL)) // abort
157 if (test__mulvdi3(0x8000000000000001LL
, -1, 0x7FFFFFFFFFFFFFFFLL
))
159 if (test__mulvdi3(-1, 0x8000000000000001LL
, 0x7FFFFFFFFFFFFFFFLL
))
161 if (test__mulvdi3(0x8000000000000001LL
, 0, 0))
163 if (test__mulvdi3(0, 0x8000000000000001LL
, 0))
165 if (test__mulvdi3(0x8000000000000001LL
, 1, 0x8000000000000001LL
))
167 if (test__mulvdi3(1, 0x8000000000000001LL
, 0x8000000000000001LL
))
169 // if (test__mulvdi3(0x8000000000000001LL, 2, 0x8000000000000000LL)) // abort
171 // if (test__mulvdi3(2, 0x8000000000000001LL, 0x8000000000000000LL)) // abort