Commit Graph

317439 Commits

Author SHA1 Message Date
Trevor Gross 44ee391300 meta: Allow a clippy lint that appears in recent versions
We are now getting this warning:

    warning: the variable `j` is used as a loop counter
       --> libm/src/math/rem_pio2_large.rs:268:5
        |
    268 |     for i in 0..=m {
        |     ^^^^^^^^^^^^^^ help: consider using: `for (j, i) in ((jv as i32) - (jx as i32)..).zip((0..=m))`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_counter_loop
        = note: `#[warn(clippy::explicit_counter_loop)]` on by default

    warning: `libm` (lib) generated 1 warning

Where the suggestion is definitely not an improvement.
2026-03-05 19:57:57 -05:00
Trevor Gross 2891905c7d meta: Commit changes applied by recent versions of rustfmt 2026-03-05 19:57:57 -05:00
Trevor Gross b4ec29c993 libm: Replace div! with unchecked_div_*
`div!` looks innocuous but is actually unsafe. Replace it with function
calls that require us to actually use `unsafe`, and add the precondition
notes. These can likely be removed completely in the near future.

There is one case in `rem_pio2_large` and one in `exp2` where
preconditions aren't as easy to define, but fortunately it seems like we
are able to just use regular division there without affecting codegen.
2026-02-20 16:57:34 -06:00
Trevor Gross 8b9bbbccef c-b: Replace core::intrinsics::{cold_path, likely}
Replace the use of intrinsics with `core::hint::cold_path` which has
been unstably available for a while, and is on track to become stable in
the next release.
2026-02-20 16:57:34 -06:00
Trevor Gross 2b76199bfb c-b: Remove unused features in tests 2026-02-20 16:57:34 -06:00
Trevor Gross c5e7c93406 c-b: Remove #![feature(naked_functions)]
This feature has been stable for a while.
2026-02-20 16:57:34 -06:00
Trevor Gross 7ba44756aa c-b: Clean up unused imports
These are remnants of historical chkstk implementations that are no
longer relevant, so clean up the imports here.
2026-02-20 16:57:34 -06:00
Trevor Gross 00ea98816d test: Gate LSE tests by mangled-names
Resolve a CI issue when running tests with `--no-default-features`.
2026-02-20 16:18:51 -06:00
Vinícius Freitas 008f313466 Add comprehensive tests for AArch64 atomics with and without LSE
Enable aarch64 outline-atomics in tests via the mangled-names feature
gate, and add comprehensive compare-and-swap tests that run both with
LSE enabled and disabled. Improve assertion messages to better describe
expected behavior.

Co-authored-by: Trevor Gross <tmgross@umich.edu>
2026-02-20 14:17:01 -06:00
Vinícius Freitas 010e20923b Change atomic function signatures to use unsigned integer types
Replace signed integer types (i8, i16, i32, i64, i128) with their
unsigned equivalents (u8, u16, u32, u64, u128) in function declarations
and the int_ty! macro, avoiding the need for sign extension in emitted
assembly.
2026-02-20 14:17:01 -06:00
Vinícius Freitas d31b87f20b Add Apple AArch64 support for outline atomics
Add support for ELF and Mach-O AArch64 relocation specifiers for symbol
access, enabling outline-atomics to work on Apple targets. Remove the
Linux-only OS gate in tests.

Co-authored-by: Trevor Gross <tmgross@umich.edu>
2026-02-20 14:17:01 -06:00
Hans Wennborg 84cfd9a557 Check for symbols with default visibility in symbol-check
to ensure that compiler-builtins doesn't expose any symbols with default
visibility.
2026-02-16 06:20:30 -06:00
Juho Kahala 04334f0515 fix testing at lgammaf overflow threshold
The current implementation of lgammaf evaluates to f32::MAX at the first
input that would overflow if correctly rounded. This is still well within
allowed error, so special case it.
2026-02-16 06:13:43 -06:00
Trevor Gross 1542d6405c test: Enable the wasmbind feature on indicatif for wasm
As of indicatif 0.18.4, this option must be enabled in able to build.
2026-02-16 04:13:11 -06:00
Trevor Gross e12d83967e ci: Resolve an issue calculating workflow variables
PRs are now getting the following:

    Traceback (most recent call last):
      File "/home/runner/work/compiler-builtins/compiler-builtins/ci/ci-util.py", line 510, in <module>
        main()
      File "/home/runner/work/compiler-builtins/compiler-builtins/ci/ci-util.py", line 496, in main
        ctx.emit_workflow_output()
      File "/home/runner/work/compiler-builtins/compiler-builtins/ci/ci-util.py", line 294, in emit_workflow_output
        pr = PrInfo.from_env()
             ^^^^^^^^^^^^^^^^^
      File "/home/runner/work/compiler-builtins/compiler-builtins/ci/ci-util.py", line 152, in from_env
        return cls.from_pr(pr_env)
               ^^^^^^^^^^^^^^^^^^^
      File "/home/runner/work/compiler-builtins/compiler-builtins/ci/ci-util.py", line 174, in from_pr
        return cls(**json.loads(pr_info), cfg=PrCfg(pr_json["body"]))
                                              ^^^^^^^^^^^^^^^^^^^^^^
      File "/home/runner/work/compiler-builtins/compiler-builtins/ci/ci-util.py", line 134, in __init__
        pprint.pp(self)
      File "/usr/lib/python3.12/pprint.py", line 66, in pp
        pprint(object, *args, sort_dicts=sort_dicts, **kwargs)
    ...
    AttributeError: 'PrCfg' object has no attribute 'extra_extensive'. Did you mean: 'skip_extensive'?

Resolve this by using `__post_init__` rather than `__init__`.

Fixes: bba024d20464 ("ci: Allow specifying extra extensive tests to run")
2026-02-16 04:13:11 -06:00
Trevor Gross 9be3b21559 meta: Add a root Cargo.lock file
In order to improve upon some inconsistencies seen across CI runs and
locally, add a Cargo.lock file for the main workspace.
2026-02-16 04:13:11 -06:00
Trevor Gross 49e594e11a ci: Allow specifying extra extensive tests to run
For cases where we would like to run tests that aren't automatically
detected, allow the following syntax in PR descriptions:

    ci: extra-extensive=copysignf,sqrtf16
2026-02-16 02:44:11 -06:00
Aelin 7d9b412073 libm: Reenable sincosf tests on ppc64
This was missed in 6e91b0346c3d (“Revert "Disable broken powerpc64 test
due to
 https://github.com/rust-lang/rust/issues/88520"”).
2026-02-14 14:57:28 -06:00
Aelin Reidel 87166b545e libm: Reenable should_panic tests on ppc64le
The tests pass successfully for me on powerpc64le-unknown-linux-gnu
with nightly 1.95.
2026-02-14 02:45:36 -06:00
Trevor Gross 873e96b675 ci: Rewrap the command in miri.sh 2026-02-13 17:47:29 -06:00
Trevor Gross 706a3ab68e meta: Move the Criterion dependency behind a walltime feature
Currently Criterion is always built with the test crates, but it doesn't
really need to be. It wasn't a problem before but did start showing up
with the latest version bump since it added a C dependency, and for the
Miri CI runs we don't have the C toolchains. To resolve this and speed
up compilation time, move criterion behind a new feature `walltime`.

I'd rather have named this `runtime` but don't want to confuse my future
self with "what runtime?".
2026-02-13 17:47:29 -06:00
Trevor Gross 8fd2474e2d meta: Upgrade all dependencies to the latest incompatible versions
Most of the semver-breaking changes here relate to the 0.10 release of
`rand`.

Changelogs:

* https://github.com/criterion-rs/criterion.rs/releases/tag/criterion-v0.8.0
* https://github.com/gimli-rs/object/blob/master/CHANGELOG.md#0380
* https://github.com/rust-random/rand/blob/master/CHANGELOG.md#0100---2026-02-08
2026-02-13 17:47:29 -06:00
Trevor Gross dffcc200c0 libm: Add an optimization for trunc
Suggested-by: Juho Kahala <57393910+quaternic@users.noreply.github.com>
2026-02-13 05:40:39 -06:00
Trevor Gross 8c26adcab0 libm: Add an optimization for floor
ceil seems to optimize better, but this gets closer to the pre-fix
codegen.
2026-02-13 05:40:39 -06:00
Trevor Gross 70c6d5a447 libm: Fix _status status outputs on null-mantissa inputs
Values like 0.5 that have an exponent but not a mantissa are currently
being reported as OK rather than INEXACT for ceil, floor, and trunc. Fix
this and clean up the test cases.

This tries to keep the algorithm diff as simple as possible, which
introduces some small performance regressions. This is improved in a
future commit.
2026-02-13 05:40:39 -06:00
Trevor Gross 0b0d40d5f3 libm: Improve debug output for Status 2026-02-13 05:40:39 -06:00
Trevor Gross e68fc280c2 ci: Increase the benchmark rustc version to 2026-02-10
This includes the most recent LLVM bump.
2026-02-13 03:12:26 -06:00
Trevor Gross 67ab9a5568 libm: Add frexpf16
The new algorithm now correctly supports the type.
2026-02-12 01:39:50 -06:00
Trevor Gross 4401daa4ff libm: Switch to a non-recursive algorithm for subnormals
This will support `frexpf16` and should allow `generic::frexp` to be
inlined into the non-generic `frexp*` functions.

Additionally remove an unneeded `as` cast.
2026-02-12 01:39:50 -06:00
Trevor Gross e7e9546ef6 libm: Print Hexf<i32> with 0x and zero padding 2026-02-12 01:39:50 -06:00
Trevor Gross c1653840a6 util: Add an alias for the eval subcommand 2026-02-12 00:52:58 -06:00
Trevor Gross 6aa1e6932d util: Add support for decomposing floats 2026-02-12 00:52:58 -06:00
Trevor Gross 0a4613c297 util: f16 now has parsing in the standard library, use it 2026-02-12 00:52:58 -06:00
Trevor Gross 212652c5d4 libm: Add frexpf128, ilogbf16, and ilogbf128
The `frexpf16` signature is added (to make traits easier) but left
unimplemented, since it will need a slightly different algorithm.
2026-02-11 22:56:15 -06:00
Trevor Gross f2bec36b92 libm: Convert frexp and ilogb to a generic implementations 2026-02-11 22:56:15 -06:00
Trevor Gross 804a1f87cf Revert "ci: Pin rustc on the native PowerPC job"
The nightly has the LLVM bump that resolves the relevant issue.

This reverts commit 99d1fc7752b0e09cff5729cd4f3783d23c23cb66.

Link: https://github.com/rust-lang/rust/pull/152428
2026-02-11 22:15:48 -06:00
Trevor Gross 8f0208ecb2 Revert "ci: Temporarily disable native PPC and s390x jobs"
These were disabled due to permission issues, which should now be
resolved.

This reverts commit 28e0556a7bca6ca828186d9de74d30c7cb45db5e.
2026-02-11 21:58:13 -06:00
Trevor Gross 200968c81d ci: Pin Miri to the 2026-02-11 nightly
CI is failing with:

    error: failed to run custom build command for `quote v1.0.44`

    Caused by:
      process didn't exit successfully: `/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri runner /home/runner/work/compiler-builtins/compiler-builtins/target/miri/debug/build/quote-32cc00414fa6f72d/build-script-build` (exit status: 1)
      --- stderr
      fatal error: file "/home/runner/work/compiler-builtins/compiler-builtins/target/miri/debug/build/quote-32cc00414fa6f72d/build-script-build" contains outdated or invalid JSON; try `cargo clean`

Link: https://rust-lang.zulipchat.com/#narrow/channel/269128-miri/topic/build-script-build.20contains.20outdated.20or.20invalid.20JSON/with/573426109
2026-02-11 21:11:00 -06:00
Trevor Gross 15d02fc0d7 symcheck: Check for binaries requiring a writeable + executable stack
Implement the following logic:

* For elf executable binaries, check for PT_GNU_STACK with PF_X. This
  combination tells the kernel to make the stack executable.
* For elf intermediate objects, check for `.note.GNU-stack` with
  SHF_EXECINSTR. This combination in an object file tells the linker to
  give the final binary PT_GNU_STACK PF_X.
* For elf intermediate objects with no `.note.GNU-stack`, assume the
  legacy behavior that assumes an executable stack is required.
* For non-elf binaries, don't check anything. In a follow up it may be
  possible to check for `MH_ALLOW_STACK_EXECUTION` on Mach-O binaries,
  but it doesn't seem possible to get the latest compiler to emit this.

This appears to match what is done by `scanelf` to emit `!WX` [1], which
seems to be the tool used to create the output in the issue. The ld
manpage [2] also has some useful notes about these flags, as does the
presentation at [3].

Closes: https://github.com/rust-lang/compiler-builtins/issues/183

[1]: https://github.com/gentoo/pax-utils/blob/9ef54b472e42ba2c5479fbd86b8be2275724b064/scanelf.c
[2]: https://man7.org/linux/man-pages/man1/ld.1.html
[3]: https://www.ndss-symposium.org/wp-content/uploads/6D-s0924-ye.pdf
2026-02-11 14:45:47 -06:00
Trevor Gross 44b0bd98fd symcheck: Don't check for empty symbol tables with PE binaries
PE executables don't seem to have anything in the symbol table. Don't
assert that we find any symbols in this case, which allows using
symcheck for executable binaries.
2026-02-11 14:45:47 -06:00
Trevor Gross 7d5135c25b symcheck: Clean up test setup that requires environment 2026-02-11 14:45:47 -06:00
Trevor Gross 1da633ca4b symcheck: Always check args, simplify running functions 2026-02-11 14:45:47 -06:00
Trevor Gross 0d2a5d24d3 symcheck: Switch to getopts for argument parsing
It would be nice to support a few more flags here, but the current
implementation is a bit limited. Switch to `getopts` which should make
things a bit easier in the future.
2026-02-10 00:56:43 -06:00
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 3d0989266d cleanup: Perform some simplifications possible with the MSRV bump 2026-02-07 08:46:41 -06:00
Trevor Gross 1ec5101f20 Bump the libm MSRV to 1.67
This gets us:

* `saturating_sub_unsigned`
* `<int>::ilog2`
* Correct lexing of float literals with the `f16` or `f128` suffix

Link: https://github.com/rust-lang/compiler-builtins/issues/1017
2026-02-07 08:46:41 -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 5768fb7d93 symcheck: Check for core symbols with the new mangling
The recent switch in default mangling meant that the check was no longer
working correctly. Resolve this by checking for both legacy- and
v0-mangled core symbols to the extent that this is possible.
2026-02-07 06:15:42 -06:00
Trevor Gross 9184a5f661 symcheck: Add tests for the symbol checker
Ensure that these are actually doing what is expected.
2026-02-07 05:27:30 -06:00