Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libcxx/docs/Status/ParallelismProjects.csv
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ Section,Description,Dependencies,Assignee,Complete
| `[parallel.simd.mask.class] <https://wg21.link/N4808>`_, "`simd_mask load constructor <https://github.com/llvm/llvm-project/pull/76610>`_", None, Yin Zhang, |Complete|
| `[parallel.simd.mask.class] <https://wg21.link/N4808>`_, "`simd_mask subscript operators <https://github.com/llvm/llvm-project/pull/68960>`_", None, Yin Zhang, |Complete|
| `[parallel.simd.mask.class] <https://wg21.link/N4808>`_, "`simd_mask copy functions <https://github.com/llvm/llvm-project/pull/78935>`_", None, Yin Zhang, |Complete|
| `[parallel.simd.mask.class] <https://wg21.link/N4808>`_, "`simd_mask unary operators <https://github.com/llvm/llvm-project/pull/118468>`_", None, Yin Zhang, |Complete|
| `[parallel.simd.mask.class] <https://wg21.link/N4808>`_, "Class template simd_mask implementation", None, Yin Zhang, |In Progress|
| `[parallel.simd.mask.nonmembers] <https://wg21.link/N4808>`_, "simd_mask non-member operations", None, Yin Zhang, |In Progress|
2 changes: 2 additions & 0 deletions libcxx/include/experimental/__simd/scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions libcxx/include/experimental/__simd/simd_mask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions libcxx/include/experimental/__simd/vec_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}