Jyri Sarha | 6adacb8 | 2011-07-18 14:45:44 -0700 | [diff] [blame^] | 1 | /* Copyright (C) 2007-2008 Jean-Marc Valin |
| 2 | * Copyright (C) 2008 Thorvald Natvig |
| 3 | * Copyright (C) 2011 Jyri Sarha, Texas Instruments |
| 4 | */ |
| 5 | /** |
| 6 | @file resample_neon.h |
| 7 | @brief Resampler functions (NEON version) |
| 8 | */ |
| 9 | /* |
| 10 | Redistribution and use in source and binary forms, with or without |
| 11 | modification, are permitted provided that the following conditions |
| 12 | are met: |
| 13 | |
| 14 | - Redistributions of source code must retain the above copyright |
| 15 | notice, this list of conditions and the following disclaimer. |
| 16 | |
| 17 | - Redistributions in binary form must reproduce the above copyright |
| 18 | notice, this list of conditions and the following disclaimer in the |
| 19 | documentation and/or other materials provided with the distribution. |
| 20 | |
| 21 | - Neither the name of the Xiph.org Foundation nor the names of its |
| 22 | contributors may be used to endorse or promote products derived from |
| 23 | this software without specific prior written permission. |
| 24 | |
| 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 26 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 27 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 28 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR |
| 29 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 30 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 31 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 32 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <arm_neon.h> |
| 39 | |
| 40 | /* NOTE: This code only works with following filter lengths: |
| 41 | 8 or n*16 (where n = 1,2,3...) |
| 42 | The current resampler quality presets follow the above rule. |
| 43 | */ |
| 44 | |
| 45 | #ifdef FIXED_POINT |
| 46 | #define OVERRIDE_INNER_PRODUCT_SINGLE |
| 47 | static inline int32_t inner_product_single(const int16_t *a, const int16_t *b, unsigned int len) |
| 48 | { |
| 49 | int32_t ret; |
| 50 | if (len > 8) { |
| 51 | asm volatile (" vld1.16 {d16, d17, d18, d19}, [%[a]]!\n" |
| 52 | " vld1.16 {d20, d21, d22, d23}, [%[b]]!\n" |
| 53 | " subs %[len], %[len], #16\n" |
| 54 | " vmull.s16 q0, d16, d20\n" |
| 55 | " vmlal.s16 q0, d17, d21\n" |
| 56 | " vmlal.s16 q0, d18, d22\n" |
| 57 | " vmlal.s16 q0, d19, d23\n" |
| 58 | " beq 2f\n" |
| 59 | "1:" |
| 60 | " vld1.16 {d16, d17, d18, d19}, [%[a]]!\n" |
| 61 | " vld1.16 {d20, d21, d22, d23}, [%[b]]!\n" |
| 62 | " subs %[len], %[len], #16\n" |
| 63 | " vmlal.s16 q0, d16, d20\n" |
| 64 | " vmlal.s16 q0, d17, d21\n" |
| 65 | " vmlal.s16 q0, d18, d22\n" |
| 66 | " vmlal.s16 q0, d19, d23\n" |
| 67 | " bne 1b\n" |
| 68 | "2:" |
| 69 | " vaddl.s32 q0, d0, d1\n" |
| 70 | " vadd.s64 d0, d0, d1\n" |
| 71 | " vqmovn.s64 d0, q0\n" |
| 72 | " vqrshrn.s32 d0, q0, #15\n" |
| 73 | " vmov.s16 %[ret],d0[0]\n" |
| 74 | : [ret] "=&r" (ret), [a] "+r" (a), [b] "+r" (b), |
| 75 | [len] "+r" (len) |
| 76 | : |
| 77 | : "cc", "q0", |
| 78 | "d16", "d17", "d18", "d19", |
| 79 | "d20", "d21", "d22", "d23"); |
| 80 | } |
| 81 | else { |
| 82 | asm volatile ("vld1.16 {d4, d5}, [%[a]]\n" |
| 83 | "vld1.16 {d6, d7}, [%[b]]\n" |
| 84 | "vmull.s16 q0, d4, d6\n" |
| 85 | "vmlal.s16 q0, d5, d7\n" |
| 86 | "vaddl.s32 q0, d0, d1\n" |
| 87 | "vadd.s64 d0, d0, d1\n" |
| 88 | "vqmovn.s64 d0, q0\n" |
| 89 | "vqrshrn.s32 d0, q0, #15\n" |
| 90 | "vmov.s16 %[ret],d0[0]\n" |
| 91 | : [ret] "=&r" (ret) |
| 92 | : [a] "r" (a), [b] "r" (b) |
| 93 | : "q0", "d4", "d5", "d6", "d7"); |
| 94 | } |
| 95 | return ret; |
| 96 | } |
| 97 | #endif |