Skip to content

Commit

Permalink
Tear down and rewrite support for float testing
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed Dec 31, 2021
1 parent ecc00ef commit af26e3b
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 95 deletions.
3 changes: 3 additions & 0 deletions crates/core_simd/Cargo.toml
Expand Up @@ -26,3 +26,6 @@ features = ["alloc"]

[dev-dependencies.test_helpers]
path = "../test_helpers"

[dev-dependencies]
std_float = { path = "../std_float/", features = ["as_crate"] }
10 changes: 5 additions & 5 deletions crates/core_simd/examples/nbody.rs
@@ -1,11 +1,13 @@
#![cfg_attr(feature = "std", feature(portable_simd))]
#![feature(portable_simd)]
extern crate std_float;

/// Benchmarks game nbody code
/// Taken from the `packed_simd` crate
/// Run this benchmark with `cargo test --example nbody`
#[cfg(feature = "std")]
mod nbody {
use core_simd::*;
use core_simd::simd::*;
#[allow(unused)] // False positive?
use std_float::StdFloat;

use std::f64::consts::PI;
const SOLAR_MASS: f64 = 4.0 * PI * PI;
Expand Down Expand Up @@ -167,7 +169,6 @@ mod nbody {
}
}

#[cfg(feature = "std")]
#[cfg(test)]
mod tests {
// Good enough for demonstration purposes, not going for strictness here.
Expand All @@ -184,7 +185,6 @@ mod tests {
}

fn main() {
#[cfg(feature = "std")]
{
let (energy_before, energy_after) = nbody::run(1000);
println!("Energy before: {}", energy_before);
Expand Down
26 changes: 0 additions & 26 deletions crates/core_simd/src/intrinsics.rs
Expand Up @@ -87,29 +87,3 @@ extern "platform-intrinsic" {
#[allow(unused)]
pub(crate) fn simd_select_bitmask<M, T>(m: M, a: T, b: T) -> T;
}

#[cfg(feature = "std")]
mod std {
extern "platform-intrinsic" {
// ceil
pub(crate) fn simd_ceil<T>(x: T) -> T;

// 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;

// fsqrt
pub(crate) fn simd_fsqrt<T>(x: T) -> T;

// fma
pub(crate) fn simd_fma<T>(x: T, y: T, z: T) -> T;
}
}

#[cfg(feature = "std")]
pub(crate) use crate::simd::intrinsics::std::*;
41 changes: 0 additions & 41 deletions crates/core_simd/src/round.rs
Expand Up @@ -5,47 +5,6 @@ macro_rules! implement {
{
$type:ty, $int_type:ty
} => {
#[cfg(feature = "std")]
impl<const LANES: usize> Simd<$type, LANES>
where
LaneCount<LANES>: SupportedLaneCount,
{
/// 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 { 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 { intrinsics::simd_floor(self) }
}

/// 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 round(self) -> Self {
unsafe { 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 { 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()
}
}

impl<const LANES: usize> Simd<$type, LANES>
where
LaneCount<LANES>: SupportedLaneCount,
Expand Down
23 changes: 0 additions & 23 deletions crates/core_simd/src/vector/float.rs
Expand Up @@ -38,29 +38,6 @@ macro_rules! impl_float_vector {
unsafe { intrinsics::simd_fabs(self) }
}

/// Fused multiply-add. Computes `(self * a) + b` with only one rounding error,
/// yielding a more accurate result than an unfused multiply-add.
///
/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target
/// architecture has a dedicated `fma` CPU instruction. However, this is not always
/// true, and will be heavily dependent on designing algorithms with specific target
/// hardware in mind.
#[cfg(feature = "std")]
#[inline]
#[must_use = "method returns a new vector and does not mutate the original value"]
pub fn mul_add(self, a: Self, b: Self) -> Self {
unsafe { intrinsics::simd_fma(self, a, b) }
}

/// Produces a vector where every lane has the square root value
/// of the equivalently-indexed lane in `self`
#[inline]
#[must_use = "method returns a new vector and does not mutate the original value"]
#[cfg(feature = "std")]
pub fn sqrt(self) -> Self {
unsafe { intrinsics::simd_fsqrt(self) }
}

/// Takes the reciprocal (inverse) of each lane, `1/x`.
#[inline]
#[must_use = "method returns a new vector and does not mutate the original value"]
Expand Down
2 changes: 2 additions & 0 deletions crates/core_simd/tests/ops_macros.rs
Expand Up @@ -546,6 +546,8 @@ macro_rules! impl_float_tests {

#[cfg(feature = "std")]
mod std {
use std_float::StdFloat;

use super::*;
test_helpers::test_lanes! {
fn sqrt<const LANES: usize>() {
Expand Down
2 changes: 2 additions & 0 deletions crates/core_simd/tests/round.rs
Expand Up @@ -3,6 +3,8 @@
macro_rules! float_rounding_test {
{ $scalar:tt, $int_scalar:tt } => {
mod $scalar {
use std_float::StdFloat;

type Vector<const LANES: usize> = core_simd::Simd<$scalar, LANES>;
type Scalar = $scalar;
type IntScalar = $int_scalar;
Expand Down

0 comments on commit af26e3b

Please sign in to comment.