1 macro_rules! implement {
4 int_type = $int_type:ident,
5 floor = $floor_intrinsic:literal,
6 ceil = $ceil_intrinsic:literal,
7 round = $round_intrinsic:literal,
8 trunc = $trunc_intrinsic:literal,
12 #[allow(improper_ctypes)]
14 #[link_name = $floor_intrinsic]
15 fn floor_intrinsic(x: crate::$type) -> crate::$type;
16 #[link_name = $ceil_intrinsic]
17 fn ceil_intrinsic(x: crate::$type) -> crate::$type;
18 #[link_name = $round_intrinsic]
19 fn round_intrinsic(x: crate::$type) -> crate::$type;
20 #[link_name = $trunc_intrinsic]
21 fn trunc_intrinsic(x: crate::$type) -> crate::$type;
25 /// Returns the largest integer less than or equal to each lane.
26 #[must_use = "method returns a new vector and does not mutate the original value"]
28 pub fn floor(self) -> Self {
29 unsafe { floor_intrinsic(self) }
32 /// Returns the smallest integer greater than or equal to each lane.
33 #[must_use = "method returns a new vector and does not mutate the original value"]
35 pub fn ceil(self) -> Self {
36 unsafe { ceil_intrinsic(self) }
39 /// Returns the nearest integer to each lane. Round half-way cases away from 0.0.
40 #[must_use = "method returns a new vector and does not mutate the original value"]
42 pub fn round(self) -> Self {
43 unsafe { round_intrinsic(self) }
46 /// Returns the integer part of each lane.
47 #[must_use = "method returns a new vector and does not mutate the original value"]
49 pub fn trunc(self) -> Self {
50 unsafe { trunc_intrinsic(self) }
53 /// Returns the fractional part of each lane.
54 #[must_use = "method returns a new vector and does not mutate the original value"]
56 pub fn fract(self) -> Self {
60 /// Rounds toward zero and converts to the same-width integer type, assuming that
61 /// the value is finite and fits in that type.
68 /// * Be representable in the return type, after truncating off its fractional part
70 pub unsafe fn to_int_unchecked(self) -> crate::$int_type {
71 crate::intrinsics::simd_cast(self)
74 /// Creates a floating-point vector from an integer vector. Rounds values that are
75 /// not exactly representable.
77 pub fn round_from_int(value: crate::$int_type) -> Self {
78 unsafe { crate::intrinsics::simd_cast(value) }
88 floor = "llvm.floor.v2f32",
89 ceil = "llvm.ceil.v2f32",
90 round = "llvm.round.v2f32",
91 trunc = "llvm.trunc.v2f32",
98 floor = "llvm.floor.v4f32",
99 ceil = "llvm.ceil.v4f32",
100 round = "llvm.round.v4f32",
101 trunc = "llvm.trunc.v4f32",
108 floor = "llvm.floor.v8f32",
109 ceil = "llvm.ceil.v8f32",
110 round = "llvm.round.v8f32",
111 trunc = "llvm.trunc.v8f32",
118 floor = "llvm.floor.v16f32",
119 ceil = "llvm.ceil.v16f32",
120 round = "llvm.round.v16f32",
121 trunc = "llvm.trunc.v16f32",
128 floor = "llvm.floor.v2f64",
129 ceil = "llvm.ceil.v2f64",
130 round = "llvm.round.v2f64",
131 trunc = "llvm.trunc.v2f64",
138 floor = "llvm.floor.v4f64",
139 ceil = "llvm.ceil.v4f64",
140 round = "llvm.round.v4f64",
141 trunc = "llvm.trunc.v4f64",
148 floor = "llvm.floor.v8f64",
149 ceil = "llvm.ceil.v8f64",
150 round = "llvm.round.v8f64",
151 trunc = "llvm.trunc.v8f64",