[libcxx-commits] [libcxx] [libc++] <experimental/simd> Add unary operators for class simd_mask (PR #118468)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Dec 3 03:19:04 PST 2024
https://github.com/joy2myself updated https://github.com/llvm/llvm-project/pull/118468
>From 34587fe0414fcdb0e5a1898c2673f1683a361bda Mon Sep 17 00:00:00 2001
From: Yin Zhang <zhangyin2018 at iscas.ac.cn>
Date: Tue, 23 Apr 2024 14:27:45 +0800
Subject: [PATCH] [libc++] <experimental/simd> Add unary operators for class
simd_mask
---
libcxx/include/experimental/__simd/scalar.h | 2 +
.../include/experimental/__simd/simd_mask.h | 3 ++
libcxx/include/experimental/__simd/vec_ext.h | 2 +
.../simd.mask.class/simd_mask_unary.pass.cpp | 38 +++++++++++++++++++
4 files changed, 45 insertions(+)
create mode 100644 libcxx/test/std/experimental/simd/simd.mask.class/simd_mask_unary.pass.cpp
diff --git a/libcxx/include/experimental/__simd/scalar.h b/libcxx/include/experimental/__simd/scalar.h
index da318d2f4650fd..8aa4d4fb312722 100644
--- a/libcxx/include/experimental/__simd/scalar.h
+++ b/libcxx/include/experimental/__simd/scalar.h
@@ -93,6 +93,8 @@ struct __mask_operations<_Tp, simd_abi::__scalar> {
static _LIBCPP_HIDE_FROM_ABI void __load(_MaskStorage& __s, const bool* __mem) noexcept { __s.__data = __mem[0]; }
static _LIBCPP_HIDE_FROM_ABI void __store(_MaskStorage __s, bool* __mem) noexcept { __mem[0] = __s.__data; }
+
+ static _LIBCPP_HIDE_FROM_ABI _MaskStorage __negate(_MaskStorage __s) noexcept { return {{!__s.__data}}; }
};
} // namespace parallelism_v2
diff --git a/libcxx/include/experimental/__simd/simd_mask.h b/libcxx/include/experimental/__simd/simd_mask.h
index 6b6f671bf3e64c..9db2cdb5af0fa6 100644
--- a/libcxx/include/experimental/__simd/simd_mask.h
+++ b/libcxx/include/experimental/__simd/simd_mask.h
@@ -79,6 +79,9 @@ class simd_mask {
// scalar access [simd.mask.subscr]
_LIBCPP_HIDE_FROM_ABI reference operator[](size_t __i) noexcept { return reference(__s_, __i); }
_LIBCPP_HIDE_FROM_ABI value_type operator[](size_t __i) const noexcept { return __s_.__get(__i); }
+
+ // unary operators
+ _LIBCPP_HIDE_FROM_ABI simd_mask operator!() const noexcept { return simd_mask(_Impl::__negate(__s_), __storage_tag); }
};
template <class _Tp, class _Abi>
diff --git a/libcxx/include/experimental/__simd/vec_ext.h b/libcxx/include/experimental/__simd/vec_ext.h
index abc7e9595be9c8..f40aba8750925a 100644
--- a/libcxx/include/experimental/__simd/vec_ext.h
+++ b/libcxx/include/experimental/__simd/vec_ext.h
@@ -121,6 +121,8 @@ struct __mask_operations<_Tp, simd_abi::__vec_ext<_Np>> {
for (size_t __i = 0; __i < _Np; __i++)
__mem[__i] = static_cast<bool>(__s.__data[__i]);
}
+
+ static _LIBCPP_HIDE_FROM_ABI _MaskStorage __negate(_MaskStorage __s) noexcept { return {{~__s.__data}}; }
};
} // namespace parallelism_v2
diff --git a/libcxx/test/std/experimental/simd/simd.mask.class/simd_mask_unary.pass.cpp b/libcxx/test/std/experimental/simd/simd.mask.class/simd_mask_unary.pass.cpp
new file mode 100644
index 00000000000000..4f729067fa08b9
--- /dev/null
+++ b/libcxx/test/std/experimental/simd/simd.mask.class/simd_mask_unary.pass.cpp
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+// <experimental/simd>
+//
+// [simd.mask.class]
+// simd_mask operator!() const noexcept;
+
+#include "../test_utils.h"
+#include <algorithm>
+#include <experimental/simd>
+
+namespace ex = std::experimental::parallelism_v2;
+
+template <class T, std::size_t>
+struct CheckSimdMaskNotOperator {
+ template <class SimdAbi>
+ void operator()() {
+ constexpr std::size_t array_size = ex::simd_size_v<T, SimdAbi>;
+ ex::simd_mask<T, SimdAbi> origin_mask(true);
+ static_assert(noexcept(!origin_mask));
+ std::array<bool, array_size> expected_value;
+ std::fill(expected_value.begin(), expected_value.end(), false);
+ assert_simd_mask_values_equal<array_size>(!origin_mask, expected_value);
+ }
+};
+
+int main(int, char**) {
+ test_all_simd_abi<CheckSimdMaskNotOperator>();
+ return 0;
+}
More information about the libcxx-commits
mailing list