修复macos arm编译问题
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
#include "audio_buffer.h"
|
||||
|
||||
#include <cstring>
|
||||
#if CPU_AMD64
|
||||
#include <experimental/simd>
|
||||
|
||||
#endif
|
||||
#include "audio_buffer_pool.h"
|
||||
#include "misc/cpu_simd.h"
|
||||
#include "misc/likely.h"
|
||||
@@ -10,6 +11,7 @@
|
||||
void(*audio_buffer::add_func)(audio_buffer& in_buffer, audio_buffer& from_buffer, float percent);
|
||||
void(*audio_buffer::multiple_func)(audio_buffer& in_buffer, float percent);
|
||||
|
||||
#if CPU_AMD64
|
||||
template<int simd_size>
|
||||
void add_simd(audio_buffer& in_buffer, audio_buffer& from_buffer, float percent) {
|
||||
using namespace std::experimental;
|
||||
@@ -36,16 +38,6 @@ void add_simd(audio_buffer& in_buffer, audio_buffer& from_buffer, float percent)
|
||||
}
|
||||
}
|
||||
|
||||
void add_no_simd(audio_buffer& in_buffer, audio_buffer& from_buffer, float percent) {
|
||||
for (uint32_t channel_index = 0; channel_index < in_buffer.get_num_channels(); channel_index++) {
|
||||
sample_t* channel = in_buffer.get_headers()[channel_index];
|
||||
sample_t* in_channel = from_buffer.get_headers()[channel_index];
|
||||
for (int i = 0; i < in_buffer.get_num_samples(); ++i) {
|
||||
channel[i] += in_channel[i] * percent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<int simd_size>
|
||||
void multiple_simd(audio_buffer& in_buffer, float percent) {
|
||||
using namespace std::experimental;
|
||||
@@ -66,6 +58,17 @@ void multiple_simd(audio_buffer& in_buffer, float percent) {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void add_no_simd(audio_buffer& in_buffer, audio_buffer& from_buffer, float percent) {
|
||||
for (uint32_t channel_index = 0; channel_index < in_buffer.get_num_channels(); channel_index++) {
|
||||
sample_t* channel = in_buffer.get_headers()[channel_index];
|
||||
sample_t* in_channel = from_buffer.get_headers()[channel_index];
|
||||
for (int i = 0; i < in_buffer.get_num_samples(); ++i) {
|
||||
channel[i] += in_channel[i] * percent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void multiple_no_simd(audio_buffer& in_buffer, float percent) {
|
||||
for (auto channel : in_buffer.get_headers_vector()) {
|
||||
@@ -76,7 +79,9 @@ void multiple_no_simd(audio_buffer& in_buffer, float percent) {
|
||||
}
|
||||
|
||||
audio_buffer::audio_buffer() {
|
||||
#if __cplusplus >= 202600L
|
||||
using namespace std::experimental;
|
||||
#endif
|
||||
static bool func_initialized = false;
|
||||
if (UNLIKELY(!func_initialized)) {
|
||||
cpuid cpu;
|
||||
@@ -94,11 +99,11 @@ audio_buffer::audio_buffer() {
|
||||
}
|
||||
#endif
|
||||
#if CPU_ARM
|
||||
if (cpu.support_neon128()) {
|
||||
DEFINE_SIMD_FUNC(128)
|
||||
} else if (cpu.support_neon64()) {
|
||||
DEFINE_SIMD_FUNC(64)
|
||||
}
|
||||
// if (cpu.support_neon128()) {
|
||||
// DEFINE_SIMD_FUNC(128)
|
||||
// } else if (cpu.support_neon64()) {
|
||||
// DEFINE_SIMD_FUNC(64)
|
||||
// }
|
||||
#endif
|
||||
if (!add_func) {
|
||||
add_func = &add_no_simd;
|
||||
|
||||
@@ -1,22 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cpuid.h>
|
||||
#include <vector>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <intrin.h>
|
||||
#else
|
||||
#if !CPU_ARM
|
||||
#include <cpuid.h>
|
||||
#endif
|
||||
|
||||
inline void get_cpuid(int info[4], int infoType) {
|
||||
#ifdef _MSC_VER
|
||||
__cpuidex(info, infoType, 0);
|
||||
#else
|
||||
__cpuid_count(infoType, 0, info[0], info[1], info[2], info[3]);
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
enum class simd_type {
|
||||
sse2,
|
||||
@@ -32,10 +27,10 @@ enum class simd_type {
|
||||
};
|
||||
|
||||
inline std::vector<simd_type> get_simd_support_type() {
|
||||
unsigned int eax, ebx, ecx, edx;
|
||||
__get_cpuid(1, &eax, &ebx, &ecx, &edx);
|
||||
std::vector<simd_type> simd_types;
|
||||
#if CPU_AMD64
|
||||
unsigned int eax, ebx, ecx, edx;
|
||||
__get_cpuid(1, &eax, &ebx, &ecx, &edx);
|
||||
if (ecx & bit_SSE2) {
|
||||
simd_types.push_back(simd_type::sse2);
|
||||
}
|
||||
@@ -62,18 +57,13 @@ inline std::vector<simd_type> get_simd_support_type() {
|
||||
}
|
||||
#endif
|
||||
#if CPU_ARM
|
||||
uint64_t id_aa64isar0_ = 0;
|
||||
uint64_t id_aa64pfr0_ = 0;
|
||||
|
||||
// Reading the ID_AA64ISAR0_EL1 register
|
||||
asm volatile("mrs %0, ID_AA64ISAR0_EL1" : "=r" (id_aa64isar0_));
|
||||
// Reading the ID_AA64PFR0_EL1 register
|
||||
asm volatile("mrs %0, ID_AA64PFR0_EL1" : "=r" (id_aa64pfr0_));
|
||||
if ((id_aa64isar0_ >> 24) & 0xf) {
|
||||
simd_types.push_back(simd_type::neon64);
|
||||
}
|
||||
if ((id_aa64isar0_ >> 28) & 0xf) {
|
||||
simd_types.push_back(simd_type::neon128);
|
||||
int neon_support = 0;
|
||||
size_t size = sizeof(neon_support);
|
||||
if (sysctlbyname("hw.optional.neon", &neon_support, &size, NULL, 0) == 0) {
|
||||
if (neon_support) {
|
||||
simd_types.push_back(simd_type::neon64);
|
||||
simd_types.push_back(simd_type::neon128);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -118,4 +108,4 @@ public:
|
||||
}
|
||||
private:
|
||||
std::vector<simd_type> simd_types;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user