Index: compiler-rt/lib/builtins/CMakeLists.txt =================================================================== --- compiler-rt/lib/builtins/CMakeLists.txt +++ compiler-rt/lib/builtins/CMakeLists.txt @@ -556,10 +556,13 @@ set(riscv_SOURCES ${GENERIC_SOURCES} ${GENERIC_TF_SOURCES}) set(riscv32_SOURCES - riscv/mulsi3.S + riscv/mulXi3.S + ${riscv_SOURCES} +) +set(riscv64_SOURCES + riscv/mulXi3.S ${riscv_SOURCES} ) -set(riscv64_SOURCES ${riscv_SOURCES}) set(sparc_SOURCES ${GENERIC_SOURCES} ${GENERIC_TF_SOURCES}) set(sparcv9_SOURCES ${GENERIC_SOURCES} ${GENERIC_TF_SOURCES}) Index: compiler-rt/lib/builtins/riscv/mulXi3.S =================================================================== --- compiler-rt/lib/builtins/riscv/mulXi3.S +++ compiler-rt/lib/builtins/riscv/mulXi3.S @@ -1,4 +1,4 @@ -//===--- mulsi3.S - Integer multiplication routines routines ---===// +//===--- mulXi3.S - Integer multiplication routines routines ---===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,13 +6,22 @@ // //===----------------------------------------------------------------------===// -#if !defined(__riscv_mul) && __riscv_xlen == 32 +// Implement __mulsi3/__muldi3 + +#if !defined(__riscv_mul) + +#if __riscv_xlen == 64 +#define __mulXi3 __muldi3 +#elif __riscv_xlen == 32 +#define __mulXi3 __mulsi3 +#endif + .text .align 2 - .globl __mulsi3 - .type __mulsi3, @function -__mulsi3: + .globl __mulXi3 + .type __mulXi3, @function +__mulXi3: mv a2, a0 mv a0, zero .L1: Index: compiler-rt/test/builtins/Unit/riscv/muldi3_test.c =================================================================== --- /dev/null +++ compiler-rt/test/builtins/Unit/riscv/muldi3_test.c @@ -0,0 +1,199 @@ +// REQUIRES: riscv64-target-arch +// RUN: %clang_builtins %s %librt -o %t && %run %t +//===-- muldi3_test.c - Test __muldi3 -------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file tests __muldi3 for the compiler_rt library. +// +//===----------------------------------------------------------------------===// + +#include "int_lib.h" +#include +#include + +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: %ld * %ld = %ld, expected %ld\n", + a, b, __muldi3(a, b), expected); + return x != expected; +} + +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, INT_MAX, 0)) + return 1; + if (test__muldi3(INT_MAX, 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, INT_MIN, 0)) + return 1; + if (test__muldi3(INT_MIN, 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, INT_MAX, INT_MAX)) + return 1; + if (test__muldi3(INT_MAX, 1, INT_MAX)) + 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, INT_MIN, INT_MIN)) + return 1; + if (test__muldi3(INT_MIN, 1, INT_MIN)) + return 1; + if (test__muldi3(1, LONG_MIN, LONG_MIN)) + return 1; + if (test__muldi3(LONG_MIN, 1, LONG_MIN)) + return 1; + if (test__muldi3(1, LONG_MAX, LONG_MAX)) + return 1; + if (test__muldi3(LONG_MAX, 1, LONG_MAX)) + return 1; + + if (test__muldi3(46340, 46340, 2147395600)) + return 1; + if (test__muldi3(-46340, 46340, -2147395600)) + return 1; + if (test__muldi3(46340, -46340, -2147395600)) + return 1; + if (test__muldi3(-46340, -46340, 2147395600)) + return 1; + + if (test__muldi3(4194303, 8192, 34359730176)) + return 1; + if (test__muldi3(-4194303, 8192, -34359730176)) + return 1; + if (test__muldi3(4194303, -8192, -34359730176)) + return 1; + if (test__muldi3(-4194303, -8192, 34359730176)) + return 1; + + if (test__muldi3(8192, 4194303, 34359730176)) + return 1; + if (test__muldi3(-8192, 4194303, -34359730176)) + return 1; + if (test__muldi3(8192, -4194303, -34359730176)) + return 1; + if (test__muldi3(-8192, -4194303, 34359730176)) + return 1; + if (test__muldi3(31767,-8796,-279422532)) + return 1; + if (test__muldi3(18587,-32548,-604969676)) + return 1; + if (test__muldi3(-32477,281,-9126037)) + return 1; + if (test__muldi3(31580,-32364,-1022055120)) + return 1; + if (test__muldi3(19492,1800,35085600)) + return 1; + if (test__muldi3(-2452,22388,-54895376)) + return 1; + if (test__muldi3(-2284,-13777,31466668)) + return 1; + if (test__muldi3(12154,-21994,-267315076)) + return 1; + if (test__muldi3(-4816,10839,-52200624)) + return 1; + if (test__muldi3(-22371,11751,-262881621)) + return 1; + if (test__muldi3(18957,-21446,-406551822)) + return 1; + if (test__muldi3(-32616,-21865,713148840)) + return 1; + if (test__muldi3(6966,29632,206416512)) + return 1; + if (test__muldi3(6414,-23625,-151530750)) + return 1; + if (test__muldi3(13492,-16487,-222442604)) + return 1; + if (test__muldi3(31578,12700,401040600)) + return 1; + if (test__muldi3(-15230,-7334,111696820)) + return 1; + if (test__muldi3(4802,-5813,-27914026)) + return 1; + if (test__muldi3(-20481,-4637,94970397)) + return 1; + if (test__muldi3(26147,-7291,-190637777)) + return 1; + + if (test__muldi3(579010523,396005871,229291566478780533)) + return 1; + if (test__muldi3(-765293181,-1650235582,1262914037948166342)) + return 1; + if (test__muldi3(461364481,1504851578,694285067266001018)) + return 1; + if (test__muldi3(-1183908758,1759280311,-2082827367969863738)) + return 1; + if (test__muldi3(1185399628,1333591590,1580838974689928520)) + return 1; + if (test__muldi3(-1100621190,-897589936,987906503492343840)) + return 1; + if (test__muldi3(441096506,1255565143,553825397632690358)) + return 1; + if (test__muldi3(-1524826914,874985606,-1334201601391399884)) + return 1; + if (test__muldi3(-754121694,-1174589064,885783094697554416)) + return 1; + if (test__muldi3(1670049318,-1313632675,-2193831352986265650)) + return 1; + if (test__muldi3(-116800413,-1315159171,153611134333537623)) + return 1; + if (test__muldi3(859939538,1599943830,1375854957996150540)) + return 1; + if (test__muldi3(-116780799,-129085932,15074758278619668)) + return 1; + if (test__muldi3(925709728,733346070,678865590989568960)) + return 1; + if (test__muldi3(394185200,1674963196,660245702407899200)) + return 1; + if (test__muldi3(-159333098,675035088,-107555431829742624)) + return 1; + if (test__muldi3(-1562873619,-1580285540,2469786580953169260)) + return 1; + if (test__muldi3(1570149758,1143409507,1795324160710949306)) + return 1; + if (test__muldi3(-327650419,-150467587,49300767926468953)) + return 1; + if (test__muldi3(-658003974,805911219,-530292784793184306)) + return 1; + + return 0; +}