Skip to content

Commit 0ddf7ac

Browse files
committed
Reenable rounding ops
1 parent 9cc3dea commit 0ddf7ac

File tree

3 files changed

+35
-81
lines changed

3 files changed

+35
-81
lines changed

crates/core_simd/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod macros;
99
mod fmt;
1010
mod intrinsics;
1111
mod ops;
12-
//mod round;
12+
mod round;
1313

1414
mod masks;
1515
pub use masks::*;

crates/core_simd/src/round.rs

Lines changed: 34 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,45 @@
11
macro_rules! implement {
22
{
3-
impl $type:ident {
4-
int_type = $int_type:ident
5-
}
3+
$type:ident, $int_type:ident
64
} => {
7-
mod $type {
8-
impl crate::$type {
9-
/// Returns the largest integer less than or equal to each lane.
10-
#[must_use = "method returns a new vector and does not mutate the original value"]
11-
#[inline]
12-
pub fn floor(self) -> Self {
13-
unsafe { crate::intrinsics::simd_floor(self) }
14-
}
5+
impl<const LANES: usize> crate::$type<LANES> {
6+
/// Returns the largest integer less than or equal to each lane.
7+
#[must_use = "method returns a new vector and does not mutate the original value"]
8+
#[inline]
9+
pub fn floor(self) -> Self {
10+
unsafe { crate::intrinsics::simd_floor(self) }
11+
}
1512

16-
/// Returns the smallest integer greater than or equal to each lane.
17-
#[must_use = "method returns a new vector and does not mutate the original value"]
18-
#[inline]
19-
pub fn ceil(self) -> Self {
20-
unsafe { crate::intrinsics::simd_ceil(self) }
21-
}
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 { crate::intrinsics::simd_ceil(self) }
18+
}
2219

23-
/// Rounds toward zero and converts to the same-width integer type, assuming that
24-
/// the value is finite and fits in that type.
25-
///
26-
/// # Safety
27-
/// The value must:
28-
///
29-
/// * Not be NaN
30-
/// * Not be infinite
31-
/// * Be representable in the return type, after truncating off its fractional part
32-
#[inline]
33-
pub unsafe fn to_int_unchecked(self) -> crate::$int_type {
34-
crate::intrinsics::simd_cast(self)
35-
}
20+
/// Rounds toward zero and converts to the same-width integer type, assuming that
21+
/// the value is finite and fits in that type.
22+
///
23+
/// # Safety
24+
/// The value must:
25+
///
26+
/// * Not be NaN
27+
/// * Not be infinite
28+
/// * Be representable in the return type, after truncating off its fractional part
29+
#[inline]
30+
pub unsafe fn to_int_unchecked(self) -> crate::$int_type<LANES> {
31+
crate::intrinsics::simd_cast(self)
32+
}
3633

37-
/// Creates a floating-point vector from an integer vector. Rounds values that are
38-
/// not exactly representable.
39-
#[inline]
40-
pub fn round_from_int(value: crate::$int_type) -> Self {
41-
unsafe { crate::intrinsics::simd_cast(value) }
42-
}
34+
/// Creates a floating-point vector from an integer vector. Rounds values that are
35+
/// not exactly representable.
36+
#[inline]
37+
pub fn round_from_int(value: crate::$int_type<LANES>) -> Self {
38+
unsafe { crate::intrinsics::simd_cast(value) }
4339
}
4440
}
4541
}
4642
}
4743

48-
implement! {
49-
impl f32x2 {
50-
int_type = i32x2
51-
}
52-
}
53-
54-
implement! {
55-
impl f32x4 {
56-
int_type = i32x4
57-
}
58-
}
59-
60-
implement! {
61-
impl f32x8 {
62-
int_type = i32x8
63-
}
64-
}
65-
66-
implement! {
67-
impl f32x16 {
68-
int_type = i32x16
69-
}
70-
}
71-
72-
implement! {
73-
impl f64x2 {
74-
int_type = i64x2
75-
}
76-
}
77-
78-
implement! {
79-
impl f64x4 {
80-
int_type = i64x4
81-
}
82-
}
83-
84-
implement! {
85-
impl f64x8 {
86-
int_type = i64x8
87-
}
88-
}
44+
implement! { SimdF32, SimdI32 }
45+
implement! { SimdF64, SimdI64 }

crates/core_simd/tests/ops_impl/float_macros.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,6 @@ macro_rules! float_tests {
335335
}
336336
}
337337

338-
// TODO reenable after converting float ops to platform intrinsics
339-
/*
340338
#[test]
341339
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
342340
fn ceil_odd_floats() {
@@ -415,7 +413,6 @@ macro_rules! float_tests {
415413
assert_biteq!(core_simd::$vector::round_from_int(v), expected);
416414
}
417415
}
418-
*/
419416
}
420417
}
421418
}

0 commit comments

Comments
 (0)