1
0
Fork 0

fix GCC and CLANG builds for Linux

pull/3602/head
JackWright347 2021-07-24 15:48:40 +02:00
parent 217e84a29c
commit 1bd515714a
4 changed files with 34 additions and 27 deletions

View File

@ -79,7 +79,7 @@ endif
# sse41 = yes/no --- -msse4.1 --- Use Intel Streaming SIMD Extensions 4.1
# avx2 = yes/no --- -mavx2 --- Use Intel Advanced Vector Extensions 2
# avx512 = yes/no --- -mavx512bw --- Use Intel Advanced Vector Extensions 512
# vnni256 = yes/no --- -mavx512vnni --- Use Intel Vector Neural Network Instructions 256
# vnni256 = yes/no --- -mavx256vnni --- Use Intel Vector Neural Network Instructions 256
# vnni512 = yes/no --- -mavx512vnni --- Use Intel Vector Neural Network Instructions 512
# neon = yes/no --- -DUSE_NEON --- Use ARM SIMD architecture
#

View File

@ -19,8 +19,10 @@
#include <cstring>
#include "cpuinfo.h"
namespace Stockfish {
// query CPU at runtime and initialize static member data
const Stockfish::CpuInfo::CpuId Stockfish::CpuInfo::CPUID;
const CpuInfo::CpuId Stockfish::CpuInfo::CPUID;
#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86)
#if _WIN32
@ -28,31 +30,35 @@ const Stockfish::CpuInfo::CpuId Stockfish::CpuInfo::CPUID;
#include <windows.h>
#include <intrin.h>
namespace Stockfish {
void CpuInfo::cpuid(int32_t out[4], int32_t eax, int32_t ecx) {
__cpuidex(out, eax, ecx);
}
uint64_t CpuInfo::xgetbv(unsigned int x) {
return _xgetbv(x);
}
# elif defined(__GNUC__) || defined(__clang__)
#include <cpuid.h>
void CpuInfo::cpuid(int32_t out[4], int32_t eax, int32_t ecx) {
__cpuid_count(eax, ecx, out[0], out[1], out[2], out[3]);
}
uint64_t CpuInfo::xgetbv(unsigned int index) {
uint32_t eax, edx;
__asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(index));
return ((uint64_t)edx << 32) | eax;
}
#define _XCR_XFEATURE_ENABLED_MASK 0
void CpuInfo::cpuid(int32_t out[4], int32_t eax, int32_t ecx) {
__cpuid_count(eax, ecx, out[0], out[1], out[2], out[3]);
}
uint64_t CpuInfo::xgetbv(unsigned int index) {
uint32_t eax, edx;
__asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(index));
return ((uint64_t)edx << 32) | eax;
}
#define _XCR_XFEATURE_ENABLED_MASK 0
#else
# error "No CPU-ID intrinsic defined for compiler."
# message "No CPU-ID intrinsic defined for compiler."
#endif
#else
# error "No CPU-ID intrinsic defined for processor architecture."
# message "No CPU-ID intrinsic defined for processor architecture (currently only x86-32/64 is supported)."
#endif
bool CpuInfo::detect_OS_AVX() {
@ -61,8 +67,8 @@ bool CpuInfo::detect_OS_AVX() {
if (OSXSAVE() && AVX())
{
uint64_t xcrFeatureMask = _xgetbv(_XCR_XFEATURE_ENABLED_MASK);
avxSupported = (xcrFeatureMask & 0x6) == 0x6;
uint64_t xcrFeatureMask = xgetbv(_XCR_XFEATURE_ENABLED_MASK);
avxSupported = (xcrFeatureMask & 0x06) == 0x06;
}
return avxSupported;
@ -72,8 +78,8 @@ bool CpuInfo::detect_OS_AVX512() {
if (!detect_OS_AVX())
return false;
uint64_t xcrFeatureMask = _xgetbv(_XCR_XFEATURE_ENABLED_MASK);
return (xcrFeatureMask & 0xe6) == 0xe6;
uint64_t xcrFeatureMask = xgetbv(_XCR_XFEATURE_ENABLED_MASK);
return (xcrFeatureMask & 0xE6) == 0xE6;
}
std::string CpuInfo::get_info_string() {
@ -88,8 +94,8 @@ std::string CpuInfo::get_info_string() {
s += "\n";
s += "Hardware Features: ";
if (X64()) s += "64bit ";
if (MMX()) s += "MMX ";
if (X64()) s += "X64 ";
if (ABM()) s += "ABM ";
if (RDRAND()) s += "RDRAND ";
if (RDSEED()) s += "RDSEED ";

View File

@ -20,8 +20,6 @@
#define CPUINFO_H_INCLUDED
#include <stdint.h>
#include <intrin.h>
#include <string>
#include <bitset>
#include <vector>
@ -127,6 +125,7 @@ namespace Stockfish {
_idExtMax{ 0 },
_isIntel{ false },
_isAMD{ false },
//_f1_EBX{ 0 },
_f1_ECX{ 0 },
_f1_EDX{ 0 },
_f7_EBX{ 0 },
@ -145,7 +144,7 @@ namespace Stockfish {
cpuid(info.data(), 0, 0);
_idMax = info[0];
// call each function and store results in _data
for (int32_t i = 0; i <= _idMax; ++i)
for (uint32_t i = 0; i <= _idMax; ++i)
{
cpuid(info.data(), i, 0);
_data.push_back(info);
@ -170,6 +169,7 @@ namespace Stockfish {
// load bitset with flags for function 0x00000001
if (_idMax >= 1)
{
//_f1_EBX = _data[1][1];
_f1_ECX = _data[1][2];
_f1_EDX = _data[1][3];
}
@ -187,7 +187,7 @@ namespace Stockfish {
cpuid(info.data(), 0x80000000, 0);
_idExtMax = info[0];
// call each extended function and store results in _dataExt
for (int32_t i = 0x80000000; i <= _idExtMax; ++i)
for (uint32_t i = 0x80000000; i <= _idExtMax; ++i)
{
cpuid(info.data(), i, 0);
_dataExt.push_back(info);
@ -212,10 +212,11 @@ namespace Stockfish {
}
};
int32_t _idMax;
int32_t _idExtMax;
uint32_t _idMax;
uint32_t _idExtMax;
bool _isIntel;
bool _isAMD;
//std::bitset<32> _f1_EBX;
std::bitset<32> _f1_ECX;
std::bitset<32> _f1_EDX;
std::bitset<32> _f7_EBX;

View File

@ -266,7 +266,7 @@ namespace Stockfish::Eval::NNUE {
buffer[0] = (v < 0 ? '-' : v > 0 ? '+' : ' ');
double cp = 1.0 * std::abs(int(v)) / PawnValueEg;
sprintf(&buffer[1], "%6.2f", cp);
snprintf(&buffer[1], 7, "%6.2f", cp);
}