Skip to content

Commit

Permalink
s390x vector: add vec_and, vec_or and vec_xor
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev authored and Amanieu committed Feb 13, 2025
1 parent 255da5e commit e19ebda
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/core_arch/src/s390x/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ macro_rules! impl_vec_trait {
impl_vec_trait!{ [$Trait $m] $sg (vector_signed_long_long, ~vector_bool_long_long) -> vector_signed_long_long }
};
([$Trait:ident $m:ident] ~($fn:ident)) => {
impl_vec_trait!{ [$Trait $m] ~($fn, $fn, $fn, $fn, $fn, $fn) }
impl_vec_trait!{ [$Trait $m] ~($fn, $fn, $fn, $fn, $fn, $fn, $fn, $fn) }
};
([$Trait:ident $m:ident] 2 ($ub:ident, $sb:ident, $uh:ident, $sh:ident, $uw:ident, $sw:ident)) => {
impl_vec_trait!{ [$Trait $m] $ub (vector_unsigned_char, vector_unsigned_char) -> vector_unsigned_char }
Expand Down
58 changes: 57 additions & 1 deletion crates/core_arch/src/s390x/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,31 @@ mod sealed {
// instructions in later facilities. Add tests when possible.
test_impl! { vec_popcnt_signed +(a: vector_signed_char) -> vector_signed_char [simd_ctpop, vpopctb] }
test_impl! { vec_popcnt_unsigned +(a: vector_unsigned_char) -> vector_unsigned_char [simd_ctpop, vpopctb] }
}

#[unstable(feature = "stdarch_s390x", issue = "135681")]
pub trait VectorAnd<Other> {
type Result;
unsafe fn vec_and(self, b: Other) -> Self::Result;
}

impl_vec_trait! { [VectorAnd vec_and] ~(simd_and) }

#[unstable(feature = "stdarch_s390x", issue = "135681")]
pub trait VectorOr<Other> {
type Result;
unsafe fn vec_or(self, b: Other) -> Self::Result;
}

impl_vec_trait! { [VectorOr vec_or] ~(simd_or) }

#[unstable(feature = "stdarch_s390x", issue = "135681")]
pub trait VectorXor<Other> {
type Result;
unsafe fn vec_xor(self, b: Other) -> Self::Result;
}

impl_vec_trait! { [VectorXor vec_xor] ~(simd_xor) }
}

/// Vector element-wise addition.
#[inline]
Expand Down Expand Up @@ -641,6 +664,39 @@ where
a.vec_splats()
}

/// Vector and
#[inline]
#[target_feature(enable = "vector")]
#[unstable(feature = "stdarch_s390x", issue = "135681")]
pub unsafe fn vec_and<T, U>(a: T, b: U) -> <T as sealed::VectorAnd<U>>::Result
where
T: sealed::VectorAnd<U>,
{
a.vec_and(b)
}

/// Vector or
#[inline]
#[target_feature(enable = "vector")]
#[unstable(feature = "stdarch_s390x", issue = "135681")]
pub unsafe fn vec_or<T, U>(a: T, b: U) -> <T as sealed::VectorOr<U>>::Result
where
T: sealed::VectorOr<U>,
{
a.vec_or(b)
}

/// Vector xor
#[inline]
#[target_feature(enable = "vector")]
#[unstable(feature = "stdarch_s390x", issue = "135681")]
pub unsafe fn vec_xor<T, U>(a: T, b: U) -> <T as sealed::VectorXor<U>>::Result
where
T: sealed::VectorXor<U>,
{
a.vec_xor(b)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit e19ebda

Please sign in to comment.