4#include "native/isa_import.h"
5#include <native/simd.h>
6#include <native/integer.h>
7#include <native/packing.h>
8#include <native/simd/math/bits.h>
9#include <native/targets.h>
19 template<
class T, std::
size_t N, isa<> Arch = NATIVE_BA
SELINE>
struct simd;
23#include "native/simd/exports.h"
24export namespace native::detail {
25 template<>
struct polyfill_element_traits<fp16> {
26 static constexpr bool supported=
true;
27 static constexpr bool arithmetic=
true;
28 static constexpr auto kind=polyfill_element_kind::binary16;
29 using format=constexpr_float::binary16;
31 template<>
struct polyfill_element_traits<bf16> {
32 static constexpr bool supported=
true;
33 static constexpr bool arithmetic=
false;
34 static constexpr auto kind=polyfill_element_kind::bfloat16;
35 using format=constexpr_float::binary_format<8,7>;
39#define NATIVE_ARCH_REQUIRES(A) (::native::avx512_bf16 <= A)
40#pragma clang attribute push(__attribute__((target("avx2,fma,avx512f,avx512dq,avx512bw,avx512vl,avx512bf16"))), apply_to=function)
43 template<std::
size_t N,::native::isa<> A>
requires NATIVE_ARCH_REQUIRES(A) &&(N==8 || N==16 || N==32)
45 static constexpr isa<> value=avx512_bf16;
46 static constexpr bool known=
true;
47 static constexpr bool aggregate_default=
false;
57 template<std::
size_t N, ::native::isa<> Arch>
requires NATIVE_ARCH_REQUIRES(Arch) &&(N == 8 || N == 16 || N == 32)
66 using native_type = std::conditional_t<N == 8,__m128bh,std::conditional_t<N == 16,__m256bh,__m512bh>>;
81 static constexpr std::size_t
lanes = N;
82#include "native/simd/polyfill_lane_access.h"
89 hint_inline constexpr explicit
simd(
bf16 value) noexcept
92 hint_inline
constexpr explicit simd(std::array<bf16,lanes>
const & values) noexcept :
simd(
load(values.data())) {}
94 template<
class... T>
requires(
sizeof...(T) == lanes && (std::same_as<T,bf16> && ...))
99 [[nodiscard]] hint_inline
constexpr operator native_type() const noexcept {
return value_; }
101#include "native/simd/bf16_reject_operators.h"
106 simd result; result.value_ = value;
return result;
110 return bits_type::from_native(__builtin_bit_cast(
typename bits_type::native_type,value_));
120 [[nodiscard]]
static hint_inline
constexpr simd load_bits(std::uint16_t
const * p)
noexcept {
125 hint_inline
constexpr void store_bits(std::uint16_t * p)
const noexcept {
bits().store(p); }
130 template<std::
size_t Alignment = 1>
132 static_assert(Alignment > 0 && (Alignment & (Alignment - 1)) == 0);
134 std::array<std::uint16_t,lanes> words{};
135 for (std::size_t i=0;i<
lanes;++i) words[i]=p[i].
to_bits();
138 native_type value; std::memcpy(&value,
reinterpret_cast<unsigned char const *
>(p),
sizeof(value));
return from_native(value);
144 template<std::
size_t Alignment = 1>
146 static_assert(Alignment > 0 && (Alignment & (Alignment - 1)) == 0);
148 std::array<std::uint16_t,lanes> words{};
store_bits(words.data());
152 std::memcpy(
reinterpret_cast<unsigned char *
>(p), &value_,
sizeof(value_));
159 [[nodiscard]]
static hint_inline
constexpr simd loadu(
bf16 const * p)
noexcept {
return load(p); }
169 std::array<bf16,lanes> values; values.fill(fill);
171 for (std::size_t i=0;i<n;++i) values[i]=p[i];
172 }
else {
if (n) std::memcpy(values.data(),
reinterpret_cast<unsigned char const *
>(p), n *
sizeof(
bf16)); }
173 return load(values.data());
178 hint_inline
constexpr void store_partial(
bf16 * p, std::size_t n)
const noexcept hint_diagnose_if(n > simd::lanes,
"partial SIMD count exceeds the lane count") {
181 std::array<std::uint16_t,lanes> words{};
store_bits(words.data());
183 }
else {
if (n) std::memcpy(
reinterpret_cast<unsigned char *
>(p), &value_, n *
sizeof(
bf16)); }
193 template<std::
size_t N, ::native::isa<> Arch>
requires NATIVE_ARCH_REQUIRES(Arch) &&(N == 8 || N == 16 || N == 32)
197 if consteval {
return detail::half_constant::dot2<false>(a,b,accumulator); }
198 return simd<float,N/2,Arch>::from_native(
199 detail::avx512_bf16_backend::dot2_native(a.to_native(), b.to_native(), accumulator.to_native()));
203#pragma clang attribute pop
204#undef NATIVE_ARCH_REQUIRES
205#define NATIVE_ARCH_REQUIRES(A) (::native::avx512_fp16 <= A)
206#pragma clang attribute push(__attribute__((target("avx2,fma,avx512f,avx512dq,avx512bw,avx512vl,avx512fp16"))), apply_to=function)
209 template<::native::isa<> A>
requires NATIVE_ARCH_REQUIRES(A)
210 struct value_traits<simd<fp16,32,A>> {
211 static constexpr isa<> value=avx512_fp16;
212 static constexpr bool known=
true;
213 static constexpr bool aggregate_default=
false;
228 template<::native::isa<> Arch>
requires NATIVE_ARCH_REQUIRES(Arch)
struct simd<
fp16,32,Arch> {
251 static constexpr std::size_t
lanes = 32;
252#include "native/simd/polyfill_lane_access.h"
259 hint_inline constexpr explicit
simd(
fp16 value) noexcept
262 hint_inline
constexpr explicit simd(std::array<fp16,lanes>
const & values) noexcept :
simd(
load(values.data())) {}
264 template<
class... T>
requires(
sizeof...(T) == lanes && (std::same_as<T,fp16> && ...))
269 [[nodiscard]] hint_inline
constexpr operator native_type() const noexcept {
return value_; }
274 simd result; result.value_ = value;
return result;
278 return bits_type::from_native(__builtin_bit_cast(
typename bits_type::native_type,value_));
288 [[nodiscard]]
static hint_inline
constexpr simd load_bits(std::uint16_t
const * p)
noexcept {
293 hint_inline
constexpr void store_bits(std::uint16_t * p)
const noexcept {
bits().store(p); }
298 template<std::
size_t Alignment = 1>
300 static_assert(Alignment > 0 && (Alignment & (Alignment - 1)) == 0);
302 std::array<std::uint16_t,lanes> words{};
303 for (std::size_t i=0;i<
lanes;++i) words[i]=p[i].
to_bits();
306 native_type value; std::memcpy(&value,
reinterpret_cast<unsigned char const *
>(p),
sizeof(value));
return from_native(value);
312 template<std::
size_t Alignment = 1>
314 static_assert(Alignment > 0 && (Alignment & (Alignment - 1)) == 0);
316 std::array<std::uint16_t,lanes> words{};
store_bits(words.data());
320 std::memcpy(
reinterpret_cast<unsigned char *
>(p), &value_,
sizeof(value_));
327 [[nodiscard]]
static hint_inline
constexpr simd loadu(
fp16 const * p)
noexcept {
return load(p); }
337 std::array<fp16,lanes> values; values.fill(fill);
339 for (std::size_t i=0;i<n;++i) values[i]=p[i];
340 }
else {
if (n) std::memcpy(values.data(),
reinterpret_cast<unsigned char const *
>(p), n *
sizeof(
fp16)); }
341 return load(values.data());
346 hint_inline
constexpr void store_partial(
fp16 * p, std::size_t n)
const noexcept hint_diagnose_if(n > simd::lanes,
"partial SIMD count exceeds the lane count") {
349 std::array<std::uint16_t,lanes> words{};
store_bits(words.data());
351 }
else {
if (n) std::memcpy(
reinterpret_cast<unsigned char *
>(p), &value_, n *
sizeof(
fp16)); }
355 if consteval {
return detail::half_constant::arithmetic<detail::half_constant::operation::add,false>(a,b); }
356 return from_native(detail::avx512_fp16_backend::add_half(a.value_,b.value_));
360 if consteval {
return detail::half_constant::arithmetic<detail::half_constant::operation::subtract,false>(a,b); }
361 return from_native(detail::avx512_fp16_backend::sub_half(a.value_,b.value_));
365 if consteval {
return detail::half_constant::arithmetic<detail::half_constant::operation::multiply,false>(a,b); }
366 return from_native(detail::avx512_fp16_backend::mul_half(a.value_,b.value_));
371 if consteval {
return detail::half_constant::arithmetic<detail::half_constant::operation::divide,false>(a,b); }
372 return from_native(detail::avx512_fp16_backend::div_half(a.value_,b.value_));
377 [[nodiscard]]
friend hint_inline
constexpr simd sqrt(
simd a)
noexcept {
378 if consteval {
return detail::half_constant::square_root<false>(a); }
379 return from_native(detail::avx512_fp16_backend::sqrt_half(a.value_));
383 if consteval {
return detail::half_constant::unary(a,[](
auto x) {
return std::uint16_t(x^0x8000); }); }
384 return from_native(detail::avx512_fp16_backend::neg_half(a.value_));
389 if consteval {
return detail::half_constant::compare(a,b,[](
auto x,
auto y) {
return detail::constexpr_float::equal_bits<detail::constexpr_float::binary16>(x,y); }); }
390 return mask::from_native(detail::avx512_fp16_backend::eq_half(a.value_,b.value_));
396 if consteval {
return detail::half_constant::compare(a,b,[](
auto x,
auto y) {
return detail::constexpr_float::less_bits<detail::constexpr_float::binary16>(x,y); }); }
397 return mask::from_native(detail::avx512_fp16_backend::lt_half(a.value_,b.value_));
401 if consteval {
return detail::half_constant::compare(a,b,[](
auto x,
auto y) {
return detail::constexpr_float::less_bits<detail::constexpr_float::binary16>(x,y) || detail::constexpr_float::equal_bits<detail::constexpr_float::binary16>(x,y); }); }
402 return mask::from_native(detail::avx512_fp16_backend::le_half(a.value_,b.value_));
411 if consteval {
return detail::half_constant::select(m,a,b); }
412 return from_native(detail::avx512_fp16_backend::select_half(m.to_native(),a.value_,b.value_));
419 template<::native::isa<> Arch>
requires NATIVE_ARCH_REQUIRES(Arch)
422 if consteval {
return detail::half_constant::fused<false>(a,b,c); }
424 detail::avx512_fp16_backend::fma_half(a.to_native(),b.to_native(),c.to_native()));
428#pragma clang attribute pop
429#undef NATIVE_ARCH_REQUIRES
431#if NATIVE_HOST_NEON || defined(NATIVE_DOXYGEN)
432#define NATIVE_ARCH_REQUIRES(A) (::native::neon_bf16 <= A)
433#pragma clang attribute push(__attribute__((target("neon,bf16"))), apply_to=function)
436 template<::native::isa<> A>
requires NATIVE_ARCH_REQUIRES(A)
437 struct value_traits<simd<bf16,8,A>> {
438 static constexpr isa<> value=neon_bf16;
439 static constexpr bool known=
true;
440 static constexpr bool aggregate_default=
false;
450 template<::native::isa<> Arch>
requires NATIVE_ARCH_REQUIRES(Arch)
struct simd<
bf16,8,Arch> {
473 static constexpr std::size_t
lanes = 8;
474#include "native/simd/polyfill_lane_access.h"
481 hint_inline constexpr explicit
simd(
bf16 value) noexcept
484 hint_inline
constexpr explicit simd(std::array<bf16,lanes>
const & values) noexcept :
simd(
load(values.data())) {}
486 template<
class... T>
requires(
sizeof...(T) == lanes && (std::same_as<T,bf16> && ...))
491 [[nodiscard]] hint_inline
constexpr operator native_type() const noexcept {
return value_; }
493#include "native/simd/bf16_reject_operators.h"
498 simd result; result.value_ = value;
return result;
502 return bits_type::from_native(__builtin_bit_cast(
typename bits_type::native_type,value_));
512 [[nodiscard]]
static hint_inline
constexpr simd load_bits(std::uint16_t
const * p)
noexcept {
517 hint_inline
constexpr void store_bits(std::uint16_t * p)
const noexcept {
bits().store(p); }
522 template<std::
size_t Alignment = 1>
524 static_assert(Alignment > 0 && (Alignment & (Alignment - 1)) == 0);
526 std::array<std::uint16_t,lanes> words{};
527 for (std::size_t i=0;i<
lanes;++i) words[i]=p[i].
to_bits();
530 native_type value; std::memcpy(&value,
reinterpret_cast<unsigned char const *
>(p),
sizeof(value));
return from_native(value);
536 template<std::
size_t Alignment = 1>
538 static_assert(Alignment > 0 && (Alignment & (Alignment - 1)) == 0);
540 std::array<std::uint16_t,lanes> words{};
store_bits(words.data());
544 std::memcpy(
reinterpret_cast<unsigned char *
>(p), &value_,
sizeof(value_));
551 [[nodiscard]]
static hint_inline
constexpr simd loadu(
bf16 const * p)
noexcept {
return load(p); }
561 std::array<bf16,lanes> values; values.fill(fill);
563 for (std::size_t i=0;i<n;++i) values[i]=p[i];
564 }
else {
if (n) std::memcpy(values.data(),
reinterpret_cast<unsigned char const *
>(p), n *
sizeof(
bf16)); }
565 return load(values.data());
570 hint_inline
constexpr void store_partial(
bf16 * p, std::size_t n)
const noexcept hint_diagnose_if(n > simd::lanes,
"partial SIMD count exceeds the lane count") {
573 std::array<std::uint16_t,lanes> words{};
store_bits(words.data());
575 }
else {
if (n) std::memcpy(
reinterpret_cast<unsigned char *
>(p), &value_, n *
sizeof(
bf16)); }
590 template<::native::isa<> Arch>
requires NATIVE_ARCH_REQUIRES(Arch)
594 if consteval {
return detail::half_constant::dot2<true>(a,b,accumulator); }
596 detail::neon_bf16_backend::dot2_native(a.to_native(), b.to_native(), accumulator.to_native()));
600#pragma clang attribute pop
601#undef NATIVE_ARCH_REQUIRES
602#define NATIVE_ARCH_REQUIRES(A) (::native::neon_fp16 <= A)
603#pragma clang attribute push(__attribute__((target("neon,fullfp16"))), apply_to=function)
606 template<::native::isa<> A>
requires NATIVE_ARCH_REQUIRES(A)
607 struct value_traits<simd<fp16,8,A>> {
608 static constexpr isa<> value=neon_fp16;
609 static constexpr bool known=
true;
610 static constexpr bool aggregate_default=
false;
625 template<::native::isa<> Arch>
requires NATIVE_ARCH_REQUIRES(Arch)
struct simd<
fp16,8,Arch> {
648 static constexpr std::size_t
lanes = 8;
649#include "native/simd/polyfill_lane_access.h"
656 hint_inline constexpr explicit
simd(
fp16 value) noexcept
659 hint_inline
constexpr explicit simd(std::array<fp16,lanes>
const & values) noexcept :
simd(
load(values.data())) {}
661 template<
class... T>
requires(
sizeof...(T) == lanes && (std::same_as<T,fp16> && ...))
666 [[nodiscard]] hint_inline
constexpr operator native_type() const noexcept {
return value_; }
671 simd result; result.value_ = value;
return result;
675 return bits_type::from_native(__builtin_bit_cast(
typename bits_type::native_type,value_));
685 [[nodiscard]]
static hint_inline
constexpr simd load_bits(std::uint16_t
const * p)
noexcept {
690 hint_inline
constexpr void store_bits(std::uint16_t * p)
const noexcept {
bits().store(p); }
695 template<std::
size_t Alignment = 1>
697 static_assert(Alignment > 0 && (Alignment & (Alignment - 1)) == 0);
699 std::array<std::uint16_t,lanes> words{};
700 for (std::size_t i=0;i<
lanes;++i) words[i]=p[i].
to_bits();
703 native_type value; std::memcpy(&value,
reinterpret_cast<unsigned char const *
>(p),
sizeof(value));
return from_native(value);
709 template<std::
size_t Alignment = 1>
711 static_assert(Alignment > 0 && (Alignment & (Alignment - 1)) == 0);
713 std::array<std::uint16_t,lanes> words{};
store_bits(words.data());
717 std::memcpy(
reinterpret_cast<unsigned char *
>(p), &value_,
sizeof(value_));
724 [[nodiscard]]
static hint_inline
constexpr simd loadu(
fp16 const * p)
noexcept {
return load(p); }
734 std::array<fp16,lanes> values; values.fill(fill);
736 for (std::size_t i=0;i<n;++i) values[i]=p[i];
737 }
else {
if (n) std::memcpy(values.data(),
reinterpret_cast<unsigned char const *
>(p), n *
sizeof(
fp16)); }
738 return load(values.data());
743 hint_inline
constexpr void store_partial(
fp16 * p, std::size_t n)
const noexcept hint_diagnose_if(n > simd::lanes,
"partial SIMD count exceeds the lane count") {
746 std::array<std::uint16_t,lanes> words{};
store_bits(words.data());
748 }
else {
if (n) std::memcpy(
reinterpret_cast<unsigned char *
>(p), &value_, n *
sizeof(
fp16)); }
752 if consteval {
return detail::half_constant::arithmetic<detail::half_constant::operation::add,true>(a,b); }
753 return from_native(detail::neon_fp16_backend::add_half(a.value_,b.value_));
757 if consteval {
return detail::half_constant::arithmetic<detail::half_constant::operation::subtract,true>(a,b); }
758 return from_native(detail::neon_fp16_backend::sub_half(a.value_,b.value_));
762 if consteval {
return detail::half_constant::arithmetic<detail::half_constant::operation::multiply,true>(a,b); }
763 return from_native(detail::neon_fp16_backend::mul_half(a.value_,b.value_));
768 if consteval {
return detail::half_constant::arithmetic<detail::half_constant::operation::divide,true>(a,b); }
769 return from_native(detail::neon_fp16_backend::div_half(a.value_,b.value_));
775 [[nodiscard]]
friend hint_inline
constexpr simd sqrt(
simd a)
noexcept {
776 if consteval {
return detail::half_constant::square_root<true>(a); }
777 return from_native(detail::neon_fp16_backend::sqrt_half(a.value_));
781 if consteval {
return detail::half_constant::unary(a,[](
auto x) {
return std::uint16_t(x^0x8000); }); }
782 return from_native(detail::neon_fp16_backend::neg_half(a.value_));
787 if consteval {
return detail::half_constant::compare(a,b,[](
auto x,
auto y) {
return detail::constexpr_float::equal_bits<detail::constexpr_float::binary16>(x,y); }); }
788 return mask::unsafe_from_native(detail::neon_fp16_backend::eq_half(a.value_,b.value_));
794 if consteval {
return detail::half_constant::compare(a,b,[](
auto x,
auto y) {
return detail::constexpr_float::less_bits<detail::constexpr_float::binary16>(x,y); }); }
795 return mask::unsafe_from_native(detail::neon_fp16_backend::lt_half(a.value_,b.value_));
799 if consteval {
return detail::half_constant::compare(a,b,[](
auto x,
auto y) {
return detail::constexpr_float::less_bits<detail::constexpr_float::binary16>(x,y) || detail::constexpr_float::equal_bits<detail::constexpr_float::binary16>(x,y); }); }
800 return mask::unsafe_from_native(detail::neon_fp16_backend::le_half(a.value_,b.value_));
809 if consteval {
return detail::half_constant::select(m,a,b); }
810 return from_native(detail::neon_fp16_backend::select_half(m.to_native(),a.value_,b.value_));
817 template<::native::isa<> Arch>
requires NATIVE_ARCH_REQUIRES(Arch)
820 if consteval {
return detail::half_constant::fused<true>(a,b,c); }
822 detail::neon_fp16_backend::fma_half(a.to_native(),b.to_native(),c.to_native()));
826#pragma clang attribute pop
827#undef NATIVE_ARCH_REQUIRES
833 template<
class T>
concept instruction_element = simd_integer_element<T> ||
834 std::same_as<T,float> || std::same_as<T,double> ||
835 std::same_as<T,fp16> || std::same_as<T,bf16>;
837 template<
class T, std::
size_t N, isa<> A>
838 inline constexpr bool instruction_storage_shape = [] {
839 if constexpr(!instruction_element<T> || N<2)
return false;
840 else if constexpr(N>64/
sizeof(T))
return false;
841 else return instruction_only_shape<T,N,A>;
844 template<std::
size_t N,isa<> A>
inline constexpr bool instruction_predicate_shape =
847 A.has(x86_feature::sse2) && !((kernel_base<=A) &&
848 (N==1 || N==2 || N==3 || N==4 || N==8 || N==16 ||
849 ((N==32 || N==64) && A.has(x86_feature::avx512bw))));
850#elif NATIVE_HOST_NEON
856 template<
class T,std::
size_t N,isa<> A>
857 requires ordinary_simd_element<T> && instruction_storage_shape<T,N,A>
858 struct value_traits<simd<T,N,A>> {
859 static constexpr isa<> value=A;
860 static constexpr bool known=
true;
861 static constexpr bool aggregate_default=
false;
863 template<std::
size_t N,isa<> A>
requires instruction_predicate_shape<N,A>
864 struct value_traits<predicate<N,A>> {
865 static constexpr isa<> value=A;
866 static constexpr bool known=
true;
867 static constexpr bool aggregate_default=
false;
870 template<
class T, std::
size_t N>
struct instruction_register {
872 using type=std::conditional_t<std::same_as<T,double>,float64x2_t,
873 std::conditional_t<(
sizeof(T)*N<=8),uint8x8_t,uint8x16_t>>;
875 using type=std::conditional_t<std::same_as<T,float>,
876 std::conditional_t<(
sizeof(T)*N<=16),__m128,std::conditional_t<(
sizeof(T)*N==32),__m256,__m512>>,
877 std::conditional_t<std::same_as<T,double>,
878 std::conditional_t<(
sizeof(T)*N<=16),__m128d,std::conditional_t<(
sizeof(T)*N==32),__m256d,__m512d>>,
879 std::conditional_t<(
sizeof(T)*N<=16),__m128i,std::conditional_t<(
sizeof(T)*N==32),__m256i,__m512i>>>>;
885 template<std::
size_t N, isa<> A>
requires detail::instruction_predicate_shape<N,A>
887 static constexpr isa<> architecture=A;
888 static constexpr std::size_t lanes=N;
889 using native_type=std::conditional_t<(N<=8),std::uint8_t,
890 std::conditional_t<(N<=16),std::uint16_t,std::conditional_t<(N<=32),std::uint32_t,std::uint64_t>>>;
893 static constexpr bool compact=
true;
895 native_type value_{};
896 static constexpr std::uint64_t active=[] {
if constexpr(N==64)
return ~std::uint64_t{};
else return (std::uint64_t{1}<<N)-1; }();
901 explicit hint_inline constexpr
predicate(
bool value) noexcept : value_(value?native_type(active):0) {}
909 hint_inline
constexpr native_type
to_native() const noexcept {
return value_; }
911 hint_inline
constexpr std::uint64_t
bits() const noexcept {
return value_; }
913 hint_inline
constexpr std::uint64_t
to_bitset() const noexcept {
return value_; }
915 friend hint_inline
constexpr bool any(
predicate p)
noexcept {
return p.value_!=0; }
917 friend hint_inline
constexpr bool all(
predicate p)
noexcept {
return p.value_==active; }
919 friend hint_inline
constexpr bool none(
predicate p)
noexcept {
return p.value_==0; }
947 template<
class T, std::
size_t N, isa<> A>
requires detail::instruction_storage_shape<T,N,A>
948 struct alignas(typename detail::instruction_register<T,N>::type)
simd<T,N,A>
949 : detail::polyfill_storage_operations<T,N,A,simd<T,N,A>> {
951 using register_type=
simd;
952 using native_type=
typename detail::instruction_register<T,N>::type;
953 static constexpr isa<> architecture=A;
954 static constexpr std::size_t lanes=N;
955 using word_type=std::conditional_t<
sizeof(T)==1,std::uint8_t,std::conditional_t<
sizeof(T)==2,std::uint16_t,std::conditional_t<
sizeof(T)==4,std::uint32_t,std::uint64_t>>>;
957 using mask_type=mask;
958 using predicate_type=mask;
959 using bits_type=
simd<std::conditional_t<
sizeof(T)==1,std::uint8_t,
960 std::conditional_t<
sizeof(T)==2,std::uint16_t,
961 std::conditional_t<
sizeof(T)==4,std::uint32_t,std::uint64_t>>>,N,A>;
968#define NATIVE_INSTRUCTION_HALF_REJECT_BINARY(OP) \
970 friend void operator OP(simd,simd) \
971 requires((std::same_as<T,fp16> && !A.has(polyfill)) || std::same_as<T,bf16>) = delete; \
973 template<class U> requires(((std::same_as<T,fp16> && !A.has(polyfill)) || std::same_as<T,bf16>) && \
974 !std::same_as<std::remove_cvref_t<U>,simd>) \
975 friend void operator OP(simd,U) = delete; \
977 template<class U> requires(((std::same_as<T,fp16> && !A.has(polyfill)) || std::same_as<T,bf16>) && \
978 !std::same_as<std::remove_cvref_t<U>,simd>) \
979 friend void operator OP(U,simd) = delete;
980 NATIVE_INSTRUCTION_HALF_REJECT_BINARY(+)
981 NATIVE_INSTRUCTION_HALF_REJECT_BINARY(-)
982 NATIVE_INSTRUCTION_HALF_REJECT_BINARY(*)
983 NATIVE_INSTRUCTION_HALF_REJECT_BINARY(/)
984 NATIVE_INSTRUCTION_HALF_REJECT_BINARY(%)
985 NATIVE_INSTRUCTION_HALF_REJECT_BINARY(&)
986 NATIVE_INSTRUCTION_HALF_REJECT_BINARY(|)
987 NATIVE_INSTRUCTION_HALF_REJECT_BINARY(^)
988 NATIVE_INSTRUCTION_HALF_REJECT_BINARY(<<)
989 NATIVE_INSTRUCTION_HALF_REJECT_BINARY(>>)
990 NATIVE_INSTRUCTION_HALF_REJECT_BINARY(==)
991 NATIVE_INSTRUCTION_HALF_REJECT_BINARY(!=)
992 NATIVE_INSTRUCTION_HALF_REJECT_BINARY(<)
993 NATIVE_INSTRUCTION_HALF_REJECT_BINARY(<=)
994 NATIVE_INSTRUCTION_HALF_REJECT_BINARY(>)
995 NATIVE_INSTRUCTION_HALF_REJECT_BINARY(>=)
996#undef NATIVE_INSTRUCTION_HALF_REJECT_BINARY
997#define NATIVE_INSTRUCTION_HALF_REJECT_ASSIGN(OP) \
999 template<class U> requires((std::same_as<T,fp16> && !A.has(polyfill)) || std::same_as<T,bf16>) \
1000 void operator OP(U) = delete;
1001 NATIVE_INSTRUCTION_HALF_REJECT_ASSIGN(+=)
1002 NATIVE_INSTRUCTION_HALF_REJECT_ASSIGN(-=)
1003 NATIVE_INSTRUCTION_HALF_REJECT_ASSIGN(*=)
1004 NATIVE_INSTRUCTION_HALF_REJECT_ASSIGN(/=)
1005 NATIVE_INSTRUCTION_HALF_REJECT_ASSIGN(%=)
1006 NATIVE_INSTRUCTION_HALF_REJECT_ASSIGN(&=)
1007 NATIVE_INSTRUCTION_HALF_REJECT_ASSIGN(|=)
1008 NATIVE_INSTRUCTION_HALF_REJECT_ASSIGN(^=)
1009 NATIVE_INSTRUCTION_HALF_REJECT_ASSIGN(<<=)
1010 NATIVE_INSTRUCTION_HALF_REJECT_ASSIGN(>>=)
1011#undef NATIVE_INSTRUCTION_HALF_REJECT_ASSIGN
1012#define NATIVE_INSTRUCTION_POLYFILL_ASSIGN(OP) \
1014 template<class U> requires(A.has(polyfill) && requires(simd x,U y) { { x OP y } -> std::same_as<simd>; }) \
1015 constexpr simd & operator OP##=(U value) noexcept { return *this=*this OP value; }
1016 NATIVE_INSTRUCTION_POLYFILL_ASSIGN(+)
1017 NATIVE_INSTRUCTION_POLYFILL_ASSIGN(-)
1018 NATIVE_INSTRUCTION_POLYFILL_ASSIGN(*)
1019 NATIVE_INSTRUCTION_POLYFILL_ASSIGN(/)
1020 NATIVE_INSTRUCTION_POLYFILL_ASSIGN(%)
1021 NATIVE_INSTRUCTION_POLYFILL_ASSIGN(&)
1022 NATIVE_INSTRUCTION_POLYFILL_ASSIGN(|)
1023 NATIVE_INSTRUCTION_POLYFILL_ASSIGN(^)
1024#undef NATIVE_INSTRUCTION_POLYFILL_ASSIGN
1036 hint_inline constexpr explicit
simd(T value) noexcept {
1037 std::array<T,N> values;
1039 *
this=
load(values.data());
1042 hint_inline
constexpr explicit simd(std::array<T,N>
const & values) noexcept :
simd(
load(values.data())) {}
1044 template<
class... U>
requires(
sizeof...(U)==N && (std::same_as<U,T> && ...))
1045 hint_inline constexpr
simd(U... values) noexcept :
simd(
std::array<T,N>{values...}) {}
1050 [[nodiscard]] hint_inline
constexpr hint_target(
"sse2")
1051 native_type
to_native() const noexcept requires(sizeof(native_type)==16) {
return value_; }
1053 [[nodiscard]]
static hint_inline
constexpr hint_target(
"sse2")
1055 simd result; result.value_=value;
return result;
1058 [[nodiscard]]
static hint_inline
constexpr hint_target(
"sse2")
1060 simd result; result.value_=value;
return result;
1063 [[nodiscard]] hint_inline
constexpr hint_target(
"avx")
1064 native_type
to_native() const noexcept requires(sizeof(native_type)==32) {
return value_; }
1066 [[nodiscard]]
static hint_inline
constexpr hint_target(
"avx")
1068 simd result; result.value_=value;
return result;
1071 [[nodiscard]]
static hint_inline
constexpr hint_target(
"avx")
1073 simd result; result.value_=value;
return result;
1076 [[nodiscard]] hint_inline
constexpr hint_target(
"avx512f")
1077 native_type
to_native() const noexcept requires(sizeof(native_type)==64) {
return value_; }
1079 [[nodiscard]]
static hint_inline
constexpr hint_target(
"avx512f")
1081 simd result; result.value_=value;
return result;
1084 [[nodiscard]]
static hint_inline
constexpr hint_target(
"avx512f")
1086 simd result; result.value_=value;
return result;
1090 [[nodiscard]] hint_inline
constexpr native_type to_native() const noexcept {
return value_; }
1092 [[nodiscard]]
static hint_inline
constexpr simd from_native(native_type value)
noexcept {
1093 simd result; result.value_=value;
return result;
1097 template<std::
size_t Alignment=1>
1099 static_assert(Alignment>0 && (Alignment&(Alignment-1))==0);
1102 std::array<T,
sizeof(native_type)/
sizeof(T)> values{};
1103 for(std::size_t i=0;i<N;++i) values[i]=p[i];
1104 result.value_=std::bit_cast<native_type>(values);
1105 }
else { std::memcpy(&result.value_,
reinterpret_cast<unsigned char const *
>(p),
sizeof(T)*N); }
1109 template<std::
size_t Alignment=1>
1111 static_assert(Alignment>0 && (Alignment&(Alignment-1))==0);
1113 auto values=std::bit_cast<std::array<T,
sizeof(native_type)/
sizeof(T)>>(value_);
1114 for(std::size_t i=0;i<N;++i) p[i]=values[i];
1115 }
else { std::memcpy(
reinterpret_cast<unsigned char *
>(p),&value_,
sizeof(T)*N); }
1120 [[nodiscard]]
static hint_inline
constexpr simd loadu(T
const * p)
noexcept {
return load(p); }
1126 [[nodiscard]]
static hint_inline
constexpr simd load_partial(T
const * p,std::size_t n,T fill=T{})
noexcept hint_diagnose_if(n > simd::lanes,
"partial SIMD count exceeds the lane count") {
1128 std::array<T,N> values; values.fill(fill);
1130 for(std::size_t i=0;i<n;++i) values[i]=p[i];
1131 }
else {
if(n) std::memcpy(values.data(),
reinterpret_cast<unsigned char const *
>(p),n*
sizeof(T)); }
1132 return load(values.data());
1135 hint_inline
constexpr void store_partial(T * p,std::size_t n)
const noexcept hint_diagnose_if(n > simd::lanes,
"partial SIMD count exceeds the lane count") {
1139 auto values=std::bit_cast<std::array<T,
sizeof(native_type)/
sizeof(T)>>(value_);
1140 for(std::size_t i=0;i<n;++i) p[i]=values[i];
1142 }
else {
if(n) std::memcpy(
reinterpret_cast<unsigned char *
>(p),&value_,n*
sizeof(T)); }
1146 return bits_type::from_native(std::bit_cast<typename bits_type::native_type>(value_));
1151 [[nodiscard]]
static hint_inline
constexpr simd from_bits(bits_type words)
noexcept requires(std::same_as<T,fp16> || std::same_as<T,bf16> || A.has(
polyfill)) {
1152 return from_native(std::bit_cast<native_type>(words.to_native()));
1155 [[nodiscard]]
static hint_inline
constexpr simd load_bits(word_type
const * p)
noexcept requires(std::same_as<T,fp16> || std::same_as<T,bf16> || A.has(
polyfill)) {
1156 if consteval {
return from_bits(bits_type::load(p)); }
1157 else {
simd result{}; std::memcpy(&result.value_,
reinterpret_cast<unsigned char const *
>(p),
sizeof(T)*N);
return result; }
1160 hint_inline
constexpr void store_bits(word_type * p)
const noexcept requires(std::same_as<T,fp16> || std::same_as<T,bf16> || A.has(
polyfill)) {
1161 if consteval {
bits().store(p); }
1162 else { std::memcpy(
reinterpret_cast<unsigned char *
>(p),&value_,
sizeof(T)*N); }
1169#if NATIVE_HOST_NEON || NATIVE_HOST_X86
1175 template<std::
size_t N,isa<> A>
requires(N>0 && N<=64 && N%2==0 && A.has(
polyfill) &&
1177 !A.has(arm_feature::neon_bf16) &&
1179 !A.has(x86_feature::avx512bf16) &&
1181 requires { sizeof(simd<bf16,N,A>); sizeof(simd<float,N/2,A>); })
1182 [[nodiscard]] hint_inline
constexpr simd<float,N/2,A>
dot2(
1184 return detail::half_constant::dot2<NATIVE_HOST_NEON!=0>(a,b,accumulator);
1188#pragma clang attribute push(__attribute__((target("neon,bf16"))), apply_to=function)
1190#pragma clang attribute push(__attribute__((target("avx512bf16"))), apply_to=function)
1196 template<std::
size_t N,isa<> A>
requires(N>0 && N<=64 && N%2==0 && A.has(
polyfill) &&
1198 A.has(arm_feature::neon_bf16) && !(N==8 && neon_bf16<=A) &&
1200 A.has(x86_feature::avx512bf16) && !((N==8 || N==16 || N==32) && avx512_bf16<=A) &&
1202 requires { sizeof(simd<bf16,N,A>); sizeof(simd<float,N/2,A>); })
1203 [[nodiscard]] hint_inline
constexpr simd<float,N/2,A>
dot2(
1205 return detail::polyfill_dot2_native(a,b,accumulator);
1208#pragma clang attribute pop
Scalar half storage, numeric limits and legacy scalar predicates.
Architecture-tagged vectors, register packs and supporting value types. Native arithmetic follows its...
constexpr simd< float, N/2, Arch > dot2(simd< bf16, N, Arch > a, simd< bf16, N, Arch > b, simd< float, N/2, Arch > accumulator) noexcept
constexpr simd< fp16, 32, Arch > fma(simd< fp16, 32, Arch > a, simd< fp16, 32, Arch > b, simd< fp16, 32, Arch > c) noexcept
constexpr polyfill_t polyfill
Compose this permission with an ISA using A | polyfill. Used alone, it selects scalar emulation in th...
Standard-library adaptations documented here for SIMD value types.
static constexpr bf16 from_bits(uint16_t data) noexcept
Adopt the exact sixteen representation bits without normalization.
static constexpr fp16 from_bits(uint16_t data) noexcept
Adopt the exact sixteen representation bits without normalization.
constexpr std::uint64_t to_bitset() const noexcept
Return the logical lane bitset.
static constexpr predicate from_bits(std::uint64_t bits) noexcept
Read one bit per lane and clear bits above the logical lane count.
friend constexpr bool all(predicate p) noexcept
Test whether every logical lane is set.
static constexpr predicate from_bitset(std::uint64_t bits) noexcept
Construct from the logical lane bitset.
friend constexpr predicate operator~(predicate p) noexcept
Complement logical lanes, leaving padding clear.
constexpr std::uint64_t bits() const noexcept
Return one bit per logical lane.
friend constexpr predicate operator==(predicate a, predicate b) noexcept
Mark lanes whose truth values agree.
friend constexpr bool none(predicate p) noexcept
Test whether every logical lane is clear.
constexpr native_type to_native() const noexcept
Return the compact implementation representation.
constexpr predicate & operator^=(predicate b) noexcept
Toggle lanes present in another mask.
friend constexpr predicate operator!(predicate p) noexcept
Complement each logical lane.
static constexpr predicate from_native(native_type bits) noexcept
Adopt the compact representation, clearing unused bits.
friend constexpr predicate operator&(predicate a, predicate b) noexcept
Intersect the logical lane masks.
friend constexpr bool any(predicate p) noexcept
Test whether any logical lane is set.
friend constexpr predicate operator^(predicate a, predicate b) noexcept
Toggle lanes present in exactly one operand.
friend constexpr predicate select(predicate p, predicate a, predicate b) noexcept
Choose each mask lane from a or b according to p.
friend constexpr predicate operator!=(predicate a, predicate b) noexcept
Mark lanes whose truth values differ.
constexpr predicate & operator&=(predicate b) noexcept
Intersect with another mask in place.
friend constexpr predicate operator|(predicate a, predicate b) noexcept
Unite the logical lane masks.
constexpr predicate() noexcept=default
Construct an empty mask.
constexpr predicate & operator|=(predicate b) noexcept
Unite with another mask in place.
friend void operator+(simd)=delete
Reject unary arithmetic on half instruction storage.
static constexpr simd load(T const *p) noexcept
Read exactly N elements with their natural alignment.
static constexpr simd load_bits(word_type const *p) noexcept
Read N unsigned lane representations without numerical conversion.
constexpr void store_memory(T *p) const noexcept
Write exactly N objects; Alignment is a caller promise.
constexpr bits_type to_bits() const noexcept
Synonym for bits; no floating-point conversion occurs.
friend void operator-(simd)=delete
Reject unary arithmetic on half instruction storage.
constexpr bits_type bits() const noexcept
Return each lane as its unchanged unsigned representation.
friend void operator!(simd)=delete
Half storage does not define a predicate conversion.
constexpr simd() noexcept=default
Default initialization leaves storage unspecified; braces zero it.
constexpr void store_partial(T *p, std::size_t n) const noexcept
Write the first n <= N elements; a null pointer is valid for n == 0.
constexpr native_type to_native() const noexcept
Bridge to the implementation register without numerical conversion.
static constexpr simd unsafe_from_native(native_type value) noexcept
Synonym for from_native; these storage-only shapes do not normalize padding.
static constexpr simd loadu(T const *p) noexcept
Synonym for load; register alignment is unnecessary.
constexpr simd(std::array< T, N > const &values) noexcept
Copy the array elements in lane order.
friend void operator~(simd)=delete
Use bits() for explicit bitwise operations on half representations.
static constexpr simd from_bits(bits_type words) noexcept
Interpret unsigned words as lane representations without conversion.
static constexpr simd from_native(native_type value) noexcept
Adopt register bits unchanged; unused physical bytes are unspecified.
static constexpr simd load_memory(T const *p) noexcept
Read exactly N objects, without requiring register-width alignment.
constexpr void store(T *p) const noexcept
Write exactly N elements in lane order.
static constexpr simd load_partial(T const *p, std::size_t n, T fill=T{}) noexcept
Read n <= N elements and fill the remainder; a null pointer is valid for n == 0.
constexpr void store_bits(word_type *p) const noexcept
Write N unsigned lane representations without numerical conversion.
constexpr void storeu(T *p) const noexcept
Synonym for store; register alignment is unnecessary.
constexpr void store_partial(bf16 *p, std::size_t n) const noexcept
simd() noexcept=default
Default initialization leaves storage unspecified; braces zero it.
simd< std::uint16_t, 8, architecture > bits_type
Unsigned 16-bit lanes in the same profile and lane order.
static constexpr simd from_bits(bits_type value) noexcept
Interpret each unsigned lane as a BF16 representation without changing its bits.
static constexpr simd load_bits(std::uint16_t const *p) noexcept
static constexpr std::size_t lanes
Number of logical BF16 lanes, with no padding lanes.
constexpr bits_type to_bits() const noexcept
Synonym for bits(); this is a representation bridge, not a numeric conversion.
constexpr void store(bf16 *p) const noexcept
Store 8 BF16 objects with the default alignment contract of store_memory().
constexpr native_type to_native() const noexcept
Return all lane bits as a native register, without conversion or lane reordering.
constexpr void store_memory(bf16 *p) const noexcept
static constexpr simd loadu(bf16 const *p) noexcept
Synonym for load(); no register-width alignment is required.
simd< T, 8, architecture > rebind
constexpr bits_type bits() const noexcept
Return the 16-bit representation of each lane in an unsigned vector.
static constexpr simd load_memory(bf16 const *p) noexcept
simd< mask16, 8, architecture > mask
Full-register predicate with zero or all-one 16-bit lanes.
constexpr simd(native_type value) noexcept
Adopt a native register without conversion or representation changes.
constexpr void store_bits(std::uint16_t *p) const noexcept
static constexpr isa architecture
The distinct compile-time NEON_BF16 instruction profile.
mask predicate_type
Explicit predicate spelling for the same full-register mask type.
bf16 value_type
Scalar storage element; each lane retains all 16 representation bits.
static constexpr simd load(bf16 const *p) noexcept
Load 8 BF16 objects with the default alignment contract of load_memory().
constexpr void storeu(bf16 *p) const noexcept
Synonym for store(); no register-width alignment is required.
static constexpr simd from_native(native_type value) noexcept
Copy a native BF16 register into this vector, preserving every representation bit.
bfloat16x8_t native_type
Native 128-bit BF16 register representation; native bridges copy bits.
constexpr simd(std::array< bf16, lanes > const &values) noexcept
Copy array element i into lane i without conversion or representation changes.
simd register_type
This one-register vector type, for generic register-based algorithms.
mask mask_type
Generic mask spelling for the full-register lane mask.
simd< mask16, 8, architecture > vector_mask_type
Full-register mask shape with zero or all-one 16-bit lanes.
static constexpr simd load_partial(bf16 const *p, std::size_t n, bf16 fill=bf16::from_bits(0)) noexcept
static constexpr std::size_t lanes
Number of logical BF16 lanes, with no padding lanes.
static constexpr simd load_memory(bf16 const *p) noexcept
static constexpr simd loadu(bf16 const *p) noexcept
Synonym for load(); no register-width alignment is required.
constexpr void store_memory(bf16 *p) const noexcept
static constexpr simd load_bits(std::uint16_t const *p) noexcept
constexpr simd(native_type value) noexcept
Adopt a native register without conversion or representation changes.
constexpr void store_bits(std::uint16_t *p) const noexcept
std::conditional_t< N==8, __m128bh, std::conditional_t< N==16, __m256bh, __m512bh > > native_type
Native register-width BF16 register representation; native bridges copy bits.
constexpr simd(std::array< bf16, lanes > const &values) noexcept
Copy array element i into lane i without conversion or representation changes.
constexpr void store_partial(bf16 *p, std::size_t n) const noexcept
simd< mask16, N, architecture > vector_mask_type
Full-register mask shape with zero or all-one 16-bit lanes.
bf16 value_type
Scalar storage element; each lane retains all 16 representation bits.
static constexpr isa architecture
The distinct compile-time AVX512_BF16 instruction profile.
constexpr bits_type to_bits() const noexcept
Synonym for bits(); this is a representation bridge, not a numeric conversion.
constexpr void storeu(bf16 *p) const noexcept
Synonym for store(); no register-width alignment is required.
static constexpr simd load(bf16 const *p) noexcept
Load N BF16 objects with the default alignment contract of load_memory().
static constexpr simd load_partial(bf16 const *p, std::size_t n, bf16 fill=bf16::from_bits(0)) noexcept
constexpr bits_type bits() const noexcept
Return the 16-bit representation of each lane in an unsigned vector.
constexpr void store(bf16 *p) const noexcept
Store N BF16 objects with the default alignment contract of store_memory().
simd< std::uint16_t, N, architecture > bits_type
Unsigned 16-bit lanes in the same profile and lane order.
mask mask_type
Generic mask spelling for the compact lane predicate.
static constexpr simd from_bits(bits_type value) noexcept
Interpret each unsigned lane as a BF16 representation without changing its bits.
predicate< N, architecture > mask
Compact predicate with bit i selecting BF16 lane i.
mask predicate_type
Explicit predicate spelling for the same compact mask type.
simd< T, N, architecture > rebind
constexpr native_type to_native() const noexcept
Return all lane bits as a native register, without conversion or lane reordering.
simd register_type
This one-register vector type, for generic register-based algorithms.
simd() noexcept=default
Default initialization leaves storage unspecified; braces zero it.
static constexpr simd from_native(native_type value) noexcept
Copy a native BF16 register into this vector, preserving every representation bit.
constexpr bits_type bits() const noexcept
Return the 16-bit representation of each lane in an unsigned vector.
constexpr void store_partial(fp16 *p, std::size_t n) const noexcept
constexpr void store_bits(std::uint16_t *p) const noexcept
friend constexpr simd sqrt(simd a) noexcept
simd< T, 32, architecture > rebind
friend constexpr mask operator>=(simd a, simd b) noexcept
Ordered lane greater-or-equal, with native less-or-equal operands reversed.
static constexpr simd load_bits(std::uint16_t const *p) noexcept
simd register_type
This one-register vector type, for generic register-based algorithms.
constexpr void store(fp16 *p) const noexcept
Store 32 FP16 objects with the default alignment contract of store_memory().
constexpr bits_type to_bits() const noexcept
Synonym for bits(); this is a representation bridge, not a numeric conversion.
friend constexpr simd operator/(simd a, simd b) noexcept
simd< std::uint16_t, 32, architecture > bits_type
Unsigned 16-bit lanes in the same profile and lane order.
static constexpr simd from_native(native_type value) noexcept
Copy a native FP16 register into this vector, preserving every representation bit.
friend constexpr mask operator==(simd a, simd b) noexcept
constexpr simd(native_type value) noexcept
Adopt a native register without conversion or representation changes.
friend constexpr simd select(mask m, simd a, simd b) noexcept
static constexpr simd load_memory(fp16 const *p) noexcept
static constexpr simd from_bits(bits_type value) noexcept
Interpret each unsigned lane as a FP16 representation without changing its bits.
predicate< 32, architecture > mask
Compact predicate with bit i selecting FP16 lane i.
fp16 value_type
Scalar storage element; each lane retains all 16 representation bits.
static constexpr isa architecture
The distinct compile-time AVX512_FP16 instruction profile.
friend constexpr mask operator!=(simd a, simd b) noexcept
Lane inequality, true for unordered NaN operands; complements native equality.
static constexpr simd load_partial(fp16 const *p, std::size_t n, fp16 fill=fp16::from_bits(0)) noexcept
static constexpr simd load(fp16 const *p) noexcept
Load 32 FP16 objects with the default alignment contract of load_memory().
friend constexpr mask operator<=(simd a, simd b) noexcept
Ordered lane less-or-equal. NaNs compare false; native MXCSR exception semantics apply.
constexpr void store_memory(fp16 *p) const noexcept
static constexpr simd loadu(fp16 const *p) noexcept
Synonym for load(); no register-width alignment is required.
friend constexpr simd operator-(simd a) noexcept
Toggle every sign bit, preserving all payload bits without arithmetic exceptions.
constexpr simd(std::array< fp16, lanes > const &values) noexcept
Copy array element i into lane i without conversion or representation changes.
constexpr void storeu(fp16 *p) const noexcept
Synonym for store(); no register-width alignment is required.
friend constexpr simd operator*(simd a, simd b) noexcept
Multiply corresponding half lanes, rounding directly under the caller's MXCSR rounding control.
simd< mask16, 32, architecture > vector_mask_type
Full-register mask shape with zero or all-one 16-bit lanes.
simd() noexcept=default
Default initialization leaves storage unspecified; braces zero it.
constexpr native_type to_native() const noexcept
Return all lane bits as a native register, without conversion or lane reordering.
mask mask_type
Generic mask spelling for the compact lane predicate.
friend constexpr simd operator+(simd a, simd b) noexcept
Add corresponding half lanes, rounding directly under the caller's MXCSR rounding control.
mask predicate_type
Explicit predicate spelling for the same compact predicate type.
friend constexpr simd operator-(simd a, simd b) noexcept
Subtract corresponding half lanes, rounding directly under the caller's MXCSR rounding control.
friend constexpr mask operator<(simd a, simd b) noexcept
Ordered lane less-than. NaNs compare false; native MXCSR exception semantics apply.
__m512h native_type
Native 512-bit FP16 register representation; native bridges copy bits.
static constexpr std::size_t lanes
Number of logical FP16 lanes, with no padding lanes.
friend constexpr mask operator>(simd a, simd b) noexcept
Ordered lane greater-than, with the native less-than operands reversed.
static constexpr std::size_t lanes
Number of logical FP16 lanes, with no padding lanes.
mask mask_type
Generic mask spelling for the full-register lane mask.
friend constexpr simd sqrt(simd a) noexcept
friend constexpr mask operator>=(simd a, simd b) noexcept
Ordered lane greater-or-equal, with native less-or-equal operands reversed.
simd< T, 8, architecture > rebind
static constexpr simd loadu(fp16 const *p) noexcept
Synonym for load(); no register-width alignment is required.
static constexpr simd load_memory(fp16 const *p) noexcept
static constexpr simd from_bits(bits_type value) noexcept
Interpret each unsigned lane as a FP16 representation without changing its bits.
constexpr void store(fp16 *p) const noexcept
Store 8 FP16 objects with the default alignment contract of store_memory().
friend constexpr simd operator/(simd a, simd b) noexcept
friend constexpr mask operator==(simd a, simd b) noexcept
simd< mask16, 8, architecture > mask
Full-register predicate with zero or all-one bits in each 16-bit lane.
friend constexpr simd select(mask m, simd a, simd b) noexcept
simd() noexcept=default
Default initialization leaves storage unspecified; braces zero it.
float16x8_t native_type
Native 128-bit FP16 register representation; native bridges copy bits.
friend constexpr mask operator!=(simd a, simd b) noexcept
Lane inequality, true for unordered NaN operands; complements native equality.
friend constexpr mask operator<=(simd a, simd b) noexcept
Ordered lane less-or-equal. NaNs compare false; native FPCR/FPSR semantics apply.
mask predicate_type
Explicit predicate spelling for the same full-register mask type.
static constexpr simd from_native(native_type value) noexcept
Copy a native FP16 register into this vector, preserving every representation bit.
friend constexpr simd operator-(simd a) noexcept
Apply native FNEG to each half lane; no scalar half-to-float conversion occurs.
static constexpr simd load_partial(fp16 const *p, std::size_t n, fp16 fill=fp16::from_bits(0)) noexcept
static constexpr simd load(fp16 const *p) noexcept
Load 8 FP16 objects with the default alignment contract of load_memory().
constexpr native_type to_native() const noexcept
Return all lane bits as a native register, without conversion or lane reordering.
fp16 value_type
Scalar storage element; each lane retains all 16 representation bits.
friend constexpr simd operator*(simd a, simd b) noexcept
Multiply corresponding half lanes, rounding directly under the caller's FPCR.
constexpr bits_type bits() const noexcept
Return the 16-bit representation of each lane in an unsigned vector.
constexpr void store_memory(fp16 *p) const noexcept
constexpr void store_bits(std::uint16_t *p) const noexcept
friend constexpr simd operator+(simd a, simd b) noexcept
Add corresponding half lanes, rounding directly under the caller's FPCR.
constexpr void store_partial(fp16 *p, std::size_t n) const noexcept
simd< mask16, 8, architecture > vector_mask_type
Full-register mask shape with zero or all-one 16-bit lanes.
friend constexpr simd operator-(simd a, simd b) noexcept
Subtract corresponding half lanes, rounding directly under the caller's FPCR.
constexpr bits_type to_bits() const noexcept
Synonym for bits(); this is a representation bridge, not a numeric conversion.
constexpr simd(std::array< fp16, lanes > const &values) noexcept
Copy array element i into lane i without conversion or representation changes.
static constexpr simd load_bits(std::uint16_t const *p) noexcept
simd< std::uint16_t, 8, architecture > bits_type
Unsigned 16-bit lanes in the same profile and lane order.
friend constexpr mask operator<(simd a, simd b) noexcept
Ordered lane less-than. NaNs compare false; native FPCR/FPSR semantics apply.
constexpr simd(native_type value) noexcept
Adopt a native register without conversion or representation changes.
static constexpr isa architecture
The distinct compile-time NEON_FP16 instruction profile.
constexpr void storeu(fp16 *p) const noexcept
Synonym for store(); no register-width alignment is required.
simd register_type
This one-register vector type, for generic register-based algorithms.
friend constexpr mask operator>(simd a, simd b) noexcept
Ordered lane greater-than, with the native less-than operands reversed.
Omitted architecture arguments use the native.simd provider's baseline.