@@ -14,6 +14,27 @@ cfg_if::cfg_if! {
14
14
#[ derive( Default , Clone , Copy , PartialEq , Debug ) ]
15
15
#[ repr( C , align( 16 ) ) ]
16
16
pub struct f32x4( m128) ;
17
+ } else if #[ cfg( all( feature = "simd" , target_feature = "simd128" ) ) ] {
18
+ use core:: arch:: wasm32:: * ;
19
+
20
+ // repr(transparent) allows for directly passing the v128 on the WASM stack.
21
+ #[ derive( Clone , Copy , Debug ) ]
22
+ #[ repr( transparent) ]
23
+ pub struct f32x4( v128) ;
24
+
25
+ impl Default for f32x4 {
26
+ fn default ( ) -> Self {
27
+ Self :: splat( 0.0 )
28
+ }
29
+ }
30
+
31
+ impl PartialEq for f32x4 {
32
+ fn eq( & self , other: & Self ) -> bool {
33
+ unsafe {
34
+ i32x4_all_true( f32x4_eq( self . 0 , other. 0 ) )
35
+ }
36
+ }
37
+ }
17
38
} else {
18
39
#[ derive( Default , Clone , Copy , PartialEq , Debug ) ]
19
40
#[ repr( C , align( 16 ) ) ]
@@ -33,6 +54,10 @@ impl f32x4 {
33
54
cfg_if:: cfg_if! {
34
55
if #[ cfg( all( feature = "simd" , target_feature = "sse" ) ) ] {
35
56
Self ( max_m128( self . 0 , rhs. 0 ) )
57
+ } else if #[ cfg( all( feature = "simd" , target_feature = "simd128" ) ) ] {
58
+ unsafe {
59
+ Self ( f32x4_max( self . 0 , rhs. 0 ) )
60
+ }
36
61
} else {
37
62
Self ( [
38
63
self . 0 [ 0 ] . max( rhs. 0 [ 0 ] ) ,
@@ -48,6 +73,10 @@ impl f32x4 {
48
73
cfg_if:: cfg_if! {
49
74
if #[ cfg( all( feature = "simd" , target_feature = "sse" ) ) ] {
50
75
Self ( min_m128( self . 0 , rhs. 0 ) )
76
+ } else if #[ cfg( all( feature = "simd" , target_feature = "simd128" ) ) ] {
77
+ unsafe {
78
+ Self ( f32x4_min( self . 0 , rhs. 0 ) )
79
+ }
51
80
} else {
52
81
Self ( [
53
82
self . 0 [ 0 ] . min( rhs. 0 [ 0 ] ) ,
@@ -79,6 +108,10 @@ impl core::ops::Add for f32x4 {
79
108
cfg_if:: cfg_if! {
80
109
if #[ cfg( all( feature = "simd" , target_feature = "sse" ) ) ] {
81
110
Self ( add_m128( self . 0 , rhs. 0 ) )
111
+ } else if #[ cfg( all( feature = "simd" , target_feature = "simd128" ) ) ] {
112
+ unsafe {
113
+ Self ( f32x4_add( self . 0 , rhs. 0 ) )
114
+ }
82
115
} else {
83
116
Self ( [
84
117
self . 0 [ 0 ] + rhs. 0 [ 0 ] ,
@@ -104,6 +137,10 @@ impl core::ops::Sub for f32x4 {
104
137
cfg_if:: cfg_if! {
105
138
if #[ cfg( all( feature = "simd" , target_feature = "sse" ) ) ] {
106
139
Self ( sub_m128( self . 0 , rhs. 0 ) )
140
+ } else if #[ cfg( all( feature = "simd" , target_feature = "simd128" ) ) ] {
141
+ unsafe {
142
+ Self ( f32x4_sub( self . 0 , rhs. 0 ) )
143
+ }
107
144
} else {
108
145
Self ( [
109
146
self . 0 [ 0 ] - rhs. 0 [ 0 ] ,
@@ -123,6 +160,10 @@ impl core::ops::Mul for f32x4 {
123
160
cfg_if:: cfg_if! {
124
161
if #[ cfg( all( feature = "simd" , target_feature = "sse" ) ) ] {
125
162
Self ( mul_m128( self . 0 , rhs. 0 ) )
163
+ } else if #[ cfg( all( feature = "simd" , target_feature = "simd128" ) ) ] {
164
+ unsafe {
165
+ Self ( f32x4_mul( self . 0 , rhs. 0 ) )
166
+ }
126
167
} else {
127
168
Self ( [
128
169
self . 0 [ 0 ] * rhs. 0 [ 0 ] ,
0 commit comments