resample_neon.h revision 35318dd943257760780f28b95b6ca99a79886c3d
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#ifdef FIXED_POINT
41
42
43#define OVERRIDE_INNER_PRODUCT_SINGLE
44static inline int32_t inner_product_single(const int16_t *a, const int16_t *b, unsigned int len)
45{
46    int32_t ret;
47    uint32_t remainder = len % 16;
48    len = len - remainder;
49
50    asm volatile ("	 cmp %[len], #0\n"
51		  "	 bne 1f\n"
52		  "	 vld1.16 {d16}, [%[a]]!\n"
53		  "	 vld1.16 {d20}, [%[b]]!\n"
54		  "	 subs %[remainder], %[remainder], #4\n"
55		  "	 vmull.s16 q0, d16, d20\n"
56		  "      beq 5f\n"
57		  "	 b 4f\n"
58		  "1:"
59		  "	 vld1.16 {d16, d17, d18, d19}, [%[a]]!\n"
60		  "	 vld1.16 {d20, d21, d22, d23}, [%[b]]!\n"
61		  "	 subs %[len], %[len], #16\n"
62		  "	 vmull.s16 q0, d16, d20\n"
63		  "	 vmlal.s16 q0, d17, d21\n"
64		  "	 vmlal.s16 q0, d18, d22\n"
65		  "	 vmlal.s16 q0, d19, d23\n"
66		  "	 beq 3f\n"
67		  "2:"
68		  "	 vld1.16 {d16, d17, d18, d19}, [%[a]]!\n"
69		  "	 vld1.16 {d20, d21, d22, d23}, [%[b]]!\n"
70		  "	 subs %[len], %[len], #16\n"
71		  "	 vmlal.s16 q0, d16, d20\n"
72		  "	 vmlal.s16 q0, d17, d21\n"
73		  "	 vmlal.s16 q0, d18, d22\n"
74		  "	 vmlal.s16 q0, d19, d23\n"
75		  "	 bne 2b\n"
76		  "3:"
77		  "	 cmp %[remainder], #0\n"
78		  "	 beq 5f\n"
79		  "4:"
80		  "	 vld1.16 {d16}, [%[a]]!\n"
81		  "	 vld1.16 {d20}, [%[b]]!\n"
82		  "	 subs %[remainder], %[remainder], #4\n"
83		  "	 vmlal.s16 q0, d16, d20\n"
84		  "	 bne 4b\n"
85		  "5:"
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), [a] "+r" (a), [b] "+r" (b),
92		    [len] "+r" (len), [remainder] "+r" (remainder)
93		  :
94		  : "cc", "q0",
95		    "d16", "d17", "d18", "d19",
96		    "d20", "d21", "d22", "d23");
97    return ret;
98}
99
100#endif
101