Skip to content

Commit ce46efe

Browse files
committed
perf: add #[inline] to sqrt and round functions for f32 and f64
1 parent 3603a5f commit ce46efe

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

dasp_sample/src/ops.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub mod f32 {
33
use core;
44

55
#[cfg(not(feature = "std"))]
6+
#[inline]
67
pub fn sqrt(x: f32) -> f32 {
78
if x >= 0.0 {
89
f32::from_bits((x.to_bits() + 0x3f80_0000) >> 1)
@@ -11,11 +12,13 @@ pub mod f32 {
1112
}
1213
}
1314
#[cfg(feature = "std")]
15+
#[inline]
1416
pub fn sqrt(x: f32) -> f32 {
1517
x.sqrt()
1618
}
1719

1820
#[cfg(not(feature = "std"))]
21+
#[inline]
1922
pub fn round(x: f32) -> f32 {
2023
if x >= 0.0 {
2124
(x + 0.5) as i32 as f32
@@ -24,6 +27,7 @@ pub mod f32 {
2427
}
2528
}
2629
#[cfg(feature = "std")]
30+
#[inline]
2731
pub fn round(x: f32) -> f32 {
2832
x.round()
2933
}
@@ -34,6 +38,7 @@ pub mod f64 {
3438
use core;
3539

3640
#[cfg(not(feature = "std"))]
41+
#[inline]
3742
pub fn sqrt(x: f64) -> f64 {
3843
if x >= 0.0 {
3944
f64::from_bits((x.to_bits() + 0x3f80_0000) >> 1)
@@ -42,11 +47,13 @@ pub mod f64 {
4247
}
4348
}
4449
#[cfg(feature = "std")]
50+
#[inline]
4551
pub fn sqrt(x: f64) -> f64 {
4652
x.sqrt()
4753
}
4854

4955
#[cfg(not(feature = "std"))]
56+
#[inline]
5057
pub fn round(x: f64) -> f64 {
5158
if x >= 0.0 {
5259
(x + 0.5) as i64 as f64
@@ -55,6 +62,7 @@ pub mod f64 {
5562
}
5663
}
5764
#[cfg(feature = "std")]
65+
#[inline]
5866
pub fn round(x: f64) -> f64 {
5967
x.round()
6068
}

0 commit comments

Comments
 (0)