aboutsummaryrefslogtreecommitdiffstats
path: root/alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-12-31 16:47:12 -0800
committerChris Robinson <[email protected]>2020-12-31 16:47:12 -0800
commit20ef8bf390541339f068676f9d14061fe2f5e115 (patch)
tree6cca7aa12e11a6b5918fa3748391cb336d8d00bb /alc
parent002c5062964a598f8cdf53e6b3ed4836629c5048 (diff)
Move cpu_caps and fpu_ctrl to core
Diffstat (limited to 'alc')
-rw-r--r--alc/alc.cpp4
-rw-r--r--alc/alu.cpp4
-rw-r--r--alc/converter.cpp2
-rw-r--r--alc/cpu_caps.cpp142
-rw-r--r--alc/cpu_caps.h26
-rw-r--r--alc/fpu_ctrl.cpp54
-rw-r--r--alc/fpu_ctrl.h25
-rw-r--r--alc/voice.cpp2
8 files changed, 6 insertions, 253 deletions
diff --git a/alc/alc.cpp b/alc/alc.cpp
index 9bfc0b48..8cd902ed 100644
--- a/alc/alc.cpp
+++ b/alc/alc.cpp
@@ -80,16 +80,16 @@
#include "compat.h"
#include "core/ambidefs.h"
#include "core/bs2b.h"
+#include "core/cpu_caps.h"
#include "core/devformat.h"
#include "core/except.h"
#include "core/mastering.h"
#include "core/filters/nfc.h"
#include "core/filters/splitter.h"
+#include "core/fpu_ctrl.h"
#include "core/logging.h"
#include "core/uhjfilter.h"
-#include "cpu_caps.h"
#include "effects/base.h"
-#include "fpu_ctrl.h"
#include "front_stablizer.h"
#include "hrtf.h"
#include "inprogext.h"
diff --git a/alc/alu.cpp b/alc/alu.cpp
index 5128e305..fe4c54a1 100644
--- a/alc/alu.cpp
+++ b/alc/alu.cpp
@@ -56,17 +56,17 @@
#include "core/ambidefs.h"
#include "core/bs2b.h"
#include "core/bsinc_tables.h"
+#include "core/cpu_caps.h"
#include "core/devformat.h"
#include "core/filters/biquad.h"
#include "core/filters/nfc.h"
#include "core/filters/splitter.h"
+#include "core/fpu_ctrl.h"
#include "core/mastering.h"
#include "core/mixer/defs.h"
#include "core/uhjfilter.h"
-#include "cpu_caps.h"
#include "effects/base.h"
#include "effectslot.h"
-#include "fpu_ctrl.h"
#include "front_stablizer.h"
#include "hrtf.h"
#include "inprogext.h"
diff --git a/alc/converter.cpp b/alc/converter.cpp
index 342085c5..5016b373 100644
--- a/alc/converter.cpp
+++ b/alc/converter.cpp
@@ -11,7 +11,7 @@
#include "albyte.h"
#include "alnumeric.h"
-#include "fpu_ctrl.h"
+#include "core/fpu_ctrl.h"
struct CTag;
struct CopyTag;
diff --git a/alc/cpu_caps.cpp b/alc/cpu_caps.cpp
deleted file mode 100644
index dc992663..00000000
--- a/alc/cpu_caps.cpp
+++ /dev/null
@@ -1,142 +0,0 @@
-
-#include "config.h"
-
-#include "cpu_caps.h"
-
-#if defined(_WIN32) && (defined(_M_ARM) || defined(_M_ARM64))
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#ifndef PF_ARM_NEON_INSTRUCTIONS_AVAILABLE
-#define PF_ARM_NEON_INSTRUCTIONS_AVAILABLE 19
-#endif
-#endif
-
-#ifdef HAVE_INTRIN_H
-#include <intrin.h>
-#endif
-#ifdef HAVE_CPUID_H
-#include <cpuid.h>
-#endif
-
-#include <array>
-#include <cctype>
-#include <string>
-
-
-int CPUCapFlags{0};
-
-namespace {
-
-#if defined(HAVE_GCC_GET_CPUID) \
- && (defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64))
-using reg_type = unsigned int;
-inline std::array<reg_type,4> get_cpuid(unsigned int f)
-{
- std::array<reg_type,4> ret{};
- __get_cpuid(f, &ret[0], &ret[1], &ret[2], &ret[3]);
- return ret;
-}
-#define CAN_GET_CPUID
-#elif defined(HAVE_CPUID_INTRINSIC) \
- && (defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64))
-using reg_type = int;
-inline std::array<reg_type,4> get_cpuid(unsigned int f)
-{
- std::array<reg_type,4> ret{};
- (__cpuid)(ret.data(), f);
- return ret;
-}
-#define CAN_GET_CPUID
-#endif
-
-} // namespace
-
-al::optional<CPUInfo> GetCPUInfo()
-{
- CPUInfo ret;
-
-#ifdef CAN_GET_CPUID
- auto cpuregs = get_cpuid(0);
- if(cpuregs[0] == 0)
- return al::nullopt;
-
- const reg_type maxfunc{cpuregs[0]};
-
- cpuregs = get_cpuid(0x80000000);
- const reg_type maxextfunc{cpuregs[0]};
-
- ret.mVendor.append(reinterpret_cast<char*>(&cpuregs[1]), 4);
- ret.mVendor.append(reinterpret_cast<char*>(&cpuregs[3]), 4);
- ret.mVendor.append(reinterpret_cast<char*>(&cpuregs[2]), 4);
- auto iter_end = std::remove(ret.mVendor.begin(), ret.mVendor.end(), '\0');
- while(iter_end != ret.mVendor.begin() && std::isspace(*iter_end))
- --iter_end;
- iter_end = std::unique(ret.mVendor.begin(), iter_end,
- [](auto&& c0, auto&& c1) { return std::isspace(c0) && std::isspace(c1); });
- ret.mVendor.erase(iter_end, ret.mVendor.end());
- if(!ret.mVendor.empty() && std::isspace(ret.mVendor.front()))
- ret.mVendor.erase(ret.mVendor.begin());
-
- if(maxextfunc >= 0x80000004)
- {
- cpuregs = get_cpuid(0x80000002);
- ret.mName.append(reinterpret_cast<char*>(cpuregs.data()), 16);
- cpuregs = get_cpuid(0x80000003);
- ret.mName.append(reinterpret_cast<char*>(cpuregs.data()), 16);
- cpuregs = get_cpuid(0x80000004);
- ret.mName.append(reinterpret_cast<char*>(cpuregs.data()), 16);
- iter_end = std::remove(ret.mName.begin(), ret.mName.end(), '\0');
- while(iter_end != ret.mName.begin() && std::isspace(*iter_end))
- --iter_end;
- iter_end = std::unique(ret.mName.begin(), iter_end,
- [](auto&& c0, auto&& c1) { return std::isspace(c0) && std::isspace(c1); });
- ret.mName.erase(iter_end, ret.mName.end());
- if(!ret.mName.empty() && std::isspace(ret.mName.front()))
- ret.mName.erase(ret.mName.begin());
- }
-
- if(maxfunc >= 1)
- {
- cpuregs = get_cpuid(1);
- if((cpuregs[3]&(1<<25)))
- ret.mCaps |= CPU_CAP_SSE;
- if((ret.mCaps&CPU_CAP_SSE) && (cpuregs[3]&(1<<26)))
- ret.mCaps |= CPU_CAP_SSE2;
- if((ret.mCaps&CPU_CAP_SSE2) && (cpuregs[2]&(1<<0)))
- ret.mCaps |= CPU_CAP_SSE3;
- if((ret.mCaps&CPU_CAP_SSE3) && (cpuregs[2]&(1<<19)))
- ret.mCaps |= CPU_CAP_SSE4_1;
- }
-
-#else
-
- /* Assume support for whatever's supported if we can't check for it */
-#if defined(HAVE_SSE4_1)
-#warning "Assuming SSE 4.1 run-time support!"
- ret.mCaps |= CPU_CAP_SSE | CPU_CAP_SSE2 | CPU_CAP_SSE3 | CPU_CAP_SSE4_1;
-#elif defined(HAVE_SSE3)
-#warning "Assuming SSE 3 run-time support!"
- ret.mCaps |= CPU_CAP_SSE | CPU_CAP_SSE2 | CPU_CAP_SSE3;
-#elif defined(HAVE_SSE2)
-#warning "Assuming SSE 2 run-time support!"
- ret.mCaps |= CPU_CAP_SSE | CPU_CAP_SSE2;
-#elif defined(HAVE_SSE)
-#warning "Assuming SSE run-time support!"
- ret.mCaps |= CPU_CAP_SSE;
-#endif
-#endif /* CAN_GET_CPUID */
-
-#ifdef HAVE_NEON
-#ifdef __ARM_NEON
- ret.mCaps |= CPU_CAP_NEON;
-#elif defined(_WIN32) && (defined(_M_ARM) || defined(_M_ARM64))
- if(IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE))
- ret.mCaps |= CPU_CAP_NEON;
-#else
-#warning "Assuming NEON run-time support!"
- ret.mCaps |= CPU_CAP_NEON;
-#endif
-#endif
-
- return al::make_optional(ret);
-}
diff --git a/alc/cpu_caps.h b/alc/cpu_caps.h
deleted file mode 100644
index 190355b2..00000000
--- a/alc/cpu_caps.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef CPU_CAPS_H
-#define CPU_CAPS_H
-
-#include <string>
-
-#include "aloptional.h"
-
-
-extern int CPUCapFlags;
-enum {
- CPU_CAP_SSE = 1<<0,
- CPU_CAP_SSE2 = 1<<1,
- CPU_CAP_SSE3 = 1<<2,
- CPU_CAP_SSE4_1 = 1<<3,
- CPU_CAP_NEON = 1<<4,
-};
-
-struct CPUInfo {
- std::string mVendor;
- std::string mName;
- int mCaps{0};
-};
-
-al::optional<CPUInfo> GetCPUInfo();
-
-#endif /* CPU_CAPS_H */
diff --git a/alc/fpu_ctrl.cpp b/alc/fpu_ctrl.cpp
deleted file mode 100644
index 24021c7d..00000000
--- a/alc/fpu_ctrl.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-
-#include "config.h"
-
-#include "fpu_ctrl.h"
-
-#ifdef HAVE_INTRIN_H
-#include <intrin.h>
-#endif
-#ifdef HAVE_SSE_INTRINSICS
-#include <xmmintrin.h>
-#endif
-
-#include "cpu_caps.h"
-
-
-FPUCtl::FPUCtl()
-{
-#if defined(HAVE_SSE_INTRINSICS)
- this->sse_state = _mm_getcsr();
- unsigned int sseState = this->sse_state;
- sseState |= 0x8000; /* set flush-to-zero */
- sseState |= 0x0040; /* set denormals-are-zero */
- _mm_setcsr(sseState);
-
-#elif defined(__GNUC__) && defined(HAVE_SSE)
-
- if((CPUCapFlags&CPU_CAP_SSE))
- {
- __asm__ __volatile__("stmxcsr %0" : "=m" (*&this->sse_state));
- unsigned int sseState = this->sse_state;
- sseState |= 0x8000; /* set flush-to-zero */
- if((CPUCapFlags&CPU_CAP_SSE2))
- sseState |= 0x0040; /* set denormals-are-zero */
- __asm__ __volatile__("ldmxcsr %0" : : "m" (*&sseState));
- }
-#endif
-
- this->in_mode = true;
-}
-
-void FPUCtl::leave()
-{
- if(!this->in_mode) return;
-
-#if defined(HAVE_SSE_INTRINSICS)
- _mm_setcsr(this->sse_state);
-
-#elif defined(__GNUC__) && defined(HAVE_SSE)
-
- if((CPUCapFlags&CPU_CAP_SSE))
- __asm__ __volatile__("ldmxcsr %0" : : "m" (*&this->sse_state));
-#endif
- this->in_mode = false;
-}
diff --git a/alc/fpu_ctrl.h b/alc/fpu_ctrl.h
deleted file mode 100644
index e89bdc29..00000000
--- a/alc/fpu_ctrl.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#ifndef FPU_CTRL_H
-#define FPU_CTRL_H
-
-class FPUCtl {
-#if defined(HAVE_SSE_INTRINSICS) || (defined(__GNUC__) && defined(HAVE_SSE))
- unsigned int sse_state{};
-#endif
- bool in_mode{};
-
-public:
- FPUCtl();
- /* HACK: 32-bit targets for GCC seem to have a problem here with certain
- * noexcept methods (which destructors are) causing an internal compiler
- * error. No idea why it's these methods specifically, but this is needed
- * to get it to compile.
- */
- ~FPUCtl() noexcept(false) { leave(); }
-
- FPUCtl(const FPUCtl&) = delete;
- FPUCtl& operator=(const FPUCtl&) = delete;
-
- void leave();
-};
-
-#endif /* FPU_CTRL_H */
diff --git a/alc/voice.cpp b/alc/voice.cpp
index 5618f610..9c6ff6b5 100644
--- a/alc/voice.cpp
+++ b/alc/voice.cpp
@@ -45,6 +45,7 @@
#include "alu.h"
#include "async_event.h"
#include "buffer_storage.h"
+#include "core/cpu_caps.h"
#include "core/devformat.h"
#include "core/filters/biquad.h"
#include "core/filters/nfc.h"
@@ -53,7 +54,6 @@
#include "core/logging.h"
#include "core/mixer/defs.h"
#include "core/mixer/hrtfdefs.h"
-#include "cpu_caps.h"
#include "hrtf.h"
#include "inprogext.h"
#include "opthelpers.h"