This commit is contained in:
Igor Pavlov
2023-12-22 17:17:05 +00:00
committed by Kornel
parent ec44a8a070
commit a36c48cece
954 changed files with 42199 additions and 25482 deletions

View File

@@ -102,38 +102,44 @@ static void PrintHex(AString &s, UInt64 v)
#ifdef MY_CPU_X86_OR_AMD64
Z7_NO_INLINE
static void PrintCpuChars(AString &s, UInt32 v)
{
for (int j = 0; j < 4; j++)
for (unsigned j = 0; j < 4; j++)
{
Byte b = (Byte)(v & 0xFF);
v >>= 8;
if (b == 0)
break;
s += (char)b;
if (b >= 0x20 && b <= 0x7f)
s += (char)b;
else
{
s += '[';
char temp[16];
ConvertUInt32ToHex(b, temp);
s += temp;
s += ']';
}
}
}
static void x86cpuid_to_String(const Cx86cpuid &c, AString &s, AString &ver)
static void x86cpuid_to_String(AString &s)
{
s.Empty();
UInt32 maxFunc2 = 0;
UInt32 t[3];
UInt32 a[4];
// cpuid was called already. So we don't check for cpuid availability here
z7_x86_cpuid(a, 0x80000000);
MyCPUID(0x80000000, &maxFunc2, &t[0], &t[1], &t[2]);
bool fullNameIsAvail = (maxFunc2 >= 0x80000004);
if (fullNameIsAvail)
if (a[0] >= 0x80000004) // if (maxFunc2 >= hi+4) the full name is available
{
for (unsigned i = 0; i < 3; i++)
{
UInt32 d[4] = { 0 };
MyCPUID(0x80000002 + i, &d[0], &d[1], &d[2], &d[3]);
z7_x86_cpuid(a, 0x80000002 + i);
for (unsigned j = 0; j < 4; j++)
PrintCpuChars(s, d[j]);
PrintCpuChars(s, a[j]);
}
}
@@ -141,16 +147,14 @@ static void x86cpuid_to_String(const Cx86cpuid &c, AString &s, AString &ver)
if (s.IsEmpty())
{
for (int i = 0; i < 3; i++)
PrintCpuChars(s, c.vendor[i]);
z7_x86_cpuid(a, 0);
for (unsigned i = 1; i < 4; i++)
{
const unsigned j = (i ^ (i >> 1));
PrintCpuChars(s, a[j]);
}
s.Trim();
}
{
char temp[32];
ConvertUInt32ToHex(c.ver, temp);
ver += temp;
}
}
/*
@@ -184,7 +188,7 @@ static void x86cpuid_all_to_String(AString &s)
{
char temp[32];
ConvertUInt32ToHex8Digits(d[i], temp);
s += " ";
s.Add_Space();
s += temp;
}
}
@@ -215,12 +219,12 @@ static const char * const k_PROCESSOR_ARCHITECTURE[] =
, "ARM32_ON_WIN64"
};
#define MY__PROCESSOR_ARCHITECTURE_INTEL 0
#define MY__PROCESSOR_ARCHITECTURE_AMD64 9
#define Z7_WIN_PROCESSOR_ARCHITECTURE_INTEL 0
#define Z7_WIN_PROCESSOR_ARCHITECTURE_AMD64 9
#define MY__PROCESSOR_INTEL_PENTIUM 586
#define MY__PROCESSOR_AMD_X8664 8664
#define Z7_WIN_PROCESSOR_INTEL_PENTIUM 586
#define Z7_WIN_PROCESSOR_AMD_X8664 8664
/*
static const CUInt32PCharPair k_PROCESSOR[] =
@@ -303,19 +307,20 @@ static const char * const k_PF[] =
#endif
#ifdef _WIN32
static void PrintPage(AString &s, UInt32 v)
static void PrintPage(AString &s, UInt64 v)
{
if ((v & 0x3FF) == 0)
const char *t = "B";
if ((v & 0x3ff) == 0)
{
s.Add_UInt32(v >> 10);
s += "K";
v >>= 10;
t = "KB";
}
else
s.Add_UInt32(v >> 10);
s.Add_UInt64(v);
s += t;
}
#ifdef _WIN32
static AString TypeToString2(const char * const table[], unsigned num, UInt32 value)
{
char sz[16];
@@ -330,7 +335,7 @@ static AString TypeToString2(const char * const table[], unsigned num, UInt32 va
return (AString)p;
}
// #if defined(_7ZIP_LARGE_PAGES) || defined(_WIN32)
// #if defined(Z7_LARGE_PAGES) || defined(_WIN32)
// #ifdef _WIN32
void PrintSize_KMGT_Or_Hex(AString &s, UInt64 v)
{
@@ -342,32 +347,32 @@ void PrintSize_KMGT_Or_Hex(AString &s, UInt64 v)
}}}}
else
{
// s += "0x";
PrintHex(s, v);
return;
}
char temp[32];
ConvertUInt64ToString(v, temp);
s += temp;
s.Add_UInt64(v);
if (c)
s += c;
s += 'B';
}
// #endif
// #endif
static void SysInfo_To_String(AString &s, const SYSTEM_INFO &si)
{
s += TypeToString2(k_PROCESSOR_ARCHITECTURE, ARRAY_SIZE(k_PROCESSOR_ARCHITECTURE), si.wProcessorArchitecture);
s += TypeToString2(k_PROCESSOR_ARCHITECTURE, Z7_ARRAY_SIZE(k_PROCESSOR_ARCHITECTURE), si.wProcessorArchitecture);
if (!( (si.wProcessorArchitecture == MY__PROCESSOR_ARCHITECTURE_INTEL && si.dwProcessorType == MY__PROCESSOR_INTEL_PENTIUM)
|| (si.wProcessorArchitecture == MY__PROCESSOR_ARCHITECTURE_AMD64 && si.dwProcessorType == MY__PROCESSOR_AMD_X8664)))
if (!( (si.wProcessorArchitecture == Z7_WIN_PROCESSOR_ARCHITECTURE_INTEL && si.dwProcessorType == Z7_WIN_PROCESSOR_INTEL_PENTIUM)
|| (si.wProcessorArchitecture == Z7_WIN_PROCESSOR_ARCHITECTURE_AMD64 && si.dwProcessorType == Z7_WIN_PROCESSOR_AMD_X8664)))
{
s += " ";
// s += TypePairToString(k_PROCESSOR, ARRAY_SIZE(k_PROCESSOR), si.dwProcessorType);
s.Add_Space();
// s += TypePairToString(k_PROCESSOR, Z7_ARRAY_SIZE(k_PROCESSOR), si.dwProcessorType);
s.Add_UInt32(si.dwProcessorType);
}
s += " ";
s.Add_Space();
PrintHex(s, si.wProcessorLevel);
s += ".";
s.Add_Dot();
PrintHex(s, si.wProcessorRevision);
if ((UInt64)si.dwActiveProcessorMask + 1 != ((UInt64)1 << si.dwNumberOfProcessors))
if ((UInt64)si.dwActiveProcessorMask + 1 != 0 || si.dwNumberOfProcessors != sizeof(UInt64) * 8)
@@ -387,9 +392,9 @@ static void SysInfo_To_String(AString &s, const SYSTEM_INFO &si)
s += " gran:";
PrintPage(s, si.dwAllocationGranularity);
}
s += " ";
s.Add_Space();
DWORD_PTR minAdd = (DWORD_PTR)si.lpMinimumApplicationAddress;
const DWORD_PTR minAdd = (DWORD_PTR)si.lpMinimumApplicationAddress;
UInt64 maxSize = (UInt64)(DWORD_PTR)si.lpMaximumApplicationAddress + 1;
const UInt32 kReserveSize = ((UInt32)1 << 16);
if (minAdd != kReserveSize)
@@ -419,7 +424,7 @@ static void Add_sysctlbyname_to_String(const char *name, AString &s)
{
size_t bufSize = 256;
char buf[256];
if (My_sysctlbyname_Get(name, &buf, &bufSize) == 0)
if (z7_sysctlbyname_Get(name, &buf, &bufSize) == 0)
s += buf;
}
#endif
@@ -440,12 +445,14 @@ void GetSysInfo(AString &s1, AString &s2)
}
#if !defined(_WIN64) && !defined(UNDER_CE)
Func_GetNativeSystemInfo fn_GetNativeSystemInfo = (Func_GetNativeSystemInfo)(void *)GetProcAddress(
GetModuleHandleA("kernel32.dll"), "GetNativeSystemInfo");
if (fn_GetNativeSystemInfo)
const
Func_GetNativeSystemInfo fn = Z7_GET_PROC_ADDRESS(
Func_GetNativeSystemInfo, GetModuleHandleA("kernel32.dll"),
"GetNativeSystemInfo");
if (fn)
{
SYSTEM_INFO si2;
fn_GetNativeSystemInfo(&si2);
fn(&si2);
// if (memcmp(&si, &si2, sizeof(si)) != 0)
{
// s += " - ";
@@ -500,18 +507,20 @@ void CCpuName::Fill()
#ifdef MY_CPU_X86_OR_AMD64
{
Cx86cpuid cpuid;
if (x86cpuid_CheckAndRead(&cpuid))
{
x86cpuid_to_String(cpuid, s, Revision);
}
#if !defined(MY_CPU_AMD64)
if (!z7_x86_cpuid_GetMaxFunc())
s += "x86";
else
{
#ifdef MY_CPU_AMD64
s += "x64";
#else
s += "x86";
#endif
{
x86cpuid_to_String(s);
{
UInt32 a[4];
z7_x86_cpuid(a, 1);
char temp[16];
ConvertUInt32ToHex(a[0], temp);
Revision += temp;
}
}
}
#elif defined(__APPLE__)
@@ -534,12 +543,12 @@ void CCpuName::Fill()
{
AString s2;
UInt32 v = 0;
if (My_sysctlbyname_Get_UInt32("machdep.cpu.core_count", &v) == 0)
if (z7_sysctlbyname_Get_UInt32("machdep.cpu.core_count", &v) == 0)
{
s2.Add_UInt32(v);
s2 += 'C';
}
if (My_sysctlbyname_Get_UInt32("machdep.cpu.thread_count", &v) == 0)
if (z7_sysctlbyname_Get_UInt32("machdep.cpu.thread_count", &v) == 0)
{
s2.Add_UInt32(v);
s2 += 'T';
@@ -561,7 +570,7 @@ void CCpuName::Fill()
LONG res[2];
CByteBuffer bufs[2];
{
for (int i = 0; i < 2; i++)
for (unsigned i = 0; i < 2; i++)
{
UInt32 size = 0;
res[i] = key.QueryValue(i == 0 ?
@@ -574,7 +583,7 @@ void CCpuName::Fill()
}
if (res[0] == ERROR_SUCCESS || res[1] == ERROR_SUCCESS)
{
for (int i = 0; i < 2; i++)
for (unsigned i = 0; i < 2; i++)
{
if (i == 1)
Microcode += "->";
@@ -598,7 +607,7 @@ void CCpuName::Fill()
#endif
#ifdef _7ZIP_LARGE_PAGES
#ifdef Z7_LARGE_PAGES
Add_LargePages_String(LargePages);
#endif
}
@@ -608,7 +617,7 @@ void AddCpuFeatures(AString &s)
{
#ifdef _WIN32
// const unsigned kNumFeatures_Extra = 32; // we check also for unknown features
// const unsigned kNumFeatures = ARRAY_SIZE(k_PF) + kNumFeatures_Extra;
// const unsigned kNumFeatures = Z7_ARRAY_SIZE(k_PF) + kNumFeatures_Extra;
const unsigned kNumFeatures = 64;
UInt64 flags = 0;
for (unsigned i = 0; i < kNumFeatures; i++)
@@ -617,7 +626,7 @@ void AddCpuFeatures(AString &s)
{
flags += (UInt64)1 << i;
// s.Add_Space_if_NotEmpty();
// s += TypeToString2(k_PF, ARRAY_SIZE(k_PF), i);
// s += TypeToString2(k_PF, Z7_ARRAY_SIZE(k_PF), i);
}
}
s.Add_OptSpaced("f:");
@@ -626,11 +635,10 @@ void AddCpuFeatures(AString &s)
#elif defined(__APPLE__)
{
UInt32 v = 0;
if (My_sysctlbyname_Get_UInt32("hw.pagesize", &v) == 0)
if (z7_sysctlbyname_Get_UInt32("hw.pagesize", &v) == 0)
{
s += "PageSize:";
s.Add_UInt32(v >> 10);
s += "KB";
s.Add_OptSpaced("PageSize:");
PrintPage(s, v);
}
}
@@ -639,10 +647,8 @@ void AddCpuFeatures(AString &s)
const long v = sysconf(_SC_PAGESIZE);
if (v != -1)
{
s.Add_Space_if_NotEmpty();
s += "PageSize:";
s.Add_UInt32((UInt32)(v >> 10));
s += "KB";
s.Add_OptSpaced("PageSize:");
PrintPage(s, (unsigned long)v);
}
#if !defined(_AIX)
@@ -659,11 +665,11 @@ void AddCpuFeatures(AString &s)
const int pos = s2.Find('[');
if (pos >= 0)
{
const int pos2 = s2.Find(']', pos + 1);
const int pos2 = s2.Find(']', (unsigned)pos + 1);
if (pos2 >= 0)
{
s2.DeleteFrom(pos2);
s2.DeleteFrontal(pos + 1);
s2.DeleteFrom((unsigned)pos2);
s2.DeleteFrontal((unsigned)pos + 1);
}
}
s += s2;
@@ -722,10 +728,13 @@ EXTERN_C_END
static BOOL My_RtlGetVersion(OSVERSIONINFOEXW *vi)
{
HMODULE ntdll = ::GetModuleHandleW(L"ntdll.dll");
const HMODULE ntdll = ::GetModuleHandleW(L"ntdll.dll");
if (!ntdll)
return FALSE;
Func_RtlGetVersion func = (Func_RtlGetVersion)(void *)GetProcAddress(ntdll, "RtlGetVersion");
const
Func_RtlGetVersion func = Z7_GET_PROC_ADDRESS(
Func_RtlGetVersion, ntdll,
"RtlGetVersion");
if (!func)
return FALSE;
func(vi);
@@ -752,18 +761,18 @@ void GetOsInfoText(AString &sRes)
s += "Windows";
if (vi.dwPlatformId != VER_PLATFORM_WIN32_NT)
s.Add_UInt32(vi.dwPlatformId);
s += " "; s.Add_UInt32(vi.dwMajorVersion);
s += "."; s.Add_UInt32(vi.dwMinorVersion);
s += " "; s.Add_UInt32(vi.dwBuildNumber);
s.Add_Space(); s.Add_UInt32(vi.dwMajorVersion);
s.Add_Dot(); s.Add_UInt32(vi.dwMinorVersion);
s.Add_Space(); s.Add_UInt32(vi.dwBuildNumber);
if (vi.wServicePackMajor != 0 || vi.wServicePackMinor != 0)
{
s += " SP:"; s.Add_UInt32(vi.wServicePackMajor);
s += "."; s.Add_UInt32(vi.wServicePackMinor);
s.Add_Dot(); s.Add_UInt32(vi.wServicePackMinor);
}
// s += " Suite:"; PrintHex(s, vi.wSuiteMask);
// s += " Type:"; s.Add_UInt32(vi.wProductType);
// s += " "; s += GetOemString(vi.szCSDVersion);
// s.Add_Space(); s += GetOemString(vi.szCSDVersion);
}
/*
{
@@ -793,6 +802,17 @@ void GetOsInfoText(AString &sRes)
#endif // _WIN32
sRes += s;
#ifdef MY_CPU_X86_OR_AMD64
{
AString s2;
GetVirtCpuid(s2);
if (!s2.IsEmpty())
{
sRes += " : ";
sRes += s2;
}
}
#endif
}
@@ -875,6 +895,61 @@ void GetCpuName_MultiLine(AString &s)
}
}
#ifdef MY_CPU_X86_OR_AMD64
void GetVirtCpuid(AString &s)
{
const UInt32 kHv = 0x40000000;
Z7_IF_X86_CPUID_SUPPORTED
{
UInt32 a[4];
z7_x86_cpuid(a, kHv);
if (a[0] < kHv || a[0] >= kHv + (1 << 16))
return;
{
{
for (unsigned j = 1; j < 4; j++)
PrintCpuChars(s, a[j]);
}
}
if (a[0] >= kHv + 1)
{
UInt32 d[4];
z7_x86_cpuid(d, kHv + 1);
s += " : ";
PrintCpuChars(s, d[0]);
if (a[0] >= kHv + 2)
{
z7_x86_cpuid(d, kHv + 2);
s += " : ";
s.Add_UInt32(d[1] >> 16);
s.Add_Dot(); s.Add_UInt32(d[1] & 0xffff);
s.Add_Dot(); s.Add_UInt32(d[0]);
s.Add_Dot(); s.Add_UInt32(d[2]);
s.Add_Dot(); s.Add_UInt32(d[3] >> 24);
s.Add_Dot(); s.Add_UInt32(d[3] & 0xffffff);
}
/*
if (a[0] >= kHv + 5)
{
z7_x86_cpuid(d, kHv + 5);
s += " : ";
s.Add_UInt32(d[0]);
s += "p";
s.Add_UInt32(d[1]);
s += "t";
}
*/
}
}
}
#endif
void GetCompiler(AString &s)
{
#ifdef __VERSION__
@@ -884,28 +959,28 @@ void GetCompiler(AString &s)
#ifdef __GNUC__
s += " GCC ";
s.Add_UInt32(__GNUC__);
s += '.';
s.Add_Dot();
s.Add_UInt32(__GNUC_MINOR__);
s += '.';
s.Add_Dot();
s.Add_UInt32(__GNUC_PATCHLEVEL__);
#endif
#ifdef __clang__
s += " CLANG ";
s.Add_UInt32(__clang_major__);
s += '.';
s.Add_Dot();
s.Add_UInt32(__clang_minor__);
#endif
#ifdef __xlC__
s += " XLC ";
s.Add_UInt32(__xlC__ >> 8);
s += '.';
s.Add_Dot();
s.Add_UInt32(__xlC__ & 0xFF);
#ifdef __xlC_ver__
s += '.';
s.Add_Dot();
s.Add_UInt32(__xlC_ver__ >> 8);
s += '.';
s.Add_Dot();
s.Add_UInt32(__xlC_ver__ & 0xFF);
#endif
#endif
@@ -914,4 +989,34 @@ void GetCompiler(AString &s)
s += " MSC ";
s.Add_UInt32(_MSC_VER);
#endif
#if defined(__AVX2__)
#define MY_CPU_COMPILE_ISA "AVX2"
#elif defined(__AVX__)
#define MY_CPU_COMPILE_ISA "AVX"
#elif defined(__SSE2__)
#define MY_CPU_COMPILE_ISA "SSE2"
#elif defined(_M_IX86_FP) && (_M_IX86_FP >= 2)
#define MY_CPU_COMPILE_ISA "SSE2"
#elif defined(__SSE__)
#define MY_CPU_COMPILE_ISA "SSE"
#elif defined(_M_IX86_FP) && (_M_IX86_FP >= 1)
#define MY_CPU_COMPILE_ISA "SSE"
#elif defined(__i686__)
#define MY_CPU_COMPILE_ISA "i686"
#elif defined(__i586__)
#define MY_CPU_COMPILE_ISA "i586"
#elif defined(__i486__)
#define MY_CPU_COMPILE_ISA "i486"
#elif defined(__i386__)
#define MY_CPU_COMPILE_ISA "i386"
#elif defined(_M_IX86_FP)
#define MY_CPU_COMPILE_ISA "IA32"
#endif
#ifdef MY_CPU_COMPILE_ISA
s += ':';
s.Add_OptSpaced(MY_CPU_COMPILE_ISA);
#endif
}