Add SIMD round, trunc, fract
This commit is contained in:
parent
b4fda6ef06
commit
6ea08d8d5f
@ -86,6 +86,12 @@ mod std {
|
||||
|
||||
// floor
|
||||
pub(crate) fn simd_floor<T>(x: T) -> T;
|
||||
|
||||
// round
|
||||
pub(crate) fn simd_round<T>(x: T) -> T;
|
||||
|
||||
// trunc
|
||||
pub(crate) fn simd_trunc<T>(x: T) -> T;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,18 +7,39 @@ macro_rules! implement {
|
||||
where
|
||||
Self: crate::LanesAtMost32,
|
||||
{
|
||||
/// Returns the largest integer less than or equal to each lane.
|
||||
/// Returns the smallest integer greater than or equal to each lane.
|
||||
#[must_use = "method returns a new vector and does not mutate the original value"]
|
||||
#[inline]
|
||||
pub fn ceil(self) -> Self {
|
||||
unsafe { crate::intrinsics::simd_ceil(self) }
|
||||
}
|
||||
|
||||
/// Returns the largest integer value less than or equal to each lane.
|
||||
#[must_use = "method returns a new vector and does not mutate the original value"]
|
||||
#[inline]
|
||||
pub fn floor(self) -> Self {
|
||||
unsafe { crate::intrinsics::simd_floor(self) }
|
||||
}
|
||||
|
||||
/// Returns the smallest integer greater than or equal to each lane.
|
||||
/// Rounds to the nearest integer value. Ties round toward zero.
|
||||
#[must_use = "method returns a new vector and does not mutate the original value"]
|
||||
#[inline]
|
||||
pub fn ceil(self) -> Self {
|
||||
unsafe { crate::intrinsics::simd_ceil(self) }
|
||||
pub fn round(self) -> Self {
|
||||
unsafe { crate::intrinsics::simd_round(self) }
|
||||
}
|
||||
|
||||
/// Returns the floating point's integer value, with its fractional part removed.
|
||||
#[must_use = "method returns a new vector and does not mutate the original value"]
|
||||
#[inline]
|
||||
pub fn trunc(self) -> Self {
|
||||
unsafe { crate::intrinsics::simd_trunc(self) }
|
||||
}
|
||||
|
||||
/// Returns the floating point's fractional value, with its integer part removed.
|
||||
#[must_use = "method returns a new vector and does not mutate the original value"]
|
||||
#[inline]
|
||||
pub fn fract(self) -> Self {
|
||||
self - self.trunc()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,30 @@ macro_rules! float_rounding_test {
|
||||
&|_| true,
|
||||
)
|
||||
}
|
||||
|
||||
fn round<const LANES: usize>() {
|
||||
test_helpers::test_unary_elementwise(
|
||||
&Vector::<LANES>::round,
|
||||
&Scalar::round,
|
||||
&|_| true,
|
||||
)
|
||||
}
|
||||
|
||||
fn trunc<const LANES: usize>() {
|
||||
test_helpers::test_unary_elementwise(
|
||||
&Vector::<LANES>::trunc,
|
||||
&Scalar::trunc,
|
||||
&|_| true,
|
||||
)
|
||||
}
|
||||
|
||||
fn fract<const LANES: usize>() {
|
||||
test_helpers::test_unary_elementwise(
|
||||
&Vector::<LANES>::fract,
|
||||
&Scalar::fract,
|
||||
&|_| true,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
test_helpers::test_lanes! {
|
||||
|
Loading…
x
Reference in New Issue
Block a user