1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
///
/// @file cpuid.cpp
/// @brief Test CPUID code on x86 and x64 CPUs.
///
/// Copyright (C) 2024 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
///
#if defined(ENABLE_MULTIARCH_x86_POPCNT)
#include <cpu_supports_popcnt.hpp>
#endif
#include <iostream>
int main()
{
#if defined(__x86_64__) || \
defined(__i386__) || \
defined(_M_X64) || \
defined(_M_IX86)
#if defined(__POPCNT__) && defined(ENABLE_MULTIARCH_x86_POPCNT)
std::cerr << "Error: ENABLE_MULTIARCH_x86_POPCNT must not be defined if __POPCNT__ is defined!" << std::endl;
#endif
#if defined(_MSC_VER) && \
!defined(__POPCNT__)
#if defined(__AVX__) && defined(ENABLE_MULTIARCH_x86_POPCNT)
std::cerr << "Error: ENABLE_MULTIARCH_x86_POPCNT must not be defined if __AVX__ is defined!" << std::endl;
#endif
#if defined(__AVX2__) && defined(ENABLE_MULTIARCH_x86_POPCNT)
std::cerr << "Error: ENABLE_MULTIARCH_x86_POPCNT must not be defined if __AVX2__ is defined!" << std::endl;
#endif
#endif
#if defined(ENABLE_MULTIARCH_x86_POPCNT)
std::cout << "CPU supports POPCNT: " << (cpu_supports_popcnt ? "yes" : "no") << std::endl;
#endif
#endif
std::cout << std::endl;
std::cout << "All tests passed successfully!" << std::endl;
return 0;
}
|