5 macro_rules
! impl_unary_
{
6 // implementation mapping 1:1
7 (vec
| $trait_id
:ident
, $trait_method
:ident
, $vec_id
:ident
,
9 impl $trait_id
for $vec_id
{
11 fn $
trait_method(self) -> Self {
13 use crate::mem
::transmute
;
14 transmute($
fun(transmute(self)))
19 // implementation mapping 1:1 for when `$fun` is a generic function
20 // like some of the fp math rustc intrinsics (e.g. `fn fun<T>(x: T) -> T`).
21 (gen
| $trait_id
:ident
, $trait_method
:ident
, $vec_id
:ident
,
23 impl $trait_id
for $vec_id
{
25 fn $
trait_method(self) -> Self {
27 use crate::mem
::transmute
;
28 transmute($
fun(self.0))
33 (scalar
| $trait_id
:ident
, $trait_method
:ident
,
34 $vec_id
:ident
, [$sid
:ident
; $scount
:expr
], $fun
:ident
) => {
35 impl $trait_id
for $vec_id
{
37 fn $
trait_method(self) -> Self {
41 scalars
: [$sid
; $scount
],
43 let mut scalars
= U { vec: self }
.scalars
;
44 for i
in &mut scalars
{
52 // implementation calling fun twice on each of the vector halves:
53 (halves
| $trait_id
:ident
, $trait_method
:ident
, $vec_id
:ident
,
54 $vech_id
:ident
, $fun
:ident
) => {
55 impl $trait_id
for $vec_id
{
57 fn $
trait_method(self) -> Self {
59 use crate::mem
::transmute
;
62 halves
: [$vech_id
; 2],
65 let mut halves
= U { vec: self }
.halves
;
67 *halves
.get_unchecked_mut(0) =
68 transmute($
fun(transmute(*halves
.get_unchecked(0))));
69 *halves
.get_unchecked_mut(1) =
70 transmute($
fun(transmute(*halves
.get_unchecked(1))));
77 // implementation calling fun four times on each of the vector quarters:
78 (quarter
| $trait_id
:ident
, $trait_method
:ident
, $vec_id
:ident
,
79 $vecq_id
:ident
, $fun
:ident
) => {
80 impl $trait_id
for $vec_id
{
82 fn $
trait_method(self) -> Self {
84 use crate::mem
::transmute
;
87 quarters
: [$vecq_id
; 4],
90 let mut quarters
= U { vec: self }
.quarters
;
92 *quarters
.get_unchecked_mut(0) =
93 transmute($
fun(transmute(*quarters
.get_unchecked(0))));
94 *quarters
.get_unchecked_mut(1) =
95 transmute($
fun(transmute(*quarters
.get_unchecked(1))));
96 *quarters
.get_unchecked_mut(2) =
97 transmute($
fun(transmute(*quarters
.get_unchecked(2))));
98 *quarters
.get_unchecked_mut(3) =
99 transmute($
fun(transmute(*quarters
.get_unchecked(3))));
106 // implementation calling fun once on a vector twice as large:
107 (twice
| $trait_id
:ident
, $trait_method
:ident
, $vec_id
:ident
,
108 $vect_id
:ident
, $fun
:ident
) => {
109 impl $trait_id
for $vec_id
{
111 fn $
trait_method(self) -> Self {
113 use crate::mem
::{transmute, uninitialized}
;
120 let twice
= U { vec: [self, uninitialized()] }
.twice
;
121 let twice
= transmute($
fun(transmute(twice
)));
123 *(U { twice }
.vec
.get_unchecked(0))
130 macro_rules
! gen_unary_impl_table
{
131 ($trait_id
:ident
, $trait_method
:ident
) => {
132 macro_rules
! impl_unary
{
133 ($vid
:ident
: $fun
:ident
) => {
134 impl_unary_
!(vec
| $trait_id
, $trait_method
, $vid
, $fun
);
136 ($vid
:ident
[g
]: $fun
:ident
) => {
137 impl_unary_
!(gen
| $trait_id
, $trait_method
, $vid
, $fun
);
139 ($vid
:ident
[$sid
:ident
; $sc
:expr
]: $fun
:ident
) => {
148 ($vid
:ident
[s
]: $fun
:ident
) => {
149 impl_unary_
!(scalar
| $trait_id
, $trait_method
, $vid
, $fun
);
151 ($vid
:ident
[h
=> $vid_h
:ident
]: $fun
:ident
) => {
160 ($vid
:ident
[q
=> $vid_q
:ident
]: $fun
:ident
) => {
169 ($vid
:ident
[t
=> $vid_t
:ident
]: $fun
:ident
) => {
182 macro_rules
! impl_tertiary_
{
183 // implementation mapping 1:1
184 (vec
| $trait_id
:ident
, $trait_method
:ident
, $vec_id
:ident
,
186 impl $trait_id
for $vec_id
{
188 fn $
trait_method(self, y
: Self, z
: Self) -> Self {
190 use crate::mem
::transmute
;
200 (scalar
| $trait_id
:ident
, $trait_method
:ident
,
201 $vec_id
:ident
, [$sid
:ident
; $scount
:expr
], $fun
:ident
) => {
202 impl $trait_id
for $vec_id
{
204 fn $
trait_method(self, y
: Self, z
: Self) -> Self {
208 scalars
: [$sid
; $scount
],
210 let mut x
= U { vec: self }
.scalars
;
211 let y
= U { vec: y }
.scalars
;
212 let z
= U { vec: z }
.scalars
;
213 for (x
, (y
, z
)) in (&mut scalars
).zip(&y
).zip(&z
) {
214 *i
= $
fun(*i
, *y
, *z
);
221 // implementation calling fun twice on each of the vector halves:
222 (halves
| $trait_id
:ident
, $trait_method
:ident
, $vec_id
:ident
,
223 $vech_id
:ident
, $fun
:ident
) => {
224 impl $trait_id
for $vec_id
{
226 fn $
trait_method(self, y
: Self, z
: Self) -> Self {
228 use crate::mem
::transmute
;
231 halves
: [$vech_id
; 2],
234 let mut x_halves
= U { vec: self }
.halves
;
235 let y_halves
= U { vec: y }
.halves
;
236 let z_halves
= U { vec: z }
.halves
;
238 *x_halves
.get_unchecked_mut(0) = transmute($
fun(
239 transmute(*x_halves
.get_unchecked(0)),
240 transmute(*y_halves
.get_unchecked(0)),
241 transmute(*z_halves
.get_unchecked(0)),
243 *x_halves
.get_unchecked_mut(1) = transmute($
fun(
244 transmute(*x_halves
.get_unchecked(1)),
245 transmute(*y_halves
.get_unchecked(1)),
246 transmute(*z_halves
.get_unchecked(1)),
249 U { halves: x_halves }
.vec
254 // implementation calling fun four times on each of the vector quarters:
255 (quarter
| $trait_id
:ident
, $trait_method
:ident
, $vec_id
:ident
,
256 $vecq_id
:ident
, $fun
:ident
) => {
257 impl $trait_id
for $vec_id
{
259 fn $
trait_method(self, y
: Self, z
: Self) -> Self {
261 use crate::mem
::transmute
;
264 quarters
: [$vecq_id
; 4],
267 let mut x_quarters
= U { vec: self }
.quarters
;
268 let y_quarters
= U { vec: y }
.quarters
;
269 let z_quarters
= U { vec: z }
.quarters
;
271 *x_quarters
.get_unchecked_mut(0) = transmute($
fun(
272 transmute(*x_quarters
.get_unchecked(0)),
273 transmute(*y_quarters
.get_unchecked(0)),
274 transmute(*z_quarters
.get_unchecked(0)),
277 *x_quarters
.get_unchecked_mut(1) = transmute($
fun(
278 transmute(*x_quarters
.get_unchecked(1)),
279 transmute(*y_quarters
.get_unchecked(1)),
280 transmute(*z_quarters
.get_unchecked(1)),
283 *x_quarters
.get_unchecked_mut(2) = transmute($
fun(
284 transmute(*x_quarters
.get_unchecked(2)),
285 transmute(*y_quarters
.get_unchecked(2)),
286 transmute(*z_quarters
.get_unchecked(2)),
289 *x_quarters
.get_unchecked_mut(3) = transmute($
fun(
290 transmute(*x_quarters
.get_unchecked(3)),
291 transmute(*y_quarters
.get_unchecked(3)),
292 transmute(*z_quarters
.get_unchecked(3)),
295 U { quarters: x_quarters }
.vec
300 // implementation calling fun once on a vector twice as large:
301 (twice
| $trait_id
:ident
, $trait_method
:ident
, $vec_id
:ident
,
302 $vect_id
:ident
, $fun
:ident
) => {
303 impl $trait_id
for $vec_id
{
305 fn $
trait_method(self, y
: Self, z
: Self) -> Self {
307 use crate::mem
::{transmute, uninitialized}
;
314 let x_twice
= U { vec: [self, uninitialized()] }
.twice
;
315 let y_twice
= U { vec: [y, uninitialized()] }
.twice
;
316 let z_twice
= U { vec: [z, uninitialized()] }
.twice
;
317 let twice
: $vect_id
= transmute($
fun(
323 *(U { twice }
.vec
.get_unchecked(0))
330 macro_rules
! gen_tertiary_impl_table
{
331 ($trait_id
:ident
, $trait_method
:ident
) => {
332 macro_rules
! impl_tertiary
{
333 ($vid
:ident
: $fun
:ident
) => {
334 impl_tertiary_
!(vec
| $trait_id
, $trait_method
, $vid
, $fun
);
336 ($vid
:ident
[$sid
:ident
; $sc
:expr
]: $fun
:ident
) => {
345 ($vid
:ident
[s
]: $fun
:ident
) => {
346 impl_tertiary_
!(scalar
| $trait_id
, $trait_method
, $vid
, $fun
);
348 ($vid
:ident
[h
=> $vid_h
:ident
]: $fun
:ident
) => {
357 ($vid
:ident
[q
=> $vid_q
:ident
]: $fun
:ident
) => {
366 ($vid
:ident
[t
=> $vid_t
:ident
]: $fun
:ident
) => {
379 macro_rules
! impl_binary_
{
380 // implementation mapping 1:1
381 (vec
| $trait_id
:ident
, $trait_method
:ident
, $vec_id
:ident
,
383 impl $trait_id
for $vec_id
{
385 fn $
trait_method(self, y
: Self) -> Self {
387 use crate::mem
::transmute
;
388 transmute($
fun(transmute(self), transmute(y
)))
393 (scalar
| $trait_id
:ident
, $trait_method
:ident
,
394 $vec_id
:ident
, [$sid
:ident
; $scount
:expr
], $fun
:ident
) => {
395 impl $trait_id
for $vec_id
{
397 fn $
trait_method(self, y
: Self) -> Self {
401 scalars
: [$sid
; $scount
],
403 let mut x
= U { vec: self }
.scalars
;
404 let y
= U { vec: y }
.scalars
;
405 for (x
, y
) in x
.iter_mut().zip(&y
) {
413 // implementation calling fun twice on each of the vector halves:
414 (halves
| $trait_id
:ident
, $trait_method
:ident
, $vec_id
:ident
,
415 $vech_id
:ident
, $fun
:ident
) => {
416 impl $trait_id
for $vec_id
{
418 fn $
trait_method(self, y
: Self) -> Self {
420 use crate::mem
::transmute
;
423 halves
: [$vech_id
; 2],
426 let mut x_halves
= U { vec: self }
.halves
;
427 let y_halves
= U { vec: y }
.halves
;
429 *x_halves
.get_unchecked_mut(0) = transmute($
fun(
430 transmute(*x_halves
.get_unchecked(0)),
431 transmute(*y_halves
.get_unchecked(0)),
433 *x_halves
.get_unchecked_mut(1) = transmute($
fun(
434 transmute(*x_halves
.get_unchecked(1)),
435 transmute(*y_halves
.get_unchecked(1)),
438 U { halves: x_halves }
.vec
443 // implementation calling fun four times on each of the vector quarters:
444 (quarter
| $trait_id
:ident
, $trait_method
:ident
, $vec_id
:ident
,
445 $vecq_id
:ident
, $fun
:ident
) => {
446 impl $trait_id
for $vec_id
{
448 fn $
trait_method(self, y
: Self) -> Self {
450 use crate::mem
::transmute
;
453 quarters
: [$vecq_id
; 4],
456 let mut x_quarters
= U { vec: self }
.quarters
;
457 let y_quarters
= U { vec: y }
.quarters
;
459 *x_quarters
.get_unchecked_mut(0) = transmute($
fun(
460 transmute(*x_quarters
.get_unchecked(0)),
461 transmute(*y_quarters
.get_unchecked(0)),
464 *x_quarters
.get_unchecked_mut(1) = transmute($
fun(
465 transmute(*x_quarters
.get_unchecked(1)),
466 transmute(*y_quarters
.get_unchecked(1)),
469 *x_quarters
.get_unchecked_mut(2) = transmute($
fun(
470 transmute(*x_quarters
.get_unchecked(2)),
471 transmute(*y_quarters
.get_unchecked(2)),
474 *x_quarters
.get_unchecked_mut(3) = transmute($
fun(
475 transmute(*x_quarters
.get_unchecked(3)),
476 transmute(*y_quarters
.get_unchecked(3)),
479 U { quarters: x_quarters }
.vec
484 // implementation calling fun once on a vector twice as large:
485 (twice
| $trait_id
:ident
, $trait_method
:ident
, $vec_id
:ident
,
486 $vect_id
:ident
, $fun
:ident
) => {
487 impl $trait_id
for $vec_id
{
489 fn $
trait_method(self, y
: Self) -> Self {
491 use crate::mem
::{transmute, uninitialized}
;
498 let x_twice
= U { vec: [self, uninitialized()] }
.twice
;
499 let y_twice
= U { vec: [y, uninitialized()] }
.twice
;
500 let twice
: $vect_id
= transmute($
fun(
505 *(U { twice }
.vec
.get_unchecked(0))
512 macro_rules
! gen_binary_impl_table
{
513 ($trait_id
:ident
, $trait_method
:ident
) => {
514 macro_rules
! impl_binary
{
515 ($vid
:ident
: $fun
:ident
) => {
516 impl_binary_
!(vec
| $trait_id
, $trait_method
, $vid
, $fun
);
518 ($vid
:ident
[$sid
:ident
; $sc
:expr
]: $fun
:ident
) => {
527 ($vid
:ident
[s
]: $fun
:ident
) => {
528 impl_binary_
!(scalar
| $trait_id
, $trait_method
, $vid
, $fun
);
530 ($vid
:ident
[h
=> $vid_h
:ident
]: $fun
:ident
) => {
539 ($vid
:ident
[q
=> $vid_q
:ident
]: $fun
:ident
) => {
548 ($vid
:ident
[t
=> $vid_t
:ident
]: $fun
:ident
) => {