Skip to content

Commit

Permalink
Move CpuInfo::toString to its own compilation unit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Nov 20, 2024
1 parent dc57bdb commit 01e1196
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 66 deletions.
66 changes: 0 additions & 66 deletions soup/CpuInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#if !SOUP_WASM

#if SOUP_X86
#include "string.hpp"

#if defined(_MSC_VER) && !defined(__clang__)
#include <intrin.h>
#else
Expand Down Expand Up @@ -106,70 +104,6 @@ NAMESPACE_SOUP
#endif
}

std::string CpuInfo::toString() const SOUP_EXCAL
{
#if SOUP_X86
std::string str = "CPUID Support Level: ";
str.append(string::hex(cpuid_max_eax));
str.append("\nCPUID Extended Support Level: ");
str.append(string::hex(cpuid_extended_max_eax & ~0x80000000));
str.append("\nVendor: ");
str.append(vendor_id.c_str());

if (cpuid_max_eax >= 0x01)
{
str.append("\nStepping ID: ").append(std::to_string(stepping_id));
str.append("\nModel: ").append(std::to_string(model));
str.append("\nFamily: ").append(std::to_string(family));

if (base_frequency || max_frequency || bus_frequency)
{
str.append("\nBase Frequency: ").append(std::to_string(base_frequency)).append(
" MHz\n"
"Max. Frequency: "
).append(std::to_string(max_frequency)).append(
" MHz\n"
"Bus (Reference) Frequency: "
).append(std::to_string(bus_frequency)).append(" MHz");
}
}

str.append("\nSSE Support: ");
if (supportsSSE4_2()) { str.append("SSE4.2"); }
else if (supportsSSE4_1()) { str.append("SSE4.1"); }
else if (supportsSSSE3()) { str.append("SSSE3"); }
else if (supportsSSE3()) { str.append("SSE3"); }
else if (supportsSSE2()) { str.append("SSE2"); }
else if (supportsSSE()) { str.append("SSE"); }
else { str.append("None"); }

str.append("\nAVX Support: ");
if (supportsAVX512F()) { str.append("AVX512F"); }
else if (supportsAVX2()) { str.append("AVX2"); }
else if (supportsAVX()) { str.append("AVX"); }
else { str.append("None"); }

std::string misc_features{};
if (supportsPCLMULQDQ()) { string::listAppend(misc_features, "PCLMULQDQ"); }
if (supportsAESNI()) { string::listAppend(misc_features, "AESNI"); }
if (supportsRDRAND()) { string::listAppend(misc_features, "RDRAND"); }
if (supportsRDSEED()) { string::listAppend(misc_features, "RDSEED"); }
if (supportsSHA()) { string::listAppend(misc_features, "SHA"); }
if (supportsSHA512()) { string::listAppend(misc_features, "SHA512"); }
if (supportsXOP()) { string::listAppend(misc_features, "supportsXOP"); }
str.append("\nOther Known Features: ").append(misc_features);

return str;
#elif SOUP_ARM
std::string str = "ARMv8 AES: ";
str.append(armv8_aes ? "true" : "false");
str.append("\nARMv8 SHA1: ").append(armv8_sha1 ? "true" : "false");
str.append("\nARMv8 SHA2: ").append(armv8_sha2 ? "true" : "false");
str.append("\nARMv8 CRC32: ").append(armv8_crc32 ? "true" : "false");
return str;
#endif
}

#if SOUP_X86
void CpuInfo::invokeCpuid(void* out, uint32_t eax) noexcept
{
Expand Down
75 changes: 75 additions & 0 deletions soup/CpuInfo_toString.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "CpuInfo.hpp"
#if !SOUP_WASM

#if SOUP_X86
#include "string.hpp"
#endif

NAMESPACE_SOUP
{
std::string CpuInfo::toString() const SOUP_EXCAL
{
#if SOUP_X86
std::string str = "CPUID Support Level: ";
str.append(string::hex(cpuid_max_eax));
str.append("\nCPUID Extended Support Level: ");
str.append(string::hex(cpuid_extended_max_eax & ~0x80000000));
str.append("\nVendor: ");
str.append(vendor_id.c_str());

if (cpuid_max_eax >= 0x01)
{
str.append("\nStepping ID: ").append(std::to_string(stepping_id));
str.append("\nModel: ").append(std::to_string(model));
str.append("\nFamily: ").append(std::to_string(family));

if (base_frequency || max_frequency || bus_frequency)
{
str.append("\nBase Frequency: ").append(std::to_string(base_frequency)).append(
" MHz\n"
"Max. Frequency: "
).append(std::to_string(max_frequency)).append(
" MHz\n"
"Bus (Reference) Frequency: "
).append(std::to_string(bus_frequency)).append(" MHz");
}
}

str.append("\nSSE Support: ");
if (supportsSSE4_2()) { str.append("SSE4.2"); }
else if (supportsSSE4_1()) { str.append("SSE4.1"); }
else if (supportsSSSE3()) { str.append("SSSE3"); }
else if (supportsSSE3()) { str.append("SSE3"); }
else if (supportsSSE2()) { str.append("SSE2"); }
else if (supportsSSE()) { str.append("SSE"); }
else { str.append("None"); }

str.append("\nAVX Support: ");
if (supportsAVX512F()) { str.append("AVX512F"); }
else if (supportsAVX2()) { str.append("AVX2"); }
else if (supportsAVX()) { str.append("AVX"); }
else { str.append("None"); }

std::string misc_features{};
if (supportsPCLMULQDQ()) { string::listAppend(misc_features, "PCLMULQDQ"); }
if (supportsAESNI()) { string::listAppend(misc_features, "AESNI"); }
if (supportsRDRAND()) { string::listAppend(misc_features, "RDRAND"); }
if (supportsRDSEED()) { string::listAppend(misc_features, "RDSEED"); }
if (supportsSHA()) { string::listAppend(misc_features, "SHA"); }
if (supportsSHA512()) { string::listAppend(misc_features, "SHA512"); }
if (supportsXOP()) { string::listAppend(misc_features, "supportsXOP"); }
str.append("\nOther Known Features: ").append(misc_features);

return str;
#elif SOUP_ARM
std::string str = "ARMv8 AES: ";
str.append(armv8_aes ? "true" : "false");
str.append("\nARMv8 SHA1: ").append(armv8_sha1 ? "true" : "false");
str.append("\nARMv8 SHA2: ").append(armv8_sha2 ? "true" : "false");
str.append("\nARMv8 CRC32: ").append(armv8_crc32 ? "true" : "false");
return str;
#endif
}
}

#endif
1 change: 1 addition & 0 deletions soup/Soup.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,7 @@
<ClCompile Include="bitutil.cpp" />
<ClCompile Include="BitWriter.cpp" />
<ClCompile Include="CompactDetourHook.cpp" />
<ClCompile Include="CpuInfo_toString.cpp" />
<ClCompile Include="crc32c.cpp" />
<ClCompile Include="DetourHookBase.cpp" />
<ClCompile Include="exceptions.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions soup/Soup.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -2489,6 +2489,9 @@
<ClCompile Include="DetourHookBase.cpp">
<Filter>util\hooks</Filter>
</ClCompile>
<ClCompile Include="CpuInfo_toString.cpp">
<Filter>cpu</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="os">
Expand Down

0 comments on commit 01e1196

Please sign in to comment.