native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
polyfill_feature_chunk_body.h
1// SPDX-FileCopyrightText: 2026 Edward Kmett <ekmett@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0
3// Repeated under a native half feature target. These bridges deliberately have
4// ordinary constexpr inlining: the generic register scope may call a stronger
5// feature scope, while callers compiled for that feature can inline the bridge.
6namespace native::detail {
7 template<class T,std::size_t N,isa<> A> requires NATIVE_POLYFILL_FEATURE_CHUNK(T,N,A)
8 struct polyfill_feature_chunk<T,N,A> {
9 using vector_type=simd<T,N,A>;
10 using native_type=typename vector_type::native_type;
11 static constexpr std::size_t lanes=N;
12 vector_type value{};
13 constexpr polyfill_feature_chunk() noexcept=default;
14 constexpr explicit polyfill_feature_chunk(T element) noexcept : value(element) {}
15 static constexpr polyfill_feature_chunk from_native(native_type bits) noexcept {
16 polyfill_feature_chunk result; result.value=vector_type::from_native(bits); return result;
17 }
18 constexpr native_type to_native() const noexcept { return value.to_native(); }
19 template<std::size_t Alignment=1> static constexpr polyfill_feature_chunk load_memory(T const * p) noexcept {
20 polyfill_feature_chunk result; result.value=vector_type::template load_memory<Alignment>(p); return result;
21 }
22 template<std::size_t Alignment=1> constexpr void store_memory(T * p) const noexcept {
23 value.template store_memory<Alignment>(p);
24 }
25#define NATIVE_POLYFILL_FEATURE_BINARY(OP) \
26 friend constexpr polyfill_feature_chunk operator OP(polyfill_feature_chunk a,polyfill_feature_chunk b) noexcept \
27 requires requires(vector_type x) { { x OP x } -> std::same_as<vector_type>; } { \
28 polyfill_feature_chunk result; result.value=a.value OP b.value; return result; \
29 }
30 NATIVE_POLYFILL_FEATURE_BINARY(+)
31 NATIVE_POLYFILL_FEATURE_BINARY(-)
32 NATIVE_POLYFILL_FEATURE_BINARY(*)
33 NATIVE_POLYFILL_FEATURE_BINARY(/)
34#undef NATIVE_POLYFILL_FEATURE_BINARY
35#define NATIVE_POLYFILL_FEATURE_COMPARE(OP) \
36 friend constexpr auto operator OP(polyfill_feature_chunk a,polyfill_feature_chunk b) noexcept \
37 requires requires(vector_type x) { (x OP x).to_bitset(); } { return a.value OP b.value; }
38 NATIVE_POLYFILL_FEATURE_COMPARE(==)
39 NATIVE_POLYFILL_FEATURE_COMPARE(!=)
40 NATIVE_POLYFILL_FEATURE_COMPARE(<)
41 NATIVE_POLYFILL_FEATURE_COMPARE(<=)
42 NATIVE_POLYFILL_FEATURE_COMPARE(>)
43 NATIVE_POLYFILL_FEATURE_COMPARE(>=)
44#undef NATIVE_POLYFILL_FEATURE_COMPARE
45 friend constexpr polyfill_feature_chunk operator-(polyfill_feature_chunk a) noexcept
46 requires requires(vector_type x) { { -x } -> std::same_as<vector_type>; } {
47 polyfill_feature_chunk result; result.value=-a.value; return result;
48 }
49#define NATIVE_POLYFILL_FEATURE_UNARY(NAME) \
50 friend constexpr polyfill_feature_chunk NAME(polyfill_feature_chunk a) noexcept \
51 requires requires(vector_type x) { { NAME(x) } -> std::same_as<vector_type>; } { \
52 polyfill_feature_chunk result; result.value=NAME(a.value); return result; \
53 }
54 NATIVE_POLYFILL_FEATURE_UNARY(sqrt)
55 NATIVE_POLYFILL_FEATURE_UNARY(abs)
56 NATIVE_POLYFILL_FEATURE_UNARY(floor)
57 NATIVE_POLYFILL_FEATURE_UNARY(ceil)
58 NATIVE_POLYFILL_FEATURE_UNARY(trunc)
59 NATIVE_POLYFILL_FEATURE_UNARY(round_even)
60#undef NATIVE_POLYFILL_FEATURE_UNARY
61 friend constexpr polyfill_feature_chunk fma(polyfill_feature_chunk a,polyfill_feature_chunk b,polyfill_feature_chunk c) noexcept
62 requires requires(vector_type x) { { fma(x,x,x) } -> std::same_as<vector_type>; } {
63 polyfill_feature_chunk result; result.value=fma(a.value,b.value,c.value); return result;
64 }
65 };
66}
constexpr simd< float, N, Arch > ceil(simd< float, N, Arch > x) noexcept
constexpr auto abs(simd< float, N, Arch > a) noexcept
constexpr simd< float, N, Arch > trunc(simd< float, N, Arch > x) noexcept
constexpr simd< float, N, Arch > floor(simd< float, N, Arch > x) noexcept
void operator-(simd< T, N, A >, simd< U, M, B >)=delete
Reject mixed architectures and mismatched short-vector widths before native conversions can participa...
constexpr simd< T, N, A > sqrt(simd< T, N, A > v) noexcept
Compute correctly rounded square roots; negative finite lanes produce NaN.
constexpr simd< T, N, A > round_even(simd< T, N, A > v) noexcept
Round floating lanes to nearest integers, choosing even at ties.
constexpr simd< fp16, 32, Arch > fma(simd< fp16, 32, Arch > a, simd< fp16, 32, Arch > b, simd< fp16, 32, Arch > c) noexcept