Skip to content

Commit 6ba0b5c

Browse files
Genericize to_int_unchecked
1 parent 870607d commit 6ba0b5c

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

crates/core_simd/src/lib.rs

Lines changed: 1 addition & 0 deletions
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

Lines changed: 10 additions & 5 deletions
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 }

0 commit comments

Comments
 (0)