1use fearless_simd::Simd;
19
20pub type F64s<S> = <S as Simd>::f64s;
22pub type U64s<S> = <S as Simd>::u64s;
24pub type I64s<S> = <S as Simd>::i64s;
26pub type M64s<S> = <S as Simd>::mask64s;
28
29pub type F32s<S> = <S as Simd>::f32s;
31pub type U32s<S> = <S as Simd>::u32s;
33pub type I32s<S> = <S as Simd>::i32s;
35pub type M32s<S> = <S as Simd>::mask32s;
37
38use fearless_simd::prelude::*;
39
40#[inline(always)]
47pub fn mla<S: Simd, V: SimdFloat<S>>(_simd: S, x: V, y: V, z: V) -> V {
48 x.mul_add_precise(y, z)
49}
50
51#[inline(always)]
53pub fn mul_sub<S: Simd, V: SimdFloat<S>>(_simd: S, x: V, y: V, z: V) -> V {
54 x.mul_sub_precise(y, z)
55}
56
57#[inline(always)]
59pub fn neg_mul_add<S: Simd, V: SimdFloat<S>>(_simd: S, x: V, y: V, z: V) -> V {
60 (-x).mul_add_precise(y, z)
61}
62
63#[inline(always)]
68pub fn hw_sqrt<S: Simd, V: SimdFloat<S>>(_simd: S, x: V) -> V {
69 x.sqrt()
70}
71
72#[allow(clippy::too_many_arguments)]
77#[inline(always)]
78pub fn poly2<S: Simd, V: SimdFloat<S> + Copy>(
79 simd: S,
80 x: V,
81 x2: V,
82 x4: V,
83 c1: V::Element,
84 c0: V::Element,
85) -> V {
86 let _ = (x2, x4);
87 mla(simd, x, V::splat(simd, c1), V::splat(simd, c0))
88}
89
90#[allow(clippy::too_many_arguments)]
95#[inline(always)]
96pub fn poly3<S: Simd, V: SimdFloat<S> + Copy>(
97 simd: S,
98 x: V,
99 x2: V,
100 x4: V,
101 c2: V::Element,
102 c1: V::Element,
103 c0: V::Element,
104) -> V {
105 mla(simd, x2, V::splat(simd, c2), poly2(simd, x, x2, x4, c1, c0))
106}
107
108#[allow(clippy::too_many_arguments)]
113#[inline(always)]
114pub fn poly4<S: Simd, V: SimdFloat<S> + Copy>(
115 simd: S,
116 x: V,
117 x2: V,
118 x4: V,
119 c3: V::Element,
120 c2: V::Element,
121 c1: V::Element,
122 c0: V::Element,
123) -> V {
124 let _ = x4;
125 mla(
126 simd,
127 x2,
128 mla(simd, x, V::splat(simd, c3), V::splat(simd, c2)),
129 mla(simd, x, V::splat(simd, c1), V::splat(simd, c0)),
130 )
131}
132
133#[allow(clippy::too_many_arguments)]
138#[inline(always)]
139pub fn poly5<S: Simd, V: SimdFloat<S> + Copy>(
140 simd: S,
141 x: V,
142 x2: V,
143 x4: V,
144 c4: V::Element,
145 c3: V::Element,
146 c2: V::Element,
147 c1: V::Element,
148 c0: V::Element,
149) -> V {
150 mla(
151 simd,
152 x4,
153 V::splat(simd, c4),
154 poly4(simd, x, x2, x4, c3, c2, c1, c0),
155 )
156}
157
158#[allow(clippy::too_many_arguments)]
163#[inline(always)]
164pub fn poly6<S: Simd, V: SimdFloat<S> + Copy>(
165 simd: S,
166 x: V,
167 x2: V,
168 x4: V,
169 c5: V::Element,
170 c4: V::Element,
171 c3: V::Element,
172 c2: V::Element,
173 c1: V::Element,
174 c0: V::Element,
175) -> V {
176 mla(
177 simd,
178 x4,
179 poly2(simd, x, x2, x4, c5, c4),
180 poly4(simd, x, x2, x4, c3, c2, c1, c0),
181 )
182}
183
184#[allow(clippy::too_many_arguments)]
189#[inline(always)]
190pub fn poly7<S: Simd, V: SimdFloat<S> + Copy>(
191 simd: S,
192 x: V,
193 x2: V,
194 x4: V,
195 c6: V::Element,
196 c5: V::Element,
197 c4: V::Element,
198 c3: V::Element,
199 c2: V::Element,
200 c1: V::Element,
201 c0: V::Element,
202) -> V {
203 mla(
204 simd,
205 x4,
206 poly3(simd, x, x2, x4, c6, c5, c4),
207 poly4(simd, x, x2, x4, c3, c2, c1, c0),
208 )
209}
210
211#[allow(clippy::too_many_arguments)]
216#[inline(always)]
217pub fn poly8<S: Simd, V: SimdFloat<S> + Copy>(
218 simd: S,
219 x: V,
220 x2: V,
221 x4: V,
222 c7: V::Element,
223 c6: V::Element,
224 c5: V::Element,
225 c4: V::Element,
226 c3: V::Element,
227 c2: V::Element,
228 c1: V::Element,
229 c0: V::Element,
230) -> V {
231 mla(
232 simd,
233 x4,
234 poly4(simd, x, x2, x4, c7, c6, c5, c4),
235 poly4(simd, x, x2, x4, c3, c2, c1, c0),
236 )
237}
238
239#[allow(clippy::too_many_arguments)]
244#[inline(always)]
245pub fn poly9<S: Simd, V: SimdFloat<S> + Copy>(
246 simd: S,
247 x: V,
248 x2: V,
249 x4: V,
250 x8: V,
251 c8: V::Element,
252 c7: V::Element,
253 c6: V::Element,
254 c5: V::Element,
255 c4: V::Element,
256 c3: V::Element,
257 c2: V::Element,
258 c1: V::Element,
259 c0: V::Element,
260) -> V {
261 mla(
262 simd,
263 x8,
264 V::splat(simd, c8),
265 poly8(simd, x, x2, x4, c7, c6, c5, c4, c3, c2, c1, c0),
266 )
267}
268
269#[allow(clippy::too_many_arguments)]
274#[inline(always)]
275pub fn poly10<S: Simd, V: SimdFloat<S> + Copy>(
276 simd: S,
277 x: V,
278 x2: V,
279 x4: V,
280 x8: V,
281 c9: V::Element,
282 c8: V::Element,
283 c7: V::Element,
284 c6: V::Element,
285 c5: V::Element,
286 c4: V::Element,
287 c3: V::Element,
288 c2: V::Element,
289 c1: V::Element,
290 c0: V::Element,
291) -> V {
292 mla(
293 simd,
294 x8,
295 poly2(simd, x, x2, x4, c9, c8),
296 poly8(simd, x, x2, x4, c7, c6, c5, c4, c3, c2, c1, c0),
297 )
298}
299
300#[allow(clippy::too_many_arguments)]
305#[inline(always)]
306pub fn poly11<S: Simd, V: SimdFloat<S> + Copy>(
307 simd: S,
308 x: V,
309 x2: V,
310 x4: V,
311 x8: V,
312 ca: V::Element,
313 c9: V::Element,
314 c8: V::Element,
315 c7: V::Element,
316 c6: V::Element,
317 c5: V::Element,
318 c4: V::Element,
319 c3: V::Element,
320 c2: V::Element,
321 c1: V::Element,
322 c0: V::Element,
323) -> V {
324 mla(
325 simd,
326 x8,
327 poly3(simd, x, x2, x4, ca, c9, c8),
328 poly8(simd, x, x2, x4, c7, c6, c5, c4, c3, c2, c1, c0),
329 )
330}
331
332#[allow(clippy::too_many_arguments)]
337#[inline(always)]
338pub fn poly12<S: Simd, V: SimdFloat<S> + Copy>(
339 simd: S,
340 x: V,
341 x2: V,
342 x4: V,
343 x8: V,
344 cb: V::Element,
345 ca: V::Element,
346 c9: V::Element,
347 c8: V::Element,
348 c7: V::Element,
349 c6: V::Element,
350 c5: V::Element,
351 c4: V::Element,
352 c3: V::Element,
353 c2: V::Element,
354 c1: V::Element,
355 c0: V::Element,
356) -> V {
357 mla(
358 simd,
359 x8,
360 poly4(simd, x, x2, x4, cb, ca, c9, c8),
361 poly8(simd, x, x2, x4, c7, c6, c5, c4, c3, c2, c1, c0),
362 )
363}
364
365#[allow(clippy::too_many_arguments)]
370#[inline(always)]
371pub fn poly13<S: Simd, V: SimdFloat<S> + Copy>(
372 simd: S,
373 x: V,
374 x2: V,
375 x4: V,
376 x8: V,
377 cc: V::Element,
378 cb: V::Element,
379 ca: V::Element,
380 c9: V::Element,
381 c8: V::Element,
382 c7: V::Element,
383 c6: V::Element,
384 c5: V::Element,
385 c4: V::Element,
386 c3: V::Element,
387 c2: V::Element,
388 c1: V::Element,
389 c0: V::Element,
390) -> V {
391 mla(
392 simd,
393 x8,
394 poly5(simd, x, x2, x4, cc, cb, ca, c9, c8),
395 poly8(simd, x, x2, x4, c7, c6, c5, c4, c3, c2, c1, c0),
396 )
397}
398
399#[allow(clippy::too_many_arguments)]
404#[inline(always)]
405pub fn poly14<S: Simd, V: SimdFloat<S> + Copy>(
406 simd: S,
407 x: V,
408 x2: V,
409 x4: V,
410 x8: V,
411 cd: V::Element,
412 cc: V::Element,
413 cb: V::Element,
414 ca: V::Element,
415 c9: V::Element,
416 c8: V::Element,
417 c7: V::Element,
418 c6: V::Element,
419 c5: V::Element,
420 c4: V::Element,
421 c3: V::Element,
422 c2: V::Element,
423 c1: V::Element,
424 c0: V::Element,
425) -> V {
426 mla(
427 simd,
428 x8,
429 poly6(simd, x, x2, x4, cd, cc, cb, ca, c9, c8),
430 poly8(simd, x, x2, x4, c7, c6, c5, c4, c3, c2, c1, c0),
431 )
432}
433
434#[allow(clippy::too_many_arguments)]
439#[inline(always)]
440pub fn poly15<S: Simd, V: SimdFloat<S> + Copy>(
441 simd: S,
442 x: V,
443 x2: V,
444 x4: V,
445 x8: V,
446 ce: V::Element,
447 cd: V::Element,
448 cc: V::Element,
449 cb: V::Element,
450 ca: V::Element,
451 c9: V::Element,
452 c8: V::Element,
453 c7: V::Element,
454 c6: V::Element,
455 c5: V::Element,
456 c4: V::Element,
457 c3: V::Element,
458 c2: V::Element,
459 c1: V::Element,
460 c0: V::Element,
461) -> V {
462 mla(
463 simd,
464 x8,
465 poly7(simd, x, x2, x4, ce, cd, cc, cb, ca, c9, c8),
466 poly8(simd, x, x2, x4, c7, c6, c5, c4, c3, c2, c1, c0),
467 )
468}
469
470#[allow(clippy::too_many_arguments)]
475#[inline(always)]
476pub fn poly16<S: Simd, V: SimdFloat<S> + Copy>(
477 simd: S,
478 x: V,
479 x2: V,
480 x4: V,
481 x8: V,
482 cf: V::Element,
483 ce: V::Element,
484 cd: V::Element,
485 cc: V::Element,
486 cb: V::Element,
487 ca: V::Element,
488 c9: V::Element,
489 c8: V::Element,
490 c7: V::Element,
491 c6: V::Element,
492 c5: V::Element,
493 c4: V::Element,
494 c3: V::Element,
495 c2: V::Element,
496 c1: V::Element,
497 c0: V::Element,
498) -> V {
499 mla(
500 simd,
501 x8,
502 poly8(simd, x, x2, x4, cf, ce, cd, cc, cb, ca, c9, c8),
503 poly8(simd, x, x2, x4, c7, c6, c5, c4, c3, c2, c1, c0),
504 )
505}
506
507#[allow(clippy::too_many_arguments)]
512#[inline(always)]
513pub fn poly17<S: Simd, V: SimdFloat<S> + Copy>(
514 simd: S,
515 x: V,
516 x2: V,
517 x4: V,
518 x8: V,
519 x16: V,
520 d0: V::Element,
521 cf: V::Element,
522 ce: V::Element,
523 cd: V::Element,
524 cc: V::Element,
525 cb: V::Element,
526 ca: V::Element,
527 c9: V::Element,
528 c8: V::Element,
529 c7: V::Element,
530 c6: V::Element,
531 c5: V::Element,
532 c4: V::Element,
533 c3: V::Element,
534 c2: V::Element,
535 c1: V::Element,
536 c0: V::Element,
537) -> V {
538 mla(
539 simd,
540 x16,
541 V::splat(simd, d0),
542 poly16(
543 simd, x, x2, x4, x8, cf, ce, cd, cc, cb, ca, c9, c8, c7, c6, c5, c4, c3, c2, c1, c0,
544 ),
545 )
546}
547
548#[allow(clippy::too_many_arguments)]
553#[inline(always)]
554pub fn poly18<S: Simd, V: SimdFloat<S> + Copy>(
555 simd: S,
556 x: V,
557 x2: V,
558 x4: V,
559 x8: V,
560 x16: V,
561 d1: V::Element,
562 d0: V::Element,
563 cf: V::Element,
564 ce: V::Element,
565 cd: V::Element,
566 cc: V::Element,
567 cb: V::Element,
568 ca: V::Element,
569 c9: V::Element,
570 c8: V::Element,
571 c7: V::Element,
572 c6: V::Element,
573 c5: V::Element,
574 c4: V::Element,
575 c3: V::Element,
576 c2: V::Element,
577 c1: V::Element,
578 c0: V::Element,
579) -> V {
580 mla(
581 simd,
582 x16,
583 poly2(simd, x, x2, x4, d1, d0),
584 poly16(
585 simd, x, x2, x4, x8, cf, ce, cd, cc, cb, ca, c9, c8, c7, c6, c5, c4, c3, c2, c1, c0,
586 ),
587 )
588}
589
590#[allow(clippy::too_many_arguments)]
595#[inline(always)]
596pub fn poly19<S: Simd, V: SimdFloat<S> + Copy>(
597 simd: S,
598 x: V,
599 x2: V,
600 x4: V,
601 x8: V,
602 x16: V,
603 d2: V::Element,
604 d1: V::Element,
605 d0: V::Element,
606 cf: V::Element,
607 ce: V::Element,
608 cd: V::Element,
609 cc: V::Element,
610 cb: V::Element,
611 ca: V::Element,
612 c9: V::Element,
613 c8: V::Element,
614 c7: V::Element,
615 c6: V::Element,
616 c5: V::Element,
617 c4: V::Element,
618 c3: V::Element,
619 c2: V::Element,
620 c1: V::Element,
621 c0: V::Element,
622) -> V {
623 mla(
624 simd,
625 x16,
626 poly3(simd, x, x2, x4, d2, d1, d0),
627 poly16(
628 simd, x, x2, x4, x8, cf, ce, cd, cc, cb, ca, c9, c8, c7, c6, c5, c4, c3, c2, c1, c0,
629 ),
630 )
631}
632
633#[allow(clippy::too_many_arguments)]
638#[inline(always)]
639pub fn poly20<S: Simd, V: SimdFloat<S> + Copy>(
640 simd: S,
641 x: V,
642 x2: V,
643 x4: V,
644 x8: V,
645 x16: V,
646 d3: V::Element,
647 d2: V::Element,
648 d1: V::Element,
649 d0: V::Element,
650 cf: V::Element,
651 ce: V::Element,
652 cd: V::Element,
653 cc: V::Element,
654 cb: V::Element,
655 ca: V::Element,
656 c9: V::Element,
657 c8: V::Element,
658 c7: V::Element,
659 c6: V::Element,
660 c5: V::Element,
661 c4: V::Element,
662 c3: V::Element,
663 c2: V::Element,
664 c1: V::Element,
665 c0: V::Element,
666) -> V {
667 mla(
668 simd,
669 x16,
670 poly4(simd, x, x2, x4, d3, d2, d1, d0),
671 poly16(
672 simd, x, x2, x4, x8, cf, ce, cd, cc, cb, ca, c9, c8, c7, c6, c5, c4, c3, c2, c1, c0,
673 ),
674 )
675}
676
677#[allow(clippy::too_many_arguments)]
682#[inline(always)]
683pub fn poly21<S: Simd, V: SimdFloat<S> + Copy>(
684 simd: S,
685 x: V,
686 x2: V,
687 x4: V,
688 x8: V,
689 x16: V,
690 d4: V::Element,
691 d3: V::Element,
692 d2: V::Element,
693 d1: V::Element,
694 d0: V::Element,
695 cf: V::Element,
696 ce: V::Element,
697 cd: V::Element,
698 cc: V::Element,
699 cb: V::Element,
700 ca: V::Element,
701 c9: V::Element,
702 c8: V::Element,
703 c7: V::Element,
704 c6: V::Element,
705 c5: V::Element,
706 c4: V::Element,
707 c3: V::Element,
708 c2: V::Element,
709 c1: V::Element,
710 c0: V::Element,
711) -> V {
712 mla(
713 simd,
714 x16,
715 poly5(simd, x, x2, x4, d4, d3, d2, d1, d0),
716 poly16(
717 simd, x, x2, x4, x8, cf, ce, cd, cc, cb, ca, c9, c8, c7, c6, c5, c4, c3, c2, c1, c0,
718 ),
719 )
720}