Skip to content

Commit 4910274

Browse files
Genericize to_int_unchecked
1 parent ebf65de commit 4910274

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

crates/core_simd/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![cfg_attr(not(feature = "std"), no_std)]
22
#![feature(
33
const_fn_trait_bound,
4+
convert_float_to_int,
45
decl_macro,
56
platform_intrinsics,
67
repr_simd,

crates/core_simd/src/round.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::simd::intrinsics;
2-
use crate::simd::{LaneCount, Simd, SupportedLaneCount};
2+
use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount};
3+
use core::convert::FloatToInt;
34

45
macro_rules! implement {
56
{
6-
$type:ty, $int_type:ty
7+
$type:ty
78
} => {
89
impl<const LANES: usize> Simd<$type, LANES>
910
where
@@ -19,12 +20,16 @@ macro_rules! implement {
1920
/// * Not be infinite
2021
/// * Be representable in the return type, after truncating off its fractional part
2122
#[inline]
22-
pub unsafe fn to_int_unchecked(self) -> Simd<$int_type, LANES> {
23+
pub unsafe fn to_int_unchecked<I>(self) -> Simd<I, LANES>
24+
where
25+
$type: FloatToInt<I>,
26+
I: SimdElement,
27+
{
2328
unsafe { intrinsics::simd_cast(self) }
2429
}
2530
}
2631
}
2732
}
2833

29-
implement! { f32, i32 }
30-
implement! { f64, i64 }
34+
implement! { f32 }
35+
implement! { f64 }

crates/core_simd/tests/round.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ macro_rules! float_rounding_test {
6464
runner.run(
6565
&test_helpers::array::UniformArrayStrategy::new(-MAX_REPRESENTABLE_VALUE..MAX_REPRESENTABLE_VALUE),
6666
|x| {
67-
let result_1 = unsafe { Vector::from_array(x).to_int_unchecked().to_array() };
67+
let result_1 = unsafe { Vector::from_array(x).to_int_unchecked::<IntScalar>().to_array() };
6868
let result_2 = {
69-
let mut result = [0; LANES];
69+
let mut result: [IntScalar; LANES] = [0; LANES];
7070
for (i, o) in x.iter().zip(result.iter_mut()) {
71-
*o = unsafe { i.to_int_unchecked() };
71+
*o = unsafe { i.to_int_unchecked::<IntScalar>() };
7272
}
7373
result
7474
};

0 commit comments

Comments
 (0)