88
99#![ allow( non_camel_case_types) ]
1010
11+ use super :: macros:: * ;
1112use crate :: core_arch:: powerpc:: * ;
1213use crate :: core_arch:: simd:: * ;
13- use super :: macros:: * ;
1414
1515#[ cfg( test) ]
1616use stdarch_test:: assert_instr;
1717
18- use crate :: mem:: transmute;
18+ use crate :: mem:: { self , transmute} ;
1919
2020types ! {
2121 #![ unstable( feature = "stdarch_powerpc" , issue = "111145" ) ]
@@ -172,11 +172,15 @@ mod sealed {
172172 vec_mergeeo ! { vector_unsigned_int, mergee, mergeo }
173173 vec_mergeeo ! { vector_bool_int, mergee, mergeo }
174174 vec_mergeeo ! { vector_float, mergee, mergeo }
175- }
176175
177- // Implement AltiVec's VectorSld trait for vector_double to enable vec_sld support
178- use crate :: core_arch:: powerpc:: altivec:: sealed:: { VectorSld , vsldoi, xxsldwi} ;
179- impl_vec_sld ! { vector_double }
176+ // Implement vec_xl for f64 (vector_double).
177+ use crate :: core_arch:: powerpc:: altivec:: sealed:: VectorXl ;
178+ impl_vec_xl ! { vec_xl_f64 lxvd2x / lxv f64 }
179+
180+ // Implement vec_sld for vector_double.
181+ use crate :: core_arch:: powerpc:: altivec:: sealed:: { VectorSld , vsldoi, xxsldwi} ;
182+ impl_vec_sld ! { vector_double }
183+ }
180184
181185/// Vector permute.
182186#[ inline]
@@ -268,9 +272,9 @@ mod tests {
268272 let a = vector_double:: from ( f64x2:: from_array ( [ 1.0 , 2.0 ] ) ) ;
269273 let b = vector_double:: from ( f64x2:: from_array ( [ 3.0 , 4.0 ] ) ) ;
270274
271- // Shift left by 8 bytes (1 f64 element)
272- // On little-endian: shifts right in memory, result is [b[1], a[0]] = [4.0, 1.0]
273- // On big-endian: shifts left in memory, result is [a[1], b[0]] = [2.0, 3.0]
275+ // Shift left by 8 bytes (1 f64 element).
276+ // On little-endian: shifts right in memory, result is [b[1], a[0]] = [4.0, 1.0].
277+ // On big-endian: shifts left in memory, result is [a[1], b[0]] = [2.0, 3.0].
274278 unsafe {
275279 let result: f64x2 = transmute ( a. vec_sld :: < 8 > ( b) ) ;
276280 #[ cfg( target_endian = "little" ) ]
@@ -280,4 +284,55 @@ mod tests {
280284 assert_eq ! ( result, expected) ;
281285 }
282286 }
287+
288+ #[ simd_test( enable = "vsx" ) ]
289+ fn test_vec_sldw_f64x2 ( ) {
290+ use crate :: core_arch:: powerpc:: altivec:: sealed:: VectorSld ;
291+
292+ let a = vector_double:: from ( f64x2:: from_array ( [ 1.0 , 2.0 ] ) ) ;
293+ let b = vector_double:: from ( f64x2:: from_array ( [ 3.0 , 4.0 ] ) ) ;
294+
295+ // Shift left by 1 word (4 bytes).
296+ // vec_sldw shifts by words (4-byte units), so UIMM2=1 means shift by 4 bytes
297+ // whic is equivalent to vec_sld with UIMM4=4.
298+ unsafe {
299+ let result: f64x2 = transmute ( a. vec_sldw :: < 1 > ( b) ) ;
300+ // Shifting by 4 bytes (half of an f64) will mix the high/low parts.
301+ // On little-endian: shifts right in memory, result is [b[1], a[0]] but with 4-byte shift.
302+ // On big-endian: shifts left in memory, result is [a[1], b[0]] but with 4-byte shift.
303+ // Since we're shifting by 4 bytes (half an f64), the result will have mixed bits.
304+ // Verify using vec_sld with the same shift amount for comparison.
305+ let expected: f64x2 = transmute ( a. vec_sld :: < 4 > ( b) ) ;
306+ assert_eq ! ( result, expected) ;
307+ }
308+ }
309+
310+ #[ simd_test( enable = "vsx" ) ]
311+ fn test_vec_xl_f64 ( ) {
312+ let pat = [ 1.0f64 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 , 7.0 , 8.0 ] ;
313+
314+ // Test loading from aligned offset 0
315+ unsafe {
316+ let result = vec_xl ( 0 , pat. as_ptr ( ) ) ;
317+ let result_f64: f64x2 = transmute ( result) ;
318+ assert_eq ! ( result_f64. as_array( ) [ 0 ] , 1.0 ) ;
319+ assert_eq ! ( result_f64. as_array( ) [ 1 ] , 2.0 ) ;
320+ }
321+
322+ // Test loading from offset 16 (2 f64 elements = 16 bytes)
323+ unsafe {
324+ let result = vec_xl ( 16 , pat. as_ptr ( ) ) ;
325+ let result_f64: f64x2 = transmute ( result) ;
326+ assert_eq ! ( result_f64. as_array( ) [ 0 ] , 3.0 ) ;
327+ assert_eq ! ( result_f64. as_array( ) [ 1 ] , 4.0 ) ;
328+ }
329+
330+ // Test loading from offset 32 (4 f64 elements = 32 bytes)
331+ unsafe {
332+ let result = vec_xl ( 32 , pat. as_ptr ( ) ) ;
333+ let result_f64: f64x2 = transmute ( result) ;
334+ assert_eq ! ( result_f64. as_array( ) [ 0 ] , 5.0 ) ;
335+ assert_eq ! ( result_f64. as_array( ) [ 1 ] , 6.0 ) ;
336+ }
337+ }
283338}
0 commit comments