This repository was archived by the owner on Apr 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 11 files changed +50
-90
lines changed Expand file tree Collapse file tree 11 files changed +50
-90
lines changed Original file line number Diff line number Diff line change @@ -8,14 +8,12 @@ const TOINT: f64 = 1. / f64::EPSILON;
8
8
/// Finds the nearest integer greater than or equal to `x`.
9
9
#[ cfg_attr( all( test, assert_no_panic) , no_panic:: no_panic) ]
10
10
pub fn ceil ( x : f64 ) -> f64 {
11
- // On wasm32 we know that LLVM's intrinsic will compile to an optimized
12
- // `f64.ceil` native instruction, so we can leverage this for both code size
13
- // and speed.
14
- llvm_intrinsically_optimized ! {
15
- #[ cfg( target_arch = "wasm32" ) ] {
16
- return unsafe { :: core:: intrinsics:: ceilf64( x) }
17
- }
11
+ select_implementation ! {
12
+ name: ceil,
13
+ use_intrinsic: target_arch = "wasm32" ,
14
+ args: x,
18
15
}
16
+
19
17
#[ cfg( all( target_arch = "x86" , not( target_feature = "sse2" ) ) ) ]
20
18
{
21
19
//use an alternative implementation on x86, because the
Original file line number Diff line number Diff line change @@ -5,14 +5,12 @@ use core::f32;
5
5
/// Finds the nearest integer greater than or equal to `x`.
6
6
#[ cfg_attr( all( test, assert_no_panic) , no_panic:: no_panic) ]
7
7
pub fn ceilf ( x : f32 ) -> f32 {
8
- // On wasm32 we know that LLVM's intrinsic will compile to an optimized
9
- // `f32.ceil` native instruction, so we can leverage this for both code size
10
- // and speed.
11
- llvm_intrinsically_optimized ! {
12
- #[ cfg( target_arch = "wasm32" ) ] {
13
- return unsafe { :: core:: intrinsics:: ceilf32( x) }
14
- }
8
+ select_implementation ! {
9
+ name: ceilf,
10
+ use_intrinsic: target_arch = "wasm32" ,
11
+ args: x,
15
12
}
13
+
16
14
let mut ui = x. to_bits ( ) ;
17
15
let e = ( ( ( ui >> 23 ) & 0xff ) . wrapping_sub ( 0x7f ) ) as i32 ;
18
16
Original file line number Diff line number Diff line change @@ -5,14 +5,12 @@ use core::u64;
5
5
/// by direct manipulation of the bit representation of `x`.
6
6
#[ cfg_attr( all( test, assert_no_panic) , no_panic:: no_panic) ]
7
7
pub fn fabs ( x : f64 ) -> f64 {
8
- // On wasm32 we know that LLVM's intrinsic will compile to an optimized
9
- // `f64.abs` native instruction, so we can leverage this for both code size
10
- // and speed.
11
- llvm_intrinsically_optimized ! {
12
- #[ cfg( target_arch = "wasm32" ) ] {
13
- return unsafe { :: core:: intrinsics:: fabsf64( x) }
14
- }
8
+ select_implementation ! {
9
+ name: fabs,
10
+ use_intrinsic: target_arch = "wasm32" ,
11
+ args: x,
15
12
}
13
+
16
14
f64:: from_bits ( x. to_bits ( ) & ( u64:: MAX / 2 ) )
17
15
}
18
16
Original file line number Diff line number Diff line change 3
3
/// by direct manipulation of the bit representation of `x`.
4
4
#[ cfg_attr( all( test, assert_no_panic) , no_panic:: no_panic) ]
5
5
pub fn fabsf ( x : f32 ) -> f32 {
6
- // On wasm32 we know that LLVM's intrinsic will compile to an optimized
7
- // `f32.abs` native instruction, so we can leverage this for both code size
8
- // and speed.
9
- llvm_intrinsically_optimized ! {
10
- #[ cfg( target_arch = "wasm32" ) ] {
11
- return unsafe { :: core:: intrinsics:: fabsf32( x) }
12
- }
6
+ select_implementation ! {
7
+ name: fabsf,
8
+ use_intrinsic: target_arch = "wasm32" ,
9
+ args: x,
13
10
}
11
+
14
12
f32:: from_bits ( x. to_bits ( ) & 0x7fffffff )
15
13
}
16
14
Original file line number Diff line number Diff line change @@ -8,14 +8,12 @@ const TOINT: f64 = 1. / f64::EPSILON;
8
8
/// Finds the nearest integer less than or equal to `x`.
9
9
#[ cfg_attr( all( test, assert_no_panic) , no_panic:: no_panic) ]
10
10
pub fn floor ( x : f64 ) -> f64 {
11
- // On wasm32 we know that LLVM's intrinsic will compile to an optimized
12
- // `f64.floor` native instruction, so we can leverage this for both code size
13
- // and speed.
14
- llvm_intrinsically_optimized ! {
15
- #[ cfg( target_arch = "wasm32" ) ] {
16
- return unsafe { :: core:: intrinsics:: floorf64( x) }
17
- }
11
+ select_implementation ! {
12
+ name: floor,
13
+ use_intrinsic: target_arch = "wasm32" ,
14
+ args: x,
18
15
}
16
+
19
17
#[ cfg( all( target_arch = "x86" , not( target_feature = "sse2" ) ) ) ]
20
18
{
21
19
//use an alternative implementation on x86, because the
Original file line number Diff line number Diff line change @@ -5,14 +5,12 @@ use core::f32;
5
5
/// Finds the nearest integer less than or equal to `x`.
6
6
#[ cfg_attr( all( test, assert_no_panic) , no_panic:: no_panic) ]
7
7
pub fn floorf ( x : f32 ) -> f32 {
8
- // On wasm32 we know that LLVM's intrinsic will compile to an optimized
9
- // `f32.floor` native instruction, so we can leverage this for both code size
10
- // and speed.
11
- llvm_intrinsically_optimized ! {
12
- #[ cfg( target_arch = "wasm32" ) ] {
13
- return unsafe { :: core:: intrinsics:: floorf32( x) }
14
- }
8
+ select_implementation ! {
9
+ name: floorf,
10
+ use_intrinsic: target_arch = "wasm32" ,
11
+ args: x,
15
12
}
13
+
16
14
let mut ui = x. to_bits ( ) ;
17
15
let e = ( ( ( ui >> 23 ) as i32 ) & 0xff ) - 0x7f ;
18
16
Original file line number Diff line number Diff line change @@ -74,18 +74,6 @@ macro_rules! div {
74
74
} ;
75
75
}
76
76
77
- // FIXME: phase this out, to be replaced by the more flexible `select_implementation`
78
- macro_rules! llvm_intrinsically_optimized {
79
- ( #[ cfg( $( $clause: tt) * ) ] $e: expr) => {
80
- #[ cfg( all( intrinsics_enabled, not( feature = "force-soft-floats" ) , $( $clause) * ) ) ]
81
- {
82
- if true { // thwart the dead code lint
83
- $e
84
- }
85
- }
86
- } ;
87
- }
88
-
89
77
// Private modules
90
78
#[ macro_use]
91
79
mod support;
Original file line number Diff line number Diff line change @@ -81,18 +81,12 @@ use core::f64;
81
81
/// The square root of `x` (f64).
82
82
#[ cfg_attr( all( test, assert_no_panic) , no_panic:: no_panic) ]
83
83
pub fn sqrt ( x : f64 ) -> f64 {
84
- // On wasm32 we know that LLVM's intrinsic will compile to an optimized
85
- // `f64.sqrt` native instruction, so we can leverage this for both code size
86
- // and speed.
87
- llvm_intrinsically_optimized ! {
88
- #[ cfg( target_arch = "wasm32" ) ] {
89
- return if x < 0.0 {
90
- f64 :: NAN
91
- } else {
92
- unsafe { :: core:: intrinsics:: sqrtf64( x) }
93
- }
94
- }
84
+ select_implementation ! {
85
+ name: sqrt,
86
+ use_intrinsic: target_arch = "wasm32" ,
87
+ args: x,
95
88
}
89
+
96
90
#[ cfg( all( target_feature = "sse2" , not( feature = "force-soft-floats" ) ) ) ]
97
91
{
98
92
// Note: This path is unlikely since LLVM will usually have already
Original file line number Diff line number Diff line change 16
16
/// The square root of `x` (f32).
17
17
#[ cfg_attr( all( test, assert_no_panic) , no_panic:: no_panic) ]
18
18
pub fn sqrtf ( x : f32 ) -> f32 {
19
- // On wasm32 we know that LLVM's intrinsic will compile to an optimized
20
- // `f32.sqrt` native instruction, so we can leverage this for both code size
21
- // and speed.
22
- llvm_intrinsically_optimized ! {
23
- #[ cfg( target_arch = "wasm32" ) ] {
24
- return if x < 0.0 {
25
- :: core:: f32 :: NAN
26
- } else {
27
- unsafe { :: core:: intrinsics:: sqrtf32( x) }
28
- }
29
- }
19
+ select_implementation ! {
20
+ name: sqrtf,
21
+ use_intrinsic: target_arch = "wasm32" ,
22
+ args: x,
30
23
}
24
+
31
25
#[ cfg( all( target_feature = "sse" , not( feature = "force-soft-floats" ) ) ) ]
32
26
{
33
27
// Note: This path is unlikely since LLVM will usually have already
Original file line number Diff line number Diff line change @@ -2,14 +2,12 @@ use core::f64;
2
2
3
3
#[ cfg_attr( all( test, assert_no_panic) , no_panic:: no_panic) ]
4
4
pub fn trunc ( x : f64 ) -> f64 {
5
- // On wasm32 we know that LLVM's intrinsic will compile to an optimized
6
- // `f64.trunc` native instruction, so we can leverage this for both code size
7
- // and speed.
8
- llvm_intrinsically_optimized ! {
9
- #[ cfg( target_arch = "wasm32" ) ] {
10
- return unsafe { :: core:: intrinsics:: truncf64( x) }
11
- }
5
+ select_implementation ! {
6
+ name: trunc,
7
+ use_intrinsic: target_arch = "wasm32" ,
8
+ args: x,
12
9
}
10
+
13
11
let x1p120 = f64:: from_bits ( 0x4770000000000000 ) ; // 0x1p120f === 2 ^ 120
14
12
15
13
let mut i: u64 = x. to_bits ( ) ;
You can’t perform that action at this time.
0 commit comments