#include #include #include #include "trigdx/lookup.hpp" template struct LookupBackend::Impl { std::vector lookup; static constexpr size_t MASK = NR_SAMPLES - 1; static constexpr float SCALE = NR_SAMPLES / (2.0f * float(M_PI)); void init() { lookup.resize(NR_SAMPLES); for (size_t i = 0; i < NR_SAMPLES; ++i) lookup[i] = sinf(i * (2.0f * float(M_PI) / NR_SAMPLES)); } void compute_sinf(size_t n, const float *x, float *s) const { for (size_t i = 0; i < n; ++i) { size_t idx = static_cast(x[i] * SCALE) & MASK; s[i] = lookup[idx]; } } void compute_cosf(size_t n, const float *x, float *c) const { for (size_t i = 0; i < n; ++i) { size_t idx = static_cast(x[i] * SCALE) & MASK; size_t idx_cos = (idx + NR_SAMPLES / 4) & MASK; c[i] = lookup[idx_cos]; } } void compute_sincosf(size_t n, const float *x, float *s, float *c) const { for (size_t i = 0; i < n; ++i) { size_t idx = static_cast(x[i] * SCALE) & MASK; size_t idx_cos = (idx + NR_SAMPLES / 4) & MASK; s[i] = lookup[idx]; c[i] = lookup[idx_cos]; } } }; template LookupBackend::LookupBackend() : impl(std::make_unique()) {} template LookupBackend::~LookupBackend() = default; template void LookupBackend::init(size_t) { impl->init(); } template void LookupBackend::compute_sinf(size_t n, const float *x, float *s) const { impl->compute_sinf(n, x, s); } template void LookupBackend::compute_cosf(size_t n, const float *x, float *c) const { impl->compute_cosf(n, x, c); } template void LookupBackend::compute_sincosf(size_t n, const float *x, float *s, float *c) const { impl->compute_sincosf(n, x, s, c); } template class LookupBackend<16384>; template class LookupBackend<32768>;