-
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
23ebe2a
commit fef58dc
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/// | ||
/// @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. | ||
/// | ||
|
||
#include <CPUID.hpp> | ||
#include <iostream> | ||
|
||
int main() | ||
{ | ||
#if defined(__x86_64__) || \ | ||
defined(__i386__) || \ | ||
defined(_M_X64) || \ | ||
defined(_M_IX86) | ||
|
||
#if defined(__POPCNT__) | ||
#if defined(HAS_POPCNT) | ||
std::cout << "OK: __POPCNT__ and HAS_POPCNT are defined!" << std::endl; | ||
#else | ||
std::cerr << "Error: HAS_POPCNT must be defined if __POPCNT__ is defined!" << std::endl; | ||
return 1; | ||
#endif | ||
#endif | ||
|
||
#if defined(__AVX__) | ||
#if defined(HAS_POPCNT) | ||
std::cout << "OK: __AVX__ and HAS_POPCNT are defined!" << std::endl; | ||
#else | ||
std::cerr << "Error: HAS_POPCNT must be defined if __AVX__ is defined!" << std::endl; | ||
return 1; | ||
#endif | ||
#endif | ||
|
||
#if defined(__AVX2__) | ||
#if defined(HAS_POPCNT) | ||
std::cout << "OK: __AVX2__ and HAS_POPCNT are defined!" << std::endl; | ||
#else | ||
std::cerr << "Error: HAS_POPCNT must be defined if __AVX2__ is defined!" << std::endl; | ||
return 1; | ||
#endif | ||
#endif | ||
|
||
#if defined(HAS_POPCNT) | ||
#if !defined(ENABLE_CPUID_POPCNT) | ||
std::cout << "OK: HAS_POPCNT is defined but ENABLE_CPUID_POPCNT is not defined!" << std::endl; | ||
#else | ||
std::cerr << "Error: ENABLE_CPUID_POPCNT must not be defined if HAS_POPCNT is defined!" << std::endl; | ||
return 1; | ||
#endif | ||
#endif | ||
|
||
#if !defined(HAS_POPCNT) | ||
#if defined(ENABLE_CPUID_POPCNT) | ||
std::cout << "OK: HAS_POPCNT is not defined but ENABLE_CPUID_POPCNT is defined!" << std::endl; | ||
#else | ||
std::cerr << "Error: ENABLE_CPUID_POPCNT must be defined if HAS_POPCNT is not defined!" << std::endl; | ||
return 1; | ||
#endif | ||
#endif | ||
|
||
#if defined(ENABLE_CPUID_POPCNT) | ||
std::cout << "CPU supports POPCNT: " << (HAS_CPUID_POPCNT ? "yes" : "no") << std::endl; | ||
#endif | ||
|
||
#endif | ||
|
||
std::cout << std::endl; | ||
std::cout << "All tests passed successfully!" << std::endl; | ||
|
||
return 0; | ||
} |