Commit Graph

2065 Commits

Author SHA1 Message Date
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
Trevor Gross
1112886edc Use the v2 resolver in the workspace 2025-03-06 04:04:39 -05:00
Trevor Gross
2d8c362963 Migrate testcrate and panic-handler to edition 2024
Includes `extern` -> `unsafe extern` blocks and formatting updates.
2025-03-06 03:58:28 -05:00
Trevor Gross
4735ded783 Revert "Add a test config for __gnu_h2f_ieee and __gnu_f2h_ieee"
This turned out to not be useful, so remove it.

This reverts commit b7b93103fb9293c0c502dc1ae34e2ad5c871bc39.
2025-03-05 01:42:36 -05:00
github-actions[bot]
795fa2f40a chore: release v0.1.151 2025-03-05 01:32:53 -05:00
王宇逸
f5f09d2f4b Add cygwin support
Co-authored-by: Ookiineko <chiisaineko@protonmail.com>
2025-03-05 01:17:50 -05:00
hev
890cd1e0f9 Enable f16 for LoongArch (#770)
[ the configured-out tests should be re-enabled once we have the symbols
  in nightly - Trevor ]
2025-03-05 06:11:51 +00:00
Trevor Gross
e4c1eb803d Revert "ci: Pin the nightly toolchain for aarch64-unknown-linux-gnu"
The fix to this issue was synced in [1] so we should no longer need to
keep aarch64 pinned.

This reverts commit b2bcfc838e2a4b72fa62b333e3eb91f250aa4539.

[1]: https://github.com/rust-lang/rust/pull/137661
2025-03-04 22:15:03 -05:00
Trevor Gross
968a7d0b7c Add a test config for __gnu_h2f_ieee and __gnu_f2h_ieee
Some targets do not provide these symbols since they always use
__extendhfsf and __truncsfhf. Add a configuration option for this.
2025-03-04 18:05:02 -05:00
Trevor Gross
340d3d4bd7 Simplify test crate build features
Since we have a handful of different float-related configuration in
testcrate, track a list of which are implied by others rather than
repeating the config.
2025-03-04 17:56:30 -05:00
Trevor Gross
2de09ac46a Add __extendhfdf2 and add __truncdfhf2 test
LLVM doesn't seem to emit this intrinsic but it probably should, in some
cases it lowers f16->f64 conversions as f16->f32->f64 with two libcalls.
GCC provides this intrinsic so it is good to have anyway.

Additionally, add a test for f64->f16 which was missing.

[1]: https://rust.godbolt.org/z/xezM9PEnz
2025-03-04 17:36:33 -05:00
Trevor Gross
41f1ad2732 Remove outdated information from the readme 2025-03-02 04:17:30 -05:00
github-actions[bot]
4b664fd2ef chore: release v0.1.150 2025-03-01 14:54:11 -05:00
Trevor Gross
afea1c0555 Disable f16 on AArch64 without the neon feature
There is an LLVM regression that breaks some `f16`-related code when
`fp-armv8` is disabled [1]. Since Rust ties that feature to `neon`,
disable `f16` if `neon` is not available.

[1]: https://github.com/llvm/llvm-project/issues/129394
2025-03-01 14:40:03 -05:00