Skip to content
30 changes: 28 additions & 2 deletions tests/std/include/test_vector_algorithms_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <isa_availability.h>
#include <random>
Expand Down Expand Up @@ -41,7 +42,32 @@ inline void initialize_randomness(std::mt19937_64& gen) {
extern "C" long __isa_enabled;

inline void disable_instructions(ISA_AVAILABILITY isa) {
__isa_enabled &= ~(1UL << static_cast<unsigned long>(isa));
const unsigned long as_ulong = static_cast<unsigned long>(isa);

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#else // ^^^ defined(__clang__) / !defined(__clang__) vvv
#pragma warning(push)
#pragma warning(disable : 4996)
#endif // ^^^ !defined(__clang__) ^^^
const char* const env_val = std::getenv("STL_TEST_DOWNLEVEL_HOST");
#ifdef __clang__
#pragma clang diagnostic pop
#else // ^^^ defined(__clang__) / !defined(__clang__) vvv
#pragma warning(pop)
#endif // ^^^ !defined(__clang__) ^^^

if (env_val == nullptr || std::atoi(env_val) == 0) {
if ((__isa_enabled & (1UL << as_ulong)) == 0) {
std::printf("The feature %lu is not available, the test does not have full coverage!\n", as_ulong);
std::printf("You can set environment variable STL_TEST_DOWNLEVEL_HOST to 1,\n"
"if you intentionally test on a host with not all features available.");
abort();
}
}

__isa_enabled &= ~(1UL << as_ulong);
}
#endif // (defined(_M_IX86) || defined(_M_X64)) && !defined(_M_CEE_PURE)

Expand All @@ -54,7 +80,7 @@ void run_randomized_tests_with_different_isa_levels(TestFunc tests) {

tests(gen);

#if (defined(_M_IX86) || defined(_M_X64)) && !defined(_M_CEE_PURE)
#if (defined(_M_IX86) || defined(_M_X64) && !defined(_M_ARM64EC)) && !defined(_M_CEE_PURE)
disable_instructions(__ISA_AVAILABLE_AVX2);
tests(gen);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <Windows.h>
#pragma warning(pop)

#include "test_vector_algorithms_support.hpp"

using namespace std;

template <class T>
Expand All @@ -31,14 +33,6 @@ void test_impl(void* sv, void* ev) {
}
}

#if defined(_M_IX86) || defined(_M_X64)
extern "C" long __isa_enabled;

void disable_instructions(ISA_AVAILABILITY isa) {
__isa_enabled &= ~(1UL << static_cast<unsigned long>(isa));
}
#endif // defined(_M_IX86) || defined(_M_X64)

void test_all_element_sizes(void* p, size_t page) {
test_impl<char>(p, reinterpret_cast<char*>(p) + page);
test_impl<short>(p, reinterpret_cast<char*>(p) + page);
Expand All @@ -59,7 +53,7 @@ int main() {
assert(p2 != nullptr);

test_all_element_sizes(p, page);
#if defined(_M_IX86) || defined(_M_X64)
#if defined(_M_IX86) || defined(_M_X64) && !defined(_M_ARM64EC)
disable_instructions(__ISA_AVAILABLE_AVX2);
test_all_element_sizes(p, page);
disable_instructions(__ISA_AVAILABLE_SSE42);
Expand Down
9 changes: 3 additions & 6 deletions tests/std/tests/GH_003617_vectorized_meow_element/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@
#include <vector>

#include "test_min_max_element_support.hpp"
#include "test_vector_algorithms_support.hpp"

using namespace std;

extern "C" long __isa_enabled;

void disable_instructions(ISA_AVAILABILITY isa) {
__isa_enabled &= ~(1UL << static_cast<unsigned long>(isa));
}

void test_gh_3617() {
// Test GH-3617 "<algorithm>: Silent bad codegen for vectorized meow_element() above 4 GB".
constexpr size_t n = 0x4000'0010;
Expand All @@ -33,11 +28,13 @@ void test_gh_3617() {
int main() {
test_gh_3617();

#ifndef _M_ARM64EC
disable_instructions(__ISA_AVAILABLE_AVX2);
test_gh_3617();

disable_instructions(__ISA_AVAILABLE_SSE42);
test_gh_3617();
#endif // !defined(_M_ARM64EC)
}
#else // ^^^ x64 / other architectures vvv
int main() {}
Expand Down