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

Enable f16 in assembly on aarch64 platforms that support it #126070

Closed
wants to merge 2 commits into from

Conversation

lengrongfu
Copy link
Contributor

@lengrongfu lengrongfu commented Jun 6, 2024

Issue: #125398

@rustbot
Copy link
Collaborator

rustbot commented Jun 6, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @oli-obk (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 (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 6, 2024
@lengrongfu
Copy link
Contributor Author

r? @tgross35

@rustbot
Copy link
Collaborator

rustbot commented Jun 6, 2024

Failed to set assignee to tgross35: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@tgross35
Copy link
Contributor

tgross35 commented Jun 6, 2024

That was fast :)

Can you change the “fixes” tag so it doesn’t close that issue? We’ll still have to add the other platforms, but those can come separately

@rustbot label +F-f16_and_f128

@lengrongfu lengrongfu force-pushed the feat/enable-f16 branch 2 times, most recently from a1d89bd to 488fac9 Compare June 7, 2024 01:29
@@ -62,6 +62,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
ty::Int(IntTy::I64) | ty::Uint(UintTy::U64) => Some(InlineAsmType::I64),
ty::Int(IntTy::I128) | ty::Uint(UintTy::U128) => Some(InlineAsmType::I128),
ty::Int(IntTy::Isize) | ty::Uint(UintTy::Usize) => Some(asm_ty_isize),
ty::Float(FloatTy::F16) => Some(InlineAsmType::F16),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have the same issues for f128?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably okay to handle f128 in a separate PR, since we might want a special test that it actually works right on s390x (it has f128 arithmetic operations but it looks like the float ABI might not use vector registers?). Still no harm in having it here without enabling it on a target of course

@oli-obk
Copy link
Contributor

oli-obk commented Jun 7, 2024

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jun 7, 2024

📌 Commit 488fac9 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 7, 2024
@rustbot rustbot added the F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` label Jun 7, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 7, 2024
Enable f16 in assembly on aarch64 platforms that support it

Issue: rust-lang#125398
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 7, 2024
…iaskrgr

Rollup of 11 pull requests

Successful merges:

 - rust-lang#116088 (Stabilise `c_unwind`)
 - rust-lang#124012 (Stabilize `binary_heap_as_slice`)
 - rust-lang#124214 (Parse unsafe attributes)
 - rust-lang#125572 (Detect pub structs never constructed and unused associated constants)
 - rust-lang#125781 (prefer `compile::stream_cargo` for building tools)
 - rust-lang#126030 (Update `./x fmt` command in library/std/src/sys/pal/windows/c/README.md)
 - rust-lang#126047 (Simplify the rayon calls in the installer)
 - rust-lang#126070 (Enable f16 in assembly on aarch64 platforms that support it)
 - rust-lang#126089 (Stabilize Option::take_if)
 - rust-lang#126112 (Clean up source root in run-make tests)
 - rust-lang#126119 (Improve docs for using custom paths with `--emit`)

r? `@ghost`
`@rustbot` modify labels: rollup
@matthiaskrgr
Copy link
Member

@bors r- #126124 (comment)

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 7, 2024
@tgross35
Copy link
Contributor

tgross35 commented Jun 7, 2024

@lengrongfu for reference if you are on an x86 host, you are supposed to be able to replicate the CI tests by running ./src/ci/docker/run.sh dist-aarch64-linux (see https://rustc-dev-guide.rust-lang.org/tests/docker.html). However it doesn't seem to work for me, so I don't know if you'd have better luck.

So if that doesn't work and you don't have an aarch host, you can just temporarily enable the aarch64 CI test to verify this PR (without reapproval and bors running the full suite). https://rustc-dev-guide.rust-lang.org/tests/ci.html#using-ci-to-test

@lengrongfu
Copy link
Contributor Author

@tgross35 I use macOS m3, which is aarch64 arch. I use ./x t --stage 1 tests/ui/asm/aarch64/type-f16.rs command to test, but it does not have any error info, but the test result is FAILED. can you help me?

image

file tests/ui/asm/aarch64/type-f16.rs content is:

//@ only-aarch64

#![feature(f16, f128)]
use std::arch::asm;
#[inline(never)]
pub fn f32_to_f16_asm(a: f32) -> f16 {
    let ret: f16;
    unsafe {
        asm!(
        "fcvt    {ret:h}, {a:s}",
        a = in(vreg) a,
        ret = lateout(vreg) ret,
        options(nomem, nostack),
        );
    }
    ret
}

fn main() {
    
}

@tgross35
Copy link
Contributor

tgross35 commented Jun 8, 2024

UI tests are expected to produce errors by default, meaning you need a .stderr file and ERROR directives. You need to add either //@ check-pass to indicate that a check should be successful, //@ build-pass if it should fully link, or //@ run-pass if you want it to actually run (only if you add assertions, like here).

You probably want either build-pass or assertions + run-pass here to make sure LLVM actually sees the assembly, I don’t think check-pass does that.

There is some more info here: https://rustc-dev-guide.rust-lang.org/tests/ui.html

@tgross35
Copy link
Contributor

@lengrongfu comment @rustbot ready whenever you have it passing locally and are ready for another review

@lengrongfu
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 11, 2024
@Amanieu
Copy link
Member

Amanieu commented Jun 14, 2024

This needs tests in tests/assembly/asm. See #126417 for an example.

@Amanieu Amanieu assigned Amanieu and unassigned oli-obk Jun 14, 2024
@Amanieu
Copy link
Member

Amanieu commented Jun 16, 2024

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 16, 2024
@tgross35
Copy link
Contributor

@lengrongfu are you able to rebase this and add a test? You can drop the changes to hir_analysis and target/src/asm/mod.rs since they were added in #126417, meaning this PR will look more like #126555.

Signed-off-by: rongfu.leng <lenronfu@gmail.com>
@rustbot
Copy link
Collaborator

rustbot commented Jun 27, 2024

Some changes occurred in src/tools/cargo

cc @ehuss

@rust-log-analyzer

This comment has been minimized.

@tgross35
Copy link
Contributor

Looks like you accidentally grabbed submodules while rebasing. You can do git submodule deinit --all -f to unsync them before rebasing if they show up in git status.

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label Jun 27, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jun 27, 2024

There are merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged.

You can start a rebase with the following commands:

$ # rebase
$ git pull --rebase https://github.com/rust-lang/rust.git master
$ git push --force-with-lease

The following commits are merge commits:

@lengrongfu lengrongfu closed this Jun 27, 2024
@lengrongfu lengrongfu deleted the feat/enable-f16 branch June 27, 2024 13:44
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    Checking addr2line v0.22.0
error[E0308]: `?` operator has incompatible types
   --> library/std/src/../../backtrace/src/symbolize/gimli/macho.rs:262:44
    |
262 |             *mapping = Some(object_mapping(object_map.objects().get(object_index)?));
    |                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&[u8]`, found `&ObjectMapFile<'_>`
    |
    = note: `?` operator cannot convert from `&ObjectMapFile<'_>` to `&[u8]`
    = note: expected reference `&[u8]`
               found reference `&ObjectMapFile<'_>`
For more information about this error, try `rustc --explain E0308`.
error: could not compile `std` (lib) due to 1 previous error
Build completed unsuccessfully in 0:01:10
  local time: Thu Jun 27 13:49:18 UTC 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-f16_and_f128 `#![feature(f16)]`, `#![feature(f128)]` has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants