Skip to content

Commit

Permalink
ARM64EC tweaks to CPUInfo (#51)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Walker (Baconpaul) <[email protected]>
  • Loading branch information
baconpaul and Paul Walker (Baconpaul) authored Oct 31, 2024
1 parent 2f52ea6 commit 4ef3837
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,5 @@ libs/juce-*
# A place for BP to store stuff
ignore/*
__pycache__

arm*bld
32 changes: 28 additions & 4 deletions src/cpufeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@

#if defined(__SSE2__) || defined(_M_AMD64) || defined(_M_X64) || \
(defined(_M_IX86_FP) && _M_IX86_FP >= 2) || defined(__i386__) || defined(__x86_64__)
#if defined(_M_ARM64EC)
#include <intrin.h>
#else
#define USING_X86 1
#include <xmmintrin.h>
#endif
#endif

#if MAC
#include <sys/types.h>
Expand All @@ -28,13 +32,14 @@
#include <fstream>
#endif

#if WINDOWS
#include <windows.h>
#endif

#ifdef _WIN32
#include <intrin.h>
#define cpuid(info, x) __cpuidex(info, x, 0)

#if !USING_X86
#error "Windows only works on X86 right now"
#endif
#else
#if LINUX && USING_X86
#ifdef __GNUC__
Expand Down Expand Up @@ -80,6 +85,24 @@ std::string brand()
}

#elif WINDOWS
#if defined(_M_ARM64) || defined(_M_ARM64EC)
arch = "unknown windows arm";
const char *csName = "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0";
HKEY hKey;
DWORD gotType, gotSize = 64;
char inBuffer[64];
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, csName, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
{
if (!RegQueryValueExA(hKey, "ProcessorNameString", nullptr, &gotType, (PBYTE)inBuffer,
&gotSize))
{
if (gotType == REG_SZ && strlen(inBuffer))
{
arch = inBuffer;
}
}
}
#else
std::string platform = "Windows";

int CPUInfo[4] = {-1};
Expand All @@ -100,6 +123,7 @@ std::string brand()
memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo));
}
arch = CPUBrandString;
#endif
#elif LINUX
std::string platform = "Linux";

Expand Down Expand Up @@ -132,7 +156,7 @@ std::string brand()

bool isArm()
{
#if defined(__arm__) || defined(__aarch64__)
#if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
return true;
#else
return false;
Expand Down
6 changes: 6 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ add_executable(dumppaths)
target_sources(dumppaths PRIVATE dumppaths.cpp)
target_link_libraries(dumppaths sst-plugininfra)


add_executable(cpufeatures)
target_sources(cpufeatures PRIVATE cpufeatures.cpp)
target_link_libraries(cpufeatures sst-plugininfra)

add_custom_target(sst-all-tests ALL)
add_dependencies(sst-all-tests dumppaths)
add_dependencies(sst-all-tests sst-tixml-tests)
Expand All @@ -32,6 +37,7 @@ add_custom_command(TARGET sst-all-tests
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:sst-plugininfra-tests>" test-binary
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:sst-tixml-tests>" test-binary
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:dumppaths>" test-binary
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:cpufeatures>" test-binary
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/libs/tinyxml/test/utf8test.xml test-binary
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/libs/tinyxml/test/utf8testverify.xml test-binary
)
25 changes: 25 additions & 0 deletions tests/cpufeatures.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* sst-plugininfra - an open source library of plugin infrastructure
* built by Surge Synth Team.
*
* Copyright 2018-2024, various authors, as described in the GitHub
* transaction log.
*
* sst-effects is released under the MIT License. It has subordinate
* libraries with licenses as described in libs/
*
* All source in sst-plugininfra available at
* https://github.com/surge-synthesizer/sst-plugininfra
*/

#include "sst/plugininfra/cpufeatures.h"
#include <iostream>

int main(int argc, char **argv)
{
using namespace sst::plugininfra::cpufeatures;
std::cout << "CPU Features Platform\n";
std::cout << "brand : " << brand() << "\n";
std::cout << "isArm : " << isArm() << "\n";
std::cout << "isX86 : " << isX86() << "\n";
}

0 comments on commit 4ef3837

Please sign in to comment.