]> git.proxmox.com Git - rustc.git/blob - library/portable-simd/crates/core_simd/src/round.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / library / portable-simd / crates / core_simd / src / round.rs
1 use crate::simd::intrinsics;
2 use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount};
3 use core::convert::FloatToInt;
4
5 macro_rules! implement {
6 {
7 $type:ty
8 } => {
9 impl<const LANES: usize> Simd<$type, LANES>
10 where
11 LaneCount<LANES>: SupportedLaneCount,
12 {
13 /// Rounds toward zero and converts to the same-width integer type, assuming that
14 /// the value is finite and fits in that type.
15 ///
16 /// # Safety
17 /// The value must:
18 ///
19 /// * Not be NaN
20 /// * Not be infinite
21 /// * Be representable in the return type, after truncating off its fractional part
22 ///
23 /// If these requirements are infeasible or costly, consider using the safe function [cast],
24 /// which saturates on conversion.
25 ///
26 /// [cast]: Simd::cast
27 #[inline]
28 pub unsafe fn to_int_unchecked<I>(self) -> Simd<I, LANES>
29 where
30 $type: FloatToInt<I>,
31 I: SimdElement,
32 {
33 unsafe { intrinsics::simd_cast(self) }
34 }
35 }
36 }
37 }
38
39 implement! { f32 }
40 implement! { f64 }