-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
attach global target features to module-level assembly #160594
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
Open
folkertdev
wants to merge
2
commits into
rust-lang:main
Choose a base branch
from
folkertdev:asm-forward-target-features
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| //@ revisions: aarch64-elf aarch64-macho aarch64-coff x86_64 s390x riscv64 powerpc64 loongarch64 | ||
| //@ add-minicore | ||
| //@ assembly-output: emit-asm | ||
| // | ||
| //@ [x86_64] compile-flags: --target x86_64-unknown-linux-gnu | ||
| //@ [x86_64] needs-llvm-components: x86 | ||
| // | ||
| //@ [aarch64-elf] compile-flags: --target aarch64-unknown-linux-gnu | ||
| //@ [aarch64-elf] needs-llvm-components: aarch64 | ||
| //@ [aarch64-macho] compile-flags: --target aarch64-apple-darwin | ||
| //@ [aarch64-macho] needs-llvm-components: aarch64 | ||
| //@ [aarch64-coff] compile-flags: --target aarch64-pc-windows-gnullvm | ||
| //@ [aarch64-coff] needs-llvm-components: aarch64 | ||
| // | ||
| //@ [s390x] compile-flags: --target s390x-unknown-linux-gnu | ||
| //@ [s390x] needs-llvm-components: systemz | ||
| // | ||
| //@ [powerpc64] compile-flags: --target powerpc64-unknown-linux-gnu | ||
| //@ [powerpc64] needs-llvm-components: powerpc | ||
| // | ||
| //@ [riscv64] compile-flags: --target riscv64gc-unknown-linux-gnu | ||
| //@ [riscv64] needs-llvm-components: riscv | ||
| // | ||
| // NOTE: loongarch64 does not error when using an instruction without enabling the corresponding | ||
| // target feature. | ||
| //@ [loongarch64] compile-flags: --target loongarch64-unknown-linux-gnu | ||
| //@ [loongarch64] needs-llvm-components: loongarch | ||
|
|
||
| // Test that the #[target_feature(enable = ...)]` works on naked functions. | ||
|
|
||
| #![crate_type = "lib"] | ||
| #![feature(no_core, naked_functions_target_feature, asm_experimental_arch)] | ||
| #![feature( | ||
| s390x_target_feature, | ||
| powerpc_target_feature, | ||
| loongarch_target_feature, | ||
| m68k_target_feature | ||
| )] | ||
| #![no_core] | ||
|
|
||
| extern crate minicore; | ||
| use minicore::*; | ||
|
|
||
| // x86_64-LABEL: vpclmulqdq: | ||
| // x86_64: vpclmulqdq | ||
| #[no_mangle] | ||
| #[unsafe(naked)] | ||
| #[cfg(target_arch = "x86_64")] | ||
| #[target_feature(enable = "vpclmulqdq")] | ||
| unsafe extern "C" fn vpclmulqdq() { | ||
| naked_asm!("vpclmulqdq zmm1, zmm2, zmm3, 4") | ||
| } | ||
|
|
||
| // i8mm is not enabled by default | ||
| // | ||
| // note that aarch64-apple-darwin enables more features than aarch64-unknown-linux-gnu | ||
| // | ||
| // aarch64-elf-LABEL: i8mm: | ||
| // aarch64-elf: usdot | ||
| // aarch64-macho-LABEL: i8mm: | ||
| // aarch64-macho: usdot | ||
| // aarch64-coff-LABEL: i8mm: | ||
| // aarch64-coff: usdot | ||
| #[no_mangle] | ||
| #[unsafe(naked)] | ||
| #[cfg(target_arch = "aarch64")] | ||
| #[target_feature(enable = "i8mm")] | ||
| unsafe extern "C" fn i8mm() { | ||
| naked_asm!("usdot v0.4s, v1.16b, v2.4b[3]") | ||
| } | ||
|
|
||
| // riscv64: sh1add: | ||
| // riscv64: sh1add | ||
| #[no_mangle] | ||
| #[unsafe(naked)] | ||
| #[cfg(target_arch = "riscv64")] | ||
| #[target_feature(enable = "zba")] | ||
| unsafe extern "C" fn sh1add() { | ||
| naked_asm!("sh1add a0, a1, a2", "ret"); | ||
| } | ||
|
|
||
| #[cfg(target_arch = "s390x")] | ||
| mod s390x { | ||
| use super::*; | ||
|
|
||
| // s390x: vector: | ||
| // s390x: vavglg | ||
| #[no_mangle] | ||
| #[unsafe(naked)] | ||
| #[target_feature(enable = "vector")] | ||
| unsafe extern "C" fn vector() { | ||
| naked_asm!("vavglg %v0, %v0, %v0") | ||
| } | ||
|
|
||
| // s390x: vector_enhancements_1: | ||
| // s390x: vfcesbs | ||
| #[no_mangle] | ||
| #[unsafe(naked)] | ||
| #[target_feature(enable = "vector-enhancements-1")] | ||
| unsafe extern "C" fn vector_enhancements_1() { | ||
| naked_asm!("vfcesbs %v0, %v0, %v0") | ||
| } | ||
|
|
||
| // s390x: vector_enhancements_2: | ||
| // s390x: vclfp | ||
| #[no_mangle] | ||
| #[unsafe(naked)] | ||
| #[target_feature(enable = "vector-enhancements-2")] | ||
| unsafe extern "C" fn vector_enhancements_2() { | ||
| naked_asm!("vclfp %v0, %v0, 0, 0, 0") | ||
| } | ||
|
|
||
| // s390x: vector_packed_decimal: | ||
| // s390x: vlrlr | ||
| #[no_mangle] | ||
| #[unsafe(naked)] | ||
| #[target_feature(enable = "vector-packed-decimal")] | ||
| unsafe extern "C" fn vector_packed_decimal() { | ||
| naked_asm!("vlrlr %v24, %r3, 0(%r2)", "br %r14") | ||
| } | ||
|
|
||
| // s390x: vector_packed_decimal_enhancement: | ||
| // s390x: vcvbg | ||
| #[no_mangle] | ||
| #[unsafe(naked)] | ||
| #[target_feature(enable = "vector-packed-decimal-enhancement")] | ||
| unsafe extern "C" fn vector_packed_decimal_enhancement() { | ||
| naked_asm!("vcvbg %r0, %v0, 0, 1") | ||
| } | ||
|
|
||
| // s390x: vector_packed_decimal_enhancement_2: | ||
| // s390x: vupkzl | ||
| #[no_mangle] | ||
| #[unsafe(naked)] | ||
| #[target_feature(enable = "vector-packed-decimal-enhancement-2")] | ||
| unsafe extern "C" fn vector_packed_decimal_enhancement_2() { | ||
| naked_asm!("vupkzl %v0, %v0, 0") | ||
| } | ||
| } | ||
|
|
||
| // powerpc64: power10_vector: | ||
| // powerpc64: xxpermx | ||
| #[no_mangle] | ||
| #[unsafe(naked)] | ||
| #[cfg(target_arch = "powerpc64")] | ||
| #[target_feature(enable = "power10-vector")] | ||
| unsafe extern "C" fn power10_vector() { | ||
| naked_asm!("xxpermx 34, 0, 1, 2, 0", "blr") | ||
| } | ||
|
|
||
| // loongarch64: lasx: | ||
| // loongarch64: xvadd.b | ||
| #[no_mangle] | ||
| #[unsafe(naked)] | ||
| #[cfg(target_arch = "loongarch64")] | ||
| #[target_feature(enable = "lasx")] | ||
| unsafe extern "C" fn lasx() { | ||
| naked_asm!("xvadd.b $xr0, $xr0, $xr1", "ret") | ||
| } | ||
|
|
||
| // wasm32: simd128: | ||
| // wasm32: i8x16.shuffle | ||
| #[no_mangle] | ||
| #[unsafe(naked)] | ||
| #[cfg(target_arch = "wasm32")] | ||
| #[target_feature(enable = "simd128")] | ||
| unsafe extern "C" fn simd128() { | ||
| naked_asm!("i8x16.shuffle 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15", "return"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| //@ build-pass | ||
| //@ add-minicore | ||
| //@ min-llvm-version: 23 | ||
| //@ ignore-backends: gcc | ||
| // | ||
| //@ revisions: riscv opt-0-bitcode-no opt-0 opt-s-bitcode-no | ||
| // | ||
| //@[riscv] compile-flags: --target riscv64gc-unknown-linux-gnu -Clto=thin | ||
| //@[riscv] needs-llvm-components: riscv | ||
| // | ||
| //@[opt-0-bitcode-no] compile-flags: --target armv7r-none-eabihf -Copt-level=0 -Cembed-bitcode=no | ||
| //@[opt-0-bitcode-no] needs-llvm-components: arm | ||
| // | ||
| //@[opt-0] compile-flags: --target armv7r-none-eabihf -Copt-level=0 | ||
| //@[opt-0] needs-llvm-components: arm | ||
| // | ||
| //@[opt-s-bitcode-no] compile-flags: --target armv7r-none-eabihf -Copt-level=s -Cembed-bitcode=no | ||
| //@[opt-s-bitcode-no] needs-llvm-components: arm | ||
|
|
||
| // Regression test for | ||
| // | ||
| // - https://github.com/llvm/llvm-project/issues/61991 | ||
| // - https://github.com/rust-lang/rust/issues/80608 | ||
| // - https://github.com/rust-lang/rust/issues/127269 | ||
| // | ||
| // Since LLVM 23 target features are taken into account for module-level assembly. | ||
|
|
||
| #![feature(no_core)] | ||
| #![no_core] | ||
| #![crate_type = "lib"] | ||
|
|
||
| extern crate minicore; | ||
| use minicore::*; | ||
|
|
||
| #[cfg(target_arch = "riscv64")] | ||
| global_asm!("fld f0, 0(sp)"); | ||
|
|
||
| #[cfg(target_arch = "arm")] | ||
| global_asm!( | ||
| r#" | ||
| .section .text.startup | ||
| .global _start | ||
| .code 32 | ||
| .align 0 | ||
|
|
||
| _start: | ||
| vmsr fpexc, r0 | ||
| "# | ||
| ); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we just embed bytes here, so the target features and cpu don't seem relevant.
View changes since the review