@@ -2667,6 +2667,58 @@ mod sealed {
2667
2667
vgef vector_float
2668
2668
vgeg vector_double
2669
2669
}
2670
+
2671
+ #[ unstable( feature = "stdarch_s390x" , issue = "135681" ) ]
2672
+ pub trait VectorSel < Mask > : Sized {
2673
+ unsafe fn vec_sel ( self , b : Self , c : Mask ) -> Self ;
2674
+ }
2675
+
2676
+ macro_rules! impl_vec_sel {
2677
+ ( $( $ty: ident) * ) => {
2678
+ $(
2679
+ #[ unstable( feature = "stdarch_s390x" , issue = "135681" ) ]
2680
+ impl VectorSel <t_u!( $ty) > for $ty {
2681
+ #[ inline]
2682
+ #[ target_feature( enable = "vector" ) ]
2683
+ unsafe fn vec_sel( self , b: Self , c: t_u!( $ty) ) -> Self {
2684
+ let b = simd_and( b, transmute( c) ) ;
2685
+ let a = simd_and( self , simd_xor( transmute( c) , transmute( vector_signed_char( [ !0 ; 16 ] ) ) ) ) ;
2686
+ simd_or( a, b)
2687
+ }
2688
+ }
2689
+
2690
+ #[ unstable( feature = "stdarch_s390x" , issue = "135681" ) ]
2691
+ impl VectorSel <t_b!( $ty) > for $ty {
2692
+ #[ inline]
2693
+ #[ target_feature( enable = "vector" ) ]
2694
+ unsafe fn vec_sel( self , b: Self , c: t_b!( $ty) ) -> Self {
2695
+ // defer to the implementation with an unsigned mask
2696
+ self . vec_sel( b, transmute:: <_, t_u!( $ty) >( c) )
2697
+ }
2698
+ }
2699
+ ) *
2700
+ }
2701
+ }
2702
+
2703
+ impl_vec_sel ! {
2704
+ vector_signed_char
2705
+ vector_signed_short
2706
+ vector_signed_int
2707
+ vector_signed_long_long
2708
+
2709
+ vector_unsigned_char
2710
+ vector_unsigned_short
2711
+ vector_unsigned_int
2712
+ vector_unsigned_long_long
2713
+
2714
+ vector_bool_char
2715
+ vector_bool_short
2716
+ vector_bool_int
2717
+ vector_bool_long_long
2718
+
2719
+ vector_float
2720
+ vector_double
2721
+ }
2670
2722
}
2671
2723
2672
2724
/// Load Count to Block Boundary
@@ -3837,6 +3889,14 @@ pub unsafe fn vec_gather_element<T: sealed::VectorGatherElement, const D: u32>(
3837
3889
a. vec_gather_element :: < D > ( b, c)
3838
3890
}
3839
3891
3892
+ /// Vector Select
3893
+ #[ inline]
3894
+ #[ target_feature( enable = "vector" ) ]
3895
+ #[ unstable( feature = "stdarch_s390x" , issue = "135681" ) ]
3896
+ pub unsafe fn vec_sel < T : sealed:: VectorSel < U > , U > ( a : T , b : T , c : U ) -> T {
3897
+ a. vec_sel ( b, c)
3898
+ }
3899
+
3840
3900
#[ cfg( test) ]
3841
3901
mod tests {
3842
3902
use super :: * ;
@@ -4785,6 +4845,20 @@ mod tests {
4785
4845
assert_eq ! ( d. as_array( ) , & [ 0xF00 , 0 ] ) ;
4786
4846
}
4787
4847
4848
+ #[ simd_test( enable = "vector" ) ]
4849
+ fn test_vec_sel ( ) {
4850
+ let a = vector_signed_int ( [ 1 , 2 , 3 , 4 ] ) ;
4851
+ let b = vector_signed_int ( [ 5 , 6 , 7 , 8 ] ) ;
4852
+
4853
+ let e = vector_unsigned_int ( [ 9 , 10 , 11 , 12 ] ) ;
4854
+ let f = vector_unsigned_int ( [ 9 , 9 , 11 , 11 ] ) ;
4855
+
4856
+ let c: vector_bool_int = unsafe { simd_eq ( e, f) } ;
4857
+ assert_eq ! ( c. as_array( ) , & [ !0 , 0 , !0 , 0 ] ) ;
4858
+ let d: vector_signed_int = unsafe { vec_sel ( a, b, c) } ;
4859
+ assert_eq ! ( d. as_array( ) , & [ 5 , 2 , 7 , 4 ] ) ;
4860
+ }
4861
+
4788
4862
#[ simd_test( enable = "vector" ) ]
4789
4863
fn test_vec_gather_element ( ) {
4790
4864
let a1: [ u32 ; 10 ] = [ 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 ] ;
0 commit comments