Lyrebird 2.0.0 — Linux support
Consolidated release: the cross-platform Linux port (engine, generators, CLI, REPL, NRT, portable DSP), live ALSA audio + ALSA MIDI + POSIX OSC + portable WAV codec, the GTK4 GUI (LyrebirdUI on the SwiftOpenUI backend), and the Linux live-coding scratchpad (LiveCompile). Apple platforms unchanged; all additive. See RELEASES.md and LINUX_README.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,20 +1,55 @@
|
||||
#include "LyrebirdC.h"
|
||||
#include <fenv.h>
|
||||
|
||||
// Apple's <fenv.h> exposes two different "flush denormals to zero" environments:
|
||||
// - arm64: FE_DFL_DISABLE_DENORMS_ENV (sets FPCR.FZ)
|
||||
// - x86_64: FE_DFL_DISABLE_SSE_DENORMS_ENV (sets MXCSR.FZ + DAZ for SSE)
|
||||
// Universal-binary builds compile this TU for both archs, so each must use
|
||||
// the macro that exists on its target arch. Same end effect for SIMD float
|
||||
// math in the RT path either way.
|
||||
// Header selection is platform/arch dependent:
|
||||
// - Apple: <fenv.h> exposes the arch-specific "flush denormals" environments.
|
||||
// - non-Apple x86: SSE control via the Intel intrinsics headers.
|
||||
#if defined(__APPLE__)
|
||||
#include <fenv.h>
|
||||
#elif defined(__x86_64__) || defined(__i386__)
|
||||
#include <xmmintrin.h> // _MM_SET_FLUSH_ZERO_MODE (FTZ)
|
||||
#include <pmmintrin.h> // _MM_SET_DENORMALS_ZERO_MODE (DAZ)
|
||||
#endif
|
||||
|
||||
// Enable flush-to-zero / denormals-are-zero for float SIMD math on the RT path.
|
||||
// Denormal handling is catastrophically slow on most FPUs, so audio DSP disables
|
||||
// it. The mechanism differs by platform and arch; the end effect is the same.
|
||||
//
|
||||
// This is thread-local state, so every thread that runs DSP has to set it:
|
||||
// engine start does so for the setup thread, and each driver's render callback
|
||||
// (CoreAudioDriver, iOSAudioDriver, ALSAAudioDriver) calls it on entry. It is a
|
||||
// few register writes — cheap enough per callback, never per-sample.
|
||||
void lyrebird_enable_flush_to_zero(void) {
|
||||
#if defined(__APPLE__)
|
||||
// Apple's <fenv.h> exposes two arch-specific environments:
|
||||
// - arm64: FE_DFL_DISABLE_DENORMS_ENV (sets FPCR.FZ)
|
||||
// - x86_64: FE_DFL_DISABLE_SSE_DENORMS_ENV (sets MXCSR.FZ + DAZ for SSE)
|
||||
// Universal-binary builds compile this TU for both archs; each uses the
|
||||
// macro that exists on its target arch. These macros are Darwin-only.
|
||||
#if defined(__arm64__)
|
||||
fesetenv(FE_DFL_DISABLE_DENORMS_ENV);
|
||||
#elif defined(__i386__) || defined(__x86_64__)
|
||||
fesetenv(FE_DFL_DISABLE_SSE_DENORMS_ENV);
|
||||
#else
|
||||
// Unsupported arch — leave FPU in default IEEE-754 mode. Denormals are
|
||||
// still processed but the build doesn't fail.
|
||||
(void)0;
|
||||
#endif
|
||||
#elif defined(__x86_64__) || defined(__i386__)
|
||||
// Non-Apple x86 (Linux/Windows): set SSE flush-to-zero + denormals-are-zero
|
||||
// directly in MXCSR. FZ is SSE1, so it is safe on any x86 that gets here;
|
||||
// DAZ needs SSE3, which is baseline on x86_64 but NOT on 32-bit x86 — a
|
||||
// pre-SSE3 i386 CPU faults on the instruction, so it is gated.
|
||||
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
|
||||
#if defined(__x86_64__) || defined(__SSE3__)
|
||||
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
|
||||
#endif
|
||||
#elif defined(__aarch64__)
|
||||
// Non-Apple AArch64 (Linux): set FPCR.FZ (bit 24) to flush denormals to zero.
|
||||
unsigned long fpcr;
|
||||
__asm__ __volatile__("mrs %0, fpcr" : "=r"(fpcr));
|
||||
fpcr |= (1UL << 24);
|
||||
__asm__ __volatile__("msr fpcr, %0" : : "r"(fpcr));
|
||||
#else
|
||||
// Unsupported arch — leave the FPU in default IEEE-754 mode. Denormals are
|
||||
// still processed correctly, just without the performance win.
|
||||
(void)0;
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user