Commit Graph

2078 Commits

Author SHA1 Message Date
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
Trevor Gross
683485cda2 Switch repository layout to use a virtual manifest
The current setup has the `Cargo.toml` for `compiler-builtins` at the
repository root, which means all support crates and other files are
located within the package root. This works for now but is not the
cleanest setup since files that should or shouldn't be included in the
package need to be configured in `Cargo.toml`. If we eventually merge
`libm` development into this repository, it would be nice to make this
separation more straightforward.

Begin cleaning things up by moving the crate source to a new
`compiler-builtins` directory and adding a virtual manifest. For now the
`libm` submodule is also moved, but in the future it can likely move
back to the top level (ideally `compiler-builtins/src` would contain a
symlink to `libm/src/math`, but unfortunately it seems like Cargo does
not like something about the submodule + symlink combination).
2025-03-19 00:49:34 -05:00
Trevor Gross
3167cbb6d0 Temporarily disable the test call to rust_begin_unwind
Since [1] this symbol is mangled, meaning it is not easy to call
directly. A better fix will come in [2] but for now, just disable that
portion of the test.

[1]: https://github.com/rust-lang/rust/pull/127173
[2]: https://github.com/rust-lang/compiler-builtins/pull/802
2025-03-18 23:10:02 -05:00
Trevor Gross
725759602a Upgrade all dependencies to the latest
This is mostly done to get the latest version of `rand`, which includes
some breaking changes.
2025-03-18 19:46:34 -05:00
Ralf Jung
014f530f76 nightlies without clippy are not a thing any more 2025-03-18 16:37:52 -05:00
Trevor Gross
f8b03df54e Add a script for downloading compiler-rt
Rather than needing to copy the version and URL from the CI workflow,
put this into a script that can be directly run locally.
2025-03-18 06:23:30 -05:00
Trevor Gross
afa3eed6f0 Mark builtins-test-intrinsics as publish = false 2025-03-18 05:45:32 -05:00
Trevor Gross
a179959e0b Move examples/intrinsics.rs to its own crate
Currently there is an interesting situation with the way features get
enabled; `testcrate` enables `mangled-names`, but the `intrinsics.rs`
example requires this feature be disabled (otherwise the test fails with
missing symbols, as expected). This is also the reason that `testcrate`
is not a default workspace member, meaning `cargo test` doesn't actually
run `testcrate`'s tests; making it a default member would mean that
`compiler-builtins/mangled-names` gets enabled when
`examples/intrinsics.rs` gets built, due to the way features get
unified.

Simplify the situation by making moving the example to its own crate as
`builtins-test-intrinsics`. This also means `testcrate` can become a
default member so it is included in `cargo check` or `cargo test` when
run at the workspace root.

`testcrate` and `builtins-test-intrinsics` still can't be built at the
same time since there isn't a straightforward way to have Cargo build
`compiler-builtins` twice with different features. This is a side effect
of us using non-additive features, but there isn't really a better
option since enabling both mangled and unmangled names would render
`builtins-test-intrinsics` useless.
2025-03-18 05:35:19 -05:00
Ralf Jung
590a56483c remove element_unordered_atomic intrinsics 2025-03-17 19:24:07 -05:00
Jens Reidel
6d353134bc Revert "Disable broken powerpc64 test due to https://github.com/rust-lang/rust/issues/88520"
This reverts commit 55f6ecb6de9e2e10d9187b287b9e87b202d07d1e.

Fixes: https://github.com/rust-lang/rust/issues/88520
Signed-off-by: Jens Reidel <adrian@travitia.xyz>
2025-03-17 18:48:52 -05:00
Jens Reidel
192206bfbb Revert "Disable some PPC64 tests which are failing due to an LLVM(?) bug"
This reverts commit 265fdacab9b3c63b2c17a42fb17c51996c703ef8.

Fixes: https://github.com/rust-lang/rust/issues/99853

Signed-off-by: Jens Reidel <adrian@travitia.xyz>
2025-03-17 15:40:46 -05:00
Trevor Gross
1fb5e1a5ba Replace some uses of sign with sig
It seems like "sign" was used as a shortened version of "significand",
but that is easy to confuse with "sign". Update these to use "sig" like
most other places.
2025-03-07 19:31:32 -05:00