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