1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_mulvdi3
3 //===-- mulvdi3_test.c - Test __mulvdi3 -----------------------------------===//
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //===----------------------------------------------------------------------===//
11 // This file tests __mulvdi3 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
20 // Effects: aborts if a * b overflows
22 COMPILER_RT_ABI di_int
__mulvdi3(di_int a
, di_int b
);
24 int test__mulvdi3(di_int a
, di_int b
, di_int expected
)
26 di_int x
= __mulvdi3(a
, b
);
28 printf("error in __mulvdi3: %lld * %lld = %lld, expected %lld\n",
35 if (test__mulvdi3(0, 0, 0))
37 if (test__mulvdi3(0, 1, 0))
39 if (test__mulvdi3(1, 0, 0))
41 if (test__mulvdi3(0, 10, 0))
43 if (test__mulvdi3(10, 0, 0))
45 if (test__mulvdi3(0, 81985529216486895LL, 0))
47 if (test__mulvdi3(81985529216486895LL, 0, 0))
50 if (test__mulvdi3(0, -1, 0))
52 if (test__mulvdi3(-1, 0, 0))
54 if (test__mulvdi3(0, -10, 0))
56 if (test__mulvdi3(-10, 0, 0))
58 if (test__mulvdi3(0, -81985529216486895LL, 0))
60 if (test__mulvdi3(-81985529216486895LL, 0, 0))
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(1, -1, -1))
76 if (test__mulvdi3(1, -10, -10))
78 if (test__mulvdi3(-10, 1, -10))
80 if (test__mulvdi3(1, -81985529216486895LL, -81985529216486895LL))
82 if (test__mulvdi3(-81985529216486895LL, 1, -81985529216486895LL))
85 if (test__mulvdi3(3037000499LL, 3037000499LL, 9223372030926249001LL))
87 if (test__mulvdi3(-3037000499LL, 3037000499LL, -9223372030926249001LL))
89 if (test__mulvdi3(3037000499LL, -3037000499LL, -9223372030926249001LL))
91 if (test__mulvdi3(-3037000499LL, -3037000499LL, 9223372030926249001LL))
94 if (test__mulvdi3(4398046511103LL, 2097152LL, 9223372036852678656LL))
96 if (test__mulvdi3(-4398046511103LL, 2097152LL, -9223372036852678656LL))
98 if (test__mulvdi3(4398046511103LL, -2097152LL, -9223372036852678656LL))
100 if (test__mulvdi3(-4398046511103LL, -2097152LL, 9223372036852678656LL))
103 if (test__mulvdi3(2097152LL, 4398046511103LL, 9223372036852678656LL))
105 if (test__mulvdi3(-2097152LL, 4398046511103LL, -9223372036852678656LL))
107 if (test__mulvdi3(2097152LL, -4398046511103LL, -9223372036852678656LL))
109 if (test__mulvdi3(-2097152LL, -4398046511103LL, 9223372036852678656LL))
112 // if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL, -2, 0x8000000000000001LL)) // abort
114 // if (test__mulvdi3(-2, 0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL)) // abort
116 if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL
, -1, 0x8000000000000001LL
))
118 if (test__mulvdi3(-1, 0x7FFFFFFFFFFFFFFFLL
, 0x8000000000000001LL
))
120 if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL
, 0, 0))
122 if (test__mulvdi3(0, 0x7FFFFFFFFFFFFFFFLL
, 0))
124 if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL
, 1, 0x7FFFFFFFFFFFFFFFLL
))
126 if (test__mulvdi3(1, 0x7FFFFFFFFFFFFFFFLL
, 0x7FFFFFFFFFFFFFFFLL
))
128 // if (test__mulvdi3(0x7FFFFFFFFFFFFFFFLL, 2, 0x8000000000000001LL)) // abort
130 // if (test__mulvdi3(2, 0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL)) // abort
133 // if (test__mulvdi3(0x8000000000000000LL, -2, 0x8000000000000000LL)) // abort
135 // if (test__mulvdi3(-2, 0x8000000000000000LL, 0x8000000000000000LL)) // abort
137 // if (test__mulvdi3(0x8000000000000000LL, -1, 0x8000000000000000LL)) // abort
139 // if (test__mulvdi3(-1, 0x8000000000000000LL, 0x8000000000000000LL)) // abort
141 if (test__mulvdi3(0x8000000000000000LL
, 0, 0))
143 if (test__mulvdi3(0, 0x8000000000000000LL
, 0))
145 if (test__mulvdi3(0x8000000000000000LL
, 1, 0x8000000000000000LL
))
147 if (test__mulvdi3(1, 0x8000000000000000LL
, 0x8000000000000000LL
))
149 // if (test__mulvdi3(0x8000000000000000LL, 2, 0x8000000000000000LL)) // abort
151 // if (test__mulvdi3(2, 0x8000000000000000LL, 0x8000000000000000LL)) // abort
154 // if (test__mulvdi3(0x8000000000000001LL, -2, 0x8000000000000001LL)) // abort
156 // if (test__mulvdi3(-2, 0x8000000000000001LL, 0x8000000000000001LL)) // abort
158 if (test__mulvdi3(0x8000000000000001LL
, -1, 0x7FFFFFFFFFFFFFFFLL
))
160 if (test__mulvdi3(-1, 0x8000000000000001LL
, 0x7FFFFFFFFFFFFFFFLL
))
162 if (test__mulvdi3(0x8000000000000001LL
, 0, 0))
164 if (test__mulvdi3(0, 0x8000000000000001LL
, 0))
166 if (test__mulvdi3(0x8000000000000001LL
, 1, 0x8000000000000001LL
))
168 if (test__mulvdi3(1, 0x8000000000000001LL
, 0x8000000000000001LL
))
170 // if (test__mulvdi3(0x8000000000000001LL, 2, 0x8000000000000000LL)) // abort
172 // if (test__mulvdi3(2, 0x8000000000000001LL, 0x8000000000000000LL)) // abort