[libcxx-commits] [PATCH] D144362: [libcxx] <experimental/simd> Add ABI tags, class template simd/simd_mask implementations. Add related simd traits and tests.

Yin Zhang via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jun 25 08:26:35 PDT 2023


Joy12138 added a comment.

In D144362#4445885 <https://reviews.llvm.org/D144362#4445885>, @philnik wrote:

> I've applied for patch locally and reworked the instantiation logic a bit. This is my solution:
>
> name=test_utils.h
>   //===----------------------------------------------------------------------===//
>   //
>   // 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
>   //
>   //===----------------------------------------------------------------------===//
>   
>   #ifndef TEST_UTIL_H
>   #define TEST_UTIL_H
>   
>   #include <utility>
>   #include <experimental/simd>
>   #include "type_algorithms.h"
>   
>   namespace ex = std::experimental::parallelism_v2;
>   
>   constexpr std::size_t max_simd_size = 32;
>   
>   template <template <std::size_t N> class F>
>   struct TestAllSimdAbiFunctor {
>     template <class T, std::size_t N>
>     using sized_abis = types::type_list<ex::simd_abi::fixed_size<N>, ex::simd_abi::deduce_t<T, N>>;
>   
>     template <class T, std::size_t... Ns>
>     void instantiate_with_n(std::index_sequence<Ns...>) {
>       (types::for_each(sized_abis<T, Ns + 1>{}, F<Ns + 1>{}), ...);
>     }
>   
>     template <class T>
>     void operator()() {
>       using abis = types::type_list<ex::simd_abi::scalar, ex::simd_abi::native<T>, ex::simd_abi::compatible<T>>;
>       types::for_each(abis{}, F<1>());
>   
>       instantiate_with_n<T>(std::make_index_sequence<max_simd_size - 1>{});
>     }
>   };
>   
>   template <template <std::size_t N> class Func>
>   void test_all_simd_abi() {
>     using arithmetic_no_bool_types = types::concatenate_t<types::integer_types, types::floating_point_types>;
>     types::for_each(arithmetic_no_bool_types(), TestAllSimdAbiFunctor<Func>());
>   }
>   
>   #endif // TEST_UTIL_H
>
> name=is_abi_tag.pass.cpp
>   //===----------------------------------------------------------------------===//
>   //
>   // 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.traits]
>   // template <class T> struct is_abi_tag;
>   // template <class T> inline constexpr bool ex::is_abi_tag_v = ex::is_abi_tag<T>::value;
>   
>   #include "../test_utils.h"
>   #include <experimental/simd>
>   
>   namespace ex = std::experimental::parallelism_v2;
>   
>   class EmptyEntry {};
>   
>   template <std::size_t N>
>   struct Test {
>     template <class SimdAbi>
>     void operator()() {
>       static_assert(ex::is_abi_tag<SimdAbi>::value);
>   
>       static_assert(!ex::is_abi_tag<EmptyEntry>::value);
>       static_assert(!ex::is_abi_tag<ex::simd< EmptyEntry, SimdAbi>>::value);
>       static_assert(!ex::is_abi_tag<ex::simd_mask< EmptyEntry, SimdAbi>>::value);
>   
>       static_assert(ex::is_abi_tag_v<SimdAbi>);
>   
>       static_assert(!ex::is_abi_tag_v<EmptyEntry>);
>       static_assert(!ex::is_abi_tag_v<ex::simd< EmptyEntry, SimdAbi>>);
>       static_assert(!ex::is_abi_tag_v<ex::simd_mask< EmptyEntry, SimdAbi>>);
>     }
>   };
>   
>   int main(int, char**) {
>     test_all_simd_abi<Test>();
>     return 0;
>   }
>
> I think this version is quite a bit easier to follow. WDYT?

The solution looks great. It works well overall, but there's one aspect I believe could be improved. Since a basic `simd` need `type` and `simdabi` 2 factors, `type` will usually be used in most of the test functors. I intend to pass the `type` to `F`.

For clarity, I've made a comparison of the codes which you can review at the following link: https://www.diffchecker.com/2ja2Qq7t/


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144362/new/

https://reviews.llvm.org/D144362



More information about the libcxx-commits mailing list