-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
aaarch64: there is no way to use the FPU/SIMD 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. |
Indeed we are running into this now (see rust-lang/rust#134375). And as mentioned above, there is a concrete motivation: the Linux kernel generally uses softfloat ABIs to avoid having to persist FPU registers. However, certain modules (e.g. cryptography, compression) want to make use of SIMD operations, so when those modules are executed, the kernel sets a flag ensuring that for the current kernel thread, FPU registers are persisted, and then jumps to code built with this target feature. We can "be careful" to avoid ABI issues here, but I hope at this point it is generally understood that "being careful" doesn't scale. The proper solution is to consistently use a softfloat ABI for all code, but LLVM currently makes this impossible. On every other target (I looked at x86-32/64, arm-32, riscv-32/64), LLVM allows independently controlling the float ABI and the availability of hardware float support. It seems like a mere oversight that aarch64 doesn't allow this, and it'd be great to see this fixed. |
On 32-bit arm this is controlled via IMHO the way this should be working is that |
I can only say what the Rust targets do -- they set
ISTM that on x86, If
What is going on in https://godbolt.org/z/v4f1hsqjh ? This is a target that explicitly sets the ABI to Is there any target where LLVM supports the combination of softfloat ABI and hardfloat instructions? |
This comment has been minimized.
This comment has been minimized.
Weird, I don't get notifications from this thread either. Here are examples for using soft-float ABI with hard-float instructions: |
Thanks for pointing me towards So the summary is that for ARM-32 and for RISCV, LLVM provides reasonably clean and explicit ways to control the ABI. RISCV even warns when the ABI cannot be implemented; sadly the ARM backend does not do that but that seems like a separate issue. However, for aarch64, the equivalent functionality is missing. LLVM does have a de-facto soft-float ABI that it will use on those targets when Alternatively if "returning floats without having the requisite target features" is not supported by LLVM on aarch64, I would expect at least a suitable warning indicating as much. However unfortunately Rust now already claims to support this combination (after all, LLVM seemed to support this) and this could be non-trivial for us to change/roll back... (On X86, there is the option of setting |
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: