about summary refs log tree commit diff
path: root/library/compiler-builtins/libm/src/math/support
AgeCommit message (Collapse)AuthorLines
2025-09-21Mark float intrinsics with no preconditions as safeltdk-1/+1
2025-07-26libm: Update for new warn-by-default clippy lintsTrevor Gross-1/+2
Silence the approximate constant lint because it is noisy and not always correct. `single_component_path_imports` is also not accurate when built as part of `compiler-builtins`, so that needs to be `allow`ed as well.
2025-07-17Allow a new lint failure in nightlyTrevor Gross-0/+2
```text warning: function `f32_to_bits` is never used --> libm/src/math/support/float_traits.rs:367:14 | 367 | pub const fn f32_to_bits(x: f32) -> u32 { | ^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default warning: function `f64_to_bits` is never used --> libm/src/math/support/float_traits.rs:381:14 | 381 | pub const fn f64_to_bits(x: f64) -> u64 { | ^^^^^^^^^^^ warning: `libm` (lib) generated 2 warnings ``` This is a false positive, see RUST-144060.
2025-07-01libm: Improved integer utilities, implement shifts and bug fixes for i256 ↵quaternic-57/+162
and u256 `i256` and `u256` - operators now use the same overflow convention as primitives - implement `<<` and `-` (previously just `>>` and `+`) - implement `Ord` correctly (the previous `PartialOrd` was broken) - correct `i256::SIGNED` to `true` The `Int`-trait is extended with `trailing_zeros`, `carrying_add`, and `borrowing_sub`.
2025-06-13fmaximum,fminimum: Fix incorrect result and add testsTrevor Gross-1/+12
After adding tests, the current implementation for fminimum fails when provided a negative zero and NaN as inputs: ---- math::fminimum_fmaximum_num::tests::fmaximum_num_spec_tests_f64 stdout ---- thread 'math::fminimum_fmaximum_num::tests::fmaximum_num_spec_tests_f64' panicked at libm/src/math/fminimum_fmaximum_num.rs:240:13: fmaximum_num(-0x0p+0, NaN) l: NaN (0x7ff8000000000000) r: -0.0 (0x8000000000000000) ---- math::fminimum_fmaximum_num::tests::fmaximum_num_spec_tests_f32 stdout ---- thread 'math::fminimum_fmaximum_num::tests::fmaximum_num_spec_tests_f32' panicked at libm/src/math/fminimum_fmaximum_num.rs:240:13: fmaximum_num(-0x0p+0, NaN) l: NaN (0x7fc00000) r: -0.0 (0x80000000) Add more thorough spec tests for these functions and correct the implementations. Canonicalization is also moved to a trait method to centralize documentation about what it does and doesn't do.
2025-06-01Fix new `dead_code` warnings from recent nightliesTrevor Gross-103/+116
2025-05-29Reuse `libm`'s `Caat` and `CastFrom` in `compiler-builtins`Trevor Gross-0/+5
2025-05-29cleanup: Reuse `MinInt` and `Int` from `libm` in `compiler-builtins`Trevor Gross-0/+9
Since the two crates are now in the same repo, it is easier to share code. Begin some deduplication with the integer traits.
2025-05-28Update `CmpResult` to use a pointer-sized return typeTrevor Gross-0/+2
As seen at [1], LLVM uses `long long` on LLP64 (to get a 64-bit integer matching pointer size) and `long` on everything else, with exceptions for AArch64 and AVR. Our current logic always uses an `i32`. This happens to work because LLVM uses 32-bit instructions to check the output on x86-64, but the GCC checks the full 64-bit register so garbage in the upper half leads to incorrect results. Update our return type to be `isize`, with exceptions for AArch64 and AVR. Fixes: https://github.com/rust-lang/compiler-builtins/issues/919 [1]: https://github.com/llvm/llvm-project/blob/0cf3c437c18ed27d9663d87804a9a15ff6874af2/compiler-rt/lib/builtins/fp_compare_impl.inc#L11-L27
2025-05-13Fix `i256::MAX`Tobias Decking-1/+1
2025-05-06Require `target_has_atomic = "ptr"` for runtime feature detectionTrevor Gross-3/+8
The `feature_detect` module is currently being built on all targets, but the use of `AtomicU32` causes a problem if atomics are not available (such as with `bpfel-unknown-none`). Gate this module behind `target_has_atomic = "ptr"`. The below now completes successfully: cargo build -p compiler_builtins --target=bpfel-unknown-none -Z build-std=core Fixes: https://github.com/rust-lang/compiler-builtins/issues/908
2025-05-03Use runtime feature detection for fma routines on x86Trevor Gross-0/+209
Get performance closer to the glibc implementations by adding assembly fma routines, with runtime feature detection so they are used even if not compiled with `+fma` (as the distributed standard library is often not). Glibc uses ifuncs, this implementation stores a function pointer in an atomic. Results of CPU flags are also cached in order to avoid repeating the startup time in calls to different functions. The feature detection code is a slightly simplified version of `std-detect`. Musl sources were used as a reference [1]. Fixes: https://github.com/rust-lang/rust/issues/140452 once synced [1]: https://github.com/bminor/musl/blob/c47ad25ea3b484e10326f933e927c0bc8cded3da/src/math/x32/fma.c
2025-04-29Resolve `unnecessary_transmutes` lintsTrevor Gross-0/+6
These appeared in a later nightly. In compiler-builtins we can apply the suggestion, but in `libm` we need to ignore them since `fx::from_bits` is not `const` at the MSRV. `clippy::uninlined_format_args` also seems to have gotten stricter, so fix those here.
2025-04-22Reimplement the generic fmodquaternic-0/+4
2025-04-19Run `cargo fmt` on all projectsTrevor Gross-47/+283
Apply the same formatting rules to both `libm` and `compiler-builtins`.
2025-04-19libm: Flatten the `libm/libm` directoryTrevor Gross-0/+2791