Path: blob/master/dep/cubeb/subprojects/speex/resample_neon.h
4247 views
/* Copyright (C) 2007-2008 Jean-Marc Valin1* Copyright (C) 2008 Thorvald Natvig2* Copyright (C) 2011 Texas Instruments3* author Jyri Sarha4*/5/**6@file resample_neon.h7@brief Resampler functions (NEON version)8*/9/*10Redistribution and use in source and binary forms, with or without11modification, are permitted provided that the following conditions12are met:1314- Redistributions of source code must retain the above copyright15notice, this list of conditions and the following disclaimer.1617- Redistributions in binary form must reproduce the above copyright18notice, this list of conditions and the following disclaimer in the19documentation and/or other materials provided with the distribution.2021- Neither the name of the Xiph.org Foundation nor the names of its22contributors may be used to endorse or promote products derived from23this software without specific prior written permission.2425THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS26``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT27LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR28A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR29CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,30EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,31PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR32PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF33LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING34NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS35SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.36*/3738#include <arm_neon.h>3940#ifdef FIXED_POINT41#ifdef __thumb2__42static inline int32_t saturate_32bit_to_16bit(int32_t a) {43int32_t ret;44asm ("ssat %[ret], #16, %[a]"45: [ret] "=&r" (ret)46: [a] "r" (a)47: );48return ret;49}50#else51static inline int32_t saturate_32bit_to_16bit(int32_t a) {52int32_t ret;53asm ("vmov.s32 d0[0], %[a]\n"54"vqmovn.s32 d0, q0\n"55"vmov.s16 %[ret], d0[0]\n"56: [ret] "=&r" (ret)57: [a] "r" (a)58: "q0");59return ret;60}61#endif62#undef WORD2INT63#define WORD2INT(x) (saturate_32bit_to_16bit(x))6465#define OVERRIDE_INNER_PRODUCT_SINGLE66/* Only works when len % 4 == 0 */67static inline int32_t inner_product_single(const int16_t *a, const int16_t *b, unsigned int len)68{69int32_t ret;70uint32_t remainder = len % 16;71len = len - remainder;7273asm volatile (" cmp %[len], #0\n"74" bne 1f\n"75" vld1.16 {d16}, [%[b]]!\n"76" vld1.16 {d20}, [%[a]]!\n"77" subs %[remainder], %[remainder], #4\n"78" vmull.s16 q0, d16, d20\n"79" beq 5f\n"80" b 4f\n"81"1:"82" vld1.16 {d16, d17, d18, d19}, [%[b]]!\n"83" vld1.16 {d20, d21, d22, d23}, [%[a]]!\n"84" subs %[len], %[len], #16\n"85" vmull.s16 q0, d16, d20\n"86" vmlal.s16 q0, d17, d21\n"87" vmlal.s16 q0, d18, d22\n"88" vmlal.s16 q0, d19, d23\n"89" beq 3f\n"90"2:"91" vld1.16 {d16, d17, d18, d19}, [%[b]]!\n"92" vld1.16 {d20, d21, d22, d23}, [%[a]]!\n"93" subs %[len], %[len], #16\n"94" vmlal.s16 q0, d16, d20\n"95" vmlal.s16 q0, d17, d21\n"96" vmlal.s16 q0, d18, d22\n"97" vmlal.s16 q0, d19, d23\n"98" bne 2b\n"99"3:"100" cmp %[remainder], #0\n"101" beq 5f\n"102"4:"103" vld1.16 {d16}, [%[b]]!\n"104" vld1.16 {d20}, [%[a]]!\n"105" subs %[remainder], %[remainder], #4\n"106" vmlal.s16 q0, d16, d20\n"107" bne 4b\n"108"5:"109" vaddl.s32 q0, d0, d1\n"110" vadd.s64 d0, d0, d1\n"111" vqmovn.s64 d0, q0\n"112" vqrshrn.s32 d0, q0, #15\n"113" vmov.s16 %[ret], d0[0]\n"114: [ret] "=&r" (ret), [a] "+r" (a), [b] "+r" (b),115[len] "+r" (len), [remainder] "+r" (remainder)116:117: "cc", "q0",118"d16", "d17", "d18", "d19",119"d20", "d21", "d22", "d23");120121return ret;122}123#elif defined(FLOATING_POINT)124125static inline int32_t saturate_float_to_16bit(float a) {126int32_t ret;127asm ("vmov.f32 d0[0], %[a]\n"128"vcvt.s32.f32 d0, d0, #15\n"129"vqrshrn.s32 d0, q0, #15\n"130"vmov.s16 %[ret], d0[0]\n"131: [ret] "=&r" (ret)132: [a] "r" (a)133: "q0");134return ret;135}136#undef WORD2INT137#define WORD2INT(x) (saturate_float_to_16bit(x))138139#define OVERRIDE_INNER_PRODUCT_SINGLE140/* Only works when len % 4 == 0 */141static inline float inner_product_single(const float *a, const float *b, unsigned int len)142{143float ret;144uint32_t remainder = len % 16;145len = len - remainder;146147asm volatile (" cmp %[len], #0\n"148" bne 1f\n"149" vld1.32 {q4}, [%[b]]!\n"150" vld1.32 {q8}, [%[a]]!\n"151" subs %[remainder], %[remainder], #4\n"152" vmul.f32 q0, q4, q8\n"153" bne 4f\n"154" b 5f\n"155"1:"156" vld1.32 {q4, q5}, [%[b]]!\n"157" vld1.32 {q8, q9}, [%[a]]!\n"158" vld1.32 {q6, q7}, [%[b]]!\n"159" vld1.32 {q10, q11}, [%[a]]!\n"160" subs %[len], %[len], #16\n"161" vmul.f32 q0, q4, q8\n"162" vmul.f32 q1, q5, q9\n"163" vmul.f32 q2, q6, q10\n"164" vmul.f32 q3, q7, q11\n"165" beq 3f\n"166"2:"167" vld1.32 {q4, q5}, [%[b]]!\n"168" vld1.32 {q8, q9}, [%[a]]!\n"169" vld1.32 {q6, q7}, [%[b]]!\n"170" vld1.32 {q10, q11}, [%[a]]!\n"171" subs %[len], %[len], #16\n"172" vmla.f32 q0, q4, q8\n"173" vmla.f32 q1, q5, q9\n"174" vmla.f32 q2, q6, q10\n"175" vmla.f32 q3, q7, q11\n"176" bne 2b\n"177"3:"178" vadd.f32 q4, q0, q1\n"179" vadd.f32 q5, q2, q3\n"180" cmp %[remainder], #0\n"181" vadd.f32 q0, q4, q5\n"182" beq 5f\n"183"4:"184" vld1.32 {q6}, [%[b]]!\n"185" vld1.32 {q10}, [%[a]]!\n"186" subs %[remainder], %[remainder], #4\n"187" vmla.f32 q0, q6, q10\n"188" bne 4b\n"189"5:"190" vadd.f32 d0, d0, d1\n"191" vpadd.f32 d0, d0, d0\n"192" vmov.f32 %[ret], d0[0]\n"193: [ret] "=&r" (ret), [a] "+r" (a), [b] "+r" (b),194[len] "+l" (len), [remainder] "+l" (remainder)195:196: "cc", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8",197"q9", "q10", "q11");198return ret;199}200#endif201202203