File tree 5 files changed +151
-5
lines changed
5 files changed +151
-5
lines changed Original file line number Diff line number Diff line change 1
1
//! Vector absolute value
2
-
2
+ #! [ allow ( dead_code ) ]
3
3
use coresimd:: simd:: * ;
4
4
5
5
#[ allow( improper_ctypes) ]
6
6
extern "C" {
7
+ #[ link_name = "llvm.fabs.f32" ]
8
+ fn abs_f32 ( x : f32 ) -> f32 ;
9
+ #[ link_name = "llvm.fabs.f64" ]
10
+ fn abs_f64 ( x : f64 ) -> f64 ;
11
+
7
12
#[ link_name = "llvm.fabs.v2f32" ]
8
13
fn abs_v2f32 ( x : f32x2 ) -> f32x2 ;
9
14
#[ link_name = "llvm.fabs.v4f32" ]
@@ -24,13 +29,42 @@ pub(crate) trait FloatAbs {
24
29
fn abs ( self ) -> Self ;
25
30
}
26
31
32
+ trait RawAbs {
33
+ fn raw_abs ( self ) -> Self ;
34
+ }
35
+
36
+ impl RawAbs for f32 {
37
+ fn raw_abs ( self ) -> Self {
38
+ unsafe { abs_f32 ( self ) }
39
+ }
40
+ }
41
+
42
+ impl RawAbs for f64 {
43
+ fn raw_abs ( self ) -> Self {
44
+ unsafe { abs_f64 ( self ) }
45
+ }
46
+ }
47
+
48
+
27
49
macro_rules! impl_fabs {
28
50
( $id: ident : $fn: ident) => {
51
+ #[ cfg( not( target_arch = "s390x" ) ) ]
29
52
impl FloatAbs for $id {
30
53
fn abs( self ) -> Self {
31
54
unsafe { $fn( self ) }
32
55
}
33
56
}
57
+ // FIXME: https://github.com/rust-lang-nursery/stdsimd/issues/501
58
+ #[ cfg( target_arch = "s390x" ) ]
59
+ impl FloatAbs for $id {
60
+ fn abs( self ) -> Self {
61
+ let mut v = $id:: splat( 0. ) ;
62
+ for i in 0 ..$id:: lanes( ) {
63
+ v = v. replace( i, self . extract( i) . raw_abs( ) )
64
+ }
65
+ v
66
+ }
67
+ }
34
68
} ;
35
69
}
36
70
Original file line number Diff line number Diff line change 1
1
//! Exact vector cos
2
-
2
+ #! [ allow ( dead_code ) ]
3
3
use coresimd:: simd:: * ;
4
4
5
5
#[ allow( improper_ctypes) ]
6
6
extern "C" {
7
+ #[ link_name = "llvm.cos.f32" ]
8
+ fn cos_f32 ( x : f32 ) -> f32 ;
9
+ #[ link_name = "llvm.cos.f64" ]
10
+ fn cos_f64 ( x : f64 ) -> f64 ;
11
+
7
12
#[ link_name = "llvm.cos.v2f32" ]
8
13
fn cos_v2f32 ( x : f32x2 ) -> f32x2 ;
9
14
#[ link_name = "llvm.cos.v4f32" ]
@@ -24,13 +29,43 @@ pub(crate) trait FloatCos {
24
29
fn cos ( self ) -> Self ;
25
30
}
26
31
32
+ trait RawCos {
33
+ fn raw_cos ( self ) -> Self ;
34
+ }
35
+
36
+ impl RawCos for f32 {
37
+ fn raw_cos ( self ) -> Self {
38
+ unsafe { cos_f32 ( self ) }
39
+ }
40
+ }
41
+
42
+ impl RawCos for f64 {
43
+ fn raw_cos ( self ) -> Self {
44
+ unsafe { cos_f64 ( self ) }
45
+ }
46
+ }
47
+
48
+
27
49
macro_rules! impl_fcos {
28
50
( $id: ident : $fn: ident) => {
51
+ #[ cfg( not( target_arch = "s390x" ) ) ]
29
52
impl FloatCos for $id {
30
53
fn cos( self ) -> Self {
31
54
unsafe { $fn( self ) }
32
55
}
33
56
}
57
+
58
+ // FIXME: https://github.com/rust-lang-nursery/stdsimd/issues/501
59
+ #[ cfg( target_arch = "s390x" ) ]
60
+ impl FloatCos for $id {
61
+ fn cos( self ) -> Self {
62
+ let mut v = $id:: splat( 0. ) ;
63
+ for i in 0 ..$id:: lanes( ) {
64
+ v = v. replace( i, self . extract( i) . raw_cos( ) )
65
+ }
66
+ v
67
+ }
68
+ }
34
69
} ;
35
70
}
36
71
Original file line number Diff line number Diff line change 1
1
//! Vector fused multiply add
2
-
2
+ #! [ allow ( dead_code ) ]
3
3
use coresimd:: simd:: * ;
4
4
5
5
#[ allow( improper_ctypes) ]
@@ -26,11 +26,19 @@ pub(crate) trait FloatFma {
26
26
27
27
macro_rules! impl_fma {
28
28
( $id: ident : $fn: ident) => {
29
+ #[ cfg( not( target_arch = "s390x" ) ) ]
29
30
impl FloatFma for $id {
30
31
fn fma( self , y: Self , z: Self ) -> Self {
31
32
unsafe { $fn( self , y, z) }
32
33
}
33
34
}
35
+ // FIXME: https://github.com/rust-lang-nursery/stdsimd/issues/501
36
+ #[ cfg( target_arch = "s390x" ) ]
37
+ impl FloatFma for $id {
38
+ fn fma( self , y: Self , z: Self ) -> Self {
39
+ self * y + z
40
+ }
41
+ }
34
42
} ;
35
43
}
36
44
Original file line number Diff line number Diff line change 1
1
//! Exact vector sin
2
-
2
+ #! [ allow ( dead_code ) ]
3
3
use coresimd:: simd:: * ;
4
4
5
5
#[ allow( improper_ctypes) ]
6
6
extern "C" {
7
+ #[ link_name = "llvm.sin.f32" ]
8
+ fn sin_f32 ( x : f32 ) -> f32 ;
9
+ #[ link_name = "llvm.sin.f64" ]
10
+ fn sin_f64 ( x : f64 ) -> f64 ;
11
+
7
12
#[ link_name = "llvm.sin.v2f32" ]
8
13
fn sin_v2f32 ( x : f32x2 ) -> f32x2 ;
9
14
#[ link_name = "llvm.sin.v4f32" ]
@@ -24,13 +29,43 @@ pub(crate) trait FloatSin {
24
29
fn sin ( self ) -> Self ;
25
30
}
26
31
32
+ trait RawSin {
33
+ fn raw_sin ( self ) -> Self ;
34
+ }
35
+
36
+ impl RawSin for f32 {
37
+ fn raw_sin ( self ) -> Self {
38
+ unsafe { sin_f32 ( self ) }
39
+ }
40
+ }
41
+
42
+ impl RawSin for f64 {
43
+ fn raw_sin ( self ) -> Self {
44
+ unsafe { sin_f64 ( self ) }
45
+ }
46
+ }
47
+
27
48
macro_rules! impl_fsin {
28
49
( $id: ident : $fn: ident) => {
50
+ #[ cfg( not( target_arch = "s390x" ) ) ]
29
51
impl FloatSin for $id {
30
52
fn sin( self ) -> Self {
31
53
unsafe { $fn( self ) }
32
54
}
33
55
}
56
+
57
+ // FIXME: https://github.com/rust-lang-nursery/stdsimd/issues/501
58
+ #[ cfg( target_arch = "s390x" ) ]
59
+ impl FloatSin for $id {
60
+ fn sin( self ) -> Self {
61
+ let mut v = $id:: splat( 0. ) ;
62
+ for i in 0 ..$id:: lanes( ) {
63
+ v = v. replace( i, self . extract( i) . raw_sin( ) )
64
+ }
65
+ v
66
+ }
67
+ }
68
+
34
69
} ;
35
70
}
36
71
Original file line number Diff line number Diff line change 1
1
//! Exact vector square-root
2
-
2
+ #! [ allow ( dead_code ) ]
3
3
use coresimd:: simd:: * ;
4
4
5
5
#[ allow( improper_ctypes) ]
6
6
extern "C" {
7
+ #[ link_name = "llvm.sqrt.f32" ]
8
+ fn sqrt_f32 ( x : f32 ) -> f32 ;
9
+ #[ link_name = "llvm.sqrt.f64" ]
10
+ fn sqrt_f64 ( x : f64 ) -> f64 ;
11
+
7
12
#[ link_name = "llvm.sqrt.v2f32" ]
8
13
fn sqrt_v2f32 ( x : f32x2 ) -> f32x2 ;
9
14
#[ link_name = "llvm.sqrt.v4f32" ]
@@ -24,13 +29,42 @@ pub(crate) trait FloatSqrt {
24
29
fn sqrt ( self ) -> Self ;
25
30
}
26
31
32
+ trait RawSqrt {
33
+ fn raw_sqrt ( self ) -> Self ;
34
+ }
35
+
36
+ impl RawSqrt for f32 {
37
+ fn raw_sqrt ( self ) -> Self {
38
+ unsafe { sqrt_f32 ( self ) }
39
+ }
40
+ }
41
+
42
+ impl RawSqrt for f64 {
43
+ fn raw_sqrt ( self ) -> Self {
44
+ unsafe { sqrt_f64 ( self ) }
45
+ }
46
+ }
47
+
27
48
macro_rules! impl_fsqrt {
28
49
( $id: ident : $fn: ident) => {
50
+ #[ cfg( not( target_arch = "s390x" ) ) ]
29
51
impl FloatSqrt for $id {
30
52
fn sqrt( self ) -> Self {
31
53
unsafe { $fn( self ) }
32
54
}
33
55
}
56
+ // FIXME: https://github.com/rust-lang-nursery/stdsimd/issues/501
57
+ #[ cfg( target_arch = "s390x" ) ]
58
+ impl FloatSqrt for $id {
59
+ fn sqrt( self ) -> Self {
60
+ let mut v = $id:: splat( 0. ) ;
61
+ for i in 0 ..$id:: lanes( ) {
62
+ v = v. replace( i, self . extract( i) . raw_sqrt( ) ) ;
63
+ }
64
+ v
65
+ }
66
+ }
67
+
34
68
} ;
35
69
}
36
70
You can’t perform that action at this time.
0 commit comments