Browse Source

Add system::initCpuFlags(). Call it by all new threads.

tags/v2.5.0
Andrew Belt 9 months ago
parent
commit
e2a4a6209d
4 changed files with 23 additions and 20 deletions
  1. +1
    -0
      adapters/standalone.cpp
  2. +3
    -0
      include/system.hpp
  3. +2
    -20
      src/engine/Engine.cpp
  4. +17
    -0
      src/system.cpp

+ 1
- 0
adapters/standalone.cpp View File

@@ -129,6 +129,7 @@ int main(int argc, char* argv[]) {

// Initialize environment
system::init();
system::initCpuFlags();
asset::init();
if (!settings::devMode) {
logger::logPath = asset::user("log.txt");


+ 3
- 0
include/system.hpp View File

@@ -196,6 +196,9 @@ The launched process will continue running if the current process is closed.
void runProcessDetached(const std::string& path);

PRIVATE void init();
/** Sets Rack-recommended CPU flags for the current thread.
*/
void initCpuFlags();


} // namespace system


+ 2
- 20
src/engine/Engine.cpp View File

@@ -21,24 +21,6 @@ namespace rack {
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.
Not finished or tested, do not use.
*/
@@ -495,7 +477,7 @@ void Engine::stepBlock(int frames) {
SharedLock<SharedMutex> lock(internal->mutex);
// Configure thread
uint32_t csr = _mm_getcsr();
initCpu();
system::initCpuFlags();
random::init();

internal->blockFrame = internal->frame;
@@ -1289,7 +1271,7 @@ void EngineWorker::run() {
// Configure thread
contextSet(engine->internal->context);
system::setThreadName(string::f("Worker %d", id));
initCpu();
system::initCpuFlags();
random::init();

while (true) {


+ 17
- 0
src/system.cpp View File

@@ -1,6 +1,7 @@
#include <thread>
#include <regex>
#include <chrono>
#include <cfenv> // for std::fesetround
#include <ghc/filesystem.hpp>

#include <dirent.h>
@@ -38,6 +39,7 @@

#include <system.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 rack

Loading…
Cancel
Save