Skip to content

Commit

Permalink
Deduplicate to_int_unchecked
Browse files Browse the repository at this point in the history
  • Loading branch information
calebzulawski committed Jun 2, 2022
1 parent f237f13 commit 5562b02
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 43 deletions.
1 change: 0 additions & 1 deletion crates/core_simd/src/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ mod lane_count;
mod masks;
mod ops;
mod ord;
mod round;
mod select;
mod vector;
mod vendor;
Expand Down
42 changes: 0 additions & 42 deletions crates/core_simd/src/round.rs

This file was deleted.

25 changes: 25 additions & 0 deletions crates/core_simd/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,31 @@ where
unsafe { intrinsics::simd_as(self) }
}

/// Rounds toward zero and converts to the same-width integer type, assuming that
/// the value is finite and fits in that type.
///
/// # Safety
/// The value must:
///
/// * Not be NaN
/// * Not be infinite
/// * Be representable in the return type, after truncating off its fractional part
///
/// If these requirements are infeasible or costly, consider using the safe function [cast],
/// which saturates on conversion.
///
/// [cast]: Simd::cast
#[inline]
pub unsafe fn to_int_unchecked<I>(self) -> Simd<I, LANES>
where
T: core::convert::FloatToInt<I>,
I: SimdElement,
{
// Safety: `self` is a vector, and `FloatToInt` ensures the type can be casted to
// an integer.
unsafe { intrinsics::simd_cast(self) }
}

/// Reads from potentially discontiguous indices in `slice` to construct a SIMD vector.
/// If an index is out-of-bounds, the lane is instead selected from the `or` vector.
///
Expand Down

0 comments on commit 5562b02

Please sign in to comment.