@@ -95,46 +95,18 @@ wmul_impl_usize! { u32 }
95
95
wmul_impl_usize ! { u64 }
96
96
97
97
98
- pub trait CastFromInt < T > {
99
- fn cast_from_int ( i : T ) -> Self ;
100
- }
101
-
102
- impl CastFromInt < u32 > for f32 {
103
- fn cast_from_int ( i : u32 ) -> Self { i as f32 }
104
- }
105
-
106
- impl CastFromInt < u64 > for f64 {
107
- fn cast_from_int ( i : u64 ) -> Self { i as f64 }
108
- }
109
-
110
- #[ cfg( feature="simd_support" ) ]
111
- macro_rules! simd_float_from_int {
112
- ( $ty: ident, $uty: ident) => {
113
- impl CastFromInt <$uty> for $ty {
114
- fn cast_from_int( i: $uty) -> Self { $ty:: from( i) }
115
- }
116
- }
117
- }
118
-
119
- #[ cfg( feature="simd_support" ) ] simd_float_from_int ! { f32x2, u32x2 }
120
- #[ cfg( feature="simd_support" ) ] simd_float_from_int ! { f32x4, u32x4 }
121
- #[ cfg( feature="simd_support" ) ] simd_float_from_int ! { f32x8, u32x8 }
122
- #[ cfg( feature="simd_support" ) ] simd_float_from_int ! { f32x16, u32x16 }
123
- #[ cfg( feature="simd_support" ) ] simd_float_from_int ! { f64x2, u64x2 }
124
- #[ cfg( feature="simd_support" ) ] simd_float_from_int ! { f64x4, u64x4 }
125
- #[ cfg( feature="simd_support" ) ] simd_float_from_int ! { f64x8, u64x8 }
126
-
127
-
128
- /// `PartialOrd` for vectors compares lexicographically. We want to compare all
129
- /// the individual SIMD lanes instead, and get the combined result over all
130
- /// lanes. This is possible using something like `a.lt(b).all()`, but we
131
- /// implement it as a trait so we can write the same code for `f32` and `f64`.
132
- /// Only the comparison functions we need are implemented.
133
- pub trait CompareAll {
134
- type Mask ;
98
+ /// Helper trait when dealing with scalar and SIMD floating point types.
99
+ pub ( crate ) trait FloatSIMDUtils {
100
+ // `PartialOrd` for vectors compares lexicographically. We want to compare all
101
+ // the individual SIMD lanes instead, and get the combined result over all
102
+ // lanes. This is possible using something like `a.lt(b).all()`, but we
103
+ // implement it as a trait so we can write the same code for `f32` and `f64`.
104
+ // Only the comparison functions we need are implemented.
135
105
fn all_lt ( self , other : Self ) -> bool ;
136
106
fn all_le ( self , other : Self ) -> bool ;
137
107
fn all_finite ( self ) -> bool ;
108
+
109
+ type Mask ;
138
110
fn finite_mask ( self ) -> Self :: Mask ;
139
111
fn gt_mask ( self , other : Self ) -> Self :: Mask ;
140
112
fn ge_mask ( self , other : Self ) -> Self :: Mask ;
@@ -143,9 +115,14 @@ pub trait CompareAll {
143
115
// representable by the floating-point type. At least one of the lanes
144
116
// must be set.
145
117
fn decrease_masked ( self , mask : Self :: Mask ) -> Self ;
118
+
119
+ // Convert from int value. Conversion is done while retaining the numerical
120
+ // value, not by retaining the binary representation.
121
+ type UInt ;
122
+ fn cast_from_int ( i : Self :: UInt ) -> Self ;
146
123
}
147
124
148
- // Implement functions available in std builds but missing from core primitives
125
+ /// Implement functions available in std builds but missing from core primitives
149
126
#[ cfg( not( std) ) ]
150
127
pub ( crate ) trait Float : Sized {
151
128
type Bits ;
@@ -157,7 +134,7 @@ pub(crate) trait Float : Sized {
157
134
fn from_bits ( v : Self :: Bits ) -> Self ;
158
135
}
159
136
160
- // Implement functions on f32/f64 to give them APIs similar to SIMD types
137
+ /// Implement functions on f32/f64 to give them APIs similar to SIMD types
161
138
pub ( crate ) trait FloatAsSIMD : Sized {
162
139
#[ inline( always) ]
163
140
fn lanes ( ) -> usize { 1 }
@@ -217,7 +194,7 @@ macro_rules! scalar_float_impl {
217
194
}
218
195
}
219
196
220
- impl CompareAll for $ty {
197
+ impl FloatSIMDUtils for $ty {
221
198
type Mask = bool ;
222
199
#[ inline( always) ]
223
200
fn all_lt( self , other: Self ) -> bool { self < other }
@@ -236,6 +213,8 @@ macro_rules! scalar_float_impl {
236
213
debug_assert!( mask, "At least one lane must be set" ) ;
237
214
<$ty>:: from_bits( self . to_bits( ) - 1 )
238
215
}
216
+ type UInt = $uty;
217
+ fn cast_from_int( i: Self :: UInt ) -> Self { i as $ty }
239
218
}
240
219
241
220
impl FloatAsSIMD for $ty { }
@@ -249,7 +228,7 @@ scalar_float_impl!(f64, u64);
249
228
#[ cfg( feature="simd_support" ) ]
250
229
macro_rules! simd_impl {
251
230
( $ty: ident, $f_scalar: ident, $mty: ident, $uty: ident) => {
252
- impl CompareAll for $ty {
231
+ impl FloatSIMDUtils for $ty {
253
232
type Mask = $mty;
254
233
#[ inline( always) ]
255
234
fn all_lt( self , other: Self ) -> bool { self . lt( other) . all( ) }
@@ -279,6 +258,8 @@ macro_rules! simd_impl {
279
258
debug_assert!( mask. any( ) , "At least one lane must be set" ) ;
280
259
<$ty>:: from_bits( <$uty>:: from_bits( self ) + <$uty>:: from_bits( mask) )
281
260
}
261
+ type UInt = $uty;
262
+ fn cast_from_int( i: Self :: UInt ) -> Self { $ty:: from( i) }
282
263
}
283
264
}
284
265
}
0 commit comments