Skip to content
28 changes: 27 additions & 1 deletion 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 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 Down
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 Down
Loading