Skip to content

Commit ad2fb88

Browse files
committed
add vec_nabs
1 parent 8688d28 commit ad2fb88

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

crates/core_arch/src/s390x/macros.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,7 @@ macro_rules! impl_neg {
436436
impl crate::ops::Neg for s_t_l!($s) {
437437
type Output = s_t_l!($s);
438438
fn neg(self) -> Self::Output {
439-
let zero = $s::splat($zero);
440-
unsafe { transmute(simd_sub(zero, transmute(self))) }
439+
unsafe { simd_neg(self) }
441440
}
442441
}
443442
};

crates/core_arch/src/s390x/vector.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,31 @@ mod sealed {
506506
impl_vec_trait! { [VectorAbs vec_abs] vec_abs_f32 (vector_float) }
507507
impl_vec_trait! { [VectorAbs vec_abs] vec_abs_f64 (vector_double) }
508508

509+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
510+
pub trait VectorNabs {
511+
unsafe fn vec_nabs(self) -> Self;
512+
}
513+
514+
#[inline]
515+
#[target_feature(enable = "vector")]
516+
#[cfg_attr(
517+
all(test, target_feature = "vector-enhancements-1"),
518+
assert_instr(vflnsb)
519+
)]
520+
unsafe fn vec_nabs_f32(a: vector_float) -> vector_float {
521+
simd_neg(simd_fabs(a))
522+
}
523+
524+
#[inline]
525+
#[target_feature(enable = "vector")]
526+
#[cfg_attr(test, assert_instr(vflndb))]
527+
unsafe fn vec_nabs_f64(a: vector_double) -> vector_double {
528+
simd_neg(simd_fabs(a))
529+
}
530+
531+
impl_vec_trait! { [VectorNabs vec_nabs] vec_nabs_f32 (vector_float) }
532+
impl_vec_trait! { [VectorNabs vec_nabs] vec_nabs_f64 (vector_double) }
533+
509534
#[unstable(feature = "stdarch_s390x", issue = "135681")]
510535
pub trait VectorSplats<Output> {
511536
unsafe fn vec_splats(self) -> Output;
@@ -1532,6 +1557,17 @@ where
15321557
a.vec_abs()
15331558
}
15341559

1560+
/// Vector negative abs.
1561+
#[inline]
1562+
#[target_feature(enable = "vector")]
1563+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1564+
pub unsafe fn vec_nabs<T>(a: T) -> T
1565+
where
1566+
T: sealed::VectorNabs,
1567+
{
1568+
a.vec_nabs()
1569+
}
1570+
15351571
/// Vector splats.
15361572
#[inline]
15371573
#[target_feature(enable = "vector")]
@@ -2355,6 +2391,10 @@ mod tests {
23552391
test_vec_abs! { test_vec_abs_f32, f32x4, -42f32, 42f32 }
23562392
test_vec_abs! { test_vec_abs_f64, f64x2, -42f64, 42f64 }
23572393

2394+
test_vec_1! { test_vec_nabs, vec_nabs, f32x4,
2395+
[core::f32::consts::PI, 1.0, 0.0, -1.0],
2396+
[-core::f32::consts::PI, -1.0, 0.0, -1.0] }
2397+
23582398
test_vec_2! { test_vec_andc, vec_andc, i32x4,
23592399
[0b11001100, 0b11001100, 0b11001100, 0b11001100],
23602400
[0b00110011, 0b11110011, 0b00001100, 0b10000000],

0 commit comments

Comments
 (0)