Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
11c1522
Enable `__powitf2` on MSVC
beetrees May 21, 2025
7966f1b
fixed typo in readme
Lorl0rd May 10, 2025
db21837
libm: Clean up unused files
tgross35 Apr 22, 2025
4c264c9
Update `CmpResult` to use a pointer-sized return type
tgross35 May 23, 2025
c04f133
Typo in README.md
D-Dario0 May 28, 2025
5978b8b
aarch64: Add a note saying why we use `frintx` rather than `frintn`
tgross35 May 28, 2025
2c9fb22
jsondoclint: Extract `Command`/`CommandKind` into its own file
aDotInTheVoid May 28, 2025
851aa05
cleanup: Reuse `MinInt` and `Int` from `libm` in `compiler-builtins`
tgross35 Apr 21, 2025
877feef
Reuse `libm`'s `Caat` and `CastFrom` in `compiler-builtins`
tgross35 May 29, 2025
97c0beb
Remove unneeded C symbols
tgross35 May 28, 2025
a63f482
Replace the `nm` symbol check with a Rust implementation
tgross35 Apr 19, 2025
8db9bd6
Remove the now-unneeded llvm-tools-preview
tgross35 May 28, 2025
151b1cb
Change `compiler-builtins` to edition 2024
tgross35 May 29, 2025
af16553
symcheck: Print the command to make reproducing errors easier
tgross35 May 29, 2025
7db8cf1
Add benchmarks for float parsing and printing
tgross35 May 29, 2025
c136fb7
Run `builtins-test-intrinsics` when possible
tgross35 Mar 19, 2025
3464b4b
ci: Allow concurrency outside of pull requests
tgross35 May 29, 2025
9f84e99
Increase the benchmark rustc version to 2025-05-28
tgross35 May 29, 2025
8edaa6e
libm-test: Make `extensive` an attribute rather than a test type
tgross35 May 29, 2025
4d325e8
ci: Allow for multiple icount benchmarks in the same run
tgross35 May 29, 2025
14db1b5
jsondocck: command -> directive
aDotInTheVoid May 28, 2025
3c35505
chore: release
github-actions[bot] May 29, 2025
c6df6a7
Fix new `dead_code` warnings from recent nightlies
tgross35 Jun 1, 2025
0a7e592
Upgrade all dependencies to the latest available version
tgross35 Jun 1, 2025
e83ca86
cleanup: Use `x.biteq(y)` rather than `x.to_bits() == y.to_bits()`
tgross35 Jun 2, 2025
ba7cdb6
ci: Refactor benchmark regression checks
tgross35 Jun 1, 2025
5778643
libm-test: Fix unintentional skips in `binop_common`
tgross35 Jun 2, 2025
763663a
rustdoc-json-type: Depend on `serde` and `serde_derive` seperately
aDotInTheVoid Jun 3, 2025
28231d9
Replace some `Option<Span>` with `Span` and use DUMMY_SP instead of None
oli-obk Jun 4, 2025
9091a94
bootstrap: Fix file permissions when dereferencing symlinks
smpdt Jun 4, 2025
06ab34e
cleaned up some tests
Kivooeo Jun 3, 2025
6417248
Report the actual item that evaluation failed for
oli-obk Jun 4, 2025
55f59fb
Fix parsing of frontmatters with inner hyphens
matthewjasper Jun 4, 2025
e1e3cc2
Replace the musl submodule with a download script
tgross35 Jun 4, 2025
f67ca0f
Add an empty rust-version file
tgross35 May 28, 2025
3353a89
Add tooling for `josh` syncs
tgross35 May 18, 2025
eb45e57
Update the upstream Rust version
tgross35 Jun 4, 2025
1599091
Merge ref 'df8102fe5f24:/library/compiler-builtins' from https://gith…
tgross35 Jun 4, 2025
ab453db
`panic-handler`: Remove the `no_core` feature
tgross35 Jun 4, 2025
91ad4bf
jsondocck: Explain what `KNOWN_DIRECTIVE_NAMES` is doing
aDotInTheVoid Jun 5, 2025
bee6dc4
Rollup merge of #141709 - aDotInTheVoid:split-for-docs, r=GuillaumeGomez
matthiaskrgr Jun 5, 2025
5a4abf0
Rollup merge of #141974 - Kivooeo:tf4, r=jieyouxu
matthiaskrgr Jun 5, 2025
1dcd4a7
Rollup merge of #141989 - aDotInTheVoid:sin-sooner, r=GuillaumeGomez
matthiaskrgr Jun 5, 2025
276506e
Rollup merge of #142012 - oli-obk:no-optional-spans, r=fee1-dead
matthiaskrgr Jun 5, 2025
8689de4
Rollup merge of #142015 - oli-obk:wrong-instance, r=RalfJung
matthiaskrgr Jun 5, 2025
64f4bd5
Rollup merge of #142026 - smpdt:master, r=Kobzol
matthiaskrgr Jun 5, 2025
5604376
Rollup merge of #142032 - matthewjasper:frontmatter-lexing, r=fee1-dead
matthiaskrgr Jun 5, 2025
eef9831
Rollup merge of #142036 - tgross35:update-builtins, r=tgross35
matthiaskrgr Jun 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix new dead_code warnings from recent nightlies
  • Loading branch information
