Files
clang-p2996/compiler-rt/test/builtins/Unit/muldi3_test.c
Luís Marques 58f6b16c49 [compiler-rt][builtins][RISCV] Always include __mul[sd]i3 builtin definitions
The RISC-V implementations of the `__mulsi3`, `__muldi3` builtins were
conditionally compiling the actual function definitions depending on whether
the M extension was present or not. This caused Compiler-RT testing failures
for RISC-V targets with the M extension, as when these sources were included
the `librt_has_mul*i3` features were still being defined. These `librt_has_*`
definitions are used to conditionally run the respective tests. Since the
actual functions were not being compiled-in, the generic test for `__muldi3`
would fail. This patch makes these implementations follow the normal
Compiler-RT convention of always including the definition, and conditionally
running the respective tests by using the lit conditional
`REQUIRES: librt_has_*`.

Since the `mulsi3_test.c` wasn't actually RISC-V-specific, this patch also
moves it out of the `riscv` directory. It now only depends on
`librt_has_mulsi3` to run.

Differential Revision: https://reviews.llvm.org/D86457
2020-10-21 09:49:03 +01:00

101 lines
2.9 KiB
C

// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: librt_has_muldi3
#include "int_lib.h"
#include <stdio.h>
COMPILER_RT_ABI di_int __muldi3(di_int a, di_int b);
int test__muldi3(di_int a, di_int b, di_int expected)
{
di_int x = __muldi3(a, b);
if (x != expected)
printf("error in __muldi3: %lld * %lld = %lld, expected %lld\n",
a, b, x, expected);
return x != expected;
}
char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
int main()
{
if (test__muldi3(0, 0, 0))
return 1;
if (test__muldi3(0, 1, 0))
return 1;
if (test__muldi3(1, 0, 0))
return 1;
if (test__muldi3(0, 10, 0))
return 1;
if (test__muldi3(10, 0, 0))
return 1;
if (test__muldi3(0, 81985529216486895LL, 0))
return 1;
if (test__muldi3(81985529216486895LL, 0, 0))
return 1;
if (test__muldi3(0, -1, 0))
return 1;
if (test__muldi3(-1, 0, 0))
return 1;
if (test__muldi3(0, -10, 0))
return 1;
if (test__muldi3(-10, 0, 0))
return 1;
if (test__muldi3(0, -81985529216486895LL, 0))
return 1;
if (test__muldi3(-81985529216486895LL, 0, 0))
return 1;
if (test__muldi3(1, 1, 1))
return 1;
if (test__muldi3(1, 10, 10))
return 1;
if (test__muldi3(10, 1, 10))
return 1;
if (test__muldi3(1, 81985529216486895LL, 81985529216486895LL))
return 1;
if (test__muldi3(81985529216486895LL, 1, 81985529216486895LL))
return 1;
if (test__muldi3(1, -1, -1))
return 1;
if (test__muldi3(1, -10, -10))
return 1;
if (test__muldi3(-10, 1, -10))
return 1;
if (test__muldi3(1, -81985529216486895LL, -81985529216486895LL))
return 1;
if (test__muldi3(-81985529216486895LL, 1, -81985529216486895LL))
return 1;
if (test__muldi3(3037000499LL, 3037000499LL, 9223372030926249001LL))
return 1;
if (test__muldi3(-3037000499LL, 3037000499LL, -9223372030926249001LL))
return 1;
if (test__muldi3(3037000499LL, -3037000499LL, -9223372030926249001LL))
return 1;
if (test__muldi3(-3037000499LL, -3037000499LL, 9223372030926249001LL))
return 1;
if (test__muldi3(4398046511103LL, 2097152LL, 9223372036852678656LL))
return 1;
if (test__muldi3(-4398046511103LL, 2097152LL, -9223372036852678656LL))
return 1;
if (test__muldi3(4398046511103LL, -2097152LL, -9223372036852678656LL))
return 1;
if (test__muldi3(-4398046511103LL, -2097152LL, 9223372036852678656LL))
return 1;
if (test__muldi3(2097152LL, 4398046511103LL, 9223372036852678656LL))
return 1;
if (test__muldi3(-2097152LL, 4398046511103LL, -9223372036852678656LL))
return 1;
if (test__muldi3(2097152LL, -4398046511103LL, -9223372036852678656LL))
return 1;
if (test__muldi3(-2097152LL, -4398046511103LL, 9223372036852678656LL))
return 1;
return 0;
}