Skip to content

Commit 7b082b4

Browse files
committed
Dynamic dispatch VSX
1 parent 1e7c3b9 commit 7b082b4

File tree

6 files changed

+96
-6
lines changed

6 files changed

+96
-6
lines changed

.github/workflows/cross-ppc.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
uses: actions/checkout@v6
3636
- name: Setup
3737
run: |
38-
cmake -B _build \
38+
cmake -B build \
3939
-DBUILD_TESTS=ON -DDOWNLOAD_DOCTEST=ON \
4040
-DBUILD_BENCHMARK=${{ matrix.target.full }} -DBUILD_EXAMPLES=${{ matrix.target.full }} \
4141
-DCMAKE_BUILD_TYPE=Release \
@@ -44,6 +44,14 @@ jobs:
4444
-DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/.github/toolchains/${{ matrix.sys.compiler }}-${{ matrix.target.dir }}.cmake
4545
- name: Build
4646
run: cmake --build _build --verbose -j1
47+
- name: Set CPU feature test expectations
48+
run: |
4749
- name: Testing xsimd
48-
run: qemu-${{ matrix.target.platform }} -cpu power10 -L /usr/${{ matrix.target.dir}}/ ./test/test_xsimd
49-
working-directory: ${{ github.workspace }}/_build
50+
run: |
51+
# Set CPU feature test expectations, 0 is explicit absence of the feature
52+
export XSIMD_TEST_CPU_ASSUME_SSE4_2="0"
53+
export XSIMD_TEST_CPU_ASSUME_NEON64="0"
54+
export XSIMD_TEST_CPU_ASSUME_RVV="0"
55+
export XSIMD_TEST_CPU_ASSUME_VSX="1"
56+
57+
qemu-${{ matrix.target.platform }} -cpu power10 -L /usr/${{ matrix.target.dir}}/ ./build/test/test_xsimd

.github/workflows/linux.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ jobs:
123123
# Set CPU feature test expectations, 0 is explicit absence of the feature
124124
export XSIMD_TEST_CPU_ASSUME_NEON64="0"
125125
export XSIMD_TEST_CPU_ASSUME_RVV="0"
126+
export XSIMD_TEST_CPU_ASSUME_VSX="0"
126127
cd _build/test
127128
if echo '${{ matrix.sys.flags }}' | grep -q 'avx512' ; then
128129
# Running with emulation, must have AVX512, lower tier are checked by implications in tests

include/xsimd/config/xsimd_config.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,17 @@
499499
#define XSIMD_WITH_WASM 0
500500
#endif
501501

502+
/**
503+
* @ingroup xsimd_config_macro
504+
*
505+
* Set to 1 if the target is in the PowerPC architecture family, to 0 otherwise
506+
*/
507+
#if defined(__powerpc__) || defined(__powerpc64__) || defined(_ARCH_PPC) || defined(_ARCH_PPC64)
508+
#define XSIMD_TARGET_PPC 1
509+
#else
510+
#define XSIMD_TARGET_PPC 0
511+
#endif
512+
502513
/**
503514
* @ingroup xsimd_config_macro
504515
*
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/***************************************************************************
2+
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
3+
* Martin Renou *
4+
* Copyright (c) QuantStack *
5+
* Copyright (c) Serge Guelton *
6+
* *
7+
* Distributed under the terms of the BSD 3-Clause License. *
8+
* *
9+
* The full license is in the file LICENSE, distributed with this software. *
10+
***************************************************************************/
11+
12+
#ifndef XSIMD_CPU_FEATURES_PPC_HPP
13+
#define XSIMD_CPU_FEATURES_PPC_HPP
14+
15+
#include "./xsimd_config.hpp"
16+
#include "./xsimd_getauxval.hpp"
17+
18+
#if XSIMD_TARGET_PPC && XSIMD_HAVE_LINUX_GETAUXVAL
19+
// HWCAP_XXX masks to use on getauxval results.
20+
// Header does not exists on all architectures and masks are architecture
21+
// specific.
22+
#include <asm/hwcap.h>
23+
#endif // XSIMD_TARGET_PPC && XSIMD_HAVE_LINUX_GETAUXVAL
24+
25+
namespace xsimd
26+
{
27+
/**
28+
* An opinionated CPU feature detection utility for PowerPC.
29+
*
30+
* On Linux, runtime detection uses getauxval to query the auxiliary vector.
31+
* On other platforms, only compile-time information is used.
32+
*
33+
* This is well defined on all architectures.
34+
* It will always return false on non-PowerPC architectures.
35+
*/
36+
class ppc_cpu_features : private linux_hwcap_backend_default
37+
{
38+
public:
39+
inline bool vsx() const noexcept;
40+
};
41+
42+
/********************
43+
* Implementation *
44+
********************/
45+
46+
inline bool ppc_cpu_features::vsx() const noexcept
47+
{
48+
#if XSIMD_TARGET_PPC && XSIMD_HAVE_LINUX_GETAUXVAL
49+
#ifdef PPC_FEATURE_HAS_VSX
50+
return hwcap().has_feature(PPC_FEATURE_HAS_VSX);
51+
#else
52+
// Possibly missing on older Linux distributions
53+
return hwcap().has_feature(0x00000080);
54+
#endif
55+
#else
56+
return false;
57+
#endif
58+
}
59+
}
60+
61+
#endif

include/xsimd/config/xsimd_cpuid.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "../types/xsimd_all_registers.hpp"
1616
#include "./xsimd_cpu_features_arm.hpp"
1717
#include "./xsimd_cpu_features_riscv.hpp"
18+
#include "./xsimd_cpu_features_ppc.hpp"
1819
#include "./xsimd_cpu_features_x86.hpp"
1920
#include "./xsimd_inline.hpp"
2021

@@ -80,9 +81,10 @@ namespace xsimd
8081
wasm = 1;
8182
#endif
8283

83-
#if XSIMD_WITH_VSX
84-
vsx = 1;
85-
#endif
84+
// Safe on all platforms, it will be false if non PowerPC.
85+
const auto ppc_cpu = xsimd::ppc_cpu_features();
86+
87+
vsx = ppc_cpu.vsx();
8688

8789
// Safe on all platforms, it will be all false if non risc-v.
8890
const auto riscv_cpu = xsimd::riscv_cpu_features();

test/test_cpu_features.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,10 @@ TEST_CASE("[cpu_features] risc-v features from environment")
169169

170170
CHECK_ENV_FEATURE("XSIMD_TEST_CPU_ASSUME_RVV", cpu.rvv());
171171
}
172+
173+
TEST_CASE("[cpu_features] ppc features from environment")
174+
{
175+
xsimd::ppc_cpu_features cpu;
176+
177+
CHECK_ENV_FEATURE("XSIMD_TEST_CPU_ASSUME_VSX", cpu.vsx());
178+
}

0 commit comments

Comments
 (0)