Skip to content

Commit 5b5b259

Browse files
committed
Test std_float
1 parent eea6f77 commit 5b5b259

File tree

4 files changed

+78
-51
lines changed

4 files changed

+78
-51
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/std_float/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ edition = "2021"
88
[dependencies]
99
core_simd = { path = "../core_simd", default-features = false }
1010

11+
[dev-dependencies.test_helpers]
12+
path = "../test_helpers"
13+
1114
[features]
1215
default = ["as_crate"]
1316
as_crate = []

crates/std_float/src/lib.rs

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,19 @@ pub trait StdFloat: Sealed + Sized {
101101
/// in the equivalently-indexed lane in `self`.
102102
#[inline]
103103
#[must_use = "method returns a new vector and does not mutate the original value"]
104-
fn log(self) -> Self {
104+
fn ln(self) -> Self {
105105
unsafe { intrinsics::simd_flog(self) }
106106
}
107107

108+
/// Produces a vector where every lane has the logarithm with respect to an arbitrary
109+
/// in the equivalently-indexed lanes in `self` and `base`.
110+
#[inline]
111+
#[must_use = "method returns a new vector and does not mutate the original value"]
112+
fn log(self, base: Self) -> Self {
113+
unsafe { intrinsics::simd_div(self.ln(), base.ln()) }
114+
}
115+
116+
108117
/// Produces a vector where every lane has the base-2 logarithm of the value
109118
/// in the equivalently-indexed lane in `self`.
110119
#[inline]
@@ -181,53 +190,3 @@ where
181190
self - self.trunc()
182191
}
183192
}
184-
185-
#[cfg(test)]
186-
mod tests_simd_floats {
187-
use super::*;
188-
use simd::prelude::*;
189-
190-
#[test]
191-
fn everything_works_f32() {
192-
let x = f32x4::from_array([0.1, 0.5, 0.6, -1.5]);
193-
194-
let x2 = x + x;
195-
let _xc = x.ceil();
196-
let _xf = x.floor();
197-
let _xr = x.round();
198-
let _xt = x.trunc();
199-
let _xfma = x.mul_add(x, x);
200-
let _xsqrt = x.sqrt();
201-
let _abs_mul = x2.abs() * x2;
202-
203-
let _fexp = x.exp();
204-
let _fexp2 = x.exp2();
205-
let _flog = x.log();
206-
let _flog2 = x.log2();
207-
let _flog10 = x.log10();
208-
let _fsin = x.sin();
209-
let _fcos = x.cos();
210-
}
211-
212-
#[test]
213-
fn everything_works_f64() {
214-
let x = f64x4::from_array([0.1, 0.5, 0.6, -1.5]);
215-
216-
let x2 = x + x;
217-
let _xc = x.ceil();
218-
let _xf = x.floor();
219-
let _xr = x.round();
220-
let _xt = x.trunc();
221-
let _xfma = x.mul_add(x, x);
222-
let _xsqrt = x.sqrt();
223-
let _abs_mul = x2.abs() * x2;
224-
225-
let _fexp = x.exp();
226-
let _fexp2 = x.exp2();
227-
let _flog = x.log();
228-
let _flog2 = x.log2();
229-
let _flog10 = x.log10();
230-
let _fsin = x.sin();
231-
let _fcos = x.cos();
232-
}
233-
}

crates/std_float/tests/float.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#![feature(portable_simd)]
2+
3+
macro_rules! unary_test {
4+
{ $scalar:tt, $($func:tt),+ } => {
5+
test_helpers::test_lanes! {
6+
$(
7+
fn $func<const LANES: usize>() {
8+
test_helpers::test_unary_elementwise(
9+
&core_simd::simd::Simd::<$scalar, LANES>::$func,
10+
&$scalar::$func,
11+
&|_| true,
12+
)
13+
}
14+
)*
15+
}
16+
}
17+
}
18+
19+
macro_rules! binary_test {
20+
{ $scalar:tt, $($func:tt),+ } => {
21+
test_helpers::test_lanes! {
22+
$(
23+
fn $func<const LANES: usize>() {
24+
test_helpers::test_binary_elementwise(
25+
&core_simd::simd::Simd::<$scalar, LANES>::$func,
26+
&$scalar::$func,
27+
&|_, _| true,
28+
)
29+
}
30+
)*
31+
}
32+
}
33+
}
34+
35+
macro_rules! ternary_test {
36+
{ $scalar:tt, $($func:tt),+ } => {
37+
test_helpers::test_lanes! {
38+
$(
39+
fn $func<const LANES: usize>() {
40+
test_helpers::test_ternary_elementwise(
41+
&core_simd::simd::Simd::<$scalar, LANES>::$func,
42+
&$scalar::$func,
43+
&|_, _, _| true,
44+
)
45+
}
46+
)*
47+
}
48+
}
49+
}
50+
51+
macro_rules! impl_tests {
52+
{ $scalar:tt } => {
53+
mod $scalar {
54+
use std_float::StdFloat;
55+
56+
unary_test! { $scalar, sqrt, sin, cos, exp, exp2, ln, log2, log10, ceil, floor, round, trunc, fract }
57+
binary_test! { $scalar, log }
58+
ternary_test! { $scalar, mul_add }
59+
}
60+
}
61+
}
62+
63+
impl_tests! { f32 }
64+
impl_tests! { f64 }

0 commit comments

Comments
 (0)