Skip to content
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

x86 softfloat target: no way to get LLVM to make local use of the FPU or SIMD registers #136540

Open
RalfJung opened this issue Feb 4, 2025 · 7 comments
Labels
A-floating-point Area: Floating point numbers and arithmetic A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-SIMD Area: SIMD (Single Instruction Multiple Data) C-bug Category: This is a bug. C-external-bug Category: issue that is caused by bugs in software beyond our control T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

RalfJung commented Feb 4, 2025

Some softfloat targets are used in environments where an FPU and SIMD registers are present, but should not be used by default -- in particular, this is fairly common in kernels. It should be possible to still locally enable the use of these CPU features; this just adds a precondition to the function to make FPU and SIMD ready for use by the kernel before invoking this code.

This works fine on arm-32 by picking a softfloat ABI (i.e., a *eabi target) and then enabling the right target features on a function-by-function basis. However, for x86 (32bit and 64bit), this does not work: there is no dedicated ABI flag supported by LLVM here; instead, our soft-float targets work by setting target features to something like -x87,-mmx,-sse,+soft-float. When both the soft-float and the sse2 target feature are set, soft-float takes priority (example). We cannot let people disable soft-float on a per-function basis as that would change the ABI.

Ultimately this is caused by the fact that LLVM doesn't have a proper float ABI designation for x86; instead, the float ABI is inferred from target features such as soft-float. If we could set the float ABI directly like we can on arm-32, we could let people disable soft-float on a per-function basis (probably via a hard-float target feature, no need to make this a negative feature) and thus LLVM could generate code making proper use of the FPU.

Cc @nikic @workingjubilee @briansmith

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 4, 2025
@RalfJung
Copy link
Member Author

RalfJung commented Feb 4, 2025

This should probably be filed as a feature request on the LLVM side as well? This is not something we can do without LLVM support, I think.

@jieyouxu jieyouxu added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. C-external-bug Category: issue that is caused by bugs in software beyond our control A-floating-point Area: Floating point numbers and arithmetic and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 4, 2025
@briansmith
Copy link
Contributor

You mentioned x86 and arm-32. How about x86_64 and Aarch64? I think those are the ones people are most concerned about.

@nikic
Copy link
Contributor

nikic commented Feb 4, 2025

The ask here is basically the same as #134375 but for x86 instead of aarch64, right? It's something I started working on (https://github.com/nikic/llvm-project/commits/aarch64-soft-float-abi), but it will probably be a while before I can get back to this.

@briansmith
Copy link
Contributor

I noticed that this is labled "A-floating-point" and the discussion mentions floating point, but the bigger need is for non-floating point SIMD register use.

@RalfJung
Copy link
Member Author

RalfJung commented Feb 4, 2025

You mentioned x86 and arm-32. How about x86_64 and Aarch64? I think those are the ones people are most concerned about.

By "x86" I mean x86-32 and x86-64.

aarch64 is its own mess, it doesn't even have a soft-float target feature in LLVM so we don't just have a problem of "it generates bad code", we have a problem of "this is just unsound". The relevant upstream issue here is llvm/llvm-project#110632, and as Nikita mentioned our own issue for this is #134375.

The ask here is basically the same as #134375 but for x86 instead of aarch64, right?

Hm, maybe. On x86 the situation is better than on aarch64 insofar as we don't have a soundness problem. I would say "enabling the target feature does basically nothing" is better than "enabling the target feature causes unsoundness", but YMMV. ;)

I noticed that this is labled "A-floating-point" and the discussion mentions floating point, but the bigger need is for non-floating point SIMD register use.

I updated labels and description.

@RalfJung RalfJung changed the title x86 softfloat target: no way to get LLVM to make proper use of the FPU locally x86 softfloat target: no way to get LLVM to make local use of the FPU or SIMD registers Feb 4, 2025
@RalfJung RalfJung added the A-SIMD Area: SIMD (Single Instruction Multiple Data) label Feb 4, 2025
@briansmith
Copy link
Contributor

If this affects x86_64 then it is a much bigger deal than for x86. Could you update the description for that?

@RalfJung
Copy link
Member Author

RalfJung commented Feb 4, 2025

LLVM uses X86 as the name for both the 32bit and 64bit version of this architecture, so my use of this term certainly has precedent, and I think the issue title is already long enough. I made the issue description more explicit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-floating-point Area: Floating point numbers and arithmetic A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-SIMD Area: SIMD (Single Instruction Multiple Data) C-bug Category: This is a bug. C-external-bug Category: issue that is caused by bugs in software beyond our control T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants