6#pragma clang attribute push(__attribute__((target("neon,bf16"))), apply_to=function)
7namespace native::detail {
10 template<
class H,
class V>
11 hint_inline
constexpr V polyfill_dot2_native(H a,H b,V accumulator)
noexcept {
12 if consteval {
return half_constant::dot2<true>(a,b,accumulator); }
else {
13 std::array<std::uint16_t,H::lanes> left{},right{};
14 std::array<std::uint32_t,V::lanes> result{};
15 a.store_bits(left.data()); b.store_bits(right.data()); accumulator.store_bits(result.data());
16 for(std::size_t begin=0;begin<V::lanes;begin+=4) {
17 auto const count=std::min(std::size_t{4},V::lanes-begin);
18 std::array<std::uint16_t,8> x{},y{}; std::array<std::uint32_t,4> z{};
19 for(std::size_t i=0;i<count;++i) {
20 x[2*i]=left[2*(begin+i)]; x[2*i+1]=left[2*(begin+i)+1];
21 y[2*i]=right[2*(begin+i)]; y[2*i+1]=right[2*(begin+i)+1]; z[i]=result[begin+i];
23 z=__builtin_bit_cast(
decltype(z),neon_bf16_backend::dot2_native(
24 __builtin_bit_cast(bfloat16x8_t,x),__builtin_bit_cast(bfloat16x8_t,y),__builtin_bit_cast(float32x4_t,z)));
25 for(std::size_t i=0;i<count;++i) result[begin+i]=z[i];
27 return V::load_bits(result.data());
31#pragma clang attribute pop
35#pragma clang attribute push(__attribute__((target("avx512bf16"))), apply_to=function)
36namespace native::detail {
37 template<
class H,
class V>
38 hint_inline
constexpr V polyfill_dot2_native(H a,H b,V accumulator)
noexcept {
39 if consteval {
return half_constant::dot2<false>(a,b,accumulator); }
else {
40 std::array<std::uint16_t,H::lanes> left{},right{};
41 std::array<std::uint32_t,V::lanes> result{};
42 a.store_bits(left.data()); b.store_bits(right.data()); accumulator.store_bits(result.data());
43 for(std::size_t begin=0;begin<V::lanes;begin+=16) {
44 auto const count=std::min(std::size_t{16},V::lanes-begin);
45 std::array<std::uint16_t,32> x{},y{}; std::array<std::uint32_t,16> z{};
46 for(std::size_t i=0;i<count;++i) {
47 x[2*i]=left[2*(begin+i)]; x[2*i+1]=left[2*(begin+i)+1];
48 y[2*i]=right[2*(begin+i)]; y[2*i+1]=right[2*(begin+i)+1]; z[i]=result[begin+i];
50 z=__builtin_bit_cast(
decltype(z),_mm512_dpbf16_ps(__builtin_bit_cast(__m512,z),
51 __builtin_bit_cast(__m512bh,x),__builtin_bit_cast(__m512bh,y)));
52 for(std::size_t i=0;i<count;++i) result[begin+i]=z[i];
54 return V::load_bits(result.data());
58#pragma clang attribute pop