From bc489e2f0db946ab30b442c8d593f9cb4e8f4053 Mon Sep 17 00:00:00 2001 From: Drew Parsons Date: Sun, 5 Jan 2025 13:28:59 +0100 Subject: [PATCH] support non-x86 arches missing RDTSC Extends support of non-intel architectures which do not have an RDTSC timer. Applies debian patch support-non-x86.patch https://salsa.debian.org/science-team/netgen/-/blob/d7ca1c564d90d00ce3d83e0b63c36fbec11cf1ce/debian/patches/support-non-x86.patch --- libsrc/core/utils.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libsrc/core/utils.hpp b/libsrc/core/utils.hpp index a503d53c..24b171e2 100644 --- a/libsrc/core/utils.hpp +++ b/libsrc/core/utils.hpp @@ -19,7 +19,9 @@ #ifdef NETGEN_ARCH_AMD64 #ifdef WIN32 #include // for __rdtsc() CPU time step counter -#else +#define NGCORE_HAVE_RDTSC +#elif defined __SSE__ +#define NGCORE_HAVE_RDTSC #include // for __rdtsc() CPU time step counter #endif // WIN32 #endif // NETGEN_ARCH_AMD64 @@ -65,7 +67,7 @@ namespace ngcore { #if defined(__APPLE__) && defined(NETGEN_ARCH_ARM64) return mach_absolute_time(); -#elif defined(NETGEN_ARCH_AMD64) +#elif defined(NETGEN_ARCH_AMD64) || defined(NGCORE_HAVE_RDTSC) return __rdtsc(); #elif defined(NETGEN_ARCH_ARM64) && defined(__GNUC__) // __GNUC__ is also defined by CLANG. Use inline asm to read Generic Timer @@ -74,6 +76,8 @@ namespace ngcore return tics; #elif defined(__EMSCRIPTEN__) return std::chrono::high_resolution_clock::now().time_since_epoch().count(); +#elifndef NGCORE_HAVE_RDTSC + return TTimePoint(std::chrono::steady_clock::now().time_since_epoch().count()); #else #warning "Unsupported CPU architecture" return 0;