tgross35 committed Jun 1, 2025
commit c6df6a72d8f2463985b6b130673536e6d4cc7cbf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::int_traits::{CastFrom, Int, MinInt};

/// Trait for some basic operations on floats
// #[allow(dead_code)]
#[allow(dead_code)] // Some constants are only used with tests
pub trait Float:
Copy
+ fmt::Debug
Expand Down
207 changes: 108 additions & 99 deletions library/compiler-builtins/libm/src/math/support/hex_float.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! Utilities for working with hex float formats.

use core::fmt;

use super::{Float, Round, Status, f32_from_bits, f64_from_bits};
use super::{Round, Status, f32_from_bits, f64_from_bits};

/// Construct a 16-bit float from hex float representation (C-style)
#[cfg(f16_enabled)]
Expand Down Expand Up @@ -352,133 +350,143 @@ const fn u128_ilog2(v: u128) -> u32 {
u128::BITS - 1 - v.leading_zeros()
}

/// Format a floating point number as its IEEE hex (`%a`) representation.
pub struct Hexf<F>(pub F);
#[cfg(any(test, feature = "unstable-public-internals"))]
mod hex_fmt {
use core::fmt;

// Adapted from https://github.com/ericseppanen/hexfloat2/blob/a5c27932f0ff/src/format.rs
#[cfg(not(feature = "compiler-builtins"))]
fn fmt_any_hex<F: Float>(x: &F, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if x.is_sign_negative() {
write!(f, "-")?;
}
use crate::support::Float;

if x.is_nan() {
return write!(f, "NaN");
} else if x.is_infinite() {
return write!(f, "inf");
} else if *x == F::ZERO {
return write!(f, "0x0p+0");
}
/// Format a floating point number as its IEEE hex (`%a`) representation.
pub struct Hexf<F>(pub F);

let mut exponent = x.exp_unbiased();
let sig = x.to_bits() & F::SIG_MASK;

let bias = F::EXP_BIAS as i32;
// The mantissa MSB needs to be shifted up to the nearest nibble.
let mshift = (4 - (F::SIG_BITS % 4)) % 4;
let sig = sig << mshift;
// The width is rounded up to the nearest char (4 bits)
let mwidth = (F::SIG_BITS as usize + 3) / 4;
let leading = if exponent == -bias {
// subnormal number means we shift our output by 1 bit.
exponent += 1;
"0."
} else {
"1."
};
// Adapted from https://github.com/ericseppanen/hexfloat2/blob/a5c27932f0ff/src/format.rs
#[cfg(not(feature = "compiler-builtins"))]
pub(super) fn fmt_any_hex<F: Float>(x: &F, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if x.is_sign_negative() {
write!(f, "-")?;
}

write!(f, "0x{leading}{sig:0mwidth$x}p{exponent:+}")
}
if x.is_nan() {
return write!(f, "NaN");
} else if x.is_infinite() {
return write!(f, "inf");
} else if *x == F::ZERO {
return write!(f, "0x0p+0");
}

#[cfg(feature = "compiler-builtins")]
fn fmt_any_hex<F: Float>(_x: &F, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
unimplemented!()
}
let mut exponent = x.exp_unbiased();
let sig = x.to_bits() & F::SIG_MASK;

let bias = F::EXP_BIAS as i32;
// The mantissa MSB needs to be shifted up to the nearest nibble.
let mshift = (4 - (F::SIG_BITS % 4)) % 4;
let sig = sig << mshift;
// The width is rounded up to the nearest char (4 bits)
let mwidth = (F::SIG_BITS as usize + 3) / 4;
let leading = if exponent == -bias {
// subnormal number means we shift our output by 1 bit.
exponent += 1;
"0."
} else {
"1."
};

impl<F: Float> fmt::LowerHex for Hexf<F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
cfg_if! {
if #[cfg(feature = "compiler-builtins")] {
let _ = f;
unimplemented!()
} else {
fmt_any_hex(&self.0, f)
write!(f, "0x{leading}{sig:0mwidth$x}p{exponent:+}")
}

#[cfg(feature = "compiler-builtins")]
pub(super) fn fmt_any_hex<F: Float>(_x: &F, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
unimplemented!()
}

impl<F: Float> fmt::LowerHex for Hexf<F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
cfg_if! {
if #[cfg(feature = "compiler-builtins")] {
let _ = f;
unimplemented!()
} else {
fmt_any_hex(&self.0, f)
}
}
}
}
}

