Skip to content

Enable f16 and f128 in assembly on platforms that support it #125398

@tgross35

Description

@tgross35
Contributor

f16 should be okay to pass in GPRs. f16 and f128 can likely get passed in vector or FP registers, but we should prefer to only allow this if an ABI is specified for the type.

Loose list of platforms that specify an ABI:

Additionally, for f128:

  • s390x supports f128, referred to as "BFP Extended Format" in https://publibfp.dhe.ibm.com/epubs/pdf/a227832c.pdf. I am not sure if this comes with any special instructions.
  • PowerPC with -Ctarget-cpu=pwr9 seems to have f128 support via instructions like xsaddqp

Tracking issue: #116909

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on May 22, 2024
tgross35

tgross35 commented on May 22, 2024

@tgross35
ContributorAuthor

I'm adding E-Easy because a PR that just enables support for aarch64 should be pretty easy, start around

ty::Float(FloatTy::F32) => Some(InlineAsmType::F32),
ty::Float(FloatTy::F64) => Some(InlineAsmType::F64),
and massage the new types in. Actually figuring out rules for the rest of the platforms will be harder, but that can come later.

Sample for reference: https://rust.godbolt.org/z/zK4qha1qo

@rustbot label +T-compiler +E-Easy +F-f16_and_f128 +A-inline-assembly -needs-triage

added
A-inline-assemblyArea: Inline assembly (`asm!(…)`)
E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
F-f16_and_f128`#![feature(f16)]`, `#![feature(f128)]`
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on May 22, 2024
lengrongfu

lengrongfu commented on Jun 6, 2024

@lengrongfu
Contributor

@tgross35 I can try to submit a PR, can you give me some guidance?

tgross35

tgross35 commented on Jun 6, 2024

@tgross35
ContributorAuthor

Hi @lengrongfu, thanks for the interest!

This should be pretty easy I think. Start by making a test in tests/ui/asm/ that contains the assembly function from my original post. Make sure this fails when you run ./x t --stage 1 path/to/your/new/test.rs.

Then just find where the error is emitted (search the codebase for "cannot use value of type") and work backwards from that until the test passes. This will probably mean adding F16 to InlineAsmType and then chasing down errors.

We will need to make sure that this works on platforms with support (e.g. aarch64) but still fails on those without it (e.g. x86). Just focus on getting aarch64 to build first.

There is a compiler help stream on Zulip https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp feel free to ask if you get stuck! Also not a bad idea to post a draft PR as soon as you have some basic work done, even if not yet passing.

changed the title [-]Enable `f16` in assembly on platforms that support it[/-] [+]Enable `f16` and `f128` in assembly on platforms that support it[/+] on Jun 7, 2024
added a commit that references this issue on Jun 7, 2024
ec5f93a

29 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-inline-assemblyArea: Inline assembly (`asm!(…)`)E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.F-f16_and_f128`#![feature(f16)]`, `#![feature(f128)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @tgross35@lengrongfu@heiseish@ismailarilik@rustbot

      Issue actions

        Enable `f16` and `f128` in assembly on platforms that support it · Issue #125398 · rust-lang/rust