2039 Commits

Author SHA1 Message Date
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
ca5c4ed8d7 Fix the release-plz job 2025-04-19 17:31:43 -04:00
Trevor Gross
8b8bd8a0fd libm: Flatten the libm/libm directory 2025-04-19 17:20:24 -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
Trevor Gross
806bb4fa6e libm: Remove compiler-builtins-smoke-test
Since `libm` is now part of the `compiler-builtins` repo, the crate to
test that they work together is no longer needed.
2025-04-19 17:20:24 -04:00
Trevor Gross
83a8482f91 Update .git-blame-ignore-revs after the libm merge 2025-04-19 20:18:22 +00:00
Trevor Gross
1af955be9a Update path to libm after the merge 2025-04-19 20:18:22 +00:00
Trevor Gross
d794bb3492 Update submodules after the libm merge 2025-04-19 20:18:22 +00:00
Trevor Gross
e646c73c28 Merge remote-tracking branch 'libm/merge-into-builtins-prep' into absorb-libm
Absorb the libm repository into `compiler-builtins`.

This was done using `git-filter-repo` to ensure hashes mentioned in
commit messages were correctly rewritten, I used the same strategy to
merge `ctest` into `libc` [1] and it worked quite well. Approximately:

    # `git filter-repo` requires a clean clone
    git clone https://github.com/rust-lang/libm.git

    # Move all code to a `libm` subdirectory for all history
    git filter-repo --to-subdirectory-filter libm

    # The default merge messages are "merge pull request #nnn from
    # user/branch". GH links these incorrectly in the new repo, so
    # rewrite messages from `#nnn` to `rust-lang/libm#nnn`.
    echo 'regex:(^|\s)(#\d+)==>\1rust-lang/libm\2' > messages.txt
    git filter-repo --replace-message messages.txt

    # Re-add a remote and push as a new branch
    git remote add upstream https://github.com/rust-lang/libm.git
    git switch -c merge-into-builtins-prep
    git push --set-upstream upstream merge-into-builtins-prep

    # Now in a compiler-builtins, add `libm` as a remote
    git remote add libm https://github.com/rust-lang/libm.git
    git fetch libm

    # Do the merge that creates this commit
    git merge libm/merge-into-builtins-prep --allow-unrelated-histories

The result should be correct git history and blame for all files, with
messages that use correct rewritten hashes when they are referenced.
There is some reorganization and CI work needed, but that will be a
follow up.

After this merges I will need to push tags from `libm`, which I have
already rewritten to include a `libm-` prefix. Old tags in
compiler-builtins should likely also be rewritten to add a prefix (we
already have this for newer tags), but this can be done at any point.

