Skip to content

Commit 761d971

Browse files
committed
Test manufacturer id
1 parent 6fcd996 commit 761d971

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

.github/workflows/cross-sve.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
echo "XSIMD_TEST_CPU_ASSUME_SSE4_2=0" >> "$GITHUB_ENV"
4646
echo "XSIMD_TEST_CPU_ASSUME_NEON64=1" >> "$GITHUB_ENV"
4747
echo "XSIMD_TEST_CPU_ASSUME_SVE=1" >> "$GITHUB_ENV"
48+
echo "XSIMD_TEST_CPU_ASSUME_MANUFACTURER=unknown" >> "$GITHUB_ENV"
4849
- name: Testing xsimd
4950
run: qemu-aarch64 --cpu max,sve${{ matrix.vector_bits }}=on -L /usr/aarch64-linux-gnu/ ./test/test_xsimd
5051
working-directory: ${{ github.workspace }}/_build

.github/workflows/linux.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ jobs:
125125
export XSIMD_TEST_CPU_ASSUME_NEON64="0"
126126
export XSIMD_TEST_CPU_ASSUME_SSE4_2="1"
127127
export XSIMD_TEST_CPU_ASSUME_AVX="1"
128+
export XSIMD_TEST_CPU_ASSUME_MANUFACTURER="intel,amd"
128129
cd _build/test
129130
if echo '${{ matrix.sys.flags }}' | grep -q 'avx512' ; then
130131
export XSIMD_TEST_CPU_ASSUME_AVX512F="1"

.github/workflows/macos.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ jobs:
2727
if echo '${{ matrix.os }}' | grep -q intel; then
2828
echo "XSIMD_TEST_CPU_ASSUME_NEON64=0" >> "$GITHUB_ENV"
2929
echo "XSIMD_TEST_CPU_ASSUME_SSE4_2=1" >> "$GITHUB_ENV"
30+
echo "XSIMD_TEST_CPU_ASSUME_MANUFACTURER=intel" >> "$GITHUB_ENV"
3031
else
3132
echo "XSIMD_TEST_CPU_ASSUME_NEON64=1" >> "$GITHUB_ENV"
3233
echo "XSIMD_TEST_CPU_ASSUME_SSE4_2=0" >> "$GITHUB_ENV"
34+
echo "XSIMD_TEST_CPU_ASSUME_MANUFACTURER=unknown" >> "$GITHUB_ENV"
3335
fi
3436
- name: Testing xsimd
3537
run: ${{github.workspace}}/_build/test/test_xsimd

.github/workflows/windows.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ jobs:
5555
XSIMD_TEST_CPU_ASSUME_NEON64: "0"
5656
XSIMD_TEST_CPU_ASSUME_SSE4_2: "1"
5757
XSIMD_TEST_CPU_ASSUME_AVX2: "1"
58+
XSIMD_TEST_CPU_ASSUME_MANUFACTURER: "intel,amd"
5859
run: ./_build/test/test_xsimd
5960

6061
build-windows-mingw:
@@ -117,4 +118,5 @@ jobs:
117118
# Set CPU feature test expectations
118119
XSIMD_TEST_CPU_ASSUME_NEON64: "1"
119120
XSIMD_TEST_CPU_ASSUME_SSE4_2: "0"
121+
XSIMD_TEST_CPU_ASSUME_MANUFACTURER: "unknown"
120122
run: ./_build/test/test_xsimd

test/test_cpu_features.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* The full license is in the file LICENSE, distributed with this software. *
1010
****************************************************************************/
1111

12+
#include <algorithm>
13+
#include <array>
1214
#include <cstdlib>
1315
#include <string>
1416

@@ -31,6 +33,12 @@ namespace detail
3133
CHECK_EQ(actual, val[0] == '1');
3234
}
3335
}
36+
37+
// TODO(c++23): use str.contains
38+
bool contains(const std::string& haystack, const char* needle)
39+
{
40+
return haystack.find(needle) != std::string::npos;
41+
}
3442
}
3543

3644
#define CHECK_ENV_FEATURE(env_var, feature) detail::check_env_flag(env_var, #feature, feature)
@@ -72,6 +80,40 @@ TEST_CASE("[cpu_features] x86 implication chains")
7280
CHECK_IMPLICATION(cpu.avxvnni(), cpu.avx2());
7381
}
7482

83+
TEST_CASE("[cpu_features] x86 manufacturer from environment")
84+
{
85+
xsimd::x86_cpu_features cpu;
86+
87+
const char* val = std::getenv("XSIMD_TEST_CPU_ASSUME_MANUFACTURER");
88+
if (val)
89+
{
90+
struct entry
91+
{
92+
const char* name;
93+
xsimd::x86_manufacturer value;
94+
};
95+
std::array<entry, 9> manufacturers = { {
96+
{ "intel", xsimd::x86_manufacturer::intel },
97+
{ "amd", xsimd::x86_manufacturer::amd },
98+
{ "via", xsimd::x86_manufacturer::via },
99+
{ "zhaoxin", xsimd::x86_manufacturer::zhaoxin },
100+
{ "hygon", xsimd::x86_manufacturer::hygon },
101+
{ "transmeta", xsimd::x86_manufacturer::transmeta },
102+
{ "elbrus", xsimd::x86_manufacturer::elbrus },
103+
{ "microsoft_vpc", xsimd::x86_manufacturer::microsoft_vpc },
104+
{ "unknown", xsimd::x86_manufacturer::unknown },
105+
} };
106+
107+
auto manufacturer = cpu.known_manufacturer();
108+
const std::string allowed(val);
109+
bool match = std::any_of(manufacturers.begin(), manufacturers.end(), [&](const entry& e)
110+
{ return e.value == manufacturer && detail::contains(allowed, e.name); });
111+
112+
auto const msg = std::string("XSIMD_TEST_CPU_ASSUME_MANUFACTURER = ") + val;
113+
INFO(msg);
114+
CHECK_UNARY(match);
115+
}
116+
}
75117

76118
TEST_CASE("[cpu_features] x86 features from environment")
77119
{
@@ -111,4 +153,3 @@ TEST_CASE("[cpu_features] arm features from environment")
111153
CHECK_ENV_FEATURE("XSIMD_TEST_CPU_ASSUME_SVE", cpu.sve());
112154
CHECK_ENV_FEATURE("XSIMD_TEST_CPU_ASSUME_I8MM", cpu.i8mm());
113155
}
114-

0 commit comments

Comments
 (0)