Skip to content

Add IBM Z (s390x) support#1307

Merged
serge-sans-paille merged 1 commit intoxtensor-stack:masterfrom
Andreas-Krebbel:s390x-support
Apr 24, 2026
Merged

Add IBM Z (s390x) support#1307
serge-sans-paille merged 1 commit intoxtensor-stack:masterfrom
Andreas-Krebbel:s390x-support

Conversation

@Andreas-Krebbel
Copy link
Copy Markdown
Contributor

This PR adds support for IBM Z. It leverages the compiler intrinsics available with GCC and Clang:
https://www.ibm.com/docs/en/open-xl-c-cpp-zos/2.2.0?topic=reference-vector-programming-support

The intrinsics are similar to what is available for IBM Power with altivec (VSX). I've started with an initial version of my patch before VSX has been added to XSIMD. However, while refreshing my changes to the latest upstream level I've used the VSX implementation as a base.

I've tested the patch on an IBM z17 (latest machine generation) with GCC and Clang:

[100%] Built target test_xsimd
[doctest] doctest version is "2.4.9"
[doctest] run with "--help" for options
===============================================================================
[doctest] test cases:     363 |     363 passed | 0 failed | 0 skipped
[doctest] assertions: 1681618 | 1681618 passed | 0 failed |
[doctest] Status: SUCCESS!
[100%] Built target xtest

@serge-sans-paille
Copy link
Copy Markdown
Contributor

We need to setup CI for this. @Andreas-Krebbel could you do that, probably based on how it's done for vsx?

@Andreas-Krebbel
Copy link
Copy Markdown
Contributor Author

We need to setup CI for this. @Andreas-Krebbel could you do that, probably based on how it's done for vsx?

I can give it a try. Yes.

@Andreas-Krebbel
Copy link
Copy Markdown
Contributor Author

I have tested the workflow locally and it seems to work fine. I see less testcases being executed though:

| [doctest] doctest version is "2.4.9"
| [doctest] run with "--help" for options
| ===============================================================================
| [doctest] test cases:  83 |  83 passed | 0 failed | 0 skipped
| [doctest] assertions: 781 | 781 passed | 0 failed |
| [doctest] Status: SUCCESS!

Copy link
Copy Markdown
Contributor

@serge-sans-paille serge-sans-paille left a comment

Choose a reason for hiding this comment

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

Some nit picking, just missing the runtime detection and we're good.

It also means we should improve CI to detect that...

Comment thread include/xsimd/arch/xsimd_vxe.hpp Outdated
template <class A, class T_in, class T_out>
XSIMD_INLINE batch<T_out, A> bitwise_cast(batch<T_in, A> const& self, batch<T_out, A> const&, requires_arch<vxe>) noexcept
{
return (typename batch<T_out, A>::register_type)(self.data);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: could be a static_cast, but we're not very diligent on this, so feel free to ignore.

Copy link
Copy Markdown
Contributor Author

@Andreas-Krebbel Andreas-Krebbel Apr 22, 2026

Choose a reason for hiding this comment

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

A static_cast didn't work with GCC since it doesn't allow a cast between vector types with different signness. clang was ok with it though.

template <class A>
XSIMD_INLINE batch<float, A> complex_low(batch<std::complex<float>, A> const& self, requires_arch<vxe>) noexcept
{
uv16qi perm = (uv16qi) { 0, 1, 2, 3, 16, 17, 18, 19, 4, 5, 6, 7, 20, 21, 22, 23 };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

gcc constructor expression. that's a gnu extension, but I guess it's fine. I've been using it for PowerPC too.

Comment thread include/xsimd/arch/xsimd_vxe.hpp
Comment thread include/xsimd/config/xsimd_cpuid.hpp
// equivalent types.
XSIMD_DECLARE_SIMD_BOOL_VXE_REGISTER(signed char, signed char, char);
XSIMD_DECLARE_SIMD_BOOL_VXE_REGISTER(unsigned char, unsigned char, char);
#ifdef __CHAR_UNSIGNED__
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you could avoid using a macro using a type alais instead, that would be cool.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It would work with GCC, but it didn't with clang. Clang does not seem to accept type aliases in combination with __vector bool.

@serge-sans-paille
Copy link
Copy Markdown
Contributor

The error in arch consistency is related to qemu emulation capability, more on https://www.qemu.org/docs/master/system/target-s390x.html

@Andreas-Krebbel Andreas-Krebbel force-pushed the s390x-support branch 3 times, most recently from 77f0168 to 257168d Compare April 22, 2026 18:37
@serge-sans-paille
Copy link
Copy Markdown
Contributor

This all looks good to me, thanks a lot for going through this and adressing the reviews. I'll leave it to you to squash and rebase and we're good!

@serge-sans-paille
Copy link
Copy Markdown
Contributor

@Andreas-Krebbel the risc-v issue is not on you, I'll accept your PR anyway and leave it to @AntoinePrv to fix it ;-)

@AntoinePrv
Copy link
Copy Markdown
Contributor

AntoinePrv commented Apr 24, 2026

@serge-sans-paille, sure but please wait for it to be fixed before merging this one (#1322).

@AntoinePrv
Copy link
Copy Markdown
Contributor

@Andreas-Krebbel can you rebase your PR?

Add support for the IBM Z (s390x) architecture leveraging the GCC and
Clang compiler intrinsics which are similar to what is available for
IBM Power with the Altivec extension. SIMD hardware is available on
IBM Z starting with IBM z13. However, the XSIMD support requires at
least IBM z14 to also support float vectors.
@serge-sans-paille serge-sans-paille merged commit 523896f into xtensor-stack:master Apr 24, 2026
76 checks passed
@Andreas-Krebbel Andreas-Krebbel deleted the s390x-support branch April 24, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants