Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PATCH] [compiler-rt, RISCV] Support builtins for RISC-V
Summary: Support builtins for RISC-V, RV32 and RV64. Reviewers: asb, apazos, mgrang Differential Revision: https://reviews.llvm.org/D42958 llvm-svn: 326420
- Loading branch information
Showing
9 changed files
with
177 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//===--- mulsi3.S - Integer multiplication routines routines ---===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is dual licensed under the MIT and the University of Illinois Open | ||
// Source Licenses. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#if !defined(__riscv_mul) && __riscv_xlen == 32 | ||
.text | ||
.align 2 | ||
|
||
.globl __mulsi3 | ||
.type __mulsi3, @function | ||
__mulsi3: | ||
mv a2, a0 | ||
mv a0, zero | ||
.L1: | ||
andi a3, a1, 1 | ||
beqz a3, .L2 | ||
add a0, a0, a2 | ||
.L2: | ||
srli a1, a1, 1 | ||
slli a2, a2, 1 | ||
bnez a1, .L1 | ||
ret | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// REQUIRES-ANY: riscv32-target-arch | ||
// RUN: %clang_builtins %s %librt -o %t && %run %t | ||
//===-- mulsi3_test.c - Test __mulsi3 -------------------------------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is dual licensed under the MIT and the University of Illinois Open | ||
// Source Licenses. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file tests __mulsi3 for the compiler_rt library. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "int_lib.h" | ||
#include <stdio.h> | ||
#include <limits.h> | ||
|
||
#if !defined(__riscv_mul) && __riscv_xlen == 32 | ||
// Based on mulsi3_test.c | ||
|
||
COMPILER_RT_ABI si_int __mulsi3(si_int a, si_int b); | ||
|
||
int test__mulsi3(si_int a, si_int b, si_int expected) | ||
{ | ||
si_int x = __mulsi3(a, b); | ||
if (x != expected) | ||
printf("error in __mulsi3: %d * %d = %d, expected %d\n", | ||
a, b, __mulsi3(a, b), expected); | ||
return x != expected; | ||
} | ||
#endif | ||
|
||
int main() | ||
{ | ||
#if !defined(__riscv_mul) && __riscv_xlen == 32 | ||
if (test__mulsi3(0, 0, 0)) | ||
return 1; | ||
if (test__mulsi3(0, 1, 0)) | ||
return 1; | ||
if (test__mulsi3(1, 0, 0)) | ||
return 1; | ||
if (test__mulsi3(0, 10, 0)) | ||
return 1; | ||
if (test__mulsi3(10, 0, 0)) | ||
return 1; | ||
if (test__mulsi3(0, INT_MAX, 0)) | ||
return 1; | ||
if (test__mulsi3(INT_MAX, 0, 0)) | ||
return 1; | ||
|
||
if (test__mulsi3(0, -1, 0)) | ||
return 1; | ||
if (test__mulsi3(-1, 0, 0)) | ||
return 1; | ||
if (test__mulsi3(0, -10, 0)) | ||
return 1; | ||
if (test__mulsi3(-10, 0, 0)) | ||
return 1; | ||
if (test__mulsi3(0, INT_MIN, 0)) | ||
return 1; | ||
if (test__mulsi3(INT_MIN, 0, 0)) | ||
return 1; | ||
|
||
if (test__mulsi3(1, 1, 1)) | ||
return 1; | ||
if (test__mulsi3(1, 10, 10)) | ||
return 1; | ||
if (test__mulsi3(10, 1, 10)) | ||
return 1; | ||
if (test__mulsi3(1, INT_MAX, INT_MAX)) | ||
return 1; | ||
if (test__mulsi3(INT_MAX, 1, INT_MAX)) | ||
return 1; | ||
|
||
if (test__mulsi3(1, -1, -1)) | ||
return 1; | ||
if (test__mulsi3(1, -10, -10)) | ||
return 1; | ||
if (test__mulsi3(-10, 1, -10)) | ||
return 1; | ||
if (test__mulsi3(1, INT_MIN, INT_MIN)) | ||
return 1; | ||
if (test__mulsi3(INT_MIN, 1, INT_MIN)) | ||
return 1; | ||
|
||
if (test__mulsi3(46340, 46340, 2147395600)) | ||
return 1; | ||
if (test__mulsi3(-46340, 46340, -2147395600)) | ||
return 1; | ||
if (test__mulsi3(46340, -46340, -2147395600)) | ||
return 1; | ||
if (test__mulsi3(-46340, -46340, 2147395600)) | ||
return 1; | ||
|
||
if (test__mulsi3(4194303, 8192, 34359730176)) | ||
return 1; | ||
if (test__mulsi3(-4194303, 8192, -34359730176)) | ||
return 1; | ||
if (test__mulsi3(4194303, -8192, -34359730176)) | ||
return 1; | ||
if (test__mulsi3(-4194303, -8192, 34359730176)) | ||
return 1; | ||
|
||
if (test__mulsi3(8192, 4194303, 34359730176)) | ||
return 1; | ||
if (test__mulsi3(-8192, 4194303, -34359730176)) | ||
return 1; | ||
if (test__mulsi3(8192, -4194303, -34359730176)) | ||
return 1; | ||
if (test__mulsi3(-8192, -4194303, 34359730176)) | ||
return 1; | ||
#else | ||
printf("skipped\n"); | ||
#endif | ||
|
||
return 0; | ||
} |