| @@ -129,6 +129,7 @@ int main(int argc, char* argv[]) { | |||||
| // Initialize environment | // Initialize environment | ||||
| system::init(); | system::init(); | ||||
| system::initCpuFlags(); | |||||
| asset::init(); | asset::init(); | ||||
| if (!settings::devMode) { | if (!settings::devMode) { | ||||
| logger::logPath = asset::user("log.txt"); | logger::logPath = asset::user("log.txt"); | ||||
| @@ -196,6 +196,9 @@ The launched process will continue running if the current process is closed. | |||||
| void runProcessDetached(const std::string& path); | void runProcessDetached(const std::string& path); | ||||
| PRIVATE void init(); | PRIVATE void init(); | ||||
| /** Sets Rack-recommended CPU flags for the current thread. | |||||
| */ | |||||
| void initCpuFlags(); | |||||
| } // namespace system | } // namespace system | ||||
| @@ -21,24 +21,6 @@ namespace rack { | |||||
| namespace engine { | namespace engine { | ||||
| static void initCpu() { | |||||
| // Set CPU to flush-to-zero (FTZ) and denormals-are-zero (DAZ) mode | |||||
| // https://software.intel.com/en-us/node/682949 | |||||
| // On ARM64, this is a SIMDe function. | |||||
| _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); | |||||
| // ARM64 always uses DAZ | |||||
| #if defined ARCH_X64 | |||||
| _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); | |||||
| #endif | |||||
| // Reset rounding mode | |||||
| #if !defined _MM_ROUND_NEAREST | |||||
| #define _MM_ROUND_NEAREST 0x0000 | |||||
| #endif | |||||
| _MM_SET_ROUNDING_MODE(_MM_ROUND_NEAREST); | |||||
| } | |||||
| /** Barrier based on mutexes. | /** Barrier based on mutexes. | ||||
| Not finished or tested, do not use. | Not finished or tested, do not use. | ||||
| */ | */ | ||||
| @@ -495,7 +477,7 @@ void Engine::stepBlock(int frames) { | |||||
| SharedLock<SharedMutex> lock(internal->mutex); | SharedLock<SharedMutex> lock(internal->mutex); | ||||
| // Configure thread | // Configure thread | ||||
| uint32_t csr = _mm_getcsr(); | uint32_t csr = _mm_getcsr(); | ||||
| initCpu(); | |||||
| system::initCpuFlags(); | |||||
| random::init(); | random::init(); | ||||
| internal->blockFrame = internal->frame; | internal->blockFrame = internal->frame; | ||||
| @@ -1289,7 +1271,7 @@ void EngineWorker::run() { | |||||
| // Configure thread | // Configure thread | ||||
| contextSet(engine->internal->context); | contextSet(engine->internal->context); | ||||
| system::setThreadName(string::f("Worker %d", id)); | system::setThreadName(string::f("Worker %d", id)); | ||||
| initCpu(); | |||||
| system::initCpuFlags(); | |||||
| random::init(); | random::init(); | ||||
| while (true) { | while (true) { | ||||
| @@ -1,6 +1,7 @@ | |||||
| #include <thread> | #include <thread> | ||||
| #include <regex> | #include <regex> | ||||
| #include <chrono> | #include <chrono> | ||||
| #include <cfenv> // for std::fesetround | |||||
| #include <ghc/filesystem.hpp> | #include <ghc/filesystem.hpp> | ||||
| #include <dirent.h> | #include <dirent.h> | ||||
| @@ -38,6 +39,7 @@ | |||||
| #include <system.hpp> | #include <system.hpp> | ||||
| #include <string.hpp> | #include <string.hpp> | ||||
| #include <simd/common.hpp> | |||||
| /* | /* | ||||
| @@ -955,5 +957,20 @@ void init() { | |||||
| } | } | ||||
| void initCpuFlags() { | |||||
| // Set CPU to flush-to-zero (FTZ) and denormals-are-zero (DAZ) mode | |||||
| // https://software.intel.com/en-us/node/682949 | |||||
| // On ARM64, this is a SIMDe function. | |||||
| _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); | |||||
| // ARM64 always uses DAZ | |||||
| #if defined ARCH_X64 | |||||
| _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); | |||||
| #endif | |||||
| // Reset rounding mode to default (nearest) | |||||
| std::fesetround(FE_TONEAREST); | |||||
| } | |||||
| } // namespace system | } // namespace system | ||||
| } // namespace rack | } // namespace rack | ||||