Skip to content

Add IBM Z (s390x) support#1307

Open
Andreas-Krebbel wants to merge 5 commits intoxtensor-stack:masterfrom
Andreas-Krebbel:s390x-support
Open

Add IBM Z (s390x) support#1307
Andreas-Krebbel wants to merge 5 commits intoxtensor-stack:masterfrom
Andreas-Krebbel:s390x-support

Conversation

@Andreas-Krebbel
Copy link
Copy Markdown

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
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
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
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
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

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.

2 participants