24#ifndef LMMS_HARDWARE_H
25#define LMMS_HARDWARE_H
29#if __cpp_lib_hardware_interference_size >= 201703L
30 #if defined(__GNUG__) && !defined(__clang__)
32 #pragma GCC diagnostic ignored "-Winterference-size"
35#include "lmmsconfig.h"
36#if defined(LMMS_HOST_X86_64) || defined(LMMS_HOST_X86)
37 #include <immintrin.h>
38#elif defined(LMMS_HOST_ARM64) || defined(LMMS_HOST_ARM32)
39 #if defined(__ARM_ACLE)
41 #elif defined(_MSC_VER)
43 #elif defined(__GNUG__)
44 #if defined(LMMS_HOST_ARM64)
47 inline void __isb(
unsigned int) {
asm volatile (
"isb 15" :::
"memory"); }
48 #elif defined(LMMS_HOST_ARM32)
49 inline void __yield() {
asm volatile (
"yield"); }
61#if __cpp_lib_hardware_interference_size >= 201703L
62 std::hardware_destructive_interference_size;
63#elif defined(LMMS_HOST_X86_64) || defined(LMMS_HOST_X86)
65#elif defined(LMMS_HOST_ARM64)
67#elif defined(LMMS_HOST_ARM32)
69#elif defined(LMMS_HOST_RISCV64) || defined(LMMS_HOST_RISCV32)
71#elif defined(LMMS_HOST_PPC64)
73#elif defined(LMMS_HOST_PPC32)
77 #warning Defaulting to 64 for lmms::hardware_destructive_interference_size for this architecture. This may be incorrect.
91#if defined(LMMS_HOST_X86_64) || defined(LMMS_HOST_X86)
93#elif defined(LMMS_HOST_ARM64)
95#elif defined(LMMS_HOST_ARM32)
97#elif defined(LMMS_HOST_RISCV64) || defined(LMMS_HOST_RISCV32)
98 asm volatile (
"pause");
101 #warning lmms::busyWaitHint() is not implemented on this architecture and will have no effect. Performance may suffer.
115#if defined(LMMS_HOST_X86_64) || defined(LMMS_HOST_X86)
119 unsigned int flags = 0x8000;
120 alignas(16) std::uint8_t buf[512] = {0};
121 #if defined(LMMS_HOST_X86_64)
123 #elif defined(LMMS_HOST_X86)
126 flags |= buf[28] & 0x0040;
127 _mm_setcsr(_mm_getcsr() | flags);
128#elif defined(LMMS_HOST_ARM64) || defined(LMMS_HOST_ARM32)
129 constexpr auto FZ = 1 << 24;
130 #if defined(_MSC_VER) && defined(LMMS_HOST_ARM64)
133 _WriteStatusReg(0x5a20, _ReadStatusReg(0x5a20) | FZ);
134 #elif defined(_MSC_VER) && defined(LMMS_HOST_ARM32)
137 #warning MSVC for ARM32 is deprecated. lmms::disableDenormals() is not implemented and will have no effect.
138 #elif defined(LMMS_HOST_ARM64)
141 asm volatile (
"mrs %0, fpcr" :
"=r" (fpcr));
142 asm volatile (
"msr fpcr, %0" ::
"ri" (fpcr | FZ));
143 #elif defined(LMMS_HOST_ARM32)
146 asm volatile (
"vmrs %0, fpscr" :
"=r" (fpscr));
147 asm volatile (
"vmsr fpscr, %0" ::
"ri" (fpscr | FZ));
157 #warning lmms::disableDenormals() is not implemented on this architecture and will have no effect. Performance may suffer.
Definition AudioAlsa.cpp:35
void busyWaitHint()
Platform-dependent hint to the processor that it is in a busy-wait loop. This helps optimize spinlock...
Definition Hardware.h:89
void disableDenormals()
Disable IEEE 754 denormals on the current thread.
Definition Hardware.h:113
constexpr std::size_t hardware_destructive_interference_size
Platform-dependent minimum amount of padding between objects to prevent false cache sharing.
Definition Hardware.h:60