@@ -65,6 +65,62 @@ pub trait StdFloat: Sealed + Sized {
65
65
unsafe { intrinsics:: simd_fsqrt ( self ) }
66
66
}
67
67
68
+ /// Produces a vector where every lane has the sine of the value
69
+ /// in the equivalently-indexed lane in `self`.
70
+ #[ inline]
71
+ #[ must_use = "method returns a new vector and does not mutate the original value" ]
72
+ fn sin ( self ) -> Self {
73
+ unsafe { intrinsics:: simd_fsin ( self ) }
74
+ }
75
+
76
+ /// Produces a vector where every lane has the cosine of the value
77
+ /// in the equivalently-indexed lane in `self`.
78
+ #[ inline]
79
+ #[ must_use = "method returns a new vector and does not mutate the original value" ]
80
+ fn cos ( self ) -> Self {
81
+ unsafe { intrinsics:: simd_fcos ( self ) }
82
+ }
83
+
84
+ /// Produces a vector where every lane has the exponential (base e) of the value
85
+ /// in the equivalently-indexed lane in `self`.
86
+ #[ inline]
87
+ #[ must_use = "method returns a new vector and does not mutate the original value" ]
88
+ fn exp ( self ) -> Self {
89
+ unsafe { intrinsics:: simd_fexp ( self ) }
90
+ }
91
+
92
+ /// Produces a vector where every lane has the exponential (base 2) of the value
93
+ /// in the equivalently-indexed lane in `self`.
94
+ #[ inline]
95
+ #[ must_use = "method returns a new vector and does not mutate the original value" ]
96
+ fn exp2 ( self ) -> Self {
97
+ unsafe { intrinsics:: simd_fexp2 ( self ) }
98
+ }
99
+
100
+ /// Produces a vector where every lane has the natural logarithm of the value
101
+ /// in the equivalently-indexed lane in `self`.
102
+ #[ inline]
103
+ #[ must_use = "method returns a new vector and does not mutate the original value" ]
104
+ fn log ( self ) -> Self {
105
+ unsafe { intrinsics:: simd_flog ( self ) }
106
+ }
107
+
108
+ /// Produces a vector where every lane has the base-2 logarithm of the value
109
+ /// in the equivalently-indexed lane in `self`.
110
+ #[ inline]
111
+ #[ must_use = "method returns a new vector and does not mutate the original value" ]
112
+ fn log2 ( self ) -> Self {
113
+ unsafe { intrinsics:: simd_flog2 ( self ) }
114
+ }
115
+
116
+ /// Produces a vector where every lane has the base-10 logarithm of the value
117
+ /// in the equivalently-indexed lane in `self`.
118
+ #[ inline]
119
+ #[ must_use = "method returns a new vector and does not mutate the original value" ]
120
+ fn log10 ( self ) -> Self {
121
+ unsafe { intrinsics:: simd_flog10 ( self ) }
122
+ }
123
+
68
124
/// Returns the smallest integer greater than or equal to each lane.
69
125
#[ must_use = "method returns a new vector and does not mutate the original value" ]
70
126
#[ inline]
@@ -127,20 +183,51 @@ where
127
183
}
128
184
129
185
#[ cfg( test) ]
130
- mod tests {
186
+ mod tests_simd_floats {
131
187
use super :: * ;
132
188
use simd:: prelude:: * ;
133
189
134
190
#[ test]
135
- fn everything_works ( ) {
191
+ fn everything_works_f32 ( ) {
136
192
let x = f32x4:: from_array ( [ 0.1 , 0.5 , 0.6 , -1.5 ] ) ;
193
+
194
+ let x2 = x + x;
195
+ let _xc = x. ceil ( ) ;
196
+ let _xf = x. floor ( ) ;
197
+ let _xr = x. round ( ) ;
198
+ let _xt = x. trunc ( ) ;
199
+ let _xfma = x. mul_add ( x, x) ;
200
+ let _xsqrt = x. sqrt ( ) ;
201
+ let _abs_mul = x2. abs ( ) * x2;
202
+
203
+ let _fexp = x. exp ( ) ;
204
+ let _fexp2 = x. exp2 ( ) ;
205
+ let _flog = x. log ( ) ;
206
+ let _flog2 = x. log2 ( ) ;
207
+ let _flog10 = x. log10 ( ) ;
208
+ let _fsin = x. sin ( ) ;
209
+ let _fcos = x. cos ( ) ;
210
+ }
211
+
212
+ #[ test]
213
+ fn everything_works_f64 ( ) {
214
+ let x = f64x4:: from_array ( [ 0.1 , 0.5 , 0.6 , -1.5 ] ) ;
215
+
137
216
let x2 = x + x;
138
217
let _xc = x. ceil ( ) ;
139
218
let _xf = x. floor ( ) ;
140
219
let _xr = x. round ( ) ;
141
220
let _xt = x. trunc ( ) ;
142
221
let _xfma = x. mul_add ( x, x) ;
143
222
let _xsqrt = x. sqrt ( ) ;
144
- let _ = x2. abs ( ) * x2;
223
+ let _abs_mul = x2. abs ( ) * x2;
224
+
225
+ let _fexp = x. exp ( ) ;
226
+ let _fexp2 = x. exp2 ( ) ;
227
+ let _flog = x. log ( ) ;
228
+ let _flog2 = x. log2 ( ) ;
229
+ let _flog10 = x. log10 ( ) ;
230
+ let _fsin = x. sin ( ) ;
231
+ let _fcos = x. cos ( ) ;
145
232
}
146
233
}
0 commit comments