2020-12-11 01:56:36 +00:00
|
|
|
#![allow(unused_macros)]
|
2024-05-11 00:46:50 +00:00
|
|
|
#![feature(f128)]
|
|
|
|
#![feature(f16)]
|
2020-12-11 01:56:36 +00:00
|
|
|
|
2020-12-08 05:25:42 +00:00
|
|
|
use testcrate::*;
|
|
|
|
|
2024-05-18 08:07:37 +00:00
|
|
|
mod int_mul {
|
|
|
|
use super::*;
|
2020-12-08 05:25:42 +00:00
|
|
|
|
2024-05-18 08:07:37 +00:00
|
|
|
macro_rules! mul {
|
|
|
|
($($i:ty, $fn:ident);*;) => {
|
|
|
|
$(
|
|
|
|
#[test]
|
|
|
|
fn $fn() {
|
|
|
|
use compiler_builtins::int::mul::$fn;
|
2020-12-08 05:25:42 +00:00
|
|
|
|
2024-05-18 08:07:37 +00:00
|
|
|
fuzz_2(N, |x: $i, y: $i| {
|
|
|
|
let mul0 = x.wrapping_mul(y);
|
|
|
|
let mul1: $i = $fn(x, y);
|
|
|
|
if mul0 != mul1 {
|
|
|
|
panic!(
|
|
|
|
"{}({}, {}): std: {}, builtins: {}",
|
|
|
|
stringify!($fn), x, y, mul0, mul1
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
mul! {
|
2020-12-08 05:25:42 +00:00
|
|
|
u64, __muldi3;
|
|
|
|
i128, __multi3;
|
2024-05-18 08:07:37 +00:00
|
|
|
}
|
2020-12-08 05:25:42 +00:00
|
|
|
}
|
|
|
|
|
2024-05-18 08:07:37 +00:00
|
|
|
mod int_overflowing_mul {
|
|
|
|
use super::*;
|
2020-12-08 05:25:42 +00:00
|
|
|
|
2024-05-18 08:07:37 +00:00
|
|
|
macro_rules! overflowing_mul {
|
|
|
|
($($i:ty, $fn:ident);*;) => {
|
|
|
|
$(
|
|
|
|
#[test]
|
|
|
|
fn $fn() {
|
|
|
|
use compiler_builtins::int::mul::$fn;
|
|
|
|
|
|
|
|
fuzz_2(N, |x: $i, y: $i| {
|
|
|
|
let (mul0, o0) = x.overflowing_mul(y);
|
|
|
|
let mut o1 = 0i32;
|
|
|
|
let mul1: $i = $fn(x, y, &mut o1);
|
|
|
|
let o1 = o1 != 0;
|
|
|
|
if mul0 != mul1 || o0 != o1 {
|
|
|
|
panic!(
|
|
|
|
"{}({}, {}): std: ({}, {}), builtins: ({}, {})",
|
|
|
|
stringify!($fn), x, y, mul0, o0, mul1, o1
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
};
|
|
|
|
}
|
2020-12-08 05:25:42 +00:00
|
|
|
|
2024-05-18 08:07:37 +00:00
|
|
|
overflowing_mul! {
|
2020-12-08 05:25:42 +00:00
|
|
|
i32, __mulosi4;
|
|
|
|
i64, __mulodi4;
|
|
|
|
i128, __muloti4;
|
2024-05-18 08:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn overflowing_mul_u128() {
|
|
|
|
use compiler_builtins::int::mul::{__rust_i128_mulo, __rust_u128_mulo};
|
|
|
|
|
|
|
|
fuzz_2(N, |x: u128, y: u128| {
|
|
|
|
let (mul0, o0) = x.overflowing_mul(y);
|
|
|
|
let (mul1, o1) = __rust_u128_mulo(x, y);
|
|
|
|
if mul0 != mul1 || o0 != o1 {
|
|
|
|
panic!(
|
|
|
|
"__rust_u128_mulo({}, {}): std: ({}, {}), builtins: ({}, {})",
|
|
|
|
x, y, mul0, o0, mul1, o1
|
|
|
|
);
|
|
|
|
}
|
|
|
|
let x = x as i128;
|
|
|
|
let y = y as i128;
|
|
|
|
let (mul0, o0) = x.overflowing_mul(y);
|
|
|
|
let (mul1, o1) = __rust_i128_mulo(x, y);
|
|
|
|
if mul0 != mul1 || o0 != o1 {
|
|
|
|
panic!(
|
|
|
|
"__rust_i128_mulo({}, {}): std: ({}, {}), builtins: ({}, {})",
|
|
|
|
x, y, mul0, o0, mul1, o1
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-12-08 05:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! float_mul {
|
2024-05-11 00:01:49 +00:00
|
|
|
($($f:ty, $fn:ident, $apfloat_ty:ident, $sys_available:meta);*;) => {
|
2020-12-08 05:25:42 +00:00
|
|
|
$(
|
2024-05-18 08:07:37 +00:00
|
|
|
#[test]
|
|
|
|
fn $fn() {
|
|
|
|
use compiler_builtins::float::{mul::$fn, Float};
|
|
|
|
use core::ops::Mul;
|
|
|
|
|
|
|
|
fuzz_float_2(N, |x: $f, y: $f| {
|
|
|
|
let mul0 = apfloat_fallback!($f, $apfloat_ty, $sys_available, Mul::mul, x, y);
|
|
|
|
let mul1: $f = $fn(x, y);
|
2024-06-30 21:02:41 +00:00
|
|
|
if !Float::eq_repr(mul0, mul1) {
|
|
|
|
panic!(
|
|
|
|
"{}({:?}, {:?}): std: {:?}, builtins: {:?}",
|
|
|
|
stringify!($fn), x, y, mul0, mul1
|
|
|
|
);
|
2020-12-08 05:25:42 +00:00
|
|
|
}
|
2024-05-18 08:07:37 +00:00
|
|
|
});
|
|
|
|
}
|
2020-12-08 05:25:42 +00:00
|
|
|
)*
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(all(target_arch = "x86", not(target_feature = "sse"))))]
|
2024-05-18 08:07:37 +00:00
|
|
|
mod float_mul {
|
|
|
|
use super::*;
|
2020-12-08 05:25:42 +00:00
|
|
|
|
2024-06-30 21:40:57 +00:00
|
|
|
// FIXME(#616): Stop ignoring arches that don't have native support once fix for builtins is in
|
|
|
|
// nightly.
|
2024-05-18 08:07:37 +00:00
|
|
|
float_mul! {
|
2024-06-30 21:40:57 +00:00
|
|
|
f32, __mulsf3, Single, not(target_arch = "arm");
|
|
|
|
f64, __muldf3, Double, not(target_arch = "arm");
|
2024-05-18 08:07:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(feature = "no-f16-f128"))]
|
|
|
|
#[cfg(not(all(target_arch = "x86", not(target_feature = "sse"))))]
|
|
|
|
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
|
|
|
|
mod float_mul_f128 {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
float_mul! {
|
|
|
|
f128, __multf3, Quad,
|
|
|
|
// FIXME(llvm): there is a bug in LLVM rt.
|
|
|
|
// See <https://github.com/llvm/llvm-project/issues/91840>.
|
|
|
|
not(any(feature = "no-sys-f128", all(target_arch = "aarch64", target_os = "linux")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(feature = "no-f16-f128"))]
|
|
|
|
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
|
|
|
|
mod float_mul_f128_ppc {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
float_mul! {
|
|
|
|
f128, __mulkf3, Quad, not(feature = "no-sys-f128");
|
2024-05-11 00:46:50 +00:00
|
|
|
}
|
2020-12-08 05:25:42 +00:00
|
|
|
}
|
2020-12-11 01:56:36 +00:00
|
|
|
|
|
|
|
#[cfg(target_arch = "arm")]
|
2024-05-18 08:07:37 +00:00
|
|
|
mod float_mul_arm {
|
|
|
|
use super::*;
|
2020-12-11 01:56:36 +00:00
|
|
|
|
2024-05-18 08:07:37 +00:00
|
|
|
float_mul! {
|
2024-05-11 00:01:49 +00:00
|
|
|
f32, __mulsf3vfp, Single, all();
|
|
|
|
f64, __muldf3vfp, Double, all();
|
2024-05-18 08:07:37 +00:00
|
|
|
}
|
2020-12-11 01:56:36 +00:00
|
|
|
}
|