-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[libc++] <experimental/simd> Add unary operators for class simd_mask #118468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-libcxx Author: ZhangYin (joy2myself) ChangesFull diff: https://github.com/llvm/llvm-project/pull/118468.diff 4 Files Affected:
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..20a84eb28026a6
--- /dev/null
+++ b/libcxx/test/std/experimental/simd/simd.mask.class/simd_mask_unary.pass.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <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;
+}
|
3910345
to
34587fe
Compare
34587fe
to
0d51370
Compare
@philnik777 ping. |
@joy2myself Given that |
@philnik777 Thanks for raising these points! I researched P1928R15. Here's a proposal based on it's current status: |
@joy2myself I've started looking into implementing P1928 (and some changes of follow-up papers) myself. I've changed a few aspects compared to the current experimental implementation. I think we'd be happy to continue development directly upstream. Assuming I didn't do something massively wrong, I think the best way to continue would be to start upstreaming my initial patch and then we can finish the implementation in tree. WDYT? |
Oh, and here is my current implementation status: main...philnik777:llvm-project:implement_simd |
@philnik777 Your initial patch looks great. I agree to upstream this patch and continue to work on it. Can I now start working on the TODOs? Or do you have any plans for subsequent work? |
Feel free to start working on them. |
Hi @philnik777, I noticed that your initial patch has not been merged yet. My part of constructor implementations are ready but depend on it. Would you prefer I help submit the inital patch or should I wait for your PR to proceed? |
No description provided.