Commit graph

33 commits

Author SHA1 Message Date
Juho Kahala
8cd47adab2
libm: Fix tests for lgamma
The tests were using `rug::ln_gamma` as a reference for `libm::lgamma`,
which actually computes the natural logarithm *of the absolute value* of
the Gamma function.

This changes the range of inputs used for the icount-benchmarks of these
functions, which causes false regressions in [1].

[1]: https://github.com/rust-lang/compiler-builtins/actions/runs/21788698368/job/62864230903?pr=1075#step:7:2710.

Fixes: a1a066611dc2 ("Create interfaces for testing against MPFR")
2026-02-09 04:32:04 -06:00
Trevor Gross
7c9ae5b021 meta: Sort Cargo.toml [features] table after [dependencies] 2026-02-07 07:51:17 -06:00
Trevor Gross
0538f7b2ab meta: Switch to workspace dependencies
We have a handful of repeated dependencies that can be cleaned up, so
change here.
2026-02-07 07:51:17 -06:00
Trevor Gross
4d24b508bb meta: Upgrade all dependencies to the latest compatible versions
This allows us to drop wasm-specific configuration for `getrandom`.

Link: 314fd5ab3e/CHANGELOG.md (major-change-to-wasm_js-backend)
2026-02-07 05:13:21 -06:00
Juho Kahala
2f06c639c3 libm: Fix acoshf and acosh for negative inputs
The acosh functions were incorrectly returning finite values for some
negative inputs (should be NaN for any `x < 1.0`)

The bug was inherited when originally ported from musl, and this patch
follows their fix for single-precision acoshf in [1].

A similar fix is applied to acosh, though musl still has an incorrect
implementation requiring tests against that basis to be skipped.

[1]: https://git.musl-libc.org/cgit/musl/commit/?id=c4c38e6364323b6d83ba3428464e19987b981d7a

