Make it possible to use hf32! and similar macros outside of libm

Adjust paths such that these macros don't go through the private `math`
module. `feature = "private-test-deps"` is still needed.

Additionally, ensure that `cargo check` for this crate gets run in CI
because `cargo test` does not seem to identify this problem.

`compiler_builtins` will need to reexport the `support` module.
This commit is contained in:
Trevor Gross 2025-02-06 23:18:31 +00:00 committed by Trevor Gross
parent 3aa4da2756
commit bbdcc7ef89
6 changed files with 16 additions and 6 deletions

View file

@ -143,6 +143,7 @@ jobs:
- name: Install Rust
run: rustup update nightly --no-self-update && rustup default nightly
- uses: Swatinem/rust-cache@v2
- run: cargo check --manifest-path crates/compiler-builtins-smoke-test/Cargo.toml
- run: cargo test --manifest-path crates/compiler-builtins-smoke-test/Cargo.toml
benchmarks:

View file

@ -17,6 +17,9 @@ pub mod libm;
use core::ffi::c_int;
// Required for macro paths.
use libm::support;
/// Mark functions `#[no_mangle]` and with the C ABI.
macro_rules! no_mangle {
($( $name:ident( $($tt:tt)+ ) -> $ret:ty; )+) => {

View file

@ -81,7 +81,7 @@ pub mod support;
#[macro_use]
#[cfg(not(feature = "unstable-public-internals"))]
mod support;
pub(crate) mod support;
cfg_if! {
if #[cfg(feature = "unstable-public-internals")] {

View file

@ -107,7 +107,7 @@ pub trait Float:
!self.is_sign_negative()
}
/// Returns if `self` is subnormal
/// Returns if `self` is subnormal.
fn is_subnormal(self) -> bool {
(self.to_bits() & Self::EXP_MASK) == Self::Int::ZERO
}

View file

@ -90,10 +90,11 @@ macro_rules! select_implementation {
/// Construct a 16-bit float from hex float representation (C-style), guaranteed to
/// evaluate at compile time.
#[cfg(f16_enabled)]
#[cfg_attr(feature = "unstable-public-internals", macro_export)]
#[allow(unused_macros)]
macro_rules! hf16 {
($s:literal) => {{
const X: f16 = $crate::math::support::hf16($s);
const X: f16 = $crate::support::hf16($s);
X
}};
}
@ -101,9 +102,10 @@ macro_rules! hf16 {
/// Construct a 32-bit float from hex float representation (C-style), guaranteed to
/// evaluate at compile time.
#[allow(unused_macros)]
#[cfg_attr(feature = "unstable-public-internals", macro_export)]
macro_rules! hf32 {
($s:literal) => {{
const X: f32 = $crate::math::support::hf32($s);
const X: f32 = $crate::support::hf32($s);
X
}};
}
@ -111,9 +113,10 @@ macro_rules! hf32 {
/// Construct a 64-bit float from hex float representation (C-style), guaranteed to
/// evaluate at compile time.
#[allow(unused_macros)]
#[cfg_attr(feature = "unstable-public-internals", macro_export)]
macro_rules! hf64 {
($s:literal) => {{
const X: f64 = $crate::math::support::hf64($s);
const X: f64 = $crate::support::hf64($s);
X
}};
}
@ -122,9 +125,10 @@ macro_rules! hf64 {
/// evaluate at compile time.
#[cfg(f128_enabled)]
#[allow(unused_macros)]
#[cfg_attr(feature = "unstable-public-internals", macro_export)]
macro_rules! hf128 {
($s:literal) => {{
const X: f128 = $crate::math::support::hf128($s);
const X: f128 = $crate::support::hf128($s);
X
}};
}

View file

@ -9,8 +9,10 @@ mod int_traits;
pub use float_traits::{Float, IntTy};
pub(crate) use float_traits::{f32_from_bits, f64_from_bits};
#[cfg(f16_enabled)]
#[allow(unused_imports)]
pub use hex_float::hf16;
#[cfg(f128_enabled)]
#[allow(unused_imports)]
pub use hex_float::hf128;
#[allow(unused_imports)]
pub use hex_float::{Hexf, hf32, hf64};