Skip to content

Commit

Permalink
some i32::from_bits fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Jan 23, 2024
1 parent b66c9af commit 82a6394
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 19 deletions.
11 changes: 4 additions & 7 deletions src/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ pub use u10::{
};

mod u15;
#[rustfmt::skip]
pub use u15::{
erfcf as erfc_u15,
};
pub use u15::erfcf as erfc_u15;

mod u35;
#[rustfmt::skip]
Expand Down Expand Up @@ -434,7 +431,7 @@ fn ilogbkf(mut d: f32) -> i32 {
} else {
d
};
let q = ((d.to_bits() >> 23) & 0xff) as i32;
let q = ((d.to_bits() as i32) >> 23) & 0xff;
if m {
q - (64 + 0x7f)
} else {
Expand All @@ -446,7 +443,7 @@ fn ilogbkf(mut d: f32) -> i32 {
// normalized FP value.
#[inline]
fn ilogb2kf(d: f32) -> i32 {
((d.to_bits() >> 23) & 0xff) as i32 - 0x7f
(((d.to_bits() as i32) >> 23) & 0xff) - 0x7f
}

#[inline]
Expand Down Expand Up @@ -939,7 +936,7 @@ pub fn fmodf(x: f32, y: f32) -> f32 {
if d == 0. {
0.
} else {
f32::from_bits(d.to_bits() - 1)
f32::from_bits(((d.to_bits() as i32) - 1) as u32)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/f32/u05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub fn sqrtf(mut d: f32) -> f32 {
}

// http://en.wikipedia.org/wiki/Fast_inverse_square_root
let mut x = f32::from_bits(0x_5f37_5a86 - ((d + 1e-45).to_bits() >> 1));
let mut x = f32::from_bits((0x_5f37_5a86 - (((d + 1e-45).to_bits() as i32) >> 1)) as u32);

x *= 1.5 - 0.5 * d * x * x;
x *= 1.5 - 0.5 * d * x * x;
Expand Down
2 changes: 1 addition & 1 deletion src/f32/u35.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ pub fn sqrtf(mut d: f32) -> f32 {
}

// http://en.wikipedia.org/wiki/Fast_inverse_square_root
let mut x = f32::from_bits(0x_5f37_5a86 - ((d + 1e-45).to_bits() >> 1));
let mut x = f32::from_bits((0x_5f37_5a86 - (((d + 1e-45).to_bits() as i32) >> 1)) as u32);

x *= 1.5 - 0.5 * d * x * x;
x *= 1.5 - 0.5 * d * x * x;
Expand Down
6 changes: 3 additions & 3 deletions src/f32x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ where
{
let o = d.simd_lt(F32x::splat(5.421_010_862_427_522_e-20));
d = o.select(F32x::splat(1.844_674_407_370_955_2_e19) * d, d);
let q = (d.to_bits() >> U32x::splat(23)).cast() & I32x::splat(0xff);
let q = (d.to_bits().cast() >> I32x::splat(23)) & I32x::splat(0xff);
q - o.select(I32x::splat(64 + 0x7f), I32x::splat(0x7f))
}

Expand All @@ -551,8 +551,8 @@ pub(crate) fn ilogb2kf<const N: usize>(d: F32x<N>) -> I32x<N>
where
LaneCount<N>: SupportedLaneCount,
{
let q = d.to_bits();
let mut q = (q >> U32x::splat(23)).cast();
let q = d.to_bits().cast();
let mut q = q >> I32x::splat(23);
q &= I32x::splat(0xff);
q - I32x::splat(0x7f)
}
Expand Down
2 changes: 1 addition & 1 deletion src/f32x/u05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ where

let mut x = F32x::from_bits(
(I32x::splat(0x_5f37_5a86)
- ((d + F32x::splat(1e-45)).to_bits() >> U32x::splat(1)).cast())
- ((d + F32x::splat(1e-45)).to_bits().cast() >> I32x::splat(1)))
.cast(),
);

Expand Down
4 changes: 2 additions & 2 deletions src/f32x/u35.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,10 +1124,10 @@ where
{
let e = F32x::from_bits(
U32x::splat(0x_2000_0000)
+ (U32x::splat(0x_7f00_0000) & (d.to_bits() >> U32x::splat(1))),
+ (U32x::splat(0x_7f00_0000) & (d.to_bits().cast() >> I32x::splat(1))),
);
let m = F32x::from_bits(
I32x::splat(0x_3f00_0000) + (I32x::splat(0x_01ff_ffff) & I32x::from_bits(d)),
I32x::splat(0x_3f00_0000) + (I32x::splat(0x_01ff_ffff) & d.to_bits().cast()),
);
let mut x = vrsqrteq_f32(m);
x = vmulq_f32(x, vrsqrtsq_f32(m, vmulq_f32(x, x)));
Expand Down
5 changes: 1 addition & 4 deletions src/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ pub use u10::{
};

mod u15;
#[rustfmt::skip]
pub use u15::{
erfc as erfc_u15,
};
pub use u15::erfc as erfc_u15;
mod u35;
#[rustfmt::skip]
pub use u35::{
Expand Down

0 comments on commit 82a6394

Please sign in to comment.