diff --git a/Cargo.toml b/Cargo.toml index adbc68f..f85aedd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,9 +41,6 @@ rand_distr = { version = "0.5.0", default-features = false, optional = true } rkyv = { version = "0.8.0", optional = true } arbitrary = { version = "1.4.1", features = ["derive"], optional = true } -[target.'cfg(target_arch = "spirv")'.dependencies] -crunchy = "0.2.2" - [dev-dependencies] criterion = "0.5" quickcheck = "1.0" diff --git a/src/bfloat.rs b/src/bfloat.rs index 17ff777..43e2778 100644 --- a/src/bfloat.rs +++ b/src/bfloat.rs @@ -9,7 +9,6 @@ use core::{ num::FpCategory, ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign}, }; -#[cfg(not(target_arch = "spirv"))] use core::{ fmt::{ Binary, Debug, Display, Error, Formatter, LowerExp, LowerHex, Octal, UpperExp, UpperHex, @@ -918,7 +917,6 @@ impl PartialOrd for bf16 { } } -#[cfg(not(target_arch = "spirv"))] impl FromStr for bf16 { type Err = ParseFloatError; fn from_str(src: &str) -> Result { @@ -926,56 +924,48 @@ impl FromStr for bf16 { } } -#[cfg(not(target_arch = "spirv"))] impl Debug for bf16 { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { Debug::fmt(&self.to_f32(), f) } } -#[cfg(not(target_arch = "spirv"))] impl Display for bf16 { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { Display::fmt(&self.to_f32(), f) } } -#[cfg(not(target_arch = "spirv"))] impl LowerExp for bf16 { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { write!(f, "{:e}", self.to_f32()) } } -#[cfg(not(target_arch = "spirv"))] impl UpperExp for bf16 { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { write!(f, "{:E}", self.to_f32()) } } -#[cfg(not(target_arch = "spirv"))] impl Binary for bf16 { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { write!(f, "{:b}", self.0) } } -#[cfg(not(target_arch = "spirv"))] impl Octal for bf16 { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { write!(f, "{:o}", self.0) } } -#[cfg(not(target_arch = "spirv"))] impl LowerHex for bf16 { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { write!(f, "{:x}", self.0) } } -#[cfg(not(target_arch = "spirv"))] impl UpperHex for bf16 { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { write!(f, "{:X}", self.0) diff --git a/src/bfloat/convert.rs b/src/bfloat/convert.rs index 04d0649..a67dfd6 100644 --- a/src/bfloat/convert.rs +++ b/src/bfloat/convert.rs @@ -1,4 +1,3 @@ -use crate::leading_zeros::leading_zeros_u16; use core::mem; #[inline] @@ -138,7 +137,7 @@ pub(crate) const fn bf16_to_f64(i: u16) -> f64 { // Check for subnormals, which will be normalized by adjusting exponent if half_exp == 0 { // Calculate how much to adjust the exponent by - let e = leading_zeros_u16(half_man as u16) - 9; + let e = u16::leading_zeros(half_man as u16) - 9; // Rebias and adjust exponent let exp = ((1023 - 127 - e) as u64) << 52; diff --git a/src/binary16.rs b/src/binary16.rs index 0f86522..afc0f27 100644 --- a/src/binary16.rs +++ b/src/binary16.rs @@ -9,7 +9,6 @@ use core::{ num::FpCategory, ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign}, }; -#[cfg(not(target_arch = "spirv"))] use core::{ fmt::{ Binary, Debug, Display, Error, Formatter, LowerExp, LowerHex, Octal, UpperExp, UpperHex, @@ -929,7 +928,6 @@ impl PartialOrd for f16 { } } -#[cfg(not(target_arch = "spirv"))] impl FromStr for f16 { type Err = ParseFloatError; fn from_str(src: &str) -> Result { @@ -937,56 +935,48 @@ impl FromStr for f16 { } } -#[cfg(not(target_arch = "spirv"))] impl Debug for f16 { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { Debug::fmt(&self.to_f32(), f) } } -#[cfg(not(target_arch = "spirv"))] impl Display for f16 { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { Display::fmt(&self.to_f32(), f) } } -#[cfg(not(target_arch = "spirv"))] impl LowerExp for f16 { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { write!(f, "{:e}", self.to_f32()) } } -#[cfg(not(target_arch = "spirv"))] impl UpperExp for f16 { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { write!(f, "{:E}", self.to_f32()) } } -#[cfg(not(target_arch = "spirv"))] impl Binary for f16 { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { write!(f, "{:b}", self.0) } } -#[cfg(not(target_arch = "spirv"))] impl Octal for f16 { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { write!(f, "{:o}", self.0) } } -#[cfg(not(target_arch = "spirv"))] impl LowerHex for f16 { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { write!(f, "{:x}", self.0) } } -#[cfg(not(target_arch = "spirv"))] impl UpperHex for f16 { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { write!(f, "{:X}", self.0) diff --git a/src/binary16/arch.rs b/src/binary16/arch.rs index 4c003a0..829dcd4 100644 --- a/src/binary16/arch.rs +++ b/src/binary16/arch.rs @@ -1,5 +1,5 @@ #![allow(dead_code, unused_imports)] -use crate::leading_zeros::leading_zeros_u16; + use core::mem; #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] @@ -640,7 +640,7 @@ pub(crate) const fn f16_to_f32_fallback(i: u16) -> f32 { // Check for subnormals, which will be normalized by adjusting exponent if half_exp == 0 { // Calculate how much to adjust the exponent by - let e = leading_zeros_u16(half_man as u16) - 6; + let e = u16::leading_zeros(half_man as u16) - 6; // Rebias and adjust exponent let exp = (127 - 15 - e) << 23; @@ -691,7 +691,7 @@ pub(crate) const fn f16_to_f64_fallback(i: u16) -> f64 { // Check for subnormals, which will be normalized by adjusting exponent if half_exp == 0 { // Calculate how much to adjust the exponent by - let e = leading_zeros_u16(half_man as u16) - 6; + let e = u16::leading_zeros(half_man as u16) - 6; // Rebias and adjust exponent let exp = ((1023 - 15 - e) as u64) << 52; diff --git a/src/leading_zeros.rs b/src/leading_zeros.rs deleted file mode 100644 index 848afb5..0000000 --- a/src/leading_zeros.rs +++ /dev/null @@ -1,65 +0,0 @@ -// https://doc.rust-lang.org/std/primitive.u16.html#method.leading_zeros - -#[cfg(not(any(all( - target_arch = "spirv", - not(all( - target_feature = "IntegerFunctions2INTEL", - target_feature = "SPV_INTEL_shader_integer_functions2" - )) -))))] -#[inline] -pub(crate) const fn leading_zeros_u16(x: u16) -> u32 { - x.leading_zeros() -} - -#[cfg(all( - target_arch = "spirv", - not(all( - target_feature = "IntegerFunctions2INTEL", - target_feature = "SPV_INTEL_shader_integer_functions2" - )) -))] -#[inline] -pub(crate) const fn leading_zeros_u16(x: u16) -> u32 { - leading_zeros_u16_fallback(x) -} - -#[cfg(any( - test, - all( - target_arch = "spirv", - not(all( - target_feature = "IntegerFunctions2INTEL", - target_feature = "SPV_INTEL_shader_integer_functions2" - )) - ) -))] -#[inline] -const fn leading_zeros_u16_fallback(mut x: u16) -> u32 { - use crunchy::unroll; - let mut c = 0; - let msb = 1 << 15; - unroll! { for i in 0 .. 16 { - if x & msb == 0 { - c += 1; - } else { - return c; - } - #[allow(unused_assignments)] - if i < 15 { - x <<= 1; - } - }} - c -} - -#[cfg(test)] -mod test { - - #[test] - fn leading_zeros_u16_fallback() { - for x in [44, 97, 304, 1179, 23571] { - assert_eq!(super::leading_zeros_u16_fallback(x), x.leading_zeros()); - } - } -} diff --git a/src/lib.rs b/src/lib.rs index 72d3cb5..c7fe11b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -213,7 +213,6 @@ trivial_numeric_casts, future_incompatible )] -#![cfg_attr(not(target_arch = "spirv"), warn(missing_debug_implementations))] #![allow(clippy::verbose_bit_mask, clippy::cast_lossless, unexpected_cfgs)] #![cfg_attr(not(feature = "std"), no_std)] #![doc(html_root_url = "https://docs.rs/half/2.6.0")] @@ -228,7 +227,6 @@ extern crate alloc; mod bfloat; mod binary16; -mod leading_zeros; #[cfg(feature = "num-traits")] mod num_traits;