@@ -10,7 +10,15 @@ struct f32x4(f32, f32, f32, f32);
10
10
11
11
#[ repr( simd) ]
12
12
#[ derive( Copy , Clone ) ]
13
- struct S < const N : usize > ( [ f32 ; N ] ) ;
13
+ struct A < const N : usize > ( [ f32 ; N ] ) ;
14
+
15
+ #[ repr( simd) ]
16
+ #[ derive( Copy , Clone ) ]
17
+ struct B < T > ( [ T ; 4 ] ) ;
18
+
19
+ #[ repr( simd) ]
20
+ #[ derive( Copy , Clone ) ]
21
+ struct C < T , const N : usize > ( [ T ; N ] ) ;
14
22
15
23
16
24
extern "platform-intrinsic" {
@@ -29,7 +37,23 @@ impl ops::Add for f32x4 {
29
37
}
30
38
}
31
39
32
- impl ops:: Add for S < 4 > {
40
+ impl ops:: Add for A < 4 > {
41
+ type Output = Self ;
42
+
43
+ fn add ( self , rhs : Self ) -> Self {
44
+ unsafe { simd_add ( self , rhs) }
45
+ }
46
+ }
47
+
48
+ impl ops:: Add for B < f32 > {
49
+ type Output = Self ;
50
+
51
+ fn add ( self , rhs : Self ) -> Self {
52
+ unsafe { simd_add ( self , rhs) }
53
+ }
54
+ }
55
+
56
+ impl ops:: Add for C < f32 , 4 > {
33
57
type Output = Self ;
34
58
35
59
fn add ( self , rhs : Self ) -> Self {
@@ -39,19 +63,23 @@ impl ops::Add for S<4> {
39
63
40
64
41
65
pub fn main ( ) {
42
- let lr = f32x4 ( 1.0f32 , 2.0f32 , 3.0f32 , 4.0f32 ) ;
66
+ let x = [ 1.0f32 , 2.0f32 , 3.0f32 , 4.0f32 ] ;
67
+ let y = [ 2.0f32 , 4.0f32 , 6.0f32 , 8.0f32 ] ;
43
68
44
69
// lame-o
45
- let f32x4( x, y, z, w) = add ( lr, lr) ;
46
- assert_eq ! ( x, 2.0f32 ) ;
47
- assert_eq ! ( y, 4.0f32 ) ;
48
- assert_eq ! ( z, 6.0f32 ) ;
49
- assert_eq ! ( w, 8.0f32 ) ;
50
-
51
- let lr2 = S :: < 4 > ( [ 1.0f32 , 2.0f32 , 3.0f32 , 4.0f32 ] ) ;
52
- let [ x, y, z, w] = add ( lr2, lr2) . 0 ;
53
- assert_eq ! ( x, 2.0f32 ) ;
54
- assert_eq ! ( y, 4.0f32 ) ;
55
- assert_eq ! ( z, 6.0f32 ) ;
56
- assert_eq ! ( w, 8.0f32 ) ;
70
+ let a = f32x4 ( 1.0f32 , 2.0f32 , 3.0f32 , 4.0f32 ) ;
71
+ let f32x4( a0, a1, a2, a3) = add ( a, a) ;
72
+ assert_eq ! ( a0, 2.0f32 ) ;
73
+ assert_eq ! ( a1, 4.0f32 ) ;
74
+ assert_eq ! ( a2, 6.0f32 ) ;
75
+ assert_eq ! ( a3, 8.0f32 ) ;
76
+
77
+ let a = A ( x) ;
78
+ assert_eq ! ( add( a, a) . 0 , y) ;
79
+
80
+ let b = B ( x) ;
81
+ assert_eq ! ( add( b, b) . 0 , y) ;
82
+
83
+ let c = C ( x) ;
84
+ assert_eq ! ( add( c, c) . 0 , y) ;
57
85
}
0 commit comments