native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
value_traits.h
1// SPDX-FileCopyrightText: 2026 Edward Kmett <ekmett@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0
3#pragma once
4#include "native/kernel_policies.h"
5#include <concepts>
6#include <cstddef>
7#include <cstdint>
8#include <type_traits>
9
10// These primaries belong to the global module fragment, including when wide
11// needs their exact-type traits before the hub defines the specializations.
12namespace native {
13 template<class T,std::size_t N,isa<> Arch> struct simd;
14 template<std::size_t N,isa<> Arch> struct predicate;
15 template<class U> requires (std::is_unsigned_v<U> && !std::same_as<U,bool> && (sizeof(U)==1 || sizeof(U)==2 || sizeof(U)==4 || sizeof(U)==8))
16 struct mask_lane;
17
18 namespace detail {
19 template<class T> inline constexpr bool is_mask_lane=false;
20 template<class U> inline constexpr bool is_mask_lane<mask_lane<U>> = true;
21
22 // Unknown and derived types retain their declared architecture. Only exact
23 // built-in specializations have implementation requirements known here.
24 template<class T,class=void> struct value_traits {
25 static constexpr isa<> value=scalar;
26 static constexpr bool known=false;
27 static constexpr bool aggregate_default=false;
28 };
29 template<class T> requires arch<std::remove_cvref_t<decltype(T::architecture)>> &&
30 requires { typename std::integral_constant<std::remove_cvref_t<decltype(T::architecture)>,T::architecture>; }
31 struct value_traits<T,std::void_t<decltype(T::architecture)>> {
32 static_assert(arch_family_v<std::remove_cvref_t<decltype(T::architecture)>> == target_arch,
33 "value architecture must match the compiler target family");
34 static constexpr isa<> value=T::architecture;
35 static constexpr bool known=true;
36 static constexpr bool aggregate_default=false;
37 };
38 template<class T,std::size_t N,isa<> A>
39 struct value_traits<simd<T,N,A>> {
40 static constexpr isa<> value=A;
41 static constexpr bool known=true;
42 static constexpr bool aggregate_default=false;
43 };
44 template<class T> concept ordinary_simd_element =
45 std::same_as<T,float> || std::same_as<T,bool> || is_mask_lane<T> ||
46 std::same_as<T,std::int8_t> || std::same_as<T,std::uint8_t> ||
47 std::same_as<T,std::int16_t> || std::same_as<T,std::uint16_t> ||
48 std::same_as<T,std::int32_t> || std::same_as<T,std::uint32_t> ||
49 std::same_as<T,std::int64_t> || std::same_as<T,std::uint64_t>;
50 template<class T,std::size_t N,isa<> A> requires ordinary_simd_element<T>
51 struct value_traits<simd<T,N,A>> {
52 static constexpr isa<> value=abi_lookup<A,raw_kernel_policies>::architecture;
53 static constexpr bool known=true;
54 // float's one-lane specialization has a +0 member initializer. Bypassing
55 // an unattributed std::array constructor preserves both initialization forms.
56 static constexpr bool aggregate_default=std::same_as<T,float> && N==1;
57 };
58 template<std::size_t N,isa<> A> struct value_traits<predicate<N,A>> {
59 static constexpr isa<> value=abi_lookup<A,raw_kernel_policies>::architecture;
60 static constexpr bool known=true;
61 static constexpr bool aggregate_default=false;
62 };
63 template<class T> struct value_architecture : value_traits<std::remove_cv_t<T>> {};
64 template<class T> inline constexpr isa<> value_architecture_v=value_architecture<T>::value;
65 }
66}
Architecture-tagged vectors, register packs and supporting value types. Native arithmetic follows its...
constexpr architecture target_arch
The compiler target's family; no optional instruction support is implied.
Definition config.h:32
Omitted architecture arguments use the native.simd provider's baseline.