[ added context to message - Trevor ]
2026-02-07 01:36:46 -06:00
Juho Kahala
5db03861b0 libm-test: Remove exception for fmaximum_num tests
This was left over from f6a23a78c44e ("fmaximum,fminimum: Fix incorrect
result and add tests").

[ added context to body - Trevor ]
2026-02-07 01:36:46 -06:00
Trevor Gross
a47510aa0f Allow unstable_name_collisions
In recent nightlies we are hitting errors like the following:

     error: an associated constant with this name may be added to the standard library in the future
       --> libm/src/math/support/float_traits.rs:248:48
        |
    248 |               const SIGN_MASK: Self::Int = 1 << (Self::BITS - 1);
        |                                                  ^^^^^^^^^^
    ...
    324 | / float_impl!(
    325 | |     f32,
    326 | |     u32,
    327 | |     i32,
    ...   |
    333 | |     fmaf32
    334 | | );
        | |_- in this macro invocation
        |
        = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
        = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
        = note: `-D unstable-name-collisions` implied by `-D warnings`
        = help: to override `-D warnings` add `#[allow(unstable_name_collisions)]`
        = note: this error originates in the macro `float_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
    help: use the fully qualified path to the associated const
        |
    248 -             const SIGN_MASK: Self::Int = 1 << (Self::BITS - 1);
    248 +             const SIGN_MASK: Self::Int = 1 << (<f32 as float_traits::Float>::BITS - 1);
        |
    help: add `#![feature(float_bits_const)]` to the crate attributes to enable `core::f32::<impl f32>::BITS`
       --> libm/src/lib.rs:26:1
        |
     26 + #![feature(float_bits_const)]
        |

Using fully qualified syntax is verbose and `BITS` only exists since
recently, so allow this lint instead.
2026-02-06 22:51:00 +00:00
Juho Kahala
a9fa80ce91
Fix expm1f overflow threshold
Due to an erroneous overflow threshold, `expm1f` was incorrectly
returning `inf` for inputs in the range `[88.72169, 88.72283]`. This
additionally caused `sinhf` to return `NaN` for inputs in that range.

The bug was ported from the original in musl, which has since been fixed
in [1].

[1]: https://git.musl-libc.org/cgit/musl/commit/?id=964104f9f0e056cf58d9defa0b716d7756f040f6
2025-12-17 05:56:45 +00:00
Juho Kahala
65a4f94b71
libm: Implement exp and its variants for i586 with inline assembly
Resolve the severe imprecision (~2%) that is due to inconsistent
rounding.

Closes: https://github.com/rust-lang/compiler-builtins/issues/1021
2025-12-06 08:00:15 +00:00
Trevor Gross
1cfe3585e7 bench: Update the benchmark runner to gungraun 0.17
`iai-callgrind` was renamed to `gungraun` and had a new release. Update
everything to match.

There shouldn't be any changes to observable behavior here.
2025-12-04 21:35:41 -05:00
cyrgani
ee1b36a243
Remove usage of the to-be-deprecated core::f32, core::f64 items
Needed for https://github.com/rust-lang/rust/pull/146882.
2025-09-22 18:51:08 +00:00
quaternic
04909ba40a
libm: define and implement trait NarrowingDiv for unsigned integer division
New utility in `libm::support`:
- `trait NarrowingDiv` for dividing `u2N / uN` when the quotient fits in
  `uN`
- a reasonable implementation of that for primitives up to `u256 / u128`

This is the inverse operation of unsigned widening multiplication:

    let xy: u256 = u128::widen_mul(x, y);
    assert_eq!(xy.checked_narrowing_div_rem(y), Some((x, 0))); // unless y == 0

The trait API is based on x86's `div`-instruction: quotient overflow
happens exactly when the high half of the dividend is greater or equal
to the divisor, which includes division by zero.
2025-09-05 09:54:37 +00:00
Folkert de Vries
9c683d3487
Implement floor and ceil in assembly on i586
Fixes: https://github.com/rust-lang/compiler-builtins/issues/837

The assembly is based on

- 2043392793/lib/libm/arch/i387/s_floor.S
- 2043392793/lib/libm/arch/i387/s_ceil.S

Which both state

    /*
     * Written by J.T. Conklin <jtc@NetBSD.org>.
     * Public domain.
     */

Which I believe means we're good in terms of licensing.
2025-07-27 17:27:40 -04:00
Trevor Gross
f5c9403551 Upgrade iai-callgrind to 0.15
Pick up the latest version of iai-callgrind, which includes some output
improvements.

Changelog: https://github.com/iai-callgrind/iai-callgrind/releases
2025-07-10 18:47:26 -04:00
Trevor Gross
0e00ba127b Upgrade dependencies to the latest version
This picks up a fix in `rustc_apfloat` [1] that resolves a problem with
`fma`.

[1]: https://github.com/rust-lang/rustc_apfloat/releases/tag/rustc_apfloat-v0.2.3%2Bllvm-462a31f5a5ab
2025-07-10 17:50:49 -04:00
quaternic
6c4221818e
libm: Improved integer utilities, implement shifts and bug fixes for i256 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-07-01 08:07:48 +00:00
quaternic
76b9fbf5b2 apply suggestions for clippy::manual_is_multiple_of in libm-test 2025-06-29 05:03:12 -05:00
Trevor Gross
e1e3cc24a2 Replace the musl submodule with a download script
The submodule was causing issues in rust-lang/rust, so eliminiate it
here. `build-musl` is also removed from `libm-test`'s default features
so the crate doesn't need to be built by default.
2025-06-04 17:20:43 +00:00
Trevor Gross
5778643174 libm-test: Fix unintentional skips in binop_common
`binop_common` emits a `SKIP` that is intended to apply only to
`copysign`, but is instead applying to all binary operators. Correct the
general case but leave the currently-failing `maximum_num` tests as a
FIXME, to be resolved separately in [1].

Also simplify skip logic and NaN checking, and add a few more `copysign`
checks.

[1]: https://github.com/rust-lang/compiler-builtins/pull/939
2025-06-02 22:47:15 +00:00
Trevor Gross
e83ca86341 cleanup: Use x.biteq(y) rather than x.to_bits() == y.to_bits() 2025-06-02 16:10:49 +00:00
Trevor Gross
0a7e59265a Upgrade all dependencies to the latest available version
In particular, this includes a fix to `iai-callgrind` that will allow us
to simplify our benchmark runner.
2025-06-01 19:57:14 +00:00
Trevor Gross
8edaa6e5c8 libm-test: Make extensive an attribute rather than a test type
Currently we run logspace tests for extensive tests, but there isn't any
reason we couldn't also run more kinds of tests more extensively (e.g.
more edge cases, combine edge cases with logspace for multi-input
functions, etc). As a first step toward making this possible, make
`extensive` a new field in `CheckCtx`, and rename `QuickSpaced` to
`Spaced`.
2025-05-29 21:06:44 +00:00
Trevor Gross
7db8cf1fea Add benchmarks for float parsing and printing
As part of this, the u256 benchmarks are reorganized to a group.
2025-05-29 18:03:16 +00:00
Trevor Gross
1c5f8cc72d fmaf: Add a test case from a MinGW failure
This is a known problem in the MinGW fmaf implementation, identified at
[1].  Make sure our implementation passes this edge case.

