Skip to content

Commit 3e7a2ed

Browse files
Merge pull request rust-lang#281 from rust-lang/to-int-unchecked
Deduplicate to_int_unchecked
2 parents f237f13 + 5562b02 commit 3e7a2ed

File tree

3 files changed

+25
-43
lines changed

3 files changed

+25
-43
lines changed

crates/core_simd/src/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ mod lane_count;
1414
mod masks;
1515
mod ops;
1616
mod ord;
17-
mod round;
1817
mod select;
1918
mod vector;
2019
mod vendor;

crates/core_simd/src/round.rs

Lines changed: 0 additions & 42 deletions
This file was deleted.

crates/core_simd/src/vector.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,31 @@ where
217217
unsafe { intrinsics::simd_as(self) }
218218
}
219219

220+
/// Rounds toward zero and converts to the same-width integer type, assuming that
221+
/// the value is finite and fits in that type.
222+
///
223+
/// # Safety
224+
/// The value must:
225+
///
226+
/// * Not be NaN
227+
/// * Not be infinite
228+
/// * Be representable in the return type, after truncating off its fractional part
229+
///
230+
/// If these requirements are infeasible or costly, consider using the safe function [cast],
231+
/// which saturates on conversion.
232+
///
233+
/// [cast]: Simd::cast
234+
#[inline]
235+
pub unsafe fn to_int_unchecked<I>(self) -> Simd<I, LANES>
236+
where
237+
T: core::convert::FloatToInt<I>,
238+
I: SimdElement,
239+
{
240+
// Safety: `self` is a vector, and `FloatToInt` ensures the type can be casted to
241+
// an integer.
242+
unsafe { intrinsics::simd_cast(self) }
243+
}
244+
220245
/// Reads from potentially discontiguous indices in `slice` to construct a SIMD vector.
221246
/// If an index is out-of-bounds, the lane is instead selected from the `or` vector.
222247
///

0 commit comments

Comments
 (0)