@@ -350,10 +350,9 @@ mod sealed {
350350 }
351351
352352 macro_rules! impl_abs {
353- ( $name: ident, $ty: ident, $instr : ident ) => {
353+ ( $name: ident, $ty: ident) => {
354354 #[ inline]
355355 #[ target_feature( enable = "vector" ) ]
356- #[ cfg_attr( test, assert_instr( $instr) ) ]
357356 unsafe fn $name( v: s_t_l!( $ty) ) -> s_t_l!( $ty) {
358357 v. vec_max( -v)
359358 }
@@ -385,6 +384,72 @@ mod sealed {
385384
386385 impl_vec_trait ! { [ VectorAbs vec_abs] vec_abs_f32 ( vector_float) }
387386 impl_vec_trait ! { [ VectorAbs vec_abs] vec_abs_f64 ( vector_double) }
387+
388+ #[ unstable( feature = "stdarch_s390x" , issue = "135681" ) ]
389+ pub trait VectorSplats < Output > {
390+ unsafe fn vec_splats ( self ) -> Output ;
391+ }
392+
393+ macro_rules! impl_vec_splats {
394+ ( $( ( $fn: ident ( $ty: ty, $shortty: tt) $instr: ident) ) ,* ) => {
395+ $(
396+ #[ inline]
397+ #[ target_feature( enable = "vector" ) ]
398+ #[ cfg_attr( test, assert_instr( $instr) ) ]
399+ pub unsafe fn $fn( v: $ty) -> s_t_l!( $shortty) {
400+ transmute( $shortty:: splat( v) )
401+ }
402+
403+ #[ unstable( feature = "stdarch_s390x" , issue = "135681" ) ]
404+ impl VectorSplats <s_t_l!( $shortty) > for $ty {
405+ #[ inline]
406+ #[ target_feature( enable = "vector" ) ]
407+ unsafe fn vec_splats( self ) -> s_t_l!( $shortty) {
408+ $fn ( self )
409+ }
410+ }
411+ ) *
412+ }
413+ }
414+
415+ impl_vec_splats ! {
416+ ( vec_splats_u8 ( u8 , u8x16) vrepb) ,
417+ ( vec_splats_i8 ( i8 , i8x16) vrepb) ,
418+ ( vec_splats_u16 ( u16 , u16x8) vreph) ,
419+ ( vec_splats_i16 ( i16 , i16x8) vreph) ,
420+ ( vec_splats_u32 ( u32 , u32x4) vrepf) ,
421+ ( vec_splats_i32 ( i32 , i32x4) vrepf) ,
422+ ( vec_splats_u64 ( u64 , u64x2) vlvgp) ,
423+ ( vec_splats_i64 ( i64 , i64x2) vlvgp) ,
424+ ( vec_splats_f32 ( f32 , f32x4) vrepf) ,
425+ ( vec_splats_f64 ( f64 , f64x2) vrepg)
426+ }
427+
428+ macro_rules! impl_bool_vec_splats {
429+ ( $( ( $ty: ty, $shortty: tt, $boolty: ty) ) ,* ) => {
430+ $(
431+ #[ unstable( feature = "stdarch_s390x" , issue = "135681" ) ]
432+ impl VectorSplats <$boolty> for $ty {
433+ #[ inline]
434+ #[ target_feature( enable = "vector" ) ]
435+ unsafe fn vec_splats( self ) -> $boolty {
436+ transmute( $shortty:: splat( self ) )
437+ }
438+ }
439+ ) *
440+ }
441+ }
442+
443+ impl_bool_vec_splats ! {
444+ ( u8 , u8x16, vector_bool_char) ,
445+ ( i8 , i8x16, vector_bool_char) ,
446+ ( u16 , u16x8, vector_bool_short) ,
447+ ( i16 , i16x8, vector_bool_short) ,
448+ ( u32 , u32x4, vector_bool_int) ,
449+ ( i32 , i32x4, vector_bool_int) ,
450+ ( u64 , u64x2, vector_bool_long_long) ,
451+ ( i64 , i64x2, vector_bool_long_long)
452+ }
388453}
389454
390455/// Vector pointwise addition.
@@ -459,6 +524,17 @@ where
459524 a. vec_abs ( )
460525}
461526
527+ /// Vector splats.
528+ #[ inline]
529+ #[ target_feature( enable = "vector" ) ]
530+ #[ unstable( feature = "stdarch_s390x" , issue = "135681" ) ]
531+ pub unsafe fn vec_splats < T , U > ( a : T ) -> U
532+ where
533+ T : sealed:: VectorSplats < U > ,
534+ {
535+ a. vec_splats ( )
536+ }
537+
462538#[ cfg( test) ]
463539mod tests {
464540 use super :: * ;
@@ -616,4 +692,23 @@ mod tests {
616692 [ 0 , u8 :: MAX - 1 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 8 , 7 , 6 , 5 , 4 ] ,
617693 [ 5 , 6 , 7 , 8 , 9 , 8 , 7 , 6 , 5 , 4 , 0 , u8 :: MAX , 1 , 2 , 3 , 4 ] ,
618694 [ 0 , 244 , 7 , 16 , 27 , 32 , 35 , 36 , 35 , 32 , 0 , 248 , 7 , 12 , 15 , 16 ] }
695+
696+ macro_rules! test_vec_abs {
697+ { $name: ident, $ty: ident, $a: expr, $d: expr } => {
698+ #[ simd_test( enable = "vector" ) ]
699+ unsafe fn $name( ) {
700+ let a: s_t_l!( $ty) = vec_splats( $a) ;
701+ let a: s_t_l!( $ty) = vec_abs( a) ;
702+ let d = $ty:: splat( $d) ;
703+ assert_eq!( d, transmute( a) ) ;
704+ }
705+ }
706+ }
707+
708+ test_vec_abs ! { test_vec_abs_i8, i8x16, -42i8 , 42i8 }
709+ test_vec_abs ! { test_vec_abs_i16, i16x8, -42i16 , 42i16 }
710+ test_vec_abs ! { test_vec_abs_i32, i32x4, -42i32 , 42i32 }
711+ test_vec_abs ! { test_vec_abs_i64, i64x2, -42i64 , 42i64 }
712+ test_vec_abs ! { test_vec_abs_f32, f32x4, -42f32 , 42f32 }
713+ test_vec_abs ! { test_vec_abs_f64, f64x2, -42f64 , 42f64 }
619714}
0 commit comments