Commit graph

18 commits

Author SHA1 Message Date
Taiki Endo
bf1239e78c
Implement __sync builtins for thumbv6-none-eabi (#1050)
This is a PR for thumbv6-none-eabi (bere-metal Armv6k in Thumb mode)
which proposed to be added by
https://github.com/rust-lang/rust/pull/150138.

Armv6k supports atomic instructions, but they are unavailable in Thumb
mode unless Thumb-2 instructions available (v6t2).

Using Thumb interworking (can be used via `#[instruction_set]`) allows
us to use these instructions even from Thumb mode without Thumb-2
instructions, but LLVM does not implement that processing (as of LLVM
21), so this PR implements it in compiler-builtins.

The code around `__sync` builtins is basically copied from
`arm_linux.rs` which uses kernel_user_helpers for atomic implementation.
The atomic implementation is a port of my [atomic-maybe-uninit inline
assembly code].

This PR has been tested on QEMU 10.2.0 using patched compiler-builtins
and core that applied the changes in this PR and
https://github.com/rust-lang/rust/pull/150138 and the [portable-atomic
no-std test suite] (can be run with `./tools/no-std.sh
thumbv6-none-eabi` on that repo) which tests wrappers around
`core::sync::atomic`. (Note that the target-spec used in test sets
max-atomic-width to 32 and atomic_cas to true, unlike the current
https://github.com/rust-lang/rust/pull/150138.) The original
atomic-maybe-uninit implementation has been tested on real Arm hardware.

(Note that Armv6k also supports 64-bit atomic instructions, but they are
skipped here. This is because there is no corresponding code in
`arm_linux.rs` (since the kernel requirements increased in 1.64, it may
be possible to implement 64-bit atomics there as well. see also
https://github.com/taiki-e/portable-atomic/pull/82), the code becomes
more complex than for 32-bit and smaller atomics.)

[atomic-maybe-uninit inline assembly code]: https://github.com/taiki-e/atomic-maybe-uninit/blob/HEAD/src/arch/arm.rs
[portable-atomic no-std test suite]: https://github.com/taiki-e/portable-atomic/tree/HEAD/tests/no-std-qemu
2026-01-22 10:09:48 +00:00
Matthias Krüger
0e28b4201a
Rollup merge of #144443 - WaffleLapkin:integer-target-pointer-width, r=Noratrieb
Make target pointer width in target json an integer

r? Noratrieb
cc `@RalfJung` (https://github.com/rust-lang/rust/pull/142352/files#r2230380120)

try-job: x86_64-rust-for-linux
2025-08-31 13:40:34 +02:00
Waffle Lapkin
6a3187af13
fix target-pointer-width in tests 2025-08-27 23:44:49 +02:00
Stefan Schindler
ca7a0aff74
Fix some typos 2025-08-19 23:03:18 +00:00
Trevor Gross
016bc61312
Test building custom targets and resolve an issue probing rustc
The `rustc` probe done in our build scripts needs to pass `--target` to
get the correct configuration, which usually comes from the `TARGET`
environment variable. However, for targets specified via a `target.json`
file, `TARGET` gets set to the file name without an extension or path.
`rustc` will check a search path to attempt to locate the file, but this
is likely to fail since the directory where Cargo invokes build scripts
(and hence where those scripts invoke `rustc`) might not have any
relation to the JSON spec file.

Resolve this for now by leaving `f16` and `f128` disabled if the `rustc`
command fails. Result of the discussion at CARGO-14208 may eventually
provide a better solution.

A CI test is also added since custom JSON files are an edge case that
could fail in other ways. I verified this fails without the fix here.
The JSON file is the output for `thumbv7em-none-eabi`, just renamed so
`rustc` doesn't identify it.
2025-07-04 21:09:56 -05:00
Trevor Gross
8995ac0448 Use runtime feature detection for fma routines on x86
Get performance closer to the glibc implementations by adding assembly
fma routines, with runtime feature detection so they are used even if
not compiled with `+fma` (as the distributed standard library is often
not). Glibc uses ifuncs, this implementation stores a function pointer
in an atomic.

Results of CPU flags are also cached in order to avoid repeating the
startup time in calls to different functions. The feature detection code
is a slightly simplified version of `std-detect`.

Musl sources were used as a reference [1].

Fixes: https://github.com/rust-lang/rust/issues/140452 once synced

[1]: c47ad25ea3/src/math/x32/fma.c
2025-05-03 14:17:49 -04:00
Trevor Gross
4a1dc96652 Rename the i686 module to x86
This module is used for both i686 and x86-64.
2025-05-03 14:17:49 -04:00
Trevor Gross
2705f686b5 update-api-list: Match subdirectories within arch 2025-05-03 14:17:49 -04:00
Trevor Gross
caf337d467 Refactor the fma modules
Move implementations to `generic/` like the other functions. This also
allows us to combine the `fma` and `fma_wide` modules.
2025-04-29 19:09:50 -04:00
Trevor Gross
66be06a1a7 ci: Remove the old libm workflow file
All jobs are now run as part of `compiler-builtins`.
2025-04-20 05:33:19 -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
0d0d317242 Enable icount benchmarks in CI 2025-04-20 00:58:50 -04:00
Trevor Gross
c35cccd676 Move the libm .editorconfig to root 2025-04-19 20:42:40 -04:00
Trevor Gross
9b8065decb Combine the libm .gitignore 2025-04-19 20:42:40 -04:00
Trevor Gross
98acedc914 Remove libm CI dockerfiles
These are identical to what already exists in compiler-builtins except
for some base image changes, so we can eliminate the duplicates.
2025-04-19 20:42:40 -04:00
Trevor Gross
66fa4fd265 Add libm and libm-macros to the workspace
These should build and test correctly. `libm-test` and others that
depend on it are excluded since the necessary CI is not yet set up.
2025-04-19 19:05:49 -04:00
Trevor Gross
ca5c4ed8d7 Fix the release-plz job 2025-04-19 17:31:43 -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