rv64 implement muldi3 intrinsic
Implement the __muldi3 intrinsic to prevent infinite recursion during multiplication on rv64 without the 'm' extension.
This commit is contained in:
parent
c307915e78
commit
10971912e8
3 changed files with 20 additions and 2 deletions
|
|
@ -100,6 +100,7 @@ impl_signed_mulo!(i128_overflowing_mul, i128, u128);
|
|||
intrinsics! {
|
||||
#[maybe_use_optimized_c_shim]
|
||||
#[arm_aeabi_alias = __aeabi_lmul]
|
||||
#[cfg(not(target_arch = "riscv64"))]
|
||||
pub extern "C" fn __muldi3(a: u64, b: u64) -> u64 {
|
||||
a.mul(b)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,8 +60,8 @@ pub mod arm;
|
|||
))]
|
||||
pub mod arm_linux;
|
||||
|
||||
#[cfg(any(target_arch = "riscv32"))]
|
||||
pub mod riscv32;
|
||||
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
|
||||
pub mod riscv;
|
||||
|
||||
#[cfg(target_arch = "x86")]
|
||||
pub mod x86;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
intrinsics! {
|
||||
// Implementation from gcc
|
||||
// https://raw.githubusercontent.com/gcc-mirror/gcc/master/libgcc/config/epiphany/mulsi3.c
|
||||
#[cfg(target_arch = "riscv32")]
|
||||
pub extern "C" fn __mulsi3(a: u32, b: u32) -> u32 {
|
||||
let (mut a, mut b) = (a, b);
|
||||
let mut r = 0;
|
||||
|
|
@ -15,4 +16,20 @@ intrinsics! {
|
|||
|
||||
r
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "riscv64")]
|
||||
pub extern "C" fn __muldi3(a: u64, b: u64) -> u64 {
|
||||
let (mut a, mut b) = (a, b);
|
||||
let mut r = 0;
|
||||
|
||||
while a > 0 {
|
||||
if a & 1 > 0 {
|
||||
r += b;
|
||||
}
|
||||
a >>= 1;
|
||||
b <<= 1;
|
||||
}
|
||||
|
||||
r
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue