-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
aaarch64: there is no way to use the FPU on a softfloat target without creating an ABI mess #110632
Comments
Turning off simd and/or fp disallows all usage of float types (and vector types). |
What does "disallow" mean? LLVM still happily compiles such code. Rust also generally supports (This is an LLVM issue, not a clang issue.) |
Oh right and GCC does not disconnect the target options part from the backend ... |
softfloat is not a target that makes sense why LLVM has it I have no idea. |
Also clang rejects that target: |
aarch64-unknown-none-softfloat triple does not exist outside of rust. Why was it added in the first place? |
You could try emulating this on clang by setting the
LLVM defines one, I can't tell you why. 🤷 |
With
|
Seems like that happened in rust-lang/rust#64589. Cc @andre-richter @Amanieu |
Okay, maybe this is not possible to reproduce with clang then. However, LLVM seems to offer support for a softfloat ABI on aarch64 targets -- without providing sufficient control over whether and when that ABI is used. That's fundamentally what this issue is about. |
@llvm/issue-subscribers-backend-aarch64 Author: Ralf Jung (RalfJung)
On aarch64, if one is building for a softfloat target (in Rust that's e.g. the target aarch64-unknown-none-softfloat, which in particular sets `-neon,-fp-armv8` target features by default), there seems to be no way to build some code that does make use of the FPU while remaining ABI-compatible with the rest of the binary: to enable use of the FPU, we have to set `+fp-armv8`, but this will inevitably also change which registers are being used to pass float arguments around.
On other targets, one can have the target do something like set Is there a specific reason this is currently not possible on aarch64, or is it just that nobody implemented this yet? Or am I missing some other way to generate aarch64 code that uses the FPU but uses a softfloat ABI? |
When we added the AArch64 soft-float ABI in clang (#74460, #84146), we deliberately didn't allow the combination of the soft-float ABI with floating-point hardware, to avoid there being multiple, incompatible ABIs for any one target. However, the ABI used by clang is controlled by the |
I don't understand the use case. AIUI Linux needs to avoid persisting FPU registers. This then implies a soft float ABI - but that's not the goal, merely an outcome. Using the FPU means you need to persist the registers so ... why would you still want the soft-float ABI? This is distinct from Arm 32-bit where the FPU is optional and two ABIs are defined and so compatibility with soft-float libraries is required. |
clang currently has two "no-fp" configurations: -mgeneral-regs-only, and -mabi=aapcs-soft. Internally, they're actually the same thing, but -mgeneral-regs-only forbids any call that would pass a floating-point value in general registers. -mgeneral-regs-only is intended for places like the Linux kernel, which don't use any floating-point. -mabi=aapcs-soft is intended for microcontrollers that don't have an FPU. It's hard for me to imagine a situation where you'd actually want a "soft-float" ABI and access to FP registers, given that all general-purpose AArch64 processors have an FPU. But if there is some use-case, we could look at adding it. |
@efriedma-quic that's a fair question. The ability to enable We did, however, in the mean time come up with a plan that solves our problem and does not require LLVM changes. It boils down to avoiding the implicit LLVM-defined ABI for float types on the aarch64-softfloat target, and instead always passing them as |
This is going to break down in some edge cases... if you do have users for this, you probably want a real LLVM target feature. |
Which kind of edge cases are you thinking about? We're using these kind of ABI overrides for a bunch of stuff already so I don't foresee any problems here -- in particular given that we don't have to be ABI-compatible with anything else since there is no standard softfloat ABI. |
varargs (ABI rules require storing parts of floating-point registers when you va_start), intrinsics/libcalls where the backend generates a call. |
It seems like one motivation is for a kernel that is generally "nofloat" to temporarily enable use of the FPU in a kernel thread (after saving all the registers that clobbers), e.g. to execute some cryptographic code more efficiently. |
On aarch64, if one is building for a softfloat target (in Rust that's e.g. the target aarch64-unknown-none-softfloat, which in particular sets
-neon,-fp-armv8
target features by default), there seems to be no way to build some code that does make use of the FPU while remaining ABI-compatible with the rest of the binary: to enable use of the FPU, we have to set+fp-armv8
, but this will inevitably also change which registers are being used to pass float arguments around.On other targets, one can have the target do something like set
+soft-float
, so even if someone now enables e.g. SSE features on x86 orfpregs
on ARM, code will be built with the softfloat ABI and thus be compatible with this target. But aarch64 doesn't seem to have something like+soft-float
, meaning it is impossible to disentangle the float ABI from whether FPU instructions can be used.Is there a specific reason this is currently not possible on aarch64, or is it just that nobody implemented this yet? Or am I missing some other way to generate aarch64 code that uses the FPU but uses a softfloat ABI?
The text was updated successfully, but these errors were encountered: