@@ -308,7 +308,6 @@ mod sealed {
308308 impl_mul ! ( vml_double, vector_double, vfmdb) ;
309309 }
310310
311-
312311 #[ unstable( feature = "stdarch_s390x" , issue = "135681" ) ]
313312 pub trait VectorMax < Other > {
314313 type Result ;
@@ -344,6 +343,48 @@ mod sealed {
344343 test_impl ! { vec_vmnslg ( a: vector_unsigned_long_long, b: vector_unsigned_long_long) -> vector_unsigned_long_long [ vmnlg, vmnlg] }
345344
346345 impl_vec_trait ! { [ VectorMin vec_min] ~( vmxlb, vmxb, vmxlh, vmxh, vmxlf, vmxf, vmxlg, vmxg) }
346+
347+ #[ unstable( feature = "stdarch_s390x" , issue = "135681" ) ]
348+ pub trait VectorAbs {
349+ unsafe fn vec_abs ( self ) -> Self ;
350+ }
351+
352+ macro_rules! impl_abs {
353+ ( $name: ident, $ty: ident, $instr: ident) => {
354+ #[ inline]
355+ #[ target_feature( enable = "vector" ) ]
356+ #[ cfg_attr( test, assert_instr( $instr) ) ]
357+ unsafe fn $name( v: s_t_l!( $ty) ) -> s_t_l!( $ty) {
358+ v. vec_max( -v)
359+ }
360+
361+ impl_vec_trait! { [ VectorAbs vec_abs] $name ( s_t_l!( $ty) ) }
362+ } ;
363+ }
364+
365+ impl_abs ! { vec_abs_i8, i8x16 }
366+ impl_abs ! { vec_abs_i16, i16x8 }
367+ impl_abs ! { vec_abs_i32, i32x4 }
368+ impl_abs ! { vec_abs_i64, i64x2 }
369+
370+ #[ inline]
371+ #[ target_feature( enable = "vector" ) ]
372+ unsafe fn vec_abs_f32 ( v : vector_float ) -> vector_float {
373+ let v: u32x4 = transmute ( v) ;
374+
375+ transmute ( simd_and ( v, u32x4:: splat ( 0x7FFFFFFF ) ) )
376+ }
377+
378+ #[ inline]
379+ #[ target_feature( enable = "vector" ) ]
380+ unsafe fn vec_abs_f64 ( v : vector_double ) -> vector_double {
381+ let v: u64x2 = transmute ( v) ;
382+
383+ transmute ( simd_and ( v, u64x2:: splat ( 0x7FFFFFFF_FFFFFFFF ) ) )
384+ }
385+
386+ impl_vec_trait ! { [ VectorAbs vec_abs] vec_abs_f32 ( vector_float) }
387+ impl_vec_trait ! { [ VectorAbs vec_abs] vec_abs_f64 ( vector_double) }
347388}
348389
349390/// Vector pointwise addition.
@@ -407,6 +448,17 @@ where
407448 a. vec_min ( b)
408449}
409450
451+ /// Vector abs.
452+ #[ inline]
453+ #[ target_feature( enable = "vector" ) ]
454+ #[ unstable( feature = "stdarch_s390x" , issue = "135681" ) ]
455+ pub unsafe fn vec_abs < T > ( a : T ) -> T
456+ where
457+ T : sealed:: VectorAbs ,
458+ {
459+ a. vec_abs ( )
460+ }
461+
410462#[ cfg( test) ]
411463mod tests {
412464 use super :: * ;
0 commit comments