[1]: https://github.com/rust-lang/rust/issues/140515
2025-05-01 21:24:34 -04:00
Trevor Gross
99202af075 libm-macros: Allow a way to bulk match f16 and f128 functions
These are never available in musl, so introduce easier ways to skip them
rather than needing to exclude f16/f128 functions in three different
places.
2025-04-23 15:04:51 -04:00
Trevor Gross
1dd39e27f0 libm-macros: Start tracking which functions are public
It would be nice to reuse some of the macro structure for internal
functions, like `rem_pio2`. To facilitate this, add a `public` field and
make it available in the macro's API.
2025-04-23 03:48:02 -04:00
Trevor Gross
013a83acdd Update licensing information after repository refactoring
In order to disambiguate things now that libm is part of the
compiler-builtins repository, do the following:

* Mention libm in LICENSE.txt
* Clarify the default license for crates other than libm and
  compiler-builtins
* Add an explicit license field to Cargo.toml for all other crates
2025-04-21 06:16:12 -04:00
Trevor Gross
9c96f245b8 ci: Enable testing of libm crates
Update `run.sh` to start testing `libm`. Currently this is somewhat
inefficient because `builtins-test` gets run more than once on some
targets; this can be cleaned up later.
2025-04-20 03:22:27 -04:00
Trevor Gross
d02b25fd6e Fix the libm-test logfile path
This was broken since the crate's location relative to the target
directory had changed.
2025-04-20 00:58:50 -04:00
Trevor Gross
141c7b06c4 Add remaining libm crates to the workspace
These are still not yet covered in CI since we always name explicit
packages there, but all crates are now part of the workspace.
2025-04-19 23:20:13 -04:00
Trevor Gross
8d70be87e6 Run cargo fmt on all projects
Apply the same formatting rules to both `libm` and `compiler-builtins`.
2025-04-19 19:05:49 -04:00
Trevor Gross
cab8700e84 libm: Fix crate compilation
Update paths and submodules to fix `libm-test` and `util` building so we
will be able to add them to the workspace.
2025-04-19 18:23:45 -04:00
Trevor Gross
911a70381a libm: Reorganize into compiler-builtins
Distribute everything from `libm/` to better locations in the repo.
`libm/libm/*` has not moved yet to avoid Git seeing the move as an edit
to `Cargo.toml`.

Files that remain to be merged somehow are in `etc/libm`.
2025-04-19 17:20:24 -04:00