Add riscv32imfc-unknown-none-elf bare-metal target#158473
Open
sanchuanhehe wants to merge 1 commit into
Open
Conversation
Add a tier 3 bare-metal target for RV32IMFC cores that have hardware single-precision floating point (the `F` extension, `ilp32f` ABI) but no atomic (`A`) extension. This is `riscv32imafc-unknown-none-elf` minus the atomic extension, handled the same way `riscv32imc-unknown-none-elf` handles a no-`a` core: `+forced-atomics` lowers atomic load/store to plain load/store (sound on a single hart) while `atomic_cas = false` keeps RMW/CAS off, so no `lr.w`/`sc.w`/`amo*` are ever emitted and the target does not trap on a core without the `A` extension. Downstream crates use a critical-section polyfill (e.g. `portable-atomic`) for compare-and-swap. This combination has no builtin target today: cores that pair a hardware-float application core with no atomic extension otherwise need a custom target spec plus `-Zbuild-std` on nightly, which is unavailable on stable. The motivating hardware is the application core of vendor SoCs such as the HiSilicon WS63/BS2X family, but the target is vendor-neutral. Register the target, add it to the `targets-elf` assembly sanity test, and document it on the shared `riscv32-unknown-none-elf` platform-support page.
Collaborator
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @jieyouxu (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
Author
|
@rustbot label +O-riscv |
Collaborator
|
These commits modify compiler targets. Some changes occurred in src/doc/rustc/src/platform-support cc @Noratrieb |
Member
|
r? compiler_leads |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a new tier 3 bare-metal target for RV32IMFC cores: RISC-V 32-bit with
the
M,F(hardware single-precision float,ilp32fABI) andCextensions,but no atomic (
A) extension.Why a new builtin target
No builtin target pairs hardware single-float with no atomics today:
riscv32imafc-unknown-none-elf(tier 2) has hard-float but requiresA.riscv32imc-unknown-none-elfhas no atomics but is soft-float (ilp32).Cores that have an
Funit but noAextension (a common shape for theapplication core of low-power Wi-Fi/BT SoCs, where vendor-supplied closed binary
blobs are compiled with the
ilp32fABI, so the soft-float ABI is incompatible)currently have to ship a custom JSON target spec and build
corewith-Zbuild-stdon nightly. There is no stable path today: custom target specsare nightly-only, and the spec drifts with each nightly. A builtin target lets
these users stay on stable with a precompiled
core. The motivating hardwareincludes the application core of SoCs such as the HiSilicon WS63/BS2X family, but
the target itself is vendor-neutral.
A working nightly +
-Zbuild-stdproof of concept (buildscore/alloc,confirms hard-float
fmul.s/fadd.s, and that atomics lower to plainlw/swwith zero
amo*/lr.w/sc.w): https://github.com/hispark-rs/hisi-riscv-imfc-pocHow it is defined
It is
riscv32imafc-unknown-none-elfminus theAextension, handled exactly theway the existing
riscv32imc-unknown-none-elfhandles a no-acore:features = "+m,+f,+c,+forced-atomics",llvm_abiname = ilp32fatomic_cas = false:lr.w/sc.w/amo*are never emitted, so the target doesnot trap on a core without
A.+forced-atomicslowers atomic load/store toplain load/store (sound on a single hart); compare-and-swap and other RMW
atomics are off, so downstream crates use a critical-section polyfill (e.g.
portable-atomic'scritical-sectionfeature) for those.Changes
riscv32imfc_unknown_none_elf.rs+ registration inspec/mod.rs.tests/assembly-llvm/targets/targets-elf.rssanity test (satisfiesthe
target_policyandtarget_specific_teststidy checks).riscv32-unknown-none-elfplatform-support page andlisted in
platform-support.md.Verification
./x test tidy— passes../x test tests/assembly-llvm/targets/targets-elf.rs— passes (262 passed,0 failed); satisfies the "must be able to produce assembly" requirement.
Tier 3 target policy
Acknowledgement of each tier 3 target policy requirement:
Ack. @sanchuanhehe will maintain the target; recorded on the
riscv32-unknown-none-elfplatform-support page.Ack. The target is named
riscv32imfc-unknown-none-elf, fitting the existingriscv32im{,a,c,fc,ac,afc}-unknown-none-elffamily: standard RISC-V ISA-extensionletters (
imfc) and theunknown-none-elftriple shared by the other bare-metalRISC-V targets. The name uses only letters, numbers and dashes.
Ack. Everything added is under
MIT OR Apache-2.0. The change is a purelyadditive target spec plus docs and a test; it introduces no new dependency and no
proprietary component. Code generation uses the in-tree LLVM RISC-V backend only.
Ack.
Ack. This is a bare-metal
no_stdtarget (std: false).coreandallocbuild for it, the same as the sibling
riscv32imc/riscv32imafctargets;stdis not applicable as there is no operating system layer.
Ack. Documented on the shared
riscv32-unknown-none-elfplatform-support page(cross-compiled,
rust-lld, linker-script requirement). Like the other bare-metalRISC-V targets, the Rust test suite cannot be run on it; it must be run in a
simulator or on hardware.
Ack.
Ack. The change is additive only and touches no code shared with other targets;
./x test tidyand thetargets-elfassembly test pass. No unconditional use ofany feature is introduced that would affect other RISC-V target variations.
Ack. Covered by the new
tests/assembly-llvm/targets/targets-elf.rsrevision,which passes using the upstream LLVM backend.
Ack.