From 9497e4407c51d191447811f180dd37d7db83cdf6 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 28 Nov 2013 11:20:32 -0800 Subject: [PATCH] Neon detection Use runtime check to detect Neon. Also add some copyright headers. --- cpp/src/fm_op_kernel.cc | 12 ------------ cpp/src/neon_fm_kernel.s | 16 ++++++++++++++++ cpp/src/neon_ladder.s | 16 ++++++++++++++++ cpp/src/resofilter.cc | 7 ++----- cpp/src/synth.h | 15 +++++++++++++++ lab/ladder/sawtest.py | 16 ++++++++++++++++ 6 files changed, 65 insertions(+), 17 deletions(-) diff --git a/cpp/src/fm_op_kernel.cc b/cpp/src/fm_op_kernel.cc index 6f2aa69..1a7e10b 100644 --- a/cpp/src/fm_op_kernel.cc +++ b/cpp/src/fm_op_kernel.cc @@ -16,20 +16,12 @@ #include -#ifdef HAVE_NEON -#include -#endif - #include "synth.h" #include "sin.h" #include "fm_op_kernel.h" #ifdef HAVE_NEON -static bool hasNeon() { - return true; - return (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0; -} extern "C" void neon_fm_kernel(const int *in, const int *busin, int *out, int count, @@ -37,10 +29,6 @@ void neon_fm_kernel(const int *in, const int *busin, int *out, int count, const int32_t __attribute__ ((aligned(16))) zeros[N] = {0}; -#else -static bool hasNeon() { - return false; -} #endif void FmOpKernel::compute(int32_t *output, const int32_t *input, diff --git a/cpp/src/neon_fm_kernel.s b/cpp/src/neon_fm_kernel.s index 0dc2a47..1efba5c 100644 --- a/cpp/src/neon_fm_kernel.s +++ b/cpp/src/neon_fm_kernel.s @@ -1,3 +1,19 @@ +@ Copyright 2013 Google Inc. +@ +@ Licensed under the Apache License, Version 2.0 (the "License"); +@ you may not use this file except in compliance with the License. +@ You may obtain a copy of the License at +@ +@ http://www.apache.org/licenses/LICENSE-2.0 +@ +@ Unless required by applicable law or agreed to in writing, software +@ distributed under the License is distributed on an "AS IS" BASIS, +@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@ See the License for the specific language governing permissions and +@ limitations under the License. + +@ NEON assembly implementation of FM operator kernel + .text .align 2 diff --git a/cpp/src/neon_ladder.s b/cpp/src/neon_ladder.s index 9a9a6dc..565e50c 100644 --- a/cpp/src/neon_ladder.s +++ b/cpp/src/neon_ladder.s @@ -1,3 +1,19 @@ +@ Copyright 2013 Google Inc. +@ +@ Licensed under the Apache License, Version 2.0 (the "License"); +@ you may not use this file except in compliance with the License. +@ You may obtain a copy of the License at +@ +@ http://www.apache.org/licenses/LICENSE-2.0 +@ +@ Unless required by applicable law or agreed to in writing, software +@ distributed under the License is distributed on an "AS IS" BASIS, +@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@ See the License for the specific language governing permissions and +@ limitations under the License. + +@ NEON assembly implementation of ladder filter core + .text .align 2 diff --git a/cpp/src/resofilter.cc b/cpp/src/resofilter.cc index f0419ef..80aaffc 100644 --- a/cpp/src/resofilter.cc +++ b/cpp/src/resofilter.cc @@ -197,12 +197,9 @@ void ResoFilter::process(const int32_t **inbufs, const int32_t *control_in, float overdrive = control_in[2] * (1.0 / (1 << 24)); const int32_t *ibuf = inbufs[0]; int32_t *obuf = outbufs[0]; - bool useneon = false; -#ifdef HAVE_NEON - useneon = true; // TODO: detect -#endif + bool useneon = hasNeon(); - if (overdrive == 0) { + if (overdrive < 0.01) { if (useneon) { #ifdef HAVE_NEON AlignedBuf a_neon; diff --git a/cpp/src/synth.h b/cpp/src/synth.h index 2d310d8..1addd5d 100644 --- a/cpp/src/synth.h +++ b/cpp/src/synth.h @@ -21,6 +21,7 @@ // See http://stackoverflow.com/questions/126279/c99-stdint-h-header-and-ms-visual-studio #include +// TODO(raph): move from fixed to variable N #define LG_N 6 #define N (1 << LG_N) @@ -50,4 +51,18 @@ inline static T max(const T& a, const T& b) { return a > b ? a : b; } +#ifdef HAVE_NEON +#include + +static inline bool hasNeon() { + return (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0; +} +#else +static inline bool hasNeon() { + return false; +} +#endif + + + #endif // __SYNTH_H diff --git a/lab/ladder/sawtest.py b/lab/ladder/sawtest.py index 1224ade..99c9749 100644 --- a/lab/ladder/sawtest.py +++ b/lab/ladder/sawtest.py @@ -1,3 +1,19 @@ +# Copyright 2013 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Script for generating sound samples for comparing ladder filters + import argparse import struct import numpy as np