impl<F: Float> fmt::LowerHex for Hexf<(F, F)> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
cfg_if! {
if #[cfg(feature = "compiler-builtins")] {
let _ = f;
unimplemented!()
} else {
write!(f, "({:x}, {:x})", Hexf(self.0.0), Hexf(self.0.1))
impl<F: Float> fmt::LowerHex for Hexf<(F, F)> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
cfg_if! {
if #[cfg(feature = "compiler-builtins")] {
let _ = f;
unimplemented!()
} else {
write!(f, "({:x}, {:x})", Hexf(self.0.0), Hexf(self.0.1))
}
}
}
}
}

impl<F: Float> fmt::LowerHex for Hexf<(F, i32)> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
cfg_if! {
if #[cfg(feature = "compiler-builtins")] {
let _ = f;
unimplemented!()
} else {
write!(f, "({:x}, {:x})", Hexf(self.0.0), Hexf(self.0.1))
impl<F: Float> fmt::LowerHex for Hexf<(F, i32)> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
cfg_if! {
if #[cfg(feature = "compiler-builtins")] {
let _ = f;
unimplemented!()
} else {
write!(f, "({:x}, {:x})", Hexf(self.0.0), Hexf(self.0.1))
}
}
}
}
}

impl fmt::LowerHex for Hexf<i32> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
cfg_if! {
if #[cfg(feature = "compiler-builtins")] {
let _ = f;
unimplemented!()
} else {
fmt::LowerHex::fmt(&self.0, f)
impl fmt::LowerHex for Hexf<i32> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
cfg_if! {
if #[cfg(feature = "compiler-builtins")] {
let _ = f;
unimplemented!()
} else {
fmt::LowerHex::fmt(&self.0, f)
}
}
}
}
}

impl<T> fmt::Debug for Hexf<T>
where
Hexf<T>: fmt::LowerHex,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
cfg_if! {
if #[cfg(feature = "compiler-builtins")] {
let _ = f;
unimplemented!()
} else {
fmt::LowerHex::fmt(self, f)
impl<T> fmt::Debug for Hexf<T>
where
Hexf<T>: fmt::LowerHex,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
cfg_if! {
if #[cfg(feature = "compiler-builtins")] {
let _ = f;
unimplemented!()
} else {
fmt::LowerHex::fmt(self, f)
}
}
}
}
}

impl<T> fmt::Display for Hexf<T>
where
Hexf<T>: fmt::LowerHex,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
cfg_if! {
if #[cfg(feature = "compiler-builtins")] {
let _ = f;
unimplemented!()
} else {
fmt::LowerHex::fmt(self, f)
impl<T> fmt::Display for Hexf<T>
where
Hexf<T>: fmt::LowerHex,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
cfg_if! {
if #[cfg(feature = "compiler-builtins")] {
let _ = f;
unimplemented!()
} else {
fmt::LowerHex::fmt(self, f)
}
}
}
}
}

#[cfg(any(test, feature = "unstable-public-internals"))]
pub use hex_fmt::*;

#[cfg(test)]
mod parse_tests {
extern crate std;
Expand Down Expand Up @@ -1064,6 +1072,7 @@ mod print_tests {
use std::string::ToString;

use super::*;
use crate::support::Float;

#[test]
#[cfg(f16_enabled)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::{cmp, fmt, ops};

/// Minimal integer implementations needed on all integer types, including wide integers.
#[allow(dead_code)] // Some constants are only used with tests
pub trait MinInt:
Copy
+ fmt::Debug
Expand Down
6 changes: 3 additions & 3 deletions library/compiler-builtins/libm/src/math/support/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ macro_rules! hf128 {
#[cfg(test)]
macro_rules! assert_biteq {
($left:expr, $right:expr, $($tt:tt)*) => {{
use $crate::support::Int;
let l = $left;
let r = $right;
let bits = Int::leading_zeros(l.to_bits() - l.to_bits()); // hack to get the width from the value
// hack to get width from a value
let bits = $crate::support::Int::leading_zeros(l.to_bits() - l.to_bits());
assert!(
l.biteq(r),
$crate::support::Float::biteq(l, r),
"{}\nl: {l:?} ({lb:#0width$x})\nr: {r:?} ({rb:#0width$x})",
format_args!($($tt)*),
lb = l.to_bits(),
Expand Down
4 changes: 3 additions & 1 deletion library/compiler-builtins/libm/src/math/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ pub use env::{FpResult, Round, Status};
#[allow(unused_imports)]
pub use float_traits::{DFloat, Float, HFloat, IntTy};
pub(crate) use float_traits::{f32_from_bits, f64_from_bits};
#[cfg(any(test, feature = "unstable-public-internals"))]
pub use hex_float::Hexf;
#[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};
pub use hex_float::{hf32, hf64};
pub use int_traits::{CastFrom, CastInto, DInt, HInt, Int, MinInt};

/// Hint to the compiler that the current path is cold.
Expand Down