1
1
macro_rules! implement {
2
2
{
3
3
impl $type: ident {
4
+ int_type = $int_type: ident,
4
5
floor = $floor_intrinsic: literal,
5
6
ceil = $ceil_intrinsic: literal,
6
7
round = $round_intrinsic: literal,
7
8
trunc = $trunc_intrinsic: literal,
9
+ round_to_int = $round_to_int_intrinsic: literal,
8
10
}
9
11
} => {
10
12
mod $type {
@@ -18,6 +20,8 @@ macro_rules! implement {
18
20
fn round_intrinsic( x: crate :: $type) -> crate :: $type;
19
21
#[ link_name = $trunc_intrinsic]
20
22
fn trunc_intrinsic( x: crate :: $type) -> crate :: $type;
23
+ #[ link_name = $round_to_int_intrinsic]
24
+ fn round_to_int_intrinsic( x: crate :: $type) -> crate :: $int_type;
21
25
}
22
26
23
27
impl crate :: $type {
@@ -55,70 +59,91 @@ macro_rules! implement {
55
59
pub fn fract( self ) -> Self {
56
60
self - self . trunc( )
57
61
}
62
+
63
+ /// Returns the nearest integer to each lane. Round half-way cases away from 0.0.
64
+ #[ must_use = "method returns a new vector and does not mutate the original value" ]
65
+ #[ inline]
66
+ pub fn round_to_int( self ) -> crate :: $int_type {
67
+ unsafe { round_to_int_intrinsic( self ) }
68
+ }
58
69
}
59
70
}
60
71
}
61
72
}
62
73
63
74
implement ! {
64
75
impl f32x2 {
76
+ int_type = i32x2,
65
77
floor = "llvm.floor.v2f32" ,
66
78
ceil = "llvm.ceil.v2f32" ,
67
79
round = "llvm.round.v2f32" ,
68
80
trunc = "llvm.trunc.v2f32" ,
81
+ round_to_int = "llvm.lround.i32.v2f32" ,
69
82
}
70
83
}
71
84
72
85
implement ! {
73
86
impl f32x4 {
87
+ int_type = i32x4,
74
88
floor = "llvm.floor.v4f32" ,
75
89
ceil = "llvm.ceil.v4f32" ,
76
90
round = "llvm.round.v4f32" ,
77
91
trunc = "llvm.trunc.v4f32" ,
92
+ round_to_int = "llvm.lround.i32.v4f32" ,
78
93
}
79
94
}
80
95
81
96
implement ! {
82
97
impl f32x8 {
98
+ int_type = i32x8,
83
99
floor = "llvm.floor.v8f32" ,
84
100
ceil = "llvm.ceil.v8f32" ,
85
101
round = "llvm.round.v8f32" ,
86
102
trunc = "llvm.trunc.v8f32" ,
103
+ round_to_int = "llvm.lround.i32.v8f32" ,
87
104
}
88
105
}
89
106
90
107
implement ! {
91
108
impl f32x16 {
109
+ int_type = i32x16,
92
110
floor = "llvm.floor.v16f32" ,
93
111
ceil = "llvm.ceil.v16f32" ,
94
112
round = "llvm.round.v16f32" ,
95
113
trunc = "llvm.trunc.v16f32" ,
114
+ round_to_int = "llvm.lround.i32.v16f32" ,
96
115
}
97
116
}
98
117
99
118
implement ! {
100
119
impl f64x2 {
120
+ int_type = i64x2,
101
121
floor = "llvm.floor.v2f64" ,
102
122
ceil = "llvm.ceil.v2f64" ,
103
123
round = "llvm.round.v2f64" ,
104
124
trunc = "llvm.trunc.v2f64" ,
125
+ round_to_int = "llvm.lround.i64.v2f64" ,
105
126
}
106
127
}
107
128
108
129
implement ! {
109
130
impl f64x4 {
131
+ int_type = i64x4,
110
132
floor = "llvm.floor.v4f64" ,
111
133
ceil = "llvm.ceil.v4f64" ,
112
134
round = "llvm.round.v4f64" ,
113
135
trunc = "llvm.trunc.v4f64" ,
136
+ round_to_int = "llvm.lround.i64.v4f64" ,
114
137
}
115
138
}
116
139
117
140
implement ! {
118
141
impl f64x8 {
142
+ int_type = i64x8,
119
143
floor = "llvm.floor.v8f64" ,
120
144
ceil = "llvm.ceil.v8f64" ,
121
145
round = "llvm.round.v8f64" ,
122
146
trunc = "llvm.trunc.v8f64" ,
147
+ round_to_int = "llvm.lround.i64.v8f64" ,
123
148
}
124
149
}
0 commit comments