native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
native.arm.fp16fml.ccm
1// SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0
2module;
3#include "native/isa_import.h"
4#include "native/arm/neon.h"
5#include "native/arm/fp16fml.h"
6#include "native/detail/constexpr_float.h"
7#include "native/arm/float_control.h"
8import native.simd;
9#if NATIVE_HOST_NEON || defined(NATIVE_DOXYGEN)
10namespace native::detail {
11 template<isa<arm> Arch,bool Subtract,bool High,int Lane,std::size_t N,std::size_t M>
12 constexpr simd<float,N,Arch> fp16fml_value(simd<float,N,Arch> acc,
13 simd<fp16,2*N,Arch> a,simd<fp16,M,Arch> b,arm_float_control control={}) noexcept {
14 namespace cf=constexpr_float;
15 std::array<std::uint32_t,N> c{};
16 std::array<std::uint16_t,2*N> av{};
17 std::array<std::uint16_t,M> bv{};
18 acc.store_bits(c.data());a.store_bits(av.data());b.store_bits(bv.data());
19 auto widen=[&](std::uint16_t x) {
20 if(control.flush_half_inputs() && !(x&0x7c00)) x&=0x8000;
21 return cf::is_nan<cf::binary16>(x)?cf::resize_nan<cf::binary32,cf::binary16>(x,false)
22 :cf::convert_bits<cf::binary32,cf::binary16>(x);
23 };
24 for(std::size_t i=0;i<N;++i) {
25 auto index=i+(High?N:0);
26 auto x=av[index];
27 if constexpr(Subtract) x=control.negate<cf::binary16>(x);
28 c[i]=cf::fma_bits<cf::binary32>(widen(x),widen(bv[Lane<0?index:Lane]),c[i],control.rounding_mode(),control.policy<cf::binary32>());
29 }
30 return simd<float,N,Arch>::load_bits(c.data());
31 }
32}
33namespace native {
47
48 // All vector operands share Arch; native registers remain implementation details.
50 template<isa<arm> Arch> requires(Arch.has(arm_feature::fp16fml))
51 [[nodiscard]] hint_inline hint_target("fp16fml")
52 constexpr simd<float, 2, Arch> fmlal(
53 simd<float, 2, Arch> acc,
54 simd<fp16, 4, Arch> a,
55 simd<fp16, 4, Arch> b) noexcept {
56 if consteval { return detail::fp16fml_value<Arch,false,false,-1>(acc,a,b); } else {
57 auto result = detail::fmlal<Arch>(
58 vget_low_f32(detail::arm_neon::to_register<float32x4_t>(acc)),
59 __builtin_bit_cast(float16x4_t, a.to_native()),
60 __builtin_bit_cast(float16x4_t, b.to_native()));
61 return detail::arm_neon::from_register<simd<float, 2, Arch>>(vcombine_f32(result, vdup_n_f32(0.f)));
62 }
63 }
64
66 template<isa<arm> Arch> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)))
67 [[nodiscard]] consteval
71 simd<fp16, 4, Arch> b) noexcept {
72 return detail::fp16fml_value<Arch,false,false,-1>(acc,a,b);
73 }
74
76 template<isa<arm> Arch> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)))
77 [[nodiscard]] constexpr
81 simd<fp16, 4, Arch> b) noexcept {
82 return detail::fp16fml_value<Arch,false,false,-1>(acc,a,b, detail::arm_float_control::current());
83 }
84
86 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(arm_feature::fp16fml) && Lane < 4)
87 [[nodiscard]] hint_inline hint_target("fp16fml")
91 simd<fp16, 4, Arch> b) noexcept {
92 if consteval { return detail::fp16fml_value<Arch,false,false,Lane>(acc,a,b); } else {
93 auto result = detail::fmlal_lane<Arch, Lane>(
94 vget_low_f32(detail::arm_neon::to_register<float32x4_t>(acc)),
95 __builtin_bit_cast(float16x4_t, a.to_native()),
96 __builtin_bit_cast(float16x4_t, b.to_native()));
97 return detail::arm_neon::from_register<simd<float, 2, Arch>>(vcombine_f32(result, vdup_n_f32(0.f)));
98 }
99 }
100
102 template<isa<arm> Arch, unsigned Lane> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 4)
103 [[nodiscard]] consteval
107 simd<fp16, 4, Arch> b) noexcept {
108 return detail::fp16fml_value<Arch,false,false,Lane>(acc,a,b);
109 }
110
112 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 4)
113 [[nodiscard]] constexpr
117 simd<fp16, 4, Arch> b) noexcept {
118 return detail::fp16fml_value<Arch,false,false,Lane>(acc,a,b, detail::arm_float_control::current());
119 }
120
122 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(arm_feature::fp16fml) && Lane < 8)
123 [[nodiscard]] hint_inline hint_target("fp16fml")
127 simd<fp16, 8, Arch> b) noexcept {
128 if consteval { return detail::fp16fml_value<Arch,false,false,Lane>(acc,a,b); } else {
129 auto result = detail::fmlal_lane<Arch, Lane>(
130 vget_low_f32(detail::arm_neon::to_register<float32x4_t>(acc)),
131 __builtin_bit_cast(float16x4_t, a.to_native()),
132 __builtin_bit_cast(float16x8_t, b.to_native()));
133 return detail::arm_neon::from_register<simd<float, 2, Arch>>(vcombine_f32(result, vdup_n_f32(0.f)));
134 }
135 }
136
138 template<isa<arm> Arch, unsigned Lane> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 8)
139 [[nodiscard]] consteval
143 simd<fp16, 8, Arch> b) noexcept {
144 return detail::fp16fml_value<Arch,false,false,Lane>(acc,a,b);
145 }
146
148 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 8)
149 [[nodiscard]] constexpr
153 simd<fp16, 8, Arch> b) noexcept {
154 return detail::fp16fml_value<Arch,false,false,Lane>(acc,a,b, detail::arm_float_control::current());
155 }
156
158 template<isa<arm> Arch> requires(Arch.has(arm_feature::fp16fml))
159 [[nodiscard]] hint_inline hint_target("fp16fml")
163 simd<fp16, 8, Arch> b) noexcept {
164 if consteval { return detail::fp16fml_value<Arch,false,false,-1>(acc,a,b); } else {
165 auto result = detail::fmlal<Arch>(
166 detail::arm_neon::to_register<float32x4_t>(acc),
167 __builtin_bit_cast(float16x8_t, a.to_native()),
168 __builtin_bit_cast(float16x8_t, b.to_native()));
169 return simd<float, 4, Arch>::from_native(__builtin_bit_cast(typename simd<float, 4, Arch>::native_type, result));
170 }
171 }
172
174 template<isa<arm> Arch> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)))
175 [[nodiscard]] consteval
179 simd<fp16, 8, Arch> b) noexcept {
180 return detail::fp16fml_value<Arch,false,false,-1>(acc,a,b);
181 }
182
184 template<isa<arm> Arch> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)))
185 [[nodiscard]] constexpr
189 simd<fp16, 8, Arch> b) noexcept {
190 return detail::fp16fml_value<Arch,false,false,-1>(acc,a,b, detail::arm_float_control::current());
191 }
192
194 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(arm_feature::fp16fml) && Lane < 4)
195 [[nodiscard]] hint_inline hint_target("fp16fml")
199 simd<fp16, 4, Arch> b) noexcept {
200 if consteval { return detail::fp16fml_value<Arch,false,false,Lane>(acc,a,b); } else {
201 auto result = detail::fmlal_lane<Arch, Lane>(
202 detail::arm_neon::to_register<float32x4_t>(acc),
203 __builtin_bit_cast(float16x8_t, a.to_native()),
204 __builtin_bit_cast(float16x4_t, b.to_native()));
205 return simd<float, 4, Arch>::from_native(__builtin_bit_cast(typename simd<float, 4, Arch>::native_type, result));
206 }
207 }
208
210 template<isa<arm> Arch, unsigned Lane> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 4)
211 [[nodiscard]] consteval
215 simd<fp16, 4, Arch> b) noexcept {
216 return detail::fp16fml_value<Arch,false,false,Lane>(acc,a,b);
217 }
218
220 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 4)
221 [[nodiscard]] constexpr
225 simd<fp16, 4, Arch> b) noexcept {
226 return detail::fp16fml_value<Arch,false,false,Lane>(acc,a,b, detail::arm_float_control::current());
227 }
228
230 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(arm_feature::fp16fml) && Lane < 8)
231 [[nodiscard]] hint_inline hint_target("fp16fml")
235 simd<fp16, 8, Arch> b) noexcept {
236 if consteval { return detail::fp16fml_value<Arch,false,false,Lane>(acc,a,b); } else {
237 auto result = detail::fmlal_lane<Arch, Lane>(
238 detail::arm_neon::to_register<float32x4_t>(acc),
239 __builtin_bit_cast(float16x8_t, a.to_native()),
240 __builtin_bit_cast(float16x8_t, b.to_native()));
241 return simd<float, 4, Arch>::from_native(__builtin_bit_cast(typename simd<float, 4, Arch>::native_type, result));
242 }
243 }
244
246 template<isa<arm> Arch, unsigned Lane> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 8)
247 [[nodiscard]] consteval
251 simd<fp16, 8, Arch> b) noexcept {
252 return detail::fp16fml_value<Arch,false,false,Lane>(acc,a,b);
253 }
254
256 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 8)
257 [[nodiscard]] constexpr
261 simd<fp16, 8, Arch> b) noexcept {
262 return detail::fp16fml_value<Arch,false,false,Lane>(acc,a,b, detail::arm_float_control::current());
263 }
264
266 template<isa<arm> Arch> requires(Arch.has(arm_feature::fp16fml))
267 [[nodiscard]] hint_inline hint_target("fp16fml")
271 simd<fp16, 4, Arch> b) noexcept {
272 if consteval { return detail::fp16fml_value<Arch,false,true,-1>(acc,a,b); } else {
273 auto result = detail::fmlal2<Arch>(
274 vget_low_f32(detail::arm_neon::to_register<float32x4_t>(acc)),
275 __builtin_bit_cast(float16x4_t, a.to_native()),
276 __builtin_bit_cast(float16x4_t, b.to_native()));
277 return detail::arm_neon::from_register<simd<float, 2, Arch>>(vcombine_f32(result, vdup_n_f32(0.f)));
278 }
279 }
280
282 template<isa<arm> Arch> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)))
283 [[nodiscard]] consteval
287 simd<fp16, 4, Arch> b) noexcept {
288 return detail::fp16fml_value<Arch,false,true,-1>(acc,a,b);
289 }
290
292 template<isa<arm> Arch> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)))
293 [[nodiscard]] constexpr
297 simd<fp16, 4, Arch> b) noexcept {
298 return detail::fp16fml_value<Arch,false,true,-1>(acc,a,b, detail::arm_float_control::current());
299 }
300
302 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(arm_feature::fp16fml) && Lane < 4)
303 [[nodiscard]] hint_inline hint_target("fp16fml")
307 simd<fp16, 4, Arch> b) noexcept {
308 if consteval { return detail::fp16fml_value<Arch,false,true,Lane>(acc,a,b); } else {
309 auto result = detail::fmlal2_lane<Arch, Lane>(
310 vget_low_f32(detail::arm_neon::to_register<float32x4_t>(acc)),
311 __builtin_bit_cast(float16x4_t, a.to_native()),
312 __builtin_bit_cast(float16x4_t, b.to_native()));
313 return detail::arm_neon::from_register<simd<float, 2, Arch>>(vcombine_f32(result, vdup_n_f32(0.f)));
314 }
315 }
316
318 template<isa<arm> Arch, unsigned Lane> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 4)
319 [[nodiscard]] consteval
323 simd<fp16, 4, Arch> b) noexcept {
324 return detail::fp16fml_value<Arch,false,true,Lane>(acc,a,b);
325 }
326
328 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 4)
329 [[nodiscard]] constexpr
333 simd<fp16, 4, Arch> b) noexcept {
334 return detail::fp16fml_value<Arch,false,true,Lane>(acc,a,b, detail::arm_float_control::current());
335 }
336
338 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(arm_feature::fp16fml) && Lane < 8)
339 [[nodiscard]] hint_inline hint_target("fp16fml")
343 simd<fp16, 8, Arch> b) noexcept {
344 if consteval { return detail::fp16fml_value<Arch,false,true,Lane>(acc,a,b); } else {
345 auto result = detail::fmlal2_lane<Arch, Lane>(
346 vget_low_f32(detail::arm_neon::to_register<float32x4_t>(acc)),
347 __builtin_bit_cast(float16x4_t, a.to_native()),
348 __builtin_bit_cast(float16x8_t, b.to_native()));
349 return detail::arm_neon::from_register<simd<float, 2, Arch>>(vcombine_f32(result, vdup_n_f32(0.f)));
350 }
351 }
352
354 template<isa<arm> Arch, unsigned Lane> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 8)
355 [[nodiscard]] consteval
359 simd<fp16, 8, Arch> b) noexcept {
360 return detail::fp16fml_value<Arch,false,true,Lane>(acc,a,b);
361 }
362
364 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 8)
365 [[nodiscard]] constexpr
369 simd<fp16, 8, Arch> b) noexcept {
370 return detail::fp16fml_value<Arch,false,true,Lane>(acc,a,b, detail::arm_float_control::current());
371 }
372
374 template<isa<arm> Arch> requires(Arch.has(arm_feature::fp16fml))
375 [[nodiscard]] hint_inline hint_target("fp16fml")
379 simd<fp16, 8, Arch> b) noexcept {
380 if consteval { return detail::fp16fml_value<Arch,false,true,-1>(acc,a,b); } else {
381 auto result = detail::fmlal2<Arch>(
382 detail::arm_neon::to_register<float32x4_t>(acc),
383 __builtin_bit_cast(float16x8_t, a.to_native()),
384 __builtin_bit_cast(float16x8_t, b.to_native()));
385 return simd<float, 4, Arch>::from_native(__builtin_bit_cast(typename simd<float, 4, Arch>::native_type, result));
386 }
387 }
388
390 template<isa<arm> Arch> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)))
391 [[nodiscard]] consteval
395 simd<fp16, 8, Arch> b) noexcept {
396 return detail::fp16fml_value<Arch,false,true,-1>(acc,a,b);
397 }
398
400 template<isa<arm> Arch> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)))
401 [[nodiscard]] constexpr
405 simd<fp16, 8, Arch> b) noexcept {
406 return detail::fp16fml_value<Arch,false,true,-1>(acc,a,b, detail::arm_float_control::current());
407 }
408
410 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(arm_feature::fp16fml) && Lane < 4)
411 [[nodiscard]] hint_inline hint_target("fp16fml")
415 simd<fp16, 4, Arch> b) noexcept {
416 if consteval { return detail::fp16fml_value<Arch,false,true,Lane>(acc,a,b); } else {
417 auto result = detail::fmlal2_lane<Arch, Lane>(
418 detail::arm_neon::to_register<float32x4_t>(acc),
419 __builtin_bit_cast(float16x8_t, a.to_native()),
420 __builtin_bit_cast(float16x4_t, b.to_native()));
421 return simd<float, 4, Arch>::from_native(__builtin_bit_cast(typename simd<float, 4, Arch>::native_type, result));
422 }
423 }
424
426 template<isa<arm> Arch, unsigned Lane> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 4)
427 [[nodiscard]] consteval
431 simd<fp16, 4, Arch> b) noexcept {
432 return detail::fp16fml_value<Arch,false,true,Lane>(acc,a,b);
433 }
434
436 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 4)
437 [[nodiscard]] constexpr
441 simd<fp16, 4, Arch> b) noexcept {
442 return detail::fp16fml_value<Arch,false,true,Lane>(acc,a,b, detail::arm_float_control::current());
443 }
444
446 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(arm_feature::fp16fml) && Lane < 8)
447 [[nodiscard]] hint_inline hint_target("fp16fml")
451 simd<fp16, 8, Arch> b) noexcept {
452 if consteval { return detail::fp16fml_value<Arch,false,true,Lane>(acc,a,b); } else {
453 auto result = detail::fmlal2_lane<Arch, Lane>(
454 detail::arm_neon::to_register<float32x4_t>(acc),
455 __builtin_bit_cast(float16x8_t, a.to_native()),
456 __builtin_bit_cast(float16x8_t, b.to_native()));
457 return simd<float, 4, Arch>::from_native(__builtin_bit_cast(typename simd<float, 4, Arch>::native_type, result));
458 }
459 }
460
462 template<isa<arm> Arch, unsigned Lane> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 8)
463 [[nodiscard]] consteval
467 simd<fp16, 8, Arch> b) noexcept {
468 return detail::fp16fml_value<Arch,false,true,Lane>(acc,a,b);
469 }
470
472 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 8)
473 [[nodiscard]] constexpr
477 simd<fp16, 8, Arch> b) noexcept {
478 return detail::fp16fml_value<Arch,false,true,Lane>(acc,a,b, detail::arm_float_control::current());
479 }
480
482 template<isa<arm> Arch> requires(Arch.has(arm_feature::fp16fml))
483 [[nodiscard]] hint_inline hint_target("fp16fml")
487 simd<fp16, 4, Arch> b) noexcept {
488 if consteval { return detail::fp16fml_value<Arch,true,false,-1>(acc,a,b); } else {
489 auto result = detail::fmlsl<Arch>(
490 vget_low_f32(detail::arm_neon::to_register<float32x4_t>(acc)),
491 __builtin_bit_cast(float16x4_t, a.to_native()),
492 __builtin_bit_cast(float16x4_t, b.to_native()));
493 return detail::arm_neon::from_register<simd<float, 2, Arch>>(vcombine_f32(result, vdup_n_f32(0.f)));
494 }
495 }
496
498 template<isa<arm> Arch> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)))
499 [[nodiscard]] consteval
503 simd<fp16, 4, Arch> b) noexcept {
504 return detail::fp16fml_value<Arch,true,false,-1>(acc,a,b);
505 }
506
508 template<isa<arm> Arch> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)))
509 [[nodiscard]] constexpr
513 simd<fp16, 4, Arch> b) noexcept {
514 return detail::fp16fml_value<Arch,true,false,-1>(acc,a,b, detail::arm_float_control::current());
515 }
516
518 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(arm_feature::fp16fml) && Lane < 4)
519 [[nodiscard]] hint_inline hint_target("fp16fml")
523 simd<fp16, 4, Arch> b) noexcept {
524 if consteval { return detail::fp16fml_value<Arch,true,false,Lane>(acc,a,b); } else {
525 auto result = detail::fmlsl_lane<Arch, Lane>(
526 vget_low_f32(detail::arm_neon::to_register<float32x4_t>(acc)),
527 __builtin_bit_cast(float16x4_t, a.to_native()),
528 __builtin_bit_cast(float16x4_t, b.to_native()));
529 return detail::arm_neon::from_register<simd<float, 2, Arch>>(vcombine_f32(result, vdup_n_f32(0.f)));
530 }
531 }
532
534 template<isa<arm> Arch, unsigned Lane> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 4)
535 [[nodiscard]] consteval
539 simd<fp16, 4, Arch> b) noexcept {
540 return detail::fp16fml_value<Arch,true,false,Lane>(acc,a,b);
541 }
542
544 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 4)
545 [[nodiscard]] constexpr
549 simd<fp16, 4, Arch> b) noexcept {
550 return detail::fp16fml_value<Arch,true,false,Lane>(acc,a,b, detail::arm_float_control::current());
551 }
552
554 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(arm_feature::fp16fml) && Lane < 8)
555 [[nodiscard]] hint_inline hint_target("fp16fml")
559 simd<fp16, 8, Arch> b) noexcept {
560 if consteval { return detail::fp16fml_value<Arch,true,false,Lane>(acc,a,b); } else {
561 auto result = detail::fmlsl_lane<Arch, Lane>(
562 vget_low_f32(detail::arm_neon::to_register<float32x4_t>(acc)),
563 __builtin_bit_cast(float16x4_t, a.to_native()),
564 __builtin_bit_cast(float16x8_t, b.to_native()));
565 return detail::arm_neon::from_register<simd<float, 2, Arch>>(vcombine_f32(result, vdup_n_f32(0.f)));
566 }
567 }
568
570 template<isa<arm> Arch, unsigned Lane> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 8)
571 [[nodiscard]] consteval
575 simd<fp16, 8, Arch> b) noexcept {
576 return detail::fp16fml_value<Arch,true,false,Lane>(acc,a,b);
577 }
578
580 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 8)
581 [[nodiscard]] constexpr
585 simd<fp16, 8, Arch> b) noexcept {
586 return detail::fp16fml_value<Arch,true,false,Lane>(acc,a,b, detail::arm_float_control::current());
587 }
588
590 template<isa<arm> Arch> requires(Arch.has(arm_feature::fp16fml))
591 [[nodiscard]] hint_inline hint_target("fp16fml")
595 simd<fp16, 8, Arch> b) noexcept {
596 if consteval { return detail::fp16fml_value<Arch,true,false,-1>(acc,a,b); } else {
597 auto result = detail::fmlsl<Arch>(
598 detail::arm_neon::to_register<float32x4_t>(acc),
599 __builtin_bit_cast(float16x8_t, a.to_native()),
600 __builtin_bit_cast(float16x8_t, b.to_native()));
601 return simd<float, 4, Arch>::from_native(__builtin_bit_cast(typename simd<float, 4, Arch>::native_type, result));
602 }
603 }
604
606 template<isa<arm> Arch> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)))
607 [[nodiscard]] consteval
611 simd<fp16, 8, Arch> b) noexcept {
612 return detail::fp16fml_value<Arch,true,false,-1>(acc,a,b);
613 }
614
616 template<isa<arm> Arch> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)))
617 [[nodiscard]] constexpr
621 simd<fp16, 8, Arch> b) noexcept {
622 return detail::fp16fml_value<Arch,true,false,-1>(acc,a,b, detail::arm_float_control::current());
623 }
624
626 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(arm_feature::fp16fml) && Lane < 4)
627 [[nodiscard]] hint_inline hint_target("fp16fml")
631 simd<fp16, 4, Arch> b) noexcept {
632 if consteval { return detail::fp16fml_value<Arch,true,false,Lane>(acc,a,b); } else {
633 auto result = detail::fmlsl_lane<Arch, Lane>(
634 detail::arm_neon::to_register<float32x4_t>(acc),
635 __builtin_bit_cast(float16x8_t, a.to_native()),
636 __builtin_bit_cast(float16x4_t, b.to_native()));
637 return simd<float, 4, Arch>::from_native(__builtin_bit_cast(typename simd<float, 4, Arch>::native_type, result));
638 }
639 }
640
642 template<isa<arm> Arch, unsigned Lane> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 4)
643 [[nodiscard]] consteval
647 simd<fp16, 4, Arch> b) noexcept {
648 return detail::fp16fml_value<Arch,true,false,Lane>(acc,a,b);
649 }
650
652 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 4)
653 [[nodiscard]] constexpr
657 simd<fp16, 4, Arch> b) noexcept {
658 return detail::fp16fml_value<Arch,true,false,Lane>(acc,a,b, detail::arm_float_control::current());
659 }
660
662 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(arm_feature::fp16fml) && Lane < 8)
663 [[nodiscard]] hint_inline hint_target("fp16fml")
667 simd<fp16, 8, Arch> b) noexcept {
668 if consteval { return detail::fp16fml_value<Arch,true,false,Lane>(acc,a,b); } else {
669 auto result = detail::fmlsl_lane<Arch, Lane>(
670 detail::arm_neon::to_register<float32x4_t>(acc),
671 __builtin_bit_cast(float16x8_t, a.to_native()),
672 __builtin_bit_cast(float16x8_t, b.to_native()));
673 return simd<float, 4, Arch>::from_native(__builtin_bit_cast(typename simd<float, 4, Arch>::native_type, result));
674 }
675 }
676
678 template<isa<arm> Arch, unsigned Lane> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 8)
679 [[nodiscard]] consteval
683 simd<fp16, 8, Arch> b) noexcept {
684 return detail::fp16fml_value<Arch,true,false,Lane>(acc,a,b);
685 }
686
688 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 8)
689 [[nodiscard]] constexpr
693 simd<fp16, 8, Arch> b) noexcept {
694 return detail::fp16fml_value<Arch,true,false,Lane>(acc,a,b, detail::arm_float_control::current());
695 }
696
698 template<isa<arm> Arch> requires(Arch.has(arm_feature::fp16fml))
699 [[nodiscard]] hint_inline hint_target("fp16fml")
703 simd<fp16, 4, Arch> b) noexcept {
704 if consteval { return detail::fp16fml_value<Arch,true,true,-1>(acc,a,b); } else {
705 auto result = detail::fmlsl2<Arch>(
706 vget_low_f32(detail::arm_neon::to_register<float32x4_t>(acc)),
707 __builtin_bit_cast(float16x4_t, a.to_native()),
708 __builtin_bit_cast(float16x4_t, b.to_native()));
709 return detail::arm_neon::from_register<simd<float, 2, Arch>>(vcombine_f32(result, vdup_n_f32(0.f)));
710 }
711 }
712
714 template<isa<arm> Arch> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)))
715 [[nodiscard]] consteval
719 simd<fp16, 4, Arch> b) noexcept {
720 return detail::fp16fml_value<Arch,true,true,-1>(acc,a,b);
721 }
722
724 template<isa<arm> Arch> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)))
725 [[nodiscard]] constexpr
729 simd<fp16, 4, Arch> b) noexcept {
730 return detail::fp16fml_value<Arch,true,true,-1>(acc,a,b, detail::arm_float_control::current());
731 }
732
734 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(arm_feature::fp16fml) && Lane < 4)
735 [[nodiscard]] hint_inline hint_target("fp16fml")
739 simd<fp16, 4, Arch> b) noexcept {
740 if consteval { return detail::fp16fml_value<Arch,true,true,Lane>(acc,a,b); } else {
741 auto result = detail::fmlsl2_lane<Arch, Lane>(
742 vget_low_f32(detail::arm_neon::to_register<float32x4_t>(acc)),
743 __builtin_bit_cast(float16x4_t, a.to_native()),
744 __builtin_bit_cast(float16x4_t, b.to_native()));
745 return detail::arm_neon::from_register<simd<float, 2, Arch>>(vcombine_f32(result, vdup_n_f32(0.f)));
746 }
747 }
748
750 template<isa<arm> Arch, unsigned Lane> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 4)
751 [[nodiscard]] consteval
755 simd<fp16, 4, Arch> b) noexcept {
756 return detail::fp16fml_value<Arch,true,true,Lane>(acc,a,b);
757 }
758
760 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 4)
761 [[nodiscard]] constexpr
765 simd<fp16, 4, Arch> b) noexcept {
766 return detail::fp16fml_value<Arch,true,true,Lane>(acc,a,b, detail::arm_float_control::current());
767 }
768
770 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(arm_feature::fp16fml) && Lane < 8)
771 [[nodiscard]] hint_inline hint_target("fp16fml")
775 simd<fp16, 8, Arch> b) noexcept {
776 if consteval { return detail::fp16fml_value<Arch,true,true,Lane>(acc,a,b); } else {
777 auto result = detail::fmlsl2_lane<Arch, Lane>(
778 vget_low_f32(detail::arm_neon::to_register<float32x4_t>(acc)),
779 __builtin_bit_cast(float16x4_t, a.to_native()),
780 __builtin_bit_cast(float16x8_t, b.to_native()));
781 return detail::arm_neon::from_register<simd<float, 2, Arch>>(vcombine_f32(result, vdup_n_f32(0.f)));
782 }
783 }
784
786 template<isa<arm> Arch, unsigned Lane> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 8)
787 [[nodiscard]] consteval
791 simd<fp16, 8, Arch> b) noexcept {
792 return detail::fp16fml_value<Arch,true,true,Lane>(acc,a,b);
793 }
794
796 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 2, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 8)
797 [[nodiscard]] constexpr
801 simd<fp16, 8, Arch> b) noexcept {
802 return detail::fp16fml_value<Arch,true,true,Lane>(acc,a,b, detail::arm_float_control::current());
803 }
804
806 template<isa<arm> Arch> requires(Arch.has(arm_feature::fp16fml))
807 [[nodiscard]] hint_inline hint_target("fp16fml")
811 simd<fp16, 8, Arch> b) noexcept {
812 if consteval { return detail::fp16fml_value<Arch,true,true,-1>(acc,a,b); } else {
813 auto result = detail::fmlsl2<Arch>(
814 detail::arm_neon::to_register<float32x4_t>(acc),
815 __builtin_bit_cast(float16x8_t, a.to_native()),
816 __builtin_bit_cast(float16x8_t, b.to_native()));
817 return simd<float, 4, Arch>::from_native(__builtin_bit_cast(typename simd<float, 4, Arch>::native_type, result));
818 }
819 }
820
822 template<isa<arm> Arch> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)))
823 [[nodiscard]] consteval
827 simd<fp16, 8, Arch> b) noexcept {
828 return detail::fp16fml_value<Arch,true,true,-1>(acc,a,b);
829 }
830
832 template<isa<arm> Arch> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)))
833 [[nodiscard]] constexpr
837 simd<fp16, 8, Arch> b) noexcept {
838 return detail::fp16fml_value<Arch,true,true,-1>(acc,a,b, detail::arm_float_control::current());
839 }
840
842 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(arm_feature::fp16fml) && Lane < 4)
843 [[nodiscard]] hint_inline hint_target("fp16fml")
847 simd<fp16, 4, Arch> b) noexcept {
848 if consteval { return detail::fp16fml_value<Arch,true,true,Lane>(acc,a,b); } else {
849 auto result = detail::fmlsl2_lane<Arch, Lane>(
850 detail::arm_neon::to_register<float32x4_t>(acc),
851 __builtin_bit_cast(float16x8_t, a.to_native()),
852 __builtin_bit_cast(float16x4_t, b.to_native()));
853 return simd<float, 4, Arch>::from_native(__builtin_bit_cast(typename simd<float, 4, Arch>::native_type, result));
854 }
855 }
856
858 template<isa<arm> Arch, unsigned Lane> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 4)
859 [[nodiscard]] consteval
863 simd<fp16, 4, Arch> b) noexcept {
864 return detail::fp16fml_value<Arch,true,true,Lane>(acc,a,b);
865 }
866
868 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && requires { sizeof(simd<fp16, 4, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 4)
869 [[nodiscard]] constexpr
873 simd<fp16, 4, Arch> b) noexcept {
874 return detail::fp16fml_value<Arch,true,true,Lane>(acc,a,b, detail::arm_float_control::current());
875 }
876
878 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(arm_feature::fp16fml) && Lane < 8)
879 [[nodiscard]] hint_inline hint_target("fp16fml")
883 simd<fp16, 8, Arch> b) noexcept {
884 if consteval { return detail::fp16fml_value<Arch,true,true,Lane>(acc,a,b); } else {
885 auto result = detail::fmlsl2_lane<Arch, Lane>(
886 detail::arm_neon::to_register<float32x4_t>(acc),
887 __builtin_bit_cast(float16x8_t, a.to_native()),
888 __builtin_bit_cast(float16x8_t, b.to_native()));
889 return simd<float, 4, Arch>::from_native(__builtin_bit_cast(typename simd<float, 4, Arch>::native_type, result));
890 }
891 }
892
894 template<isa<arm> Arch, unsigned Lane> requires(!Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 8)
895 [[nodiscard]] consteval
899 simd<fp16, 8, Arch> b) noexcept {
900 return detail::fp16fml_value<Arch,true,true,Lane>(acc,a,b);
901 }
902
904 template<isa<arm> Arch, unsigned Lane> requires(Arch.has(polyfill) && requires { sizeof(simd<float, 4, Arch>); } && requires { sizeof(simd<fp16, 8, Arch>); } && !(Arch.has(arm_feature::fp16fml)) && Lane < 8)
905 [[nodiscard]] constexpr
909 simd<fp16, 8, Arch> b) noexcept {
910 return detail::fp16fml_value<Arch,true,true,Lane>(acc,a,b, detail::arm_float_control::current());
911 }
912
914 template<isa<arm> Arch, class A, class B, class C>
915 void fmlal(A, B, C) = delete;
916 template<isa<arm> Arch, unsigned Lane, class A, class B, class C>
917 void fmlal_lane(A, B, C) = delete;
918 template<isa<arm> Arch, class A, class B, class C>
919 void fmlal2(A, B, C) = delete;
920 template<isa<arm> Arch, unsigned Lane, class A, class B, class C>
921 void fmlal2_lane(A, B, C) = delete;
922 template<isa<arm> Arch, class A, class B, class C>
923 void fmlsl(A, B, C) = delete;
924 template<isa<arm> Arch, unsigned Lane, class A, class B, class C>
925 void fmlsl_lane(A, B, C) = delete;
926 template<isa<arm> Arch, class A, class B, class C>
927 void fmlsl2(A, B, C) = delete;
928 template<isa<arm> Arch, unsigned Lane, class A, class B, class C>
929 void fmlsl2_lane(A, B, C) = delete;
932}
933#endif
934
935export module native.arm.fp16fml;
936export import native.arm.features;
937export import native.simd;
938
939#if NATIVE_HOST_NEON || defined(NATIVE_DOXYGEN)
940export namespace native {
941 using ::native::fmlal;
942 using ::native::fmlal2;
943 using ::native::fmlal2_lane;
944 using ::native::fmlal_lane;
945 using ::native::fmlsl;
946 using ::native::fmlsl2;
947 using ::native::fmlsl2_lane;
948 using ::native::fmlsl_lane;
949}
950#endif
constexpr simd< float, 2, Arch > fmlal(simd< float, 2, Arch > acc, simd< fp16, 4, Arch > a, simd< fp16, 4, Arch > b) noexcept
Add products from the low 2 half lanes of a and b.
constexpr simd< float, 2, Arch > fmlsl(simd< float, 2, Arch > acc, simd< fp16, 4, Arch > a, simd< fp16, 4, Arch > b) noexcept
Subtract products from the low 2 half lanes of a and b.
constexpr simd< float, 2, Arch > fmlsl2_lane(simd< float, 2, Arch > acc, simd< fp16, 4, Arch > a, simd< fp16, 4, Arch > b) noexcept
FMLSL2 with b[Lane] broadcast; selects the high 2 lanes of a.
constexpr simd< float, 2, Arch > fmlal_lane(simd< float, 2, Arch > acc, simd< fp16, 4, Arch > a, simd< fp16, 4, Arch > b) noexcept
FMLAL with b[Lane] broadcast; selects the low 2 lanes of a.
constexpr simd< float, 2, Arch > fmlal2(simd< float, 2, Arch > acc, simd< fp16, 4, Arch > a, simd< fp16, 4, Arch > b) noexcept
Add products from the high 2 half lanes of a and b.
constexpr simd< float, 2, Arch > fmlsl2(simd< float, 2, Arch > acc, simd< fp16, 4, Arch > a, simd< fp16, 4, Arch > b) noexcept
Subtract products from the high 2 half lanes of a and b.
constexpr simd< float, 2, Arch > fmlal2_lane(simd< float, 2, Arch > acc, simd< fp16, 4, Arch > a, simd< fp16, 4, Arch > b) noexcept
FMLAL2 with b[Lane] broadcast; selects the high 2 lanes of a.
constexpr simd< float, 2, Arch > fmlsl_lane(simd< float, 2, Arch > acc, simd< fp16, 4, Arch > a, simd< fp16, 4, Arch > b) noexcept
FMLSL with b[Lane] broadcast; selects the low 2 lanes of a.
Architecture-tagged vectors, register packs and supporting value types. Native arithmetic follows its...
Omitted architecture arguments use the native.simd provider's baseline.