@@ -98,23 +98,48 @@ mod tests {
9898 use crate :: { core_arch:: x86:: * , mem:: transmute} ;
9999 use stdarch_test:: simd_test;
100100
101+ const F16_ONE : i16 = 0x3c00 ;
102+ const F16_TWO : i16 = 0x4000 ;
103+ const F16_THREE : i16 = 0x4200 ;
104+ const F16_FOUR : i16 = 0x4400 ;
105+ const F16_FIVE : i16 = 0x4500 ;
106+ const F16_SIX : i16 = 0x4600 ;
107+ const F16_SEVEN : i16 = 0x4700 ;
108+ const F16_EIGHT : i16 = 0x4800 ;
109+
101110 #[ simd_test( enable = "f16c" ) ]
102111 unsafe fn test_mm_cvtph_ps ( ) {
103- let array = [ 1_f32 , 2_f32 , 3_f32 , 4_f32 ] ;
104- let float_vec: __m128 = transmute ( array) ;
105- let halfs: __m128i = _mm_cvtps_ph :: < 0 > ( float_vec) ;
106- let floats: __m128 = _mm_cvtph_ps ( halfs) ;
107- let result: [ f32 ; 4 ] = transmute ( floats) ;
108- assert_eq ! ( result, array) ;
112+ let a = _mm_set_epi16 ( 0 , 0 , 0 , 0 , F16_ONE , F16_TWO , F16_THREE , F16_FOUR ) ;
113+ let r = _mm_cvtph_ps ( a) ;
114+ let e = _mm_set_ps ( 1.0 , 2.0 , 3.0 , 4.0 ) ;
115+ assert_eq_m128 ( r, e) ;
109116 }
110117
111118 #[ simd_test( enable = "f16c" ) ]
112119 unsafe fn test_mm256_cvtph_ps ( ) {
113- let array = [ 1_f32 , 2_f32 , 3_f32 , 4_f32 , 5_f32 , 6_f32 , 7_f32 , 8_f32 ] ;
114- let float_vec: __m256 = transmute ( array) ;
115- let halfs: __m128i = _mm256_cvtps_ph :: < 0 > ( float_vec) ;
116- let floats: __m256 = _mm256_cvtph_ps ( halfs) ;
117- let result: [ f32 ; 8 ] = transmute ( floats) ;
118- assert_eq ! ( result, array) ;
120+ let a = _mm_set_epi16 (
121+ F16_ONE , F16_TWO , F16_THREE , F16_FOUR , F16_FIVE , F16_SIX , F16_SEVEN , F16_EIGHT ,
122+ ) ;
123+ let r = _mm256_cvtph_ps ( a) ;
124+ let e = _mm256_set_ps ( 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 , 7.0 , 8.0 ) ;
125+ assert_eq_m256 ( r, e) ;
126+ }
127+
128+ #[ simd_test( enable = "f16c" ) ]
129+ unsafe fn test_mm_cvtps_ph ( ) {
130+ let a = _mm_set_ps ( 1.0 , 2.0 , 3.0 , 4.0 ) ;
131+ let r = _mm_cvtps_ph :: < _MM_FROUND_CUR_DIRECTION > ( a) ;
132+ let e = _mm_set_epi16 ( 0 , 0 , 0 , 0 , F16_ONE , F16_TWO , F16_THREE , F16_FOUR ) ;
133+ assert_eq_m128i ( r, e) ;
134+ }
135+
136+ #[ simd_test( enable = "f16c" ) ]
137+ unsafe fn test_mm256_cvtps_ph ( ) {
138+ let a = _mm256_set_ps ( 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 , 7.0 , 8.0 ) ;
139+ let r = _mm256_cvtps_ph :: < _MM_FROUND_CUR_DIRECTION > ( a) ;
140+ let e = _mm_set_epi16 (
141+ F16_ONE , F16_TWO , F16_THREE , F16_FOUR , F16_FIVE , F16_SIX , F16_SEVEN , F16_EIGHT ,
142+ ) ;
143+ assert_eq_m128i ( r, e) ;
119144 }
120145}
0 commit comments