@@ -18,6 +18,36 @@ use std::ops::{Add, BitAnd, BitOr, Div, Index, IndexMut, Mul, Not, Shr, Sub};
18
18
mod swizzle_f32x4;
19
19
mod swizzle_i32x4;
20
20
21
+ macro_rules! simd_shuffle2 {
22
+ ( $x: expr, $y: expr, <$( const $imm: ident : $ty: ty) ,+> $idx: expr $( , ) ?) => { {
23
+ struct ConstParam <$( const $imm: $ty) ,+>;
24
+ impl <$( const $imm: $ty) ,+> ConstParam <$( $imm) ,+> {
25
+ const IDX : [ u32 ; 2 ] = $idx;
26
+ }
27
+
28
+ simd_shuffle2( $x, $y, ConstParam :: <$( $imm) ,+>:: IDX )
29
+ } } ;
30
+ ( $x: expr, $y: expr, $idx: expr $( , ) ?) => { {
31
+ const IDX : [ u32 ; 2 ] = $idx;
32
+ simd_shuffle2( $x, $y, IDX )
33
+ } } ;
34
+ }
35
+
36
+ macro_rules! simd_shuffle4 {
37
+ ( $x: expr, $y: expr, <$( const $imm: ident : $ty: ty) ,+> $idx: expr $( , ) ?) => { {
38
+ struct ConstParam <$( const $imm: $ty) ,+>;
39
+ impl <$( const $imm: $ty) ,+> ConstParam <$( $imm) ,+> {
40
+ const IDX : [ u32 ; 4 ] = $idx;
41
+ }
42
+
43
+ simd_shuffle4( $x, $y, ConstParam :: <$( $imm) ,+>:: IDX )
44
+ } } ;
45
+ ( $x: expr, $y: expr, $idx: expr $( , ) ?) => { {
46
+ const IDX : [ u32 ; 4 ] = $idx;
47
+ simd_shuffle4( $x, $y, IDX )
48
+ } } ;
49
+ }
50
+
21
51
// Two 32-bit floats
22
52
23
53
#[ derive( Clone , Copy ) ]
@@ -122,14 +152,14 @@ impl F32x2 {
122
152
123
153
#[ inline]
124
154
pub fn yx ( self ) -> F32x2 {
125
- unsafe { F32x2 ( simd_shuffle2 ( self . 0 , self . 0 , [ 1 , 0 ] ) ) }
155
+ unsafe { F32x2 ( simd_shuffle2 ! ( self . 0 , self . 0 , [ 1 , 0 ] ) ) }
126
156
}
127
157
128
158
// Concatenations
129
159
130
160
#[ inline]
131
161
pub fn concat_xy_xy ( self , other : F32x2 ) -> F32x4 {
132
- unsafe { F32x4 ( simd_shuffle4 ( self . 0 , other. 0 , [ 0 , 1 , 2 , 3 ] ) ) }
162
+ unsafe { F32x4 ( simd_shuffle4 ! ( self . 0 , other. 0 , [ 0 , 1 , 2 , 3 ] ) ) }
133
163
}
134
164
}
135
165
@@ -287,44 +317,44 @@ impl F32x4 {
287
317
288
318
#[ inline]
289
319
pub fn xy ( self ) -> F32x2 {
290
- unsafe { F32x2 ( simd_shuffle2 ( self . 0 , self . 0 , [ 0 , 1 ] ) ) }
320
+ unsafe { F32x2 ( simd_shuffle2 ! ( self . 0 , self . 0 , [ 0 , 1 ] ) ) }
291
321
}
292
322
293
323
#[ inline]
294
324
pub fn yx ( self ) -> F32x2 {
295
- unsafe { F32x2 ( simd_shuffle2 ( self . 0 , self . 0 , [ 1 , 0 ] ) ) }
325
+ unsafe { F32x2 ( simd_shuffle2 ! ( self . 0 , self . 0 , [ 1 , 0 ] ) ) }
296
326
}
297
327
298
328
#[ inline]
299
329
pub fn xw ( self ) -> F32x2 {
300
- unsafe { F32x2 ( simd_shuffle2 ( self . 0 , self . 0 , [ 0 , 3 ] ) ) }
330
+ unsafe { F32x2 ( simd_shuffle2 ! ( self . 0 , self . 0 , [ 0 , 3 ] ) ) }
301
331
}
302
332
303
333
#[ inline]
304
334
pub fn zy ( self ) -> F32x2 {
305
- unsafe { F32x2 ( simd_shuffle2 ( self . 0 , self . 0 , [ 2 , 1 ] ) ) }
335
+ unsafe { F32x2 ( simd_shuffle2 ! ( self . 0 , self . 0 , [ 2 , 1 ] ) ) }
306
336
}
307
337
308
338
#[ inline]
309
339
pub fn zw ( self ) -> F32x2 {
310
- unsafe { F32x2 ( simd_shuffle2 ( self . 0 , self . 0 , [ 2 , 3 ] ) ) }
340
+ unsafe { F32x2 ( simd_shuffle2 ! ( self . 0 , self . 0 , [ 2 , 3 ] ) ) }
311
341
}
312
342
313
343
// Concatenations
314
344
315
345
#[ inline]
316
346
pub fn concat_xy_xy ( self , other : F32x4 ) -> F32x4 {
317
- unsafe { F32x4 ( simd_shuffle4 ( self . 0 , other. 0 , [ 0 , 1 , 2 , 3 ] ) ) }
347
+ unsafe { F32x4 ( simd_shuffle4 ! ( self . 0 , other. 0 , [ 0 , 1 , 2 , 3 ] ) ) }
318
348
}
319
349
320
350
#[ inline]
321
351
pub fn concat_xy_zw ( self , other : F32x4 ) -> F32x4 {
322
- unsafe { F32x4 ( simd_shuffle4 ( self . 0 , other. 0 , [ 0 , 1 , 6 , 7 ] ) ) }
352
+ unsafe { F32x4 ( simd_shuffle4 ! ( self . 0 , other. 0 , [ 0 , 1 , 6 , 7 ] ) ) }
323
353
}
324
354
325
355
#[ inline]
326
356
pub fn concat_zw_zw ( self , other : F32x4 ) -> F32x4 {
327
- unsafe { F32x4 ( simd_shuffle4 ( self . 0 , other. 0 , [ 2 , 3 , 6 , 7 ] ) ) }
357
+ unsafe { F32x4 ( simd_shuffle4 ! ( self . 0 , other. 0 , [ 2 , 3 , 6 , 7 ] ) ) }
328
358
}
329
359
330
360
// Conversions
@@ -461,7 +491,7 @@ impl I32x2 {
461
491
462
492
#[ inline]
463
493
pub fn concat_xy_xy ( self , other : I32x2 ) -> I32x4 {
464
- unsafe { I32x4 ( simd_shuffle4 ( self . 0 , other. 0 , [ 0 , 1 , 2 , 3 ] ) ) }
494
+ unsafe { I32x4 ( simd_shuffle4 ! ( self . 0 , other. 0 , [ 0 , 1 , 2 , 3 ] ) ) }
465
495
}
466
496
467
497
// Conversions
@@ -588,39 +618,39 @@ impl I32x4 {
588
618
589
619
#[ inline]
590
620
pub fn concat_xy_xy ( self , other : I32x4 ) -> I32x4 {
591
- unsafe { I32x4 ( simd_shuffle4 ( self . 0 , other. 0 , [ 0 , 1 , 4 , 5 ] ) ) }
621
+ unsafe { I32x4 ( simd_shuffle4 ! ( self . 0 , other. 0 , [ 0 , 1 , 4 , 5 ] ) ) }
592
622
}
593
623
594
624
#[ inline]
595
625
pub fn concat_zw_zw ( self , other : I32x4 ) -> I32x4 {
596
- unsafe { I32x4 ( simd_shuffle4 ( self . 0 , other. 0 , [ 2 , 3 , 6 , 7 ] ) ) }
626
+ unsafe { I32x4 ( simd_shuffle4 ! ( self . 0 , other. 0 , [ 2 , 3 , 6 , 7 ] ) ) }
597
627
}
598
628
599
629
// Swizzle conversions
600
630
601
631
#[ inline]
602
632
pub fn xy ( self ) -> I32x2 {
603
- unsafe { I32x2 ( simd_shuffle2 ( self . 0 , self . 0 , [ 0 , 1 ] ) ) }
633
+ unsafe { I32x2 ( simd_shuffle2 ! ( self . 0 , self . 0 , [ 0 , 1 ] ) ) }
604
634
}
605
635
606
636
#[ inline]
607
637
pub fn yx ( self ) -> I32x2 {
608
- unsafe { I32x2 ( simd_shuffle2 ( self . 0 , self . 0 , [ 1 , 0 ] ) ) }
638
+ unsafe { I32x2 ( simd_shuffle2 ! ( self . 0 , self . 0 , [ 1 , 0 ] ) ) }
609
639
}
610
640
611
641
#[ inline]
612
642
pub fn xw ( self ) -> I32x2 {
613
- unsafe { I32x2 ( simd_shuffle2 ( self . 0 , self . 0 , [ 0 , 3 ] ) ) }
643
+ unsafe { I32x2 ( simd_shuffle2 ! ( self . 0 , self . 0 , [ 0 , 3 ] ) ) }
614
644
}
615
645
616
646
#[ inline]
617
647
pub fn zy ( self ) -> I32x2 {
618
- unsafe { I32x2 ( simd_shuffle2 ( self . 0 , self . 0 , [ 2 , 1 ] ) ) }
648
+ unsafe { I32x2 ( simd_shuffle2 ! ( self . 0 , self . 0 , [ 2 , 1 ] ) ) }
619
649
}
620
650
621
651
#[ inline]
622
652
pub fn zw ( self ) -> I32x2 {
623
- unsafe { I32x2 ( simd_shuffle2 ( self . 0 , self . 0 , [ 2 , 3 ] ) ) }
653
+ unsafe { I32x2 ( simd_shuffle2 ! ( self . 0 , self . 0 , [ 2 , 3 ] ) ) }
624
654
}
625
655
626
656
// Conversions
0 commit comments