You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
6.1KB

  1. /* Copyright (C) 2007-2008 Jean-Marc Valin
  2. * Copyright (C) 2008 Thorvald Natvig
  3. * Copyright (C) 2011 Texas Instruments
  4. * author Jyri Sarha
  5. */
  6. /**
  7. @file resample_neon.h
  8. @brief Resampler functions (NEON version)
  9. */
  10. /*
  11. Redistribution and use in source and binary forms, with or without
  12. modification, are permitted provided that the following conditions
  13. are met:
  14. - Redistributions of source code must retain the above copyright
  15. notice, this list of conditions and the following disclaimer.
  16. - Redistributions in binary form must reproduce the above copyright
  17. notice, this list of conditions and the following disclaimer in the
  18. documentation and/or other materials provided with the distribution.
  19. - Neither the name of the Xiph.org Foundation nor the names of its
  20. contributors may be used to endorse or promote products derived from
  21. this software without specific prior written permission.
  22. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  26. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <arm_neon.h>
  35. #ifdef FIXED_POINT
  36. #ifdef __thumb2__
  37. static inline int32_t saturate_32bit_to_16bit(int32_t a) {
  38. int32_t ret;
  39. asm ("ssat %[ret], #16, %[a]"
  40. : [ret] "=&r" (ret)
  41. : [a] "r" (a)
  42. : );
  43. return ret;
  44. }
  45. #else
  46. static inline int32_t saturate_32bit_to_16bit(int32_t a) {
  47. int32_t ret;
  48. asm ("vmov.s32 d0[0], %[a]\n"
  49. "vqmovn.s32 d0, q0\n"
  50. "vmov.s16 %[ret], d0[0]\n"
  51. : [ret] "=&r" (ret)
  52. : [a] "r" (a)
  53. : "q0");
  54. return ret;
  55. }
  56. #endif
  57. #undef WORD2INT
  58. #define WORD2INT(x) (saturate_32bit_to_16bit(x))
  59. #define OVERRIDE_INNER_PRODUCT_SINGLE
  60. /* Only works when len % 4 == 0 */
  61. static inline int32_t inner_product_single(const int16_t *a, const int16_t *b, unsigned int len)
  62. {
  63. int32_t ret;
  64. uint32_t remainder = len % 16;
  65. len = len - remainder;
  66. asm volatile (" cmp %[len], #0\n"
  67. " bne 1f\n"
  68. " vld1.16 {d16}, [%[b]]!\n"
  69. " vld1.16 {d20}, [%[a]]!\n"
  70. " subs %[remainder], %[remainder], #4\n"
  71. " vmull.s16 q0, d16, d20\n"
  72. " beq 5f\n"
  73. " b 4f\n"
  74. "1:"
  75. " vld1.16 {d16, d17, d18, d19}, [%[b]]!\n"
  76. " vld1.16 {d20, d21, d22, d23}, [%[a]]!\n"
  77. " subs %[len], %[len], #16\n"
  78. " vmull.s16 q0, d16, d20\n"
  79. " vmlal.s16 q0, d17, d21\n"
  80. " vmlal.s16 q0, d18, d22\n"
  81. " vmlal.s16 q0, d19, d23\n"
  82. " beq 3f\n"
  83. "2:"
  84. " vld1.16 {d16, d17, d18, d19}, [%[b]]!\n"
  85. " vld1.16 {d20, d21, d22, d23}, [%[a]]!\n"
  86. " subs %[len], %[len], #16\n"
  87. " vmlal.s16 q0, d16, d20\n"
  88. " vmlal.s16 q0, d17, d21\n"
  89. " vmlal.s16 q0, d18, d22\n"
  90. " vmlal.s16 q0, d19, d23\n"
  91. " bne 2b\n"
  92. "3:"
  93. " cmp %[remainder], #0\n"
  94. " beq 5f\n"
  95. "4:"
  96. " vld1.16 {d16}, [%[b]]!\n"
  97. " vld1.16 {d20}, [%[a]]!\n"
  98. " subs %[remainder], %[remainder], #4\n"
  99. " vmlal.s16 q0, d16, d20\n"
  100. " bne 4b\n"
  101. "5:"
  102. " vaddl.s32 q0, d0, d1\n"
  103. " vadd.s64 d0, d0, d1\n"
  104. " vqmovn.s64 d0, q0\n"
  105. " vqrshrn.s32 d0, q0, #15\n"
  106. " vmov.s16 %[ret], d0[0]\n"
  107. : [ret] "=&r" (ret), [a] "+r" (a), [b] "+r" (b),
  108. [len] "+r" (len), [remainder] "+r" (remainder)
  109. :
  110. : "cc", "q0",
  111. "d16", "d17", "d18", "d19",
  112. "d20", "d21", "d22", "d23");
  113. return ret;
  114. }
  115. #elif defined(FLOATING_POINT)
  116. static inline int32_t saturate_float_to_16bit(float a) {
  117. int32_t ret;
  118. asm ("vmov.f32 d0[0], %[a]\n"
  119. "vcvt.s32.f32 d0, d0, #15\n"
  120. "vqrshrn.s32 d0, q0, #15\n"
  121. "vmov.s16 %[ret], d0[0]\n"
  122. : [ret] "=&r" (ret)
  123. : [a] "r" (a)
  124. : "q0");
  125. return ret;
  126. }
  127. #undef WORD2INT
  128. #define WORD2INT(x) (saturate_float_to_16bit(x))
  129. #define OVERRIDE_INNER_PRODUCT_SINGLE
  130. /* Only works when len % 4 == 0 */
  131. static inline float inner_product_single(const float *a, const float *b, unsigned int len)
  132. {
  133. float ret;
  134. uint32_t remainder = len % 16;
  135. len = len - remainder;
  136. asm volatile (" cmp %[len], #0\n"
  137. " bne 1f\n"
  138. " vld1.32 {q4}, [%[b]]!\n"
  139. " vld1.32 {q8}, [%[a]]!\n"
  140. " subs %[remainder], %[remainder], #4\n"
  141. " vmul.f32 q0, q4, q8\n"
  142. " bne 4f\n"
  143. " b 5f\n"
  144. "1:"
  145. " vld1.32 {q4, q5}, [%[b]]!\n"
  146. " vld1.32 {q8, q9}, [%[a]]!\n"
  147. " vld1.32 {q6, q7}, [%[b]]!\n"
  148. " vld1.32 {q10, q11}, [%[a]]!\n"
  149. " subs %[len], %[len], #16\n"
  150. " vmul.f32 q0, q4, q8\n"
  151. " vmul.f32 q1, q5, q9\n"
  152. " vmul.f32 q2, q6, q10\n"
  153. " vmul.f32 q3, q7, q11\n"
  154. " beq 3f\n"
  155. "2:"
  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. " vmla.f32 q0, q4, q8\n"
  162. " vmla.f32 q1, q5, q9\n"
  163. " vmla.f32 q2, q6, q10\n"
  164. " vmla.f32 q3, q7, q11\n"
  165. " bne 2b\n"
  166. "3:"
  167. " vadd.f32 q4, q0, q1\n"
  168. " vadd.f32 q5, q2, q3\n"
  169. " cmp %[remainder], #0\n"
  170. " vadd.f32 q0, q4, q5\n"
  171. " beq 5f\n"
  172. "4:"
  173. " vld1.32 {q6}, [%[b]]!\n"
  174. " vld1.32 {q10}, [%[a]]!\n"
  175. " subs %[remainder], %[remainder], #4\n"
  176. " vmla.f32 q0, q6, q10\n"
  177. " bne 4b\n"
  178. "5:"
  179. " vadd.f32 d0, d0, d1\n"
  180. " vpadd.f32 d0, d0, d0\n"
  181. " vmov.f32 %[ret], d0[0]\n"
  182. : [ret] "=&r" (ret), [a] "+r" (a), [b] "+r" (b),
  183. [len] "+l" (len), [remainder] "+l" (remainder)
  184. :
  185. : "cc", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8",
  186. "q9", "q10", "q11");
  187. return ret;
  188. }
  189. #endif