Skip to content

Commit af26e3b

Browse files
Tear down and rewrite support for float testing
1 parent ecc00ef commit af26e3b

File tree

7 files changed

+12
-95
lines changed

7 files changed

+12
-95
lines changed

crates/core_simd/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ features = ["alloc"]
2626

2727
[dev-dependencies.test_helpers]
2828
path = "../test_helpers"
29+
30+
[dev-dependencies]
31+
std_float = { path = "../std_float/", features = ["as_crate"] }

crates/core_simd/examples/nbody.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
#![cfg_attr(feature = "std", feature(portable_simd))]
1+
#![feature(portable_simd)]
2+
extern crate std_float;
23

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

1012
use std::f64::consts::PI;
1113
const SOLAR_MASS: f64 = 4.0 * PI * PI;
@@ -167,7 +169,6 @@ mod nbody {
167169
}
168170
}
169171

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

186187
fn main() {
187-
#[cfg(feature = "std")]
188188
{
189189
let (energy_before, energy_after) = nbody::run(1000);
190190
println!("Energy before: {}", energy_before);

crates/core_simd/src/intrinsics.rs

-26
Original file line numberDiff line numberDiff line change
@@ -87,29 +87,3 @@ extern "platform-intrinsic" {
8787
#[allow(unused)]
8888
pub(crate) fn simd_select_bitmask<M, T>(m: M, a: T, b: T) -> T;
8989
}
90-
91-
#[cfg(feature = "std")]
92-
mod std {
93-
extern "platform-intrinsic" {
94-
// ceil
95-
pub(crate) fn simd_ceil<T>(x: T) -> T;
96-
97-
// floor
98-
pub(crate) fn simd_floor<T>(x: T) -> T;
99-
100-
// round
101-
pub(crate) fn simd_round<T>(x: T) -> T;
102-
103-
// trunc
104-
pub(crate) fn simd_trunc<T>(x: T) -> T;
105-
106-
// fsqrt
107-
pub(crate) fn simd_fsqrt<T>(x: T) -> T;
108-
109-
// fma
110-
pub(crate) fn simd_fma<T>(x: T, y: T, z: T) -> T;
111-
}
112-
}
113-
114-
#[cfg(feature = "std")]
115-
pub(crate) use crate::simd::intrinsics::std::*;

crates/core_simd/src/round.rs

-41
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,6 @@ macro_rules! implement {
55
{
66
$type:ty, $int_type:ty
77
} => {
8-
#[cfg(feature = "std")]
9-
impl<const LANES: usize> Simd<$type, LANES>
10-
where
11-
LaneCount<LANES>: SupportedLaneCount,
12-
{
13-
/// Returns the smallest integer greater than or equal to each lane.
14-
#[must_use = "method returns a new vector and does not mutate the original value"]
15-
#[inline]
16-
pub fn ceil(self) -> Self {
17-
unsafe { intrinsics::simd_ceil(self) }
18-
}
19-
20-
/// Returns the largest integer value less than or equal to each lane.
21-
#[must_use = "method returns a new vector and does not mutate the original value"]
22-
#[inline]
23-
pub fn floor(self) -> Self {
24-
unsafe { intrinsics::simd_floor(self) }
25-
}
26-
27-
/// Rounds to the nearest integer value. Ties round toward zero.
28-
#[must_use = "method returns a new vector and does not mutate the original value"]
29-
#[inline]
30-
pub fn round(self) -> Self {
31-
unsafe { intrinsics::simd_round(self) }
32-
}
33-
34-
/// Returns the floating point's integer value, with its fractional part removed.
35-
#[must_use = "method returns a new vector and does not mutate the original value"]
36-
#[inline]
37-
pub fn trunc(self) -> Self {
38-
unsafe { intrinsics::simd_trunc(self) }
39-
}
40-
41-
/// Returns the floating point's fractional value, with its integer part removed.
42-
#[must_use = "method returns a new vector and does not mutate the original value"]
43-
#[inline]
44-
pub fn fract(self) -> Self {
45-
self - self.trunc()
46-
}
47-
}
48-
498
impl<const LANES: usize> Simd<$type, LANES>
509
where
5110
LaneCount<LANES>: SupportedLaneCount,

crates/core_simd/src/vector/float.rs

-23
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,6 @@ macro_rules! impl_float_vector {
3838
unsafe { intrinsics::simd_fabs(self) }
3939
}
4040

41-
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding error,
42-
/// yielding a more accurate result than an unfused multiply-add.
43-
///
44-
/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target
45-
/// architecture has a dedicated `fma` CPU instruction. However, this is not always
46-
/// true, and will be heavily dependent on designing algorithms with specific target
47-
/// hardware in mind.
48-
#[cfg(feature = "std")]
49-
#[inline]
50-
#[must_use = "method returns a new vector and does not mutate the original value"]
51-
pub fn mul_add(self, a: Self, b: Self) -> Self {
52-
unsafe { intrinsics::simd_fma(self, a, b) }
53-
}
54-
55-
/// Produces a vector where every lane has the square root value
56-
/// of the equivalently-indexed lane in `self`
57-
#[inline]
58-
#[must_use = "method returns a new vector and does not mutate the original value"]
59-
#[cfg(feature = "std")]
60-
pub fn sqrt(self) -> Self {
61-
unsafe { intrinsics::simd_fsqrt(self) }
62-
}
63-
6441
/// Takes the reciprocal (inverse) of each lane, `1/x`.
6542
#[inline]
6643
#[must_use = "method returns a new vector and does not mutate the original value"]

crates/core_simd/tests/ops_macros.rs

+2
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,8 @@ macro_rules! impl_float_tests {
546546

547547
#[cfg(feature = "std")]
548548
mod std {
549+
use std_float::StdFloat;
550+
549551
use super::*;
550552
test_helpers::test_lanes! {
551553
fn sqrt<const LANES: usize>() {

crates/core_simd/tests/round.rs

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
macro_rules! float_rounding_test {
44
{ $scalar:tt, $int_scalar:tt } => {
55
mod $scalar {
6+
use std_float::StdFloat;
7+
68
type Vector<const LANES: usize> = core_simd::Simd<$scalar, LANES>;
79
type Scalar = $scalar;
810
type IntScalar = $int_scalar;

0 commit comments

Comments
 (0)