Repository navigation
Open
Labels
A-ABIArea: Concerning the application binary interface (ABI)Area: Concerning the application binary interface (ABI)A-SIMDArea: SIMD (Single Instruction Multiple Data)Area: SIMD (Single Instruction Multiple Data)A-inline-assemblyArea: Inline assembly (`asm!(…)`)Area: Inline assembly (`asm!(…)`)O-SystemZTarget: SystemZ processors (s390x)Target: SystemZ processors (s390x)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
This tracks the status of s390x vector facilities support in rustc and standard libraries.
- ABI support
- support z13 vector ABI: done in Support s390x z13 vector ABI #131586
rust/compiler/rustc_target/src/abi/call/s390x.rs
Lines 1 to 2 in 58420a0
// FIXME: The assumes we're using the non-vector ABI, i.e., compiling // for a pre-z13 machine or using -mno-vx. - remove explicit disabling of the vector feature (blocked on the above FIXME): done in Support s390x z13 vector ABI #131586
// FIXME: The ABI implementation in abi/call/s390x.rs is for now hard-coded to assume the no-vector // ABI. Pass the -vector feature string to LLVM to respect this assumption. base.features = "-vector".into();
- support z13 vector ABI: done in Support s390x z13 vector ABI #131586
- target_feature support
- support nightly-only
cfg(target_feature = "vector")and unstabletarget_feature(enable = "vector")(underfeature(s390x_target_feature)): done in rustc_target: add known safe s390x target features #127506 - support other vector facility-related target features: vector-enhancements-1, vector-enhancements-2, etc. (see also Missing support for target features on s390x #88937); done in add more
s390xtarget features #135630 - stabilize vector-related target features: done in Stabilize s390x
vectortarget feature andis_s390x_feature_detected!macro #145656
At least blocked until ABI support doneUPDATE: ABI support done
And may be more things are needed given the precedent of postponed stabilization of vector features in RISC-V.
- support nightly-only
- asm support
- support clobber-only vector registers: done in Support clobber_abi and vector/access registers (clobber-only) in s390x inline assembly #130630
- stabilize
feature(asm_experimental_arch)on s390x: done in Stabilize s390x inline assembly #131258 - support
#[repr(simd)]types in input/output of asm (i.e., fully support vector registers) underfeature(asm_experimental_reg): pending in Support input/output in vector registers of s390x inline assembly (under asm_experimental_reg feature) #131664
Both LLVM and GCC do not documentvconstraint, but actually seem to be supported.
Blocked until ABI support done.UPDATE: ABI support done - stabilize
feature(asm_experimental_reg)for s390x vector registers (stabilize s390x vector registers #154184)
- core_arch support (tracking issue: Tracking Issue for
stdarch_s390x#135681)- add unstable vector intrinsics to
core::arch::s390x, mostly done Tracking Issue forstdarch_s390x#135681 - stabilize vector types to allow use them with inline assembly
- stabilize vector intrinsics in
core::arch::s390x
- add unstable vector intrinsics to
- std_detect support (tracking issue: Tracking Issue for
stdarch_s390x_feature_detection#135413)- support unstable
is_s390x_feature_detected!("vector"): done in addis_s390x_feature_detectedstdarch#1699 - stabilize
is_s390x_feature_detected!for vector-related target features: done in Stabilize s390xvectortarget feature andis_s390x_feature_detected!macro #145656
- support unstable
@rustbot label +O-SystemZ
Metadata
Metadata
Assignees
Labels
A-ABIArea: Concerning the application binary interface (ABI)Area: Concerning the application binary interface (ABI)A-SIMDArea: SIMD (Single Instruction Multiple Data)Area: SIMD (Single Instruction Multiple Data)A-inline-assemblyArea: Inline assembly (`asm!(…)`)Area: Inline assembly (`asm!(…)`)O-SystemZTarget: SystemZ processors (s390x)Target: SystemZ processors (s390x)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Activity
taiki-e commentedon Sep 26, 2024
cc @uweigand
uweigand commentedon Sep 30, 2024
Thanks for putting together this list! I can certainly look into providing proper vector register ABI support.
uweigand commentedon Oct 11, 2024
I've looked into this a bit, but ran into a problem I'm not sure how to address. The main issue is that on s390x, we use a different ABI depending on whether or not the vector feature is active (i.e. the processor has vector registers). The difference affects only vector types (which I guess would correspond to
#repr(simd)types in Rust), in the following manner:The calling convention should be implemented in the
rustc_target/src/abi/call/s390x.c. However, I'm not sure how to detect in this place whether or not the vector feature is active. This depends both on explicit feature flags, and also on the target processor (-march=) - processors from z13 onwards default to having the vector feature enabled, older processors have it disabled. Clang tracks this in the front-end so it can make ABI decisions based on it. I'm not sure how this is done in Rust, I'm not seeing any precedent in any of the other ABI files. (I believe there may be some similar issues e.g. on Intel for the larger vector registers like AVX-256 or AVX-512, but I wasn't able to find where this is handled.)In addition, I'm not sure where to handle the vector alignment. This currently seems to be derived solely from the datalayout string, which likely isn't correct even now - the datalayout string gives the alignment for the LLVM vector types, which is always bounded to 8 bytes, but Clang explicitly uses a different alignment for C/C++ level vector types if necessary.
taiki-e commentedon Oct 11, 2024
@uweigand Thanks for the investigation!
Hmm, I thought it is always 8-byte aligned since LLVM 16 (2e7a964).
I think we can implement this by referring to wasm code (1, 2) that determines the ABI depending on the command line option.
I will try to see if I can implement that approach...
taiki-e commentedon Oct 11, 2024
I haven't done much testing yet, but this approach appears to be working: master...taiki-e:rust:s390x-vector-abi
uweigand commentedon Oct 12, 2024
The point is that there's a difference between the LLVM IR vector types and the C/C++ language vector types. The LLVM IR vector types are indeed always 8-byte aligned now. But the C/C++ language vector types still use different ABI alignment rules depending on the vector feature. Clang handles this by mapping the C/C++ type not directly to an LLVM IR type (leaving LLVM to use its own alignment rules), but rather to an LLVM IR type with an explicit alignment override (which implements the appropriate ABI alignment rule).
Ah, interesting! It seems this
calls back into the LLVM back-end, which does already know which features are available by default depending on the target-cpu setting. I wasn't aware of that ... I'm wondering whether/how this works when using another codegen backend like GCC or Cranelift?
Otherwise, your patch looks good to me, except for
taiki-e commentedon Oct 12, 2024
Ah, thanks for the clarification.
I'm not sure how to handle it either, but considering that the current Rust SIMD types cannot be used with C FFI in the first place, and that even if it could be used, the requirement would be that the target feature be enabled, we may actually not have to very worry about the case where the vector feature is disabled here.RFC 2574 to allows using SIMD types in C FFI says:> Architecture-specific vector types require#[target_feature]s to be FFI safe. That is, they are only safely usable as part of the signature ofexternfunctions if the function has certain#[target_feature]s enabled.EDIT: I think #130869 (comment) 's approach will work.
rustc_codegen_gcc seems to have code to handle
-C target-cpuand-C target-feature, but I have not tested if it works as expected here.IIRC rustc_codegen_cranelift does not currently support the target feature at all (rust-lang/rustc_codegen_cranelift#1400), so I suspect that vector ABI cannot be enabled from any way.
It looks like the vector_small case is processed in the branch before processing the 128-bit vector.
rust/compiler/rustc_target/src/abi/call/s390x.rs
Lines 35 to 38 in a805e3e
However, I think we should handle it explicitly in the
if abi == Vector &&branch. Posted fixed version in #131586.Thanks for pointing that out. I tried to fix this, but it appears that the ABI of Wrapper<Vector> is considered Vector, even without
#[repr(transparent)]/#[repr(C)]...taiki-e commentedon Oct 12, 2024
Rust plans to disallow passing vector types to non-Rust ABI if the required target feature is disabled (#127731), so I think the issue of ABI differences with C/C++ when
vectortarget feature is disabled could be resolved by extending the ABI checks used for that to handle s390x as well.35 remaining items
Rollup merge of rust-lang#145656 - folkertdev:stabilize-s390x-vector,…
Rollup merge of rust-lang#145656 - folkertdev:stabilize-s390x-vector,…
Rollup merge of rust-lang#145656 - folkertdev:stabilize-s390x-vector,…
Rollup merge of rust-lang#145656 - folkertdev:stabilize-s390x-vector,…
Auto merge of #145656 - folkertdev:stabilize-s390x-vector, r=Amanieu
Auto merge of #145656 - folkertdev:stabilize-s390x-vector, r=Amanieu
Rollup merge of rust-lang#145656 - folkertdev:stabilize-s390x-vector,…
Unrolled build for #145656
Rollup merge of #145656 - folkertdev:stabilize-s390x-vector, r=Amanieu
Rollup merge of #145656 - folkertdev:stabilize-s390x-vector, r=Amanieu
Rollup merge of rust-lang#145656 - folkertdev:stabilize-s390x-vector,…
folkertdev commentedon Jan 9, 2026
I think the next step here is to stabilize using
vreg. Are there any blockers for that?I'm aware of llvm/llvm-project#171066 but I don't think that is a blocker because
f16is still unstable and s390x is only a tier-2 target (i.e. it should build but may not always generate correct code).One slight wrinkle is that this is guarded by
asm_experimental_reg, and it's the only thing that is guarded by this feature. It might be useful to keep the infrastructure around for future additional registers, but it would in effect become an empty feature if we pull out s390xvreg.taiki-e commentedon Jan 11, 2026
As far as I know, there are no blockers, but if vector types are unstable, they cannot be passed to inline assembly on stable. So, it would be good to also stabilize vector types, as was done with AVX512 (rust-lang/stdarch#1436).
I would like to retain
asm_experimental_reg. At the very least, I plan to use it for RISC-V GPR pair. (UPDATE: filed #150973 for RISC-V GPR pair.)Rollup merge of #131664 - taiki-e:s390x-asm-vreg-inout, r=Amanieu
Rollup merge of #131664 - taiki-e:s390x-asm-vreg-inout, r=Amanieu