* Original remote: https://github.com/rust-lang/libm.git
* Default HEAD: c94017af75c3ec4616d5b7f9b6b1b3826b934469 ("Migrate all
  crates except `libm` to edition 2024")
* HEAD after rewriting history: 15fb6307f6dc295fb965d1c4f486571cc18ab6b3
  ("Migrate all crates except `libm` to edition 2024")

[1]: https://github.com/rust-lang/libc/pull/4283#issuecomment-2773986492
2025-04-19 20:17:07 +00:00
Trevor Gross
1947f328a7 Remove the libm submodule 2025-04-19 20:16:40 +00:00
Trevor Gross
b0d6024f20 ci: Update ci/run-docker.sh to match libm
Prepare for having the repositories combined by ensuring EMULATED,
RUST_BACKTRACE, and CI are set or forwarded as applicable. Also
re-indent the file to four spaces and do some reorganization.
2025-04-19 01:04:33 -04:00
Trevor Gross
01c5888246 ci: Make CI configuration more similar to libm
Apply a handful of changes to reduce the diff between the two:

* Cancel running jobs on new pushes
* Enable log color and backtraces
* Add timeouts
* Specify CI runner versions
* Add an armv7 job
* Replace the name NO_STD with BUILD_ONLY
* Update the extension to the canonical .yaml
* Set AR_ and CC_ environments in docker
* Install requirements to build MPFR
2025-04-18 23:49:29 -04:00
Trevor Gross
92b1e8454d Rename testcrate to builtins-test
The repo will soon have `libm` as a top-level crate, so make it clear
that this is only the test crate for `compiler-builtins`.
2025-04-18 21:14:41 -04:00
Trevor Gross
cd7c76aab3 Migrate all crates except libm to edition 2024
Unfortunately this means we lose use of the convenient name `gen`, so
this includes a handful of renaming.

We can't increase the edition for `libm` yet due to MSRV, but we can
enable `unsafe_op_in_unsafe_fn` to help make that change smoother in the
future.
2025-04-18 19:00:45 -04:00
Trevor Gross
3a0b9c9f51 refactor: Introduce a virtual manifest
Move the workspace configuration to a virtual manifest. This
reorganization makes a more clear separation between package contents
and support files that don't get distributed. It will also make it
easier to merge this repository with `compiler-builtins` which is
planned (builtins had a similar update done in [1]).

LICENSE.txt and README.md are symlinkedinto the new directory to ensure
they get included in the package.

[1]: https://github.com/rust-lang/compiler-builtins/pull/702
2025-04-18 17:49:25 -04:00
Trevor Gross
7077daa6ad refactor: Move the libm crate to a subdirectory
In preparation for switching to a virtual manifest, move the `libm`
crate into a subdirectory and update paths to match.

Updating `Cargo.toml` is done in the next commit so git tracks the moved
file correctly.
2025-04-18 17:49:25 -04:00
Trevor Gross
88dcaf20b5 Mark generic functions #[inline]
Benchmarks for [1] seemed to indicate that repository organization for
some reason had an effect on performance, even though the exact same
rustc commands were running (though some with a different order). After
investigating more, it appears that dependencies may have an affect on
inlining thresholds for generic functions.

It is surprising that this happens, we more or less expect that public
functions will be standalone but everything they call will be inlined.
To help ensure this, mark all generic functions `#[inline]` if they
should be merged into the public function.

Zulip discussion at [2].

[1]: https://github.com/rust-lang/libm/pull/533
[2]: https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Dependencies.20affecting.20codegen/with/513079387
2025-04-18 16:29:27 -04:00
Trevor Gross
3cecf22e0c Combine the source files for fmod
Since `fmod` is generic, there isn't any need to have the small wrappers
in separate files. Most operations was done in [1] but `fmod` was
omitted until now.

[1]: https://github.com/rust-lang/libm/pull/537
2025-04-18 15:14:55 -04:00
Trevor Gross
8da1290f04 Ensure all public functions are marked no_panic
Fixes: https://github.com/rust-lang/libm/issues/201
2025-04-18 04:23:00 -04:00
Trevor Gross
2db05de8fd ci: Account for PR_NUMBER being set to an empty string
This is the case for CI after merge that is no longer associated with a
pull request.
2025-04-18 03:26:38 -04:00
Trevor Gross
2585a57dc7 Ensure configure.rs changes trigger rebuilds 2025-04-18 02:47:03 -04:00
Trevor Gross
1cb17773f6 ci: Increase the timeout for extensive tests
The reorganization PR has caused this to fail once before because every
file shows up as changed. Increase the timeout so this doesn't happen.

We now cancel the job if too many extensive tests are run unless `ci:
allow-many-extensive` is in the PR description, so this helps prevent
the limit being hit by accident.
2025-04-17 23:31:06 -05:00
Trevor Gross
a0e5a7a636 ci: Require ci: allow-many-extensive if a threshold is exceeded
Error out when too many extensive tests would be run unless `ci:
allow-many-extensive` is in the PR description. This allows us to set a
much higher CI timeout with less risk that a 4+ hour job gets started by
accident.
2025-04-17 23:31:06 -05:00
Trevor Gross
cad0d6f187 ci: Allow skipping extensive tests with ci: skip-extensive
Sometimes we do refactoring that moves things around and triggers an
extensive test, even though the implementation didn't change. There
isn't any need to run full extensive CI in these cases, so add a way to
skip it from the PR message.
2025-04-17 23:31:06 -05:00
Trevor Gross
014c3e4ccb ci: Cancel jobs when a new push happens
Jobs should just cancel automatically, it isn't ideal that extensive
jobs can continue running for multiple hours after code has been
updated. Use a solution from [1] to do this.

[1]: https://stackoverflow.com/a/72408109/5380651
2025-04-17 22:57:24 -05:00
Trevor Gross
a15c8c9a3d Combine the source files for more generic implementations
Splitting into different source files by float size doesn't have any
benefit when the only content is a small function that forwards to the
generic implementation. Combine the source files for all width versions
of:

* ceil
* copysign
* fabs
* fdim
* floor
* fmaximum
* fmaximum_num
* fminimum
* fminimum_num
* ldexp
* scalbn
* sqrt
* truc

fmod is excluded to avoid conflicts with an open PR.

As part of this change move unit tests out of the generic module,
instead testing the type-specific functions (e.g. `ceilf16` rather than
`ceil::<f16>()`). This ensures that unit tests are validating whatever
we expose, such as arch-specific implementations via
`select_implementation!`, which would otherwise be skipped. (They are
still covered by integration tests).
2025-04-17 22:00:42 -05:00
Trevor Gross
579627ddd5 Make assert_biteq! not rely on having Int in scope 2025-04-17 22:00:42 -05:00
Trevor Gross
f88b7c8a46 Add NEG_NAN to Float
Introduce a constant representing NaN with a negative sign bit for use
with testing. There isn't really any guarantee that `F::NAN` is positive
but in practice it always is, which is good enough for testing purposes.
2025-04-17 22:00:42 -05:00
github-actions[bot]
3ea9f849d5 chore: release v0.1.155 2025-04-17 14:04:21 -05:00
Folkert de Vries
ec74a38b25 use #[cfg(bootstrap)] for rustc sync 2025-04-17 13:56:58 -05:00
Trevor Gross
9272584533 Replace the bl! macro with asm_sym
`bl!` is being used to add a leading underscore on Apple targets.
`asm_sym` has been around since 2022 and handles platform-specific
symbol names automatically, so make use of this instead.

I have verified that `armv7s-apple-ios` still builds correctly.
2025-04-17 04:02:54 -05:00
Paul Sbarra
7fb882c3fd avr: __udivmod(h|q)i4 2025-04-16 17:35:44 -05:00
Trevor Gross
e4d716c848 fmod: Correct the normalization of subnormals
Discussed at [1], there was an off-by-one mistake when converting from
the loop routine to using `leading_zeros` for normalization.

Currently, using `EXP_BITS` has the effect that `ix` after the branch
has its MSB _one bit to the left_ of the implicit bit's position,
whereas a shift by `EXP_BITS + 1` ensures that the MSB is exactly at the
implicit bit's position, matching what is done for normals (where the
implicit bit is set to be explicit). This doesn't seem to have any
effect in our implementation since the failing test cases from [1]
appear to still have correct results.

Since the result of using `EXP_BITS + 1` is more consistent with what is
done for normals, apply this here.

[1]: https://github.com/rust-lang/libm/pull/469#discussion_r2012473920
2025-04-16 15:28:10 -05:00
Trevor Gross
14ab2453f2 fmod: Add regression tests for subnormal issue
From discussion at [1] our loop count calculation is incorrect, causing
an issue with subnormal numbers. Add test cases for known failures.

[1]: https://github.com/rust-lang/libm/pull/469#discussion_r2012473920
2025-04-16 15:28:10 -05:00
github-actions[bot]
377b08cc29 chore: release v0.1.154 2025-04-16 13:32:04 -05:00
Folkert de Vries
b8083bd87d turn #[naked] into an unsafe attribute 2025-04-16 13:23:04 -05:00
quaternic
b955cc691e Implement rounding for the hex float parsing and prepare to improve error handling
Parsing errors are now bubbled up part of the way, but that needs some
more work.

Rounding should be correct, and the `Status` returned by `parse_any`
should have the correct bits set. These are used for the current (unchanged)
behavior of the surface level functions like `hf64`: panic on invalid inputs, or
values that aren't exactly representable.
2025-04-15 00:46:12 +00:00
github-actions[bot]
73a04443bd chore: release v0.1.153 2025-04-09 15:33:43 -05:00
Trevor Gross
571a3dce9e Update the libm submodule
Includes [1] and [2], which should resolve problems cg_gcc has using
scalar math operations as a fallback for vector operations.

[1]: https://github.com/rust-lang/libm/pull/459
[2]: https://github.com/rust-lang/libm/pull/534
2025-04-09 12:51:58 -05:00
Trevor Gross
28b6df8603 Add assembly version of simple operations on aarch64
Replace `core::arch` versions of the following with handwritten
assembly, which avoids recursion issues (cg_gcc using `rint` as a
fallback) as well as problems with `aarch64be`.

* `rint`
* `rintf`

Additionally, add assembly versions of the following:

* `fma`
* `fmaf`
* `sqrt`
* `sqrtf`

If the `fp16` target feature is available, which implies `neon`, also
include the following:

* `rintf16`
* `sqrtf16`

`sqrt` is added to match the implementation for `x86`. `fma` is included
since it is used by many other routines.

There are a handful of other operations that have assembly
implementations. They are omitted here because we should have basic
float math routines available in `core` in the near future, which will
allow us to defer to LLVM for assembly lowering rather than implementing
these ourselves.
2025-04-09 00:46:53 -05:00
Trevor Gross
375cb5402f Resolve small errors identified by recent clippy 2025-04-08 22:04:58 -05:00
Trevor Gross
4e5cbbeda1 Replace calls to core::arch intrinsics with assembly
Some backends may replace calls to `core::arch` with multiple calls to
`sqrt` [1], which becomes recursive. Help mitigate this by replacing the
call with assembly.

Results in the same assembly as the current implementation when built
with optimizations.

[1]: https://github.com/rust-lang/compiler-builtins/issues/649
2025-04-08 22:04:58 -05:00
Trevor Gross
87595c5d82 Remove a mention of force-soft-float in build.rs
`libm` no longer uses this directly in `cfg`, it is only for setting
other configuration in the `libm` `build.rs`. Clean up this
configuration in `compiler-builtins` since it is unused.
2025-04-08 21:49:25 -05:00
Trevor Gross
9b8ccf67c6 Revert "Disable f16 on AArch64 without the neon feature"
The LLVM issue [1] was resolved and the fix was synced to rust-lang/rust
in [2].

This reverts commit 5cf417a9e92bb48e4e55756a645826fd167b9f3a.

[1]: https://github.com/llvm/llvm-project/issues/129394
[2]: https://github.com/rust-lang/rust/pull/138695
2025-04-02 14:27:06 -05:00
Patryk Wychowaniec
30c128006a avr: Skip No More! 2025-03-23 19:36:12 -05:00
Ralf Jung
5cf993880a
copy_misaligned_words: avoid out-of-bounds accesses (#799)
* copy_misaligned_words: avoid out-of-bounds accesses
* add test to make Miri able to detect OOB in memmove
* run Miri on CI
2025-03-22 05:36:40 +00:00
Trevor Gross
7b674e5a75 Clean up icount benchmarks
* Delete some memcpy tests that were a bit excessive
* Always use the same offset of 65
* Add a memmove test with aligned source and destination
* Improve printing output and add more comments
* Use a constant for 1 MiB so it shows up in the benchmark logs
2025-03-22 00:14:01 -05:00
Trevor Gross
f0f9cfa463 Add benchmarks using iai-callgrind
This crate [1] makes it reasonably easy to get instruction count
performance metrics that are stable enough to run in CI, and has worked
out well since integrating it with `libm`. Add new benchmarks for `mem`
functions using `iai-callgrind`, modeling them off of the existing
benchmarks.

[1]: https://github.com/iai-callgrind/iai-callgrind
2025-03-21 03:42:46 -05:00
github-actions[bot]
a0d40f287a chore: release v0.1.152 2025-03-19 21:10:16 -05:00
beetrees
fc1b87da4a Remove use of atomic_load_unordered and undefined behaviour from arm_linux.rs 2025-03-19 21:02:14 -05:00