ltp_arm4.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* Copyright (C) 2004 Jean-Marc Valin */
  2. /**
  3. @file ltp_arm4.h
  4. @brief Long-Term Prediction functions (ARM4 version)
  5. */
  6. /*
  7. Redistribution and use in source and binary forms, with or without
  8. modification, are permitted provided that the following conditions
  9. are met:
  10. - Redistributions of source code must retain the above copyright
  11. notice, this list of conditions and the following disclaimer.
  12. - Redistributions in binary form must reproduce the above copyright
  13. notice, this list of conditions and the following disclaimer in the
  14. documentation and/or other materials provided with the distribution.
  15. - Neither the name of the Xiph.org Foundation nor the names of its
  16. contributors may be used to endorse or promote products derived from
  17. this software without specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  22. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  26. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #define OVERRIDE_INNER_PROD
  31. spx_word32_t inner_prod(const spx_word16_t *x, const spx_word16_t *y, int len)
  32. {
  33. spx_word32_t sum1=0,sum2=0;
  34. spx_word16_t *deadx, *deady;
  35. int deadlen, dead1, dead2, dead3, dead4, dead5, dead6;
  36. __asm__ __volatile__ (
  37. "\tldrsh %5, [%0], #2 \n"
  38. "\tldrsh %6, [%1], #2 \n"
  39. ".inner_prod_loop%=:\n"
  40. "\tsub %7, %7, %7\n"
  41. "\tsub %10, %10, %10\n"
  42. "\tldrsh %8, [%0], #2 \n"
  43. "\tldrsh %9, [%1], #2 \n"
  44. "\tmla %7, %5, %6, %7\n"
  45. "\tldrsh %5, [%0], #2 \n"
  46. "\tldrsh %6, [%1], #2 \n"
  47. "\tmla %10, %8, %9, %10\n"
  48. "\tldrsh %8, [%0], #2 \n"
  49. "\tldrsh %9, [%1], #2 \n"
  50. "\tmla %7, %5, %6, %7\n"
  51. "\tldrsh %5, [%0], #2 \n"
  52. "\tldrsh %6, [%1], #2 \n"
  53. "\tmla %10, %8, %9, %10\n"
  54. "\tldrsh %8, [%0], #2 \n"
  55. "\tldrsh %9, [%1], #2 \n"
  56. "\tmla %7, %5, %6, %7\n"
  57. "\tldrsh %5, [%0], #2 \n"
  58. "\tldrsh %6, [%1], #2 \n"
  59. "\tmla %10, %8, %9, %10\n"
  60. "\tldrsh %8, [%0], #2 \n"
  61. "\tldrsh %9, [%1], #2 \n"
  62. "\tmla %7, %5, %6, %7\n"
  63. "\tldrsh %5, [%0], #2 \n"
  64. "\tldrsh %6, [%1], #2 \n"
  65. "\tmla %10, %8, %9, %10\n"
  66. "\tsubs %4, %4, #1\n"
  67. "\tadd %2, %2, %7, asr #5\n"
  68. "\tadd %3, %3, %10, asr #5\n"
  69. "\tbne .inner_prod_loop%=\n"
  70. : "=r" (deadx), "=r" (deady), "+r" (sum1), "+r" (sum2),
  71. "=r" (deadlen), "=r" (dead1), "=r" (dead2), "=r" (dead3),
  72. "=r" (dead4), "=r" (dead5), "=r" (dead6)
  73. : "0" (x), "1" (y), "4" (len>>3)
  74. : "cc"
  75. );
  76. return (sum1+sum2)>>1;
  77. }
  78. #define OVERRIDE_PITCH_XCORR
  79. void pitch_xcorr(const spx_word16_t *_x, const spx_word16_t *_y, spx_word32_t *corr, int len, int nb_pitch, char *stack)
  80. {
  81. int i,j;
  82. for (i=0;i<nb_pitch;i+=4)
  83. {
  84. /* Compute correlation*/
  85. //corr[nb_pitch-1-i]=inner_prod(x, _y+i, len);
  86. spx_word32_t sum1=0;
  87. spx_word32_t sum2=0;
  88. spx_word32_t sum3=0;
  89. spx_word32_t sum4=0;
  90. const spx_word16_t *y = _y+i;
  91. const spx_word16_t *x = _x;
  92. spx_word32_t y0, y1, y2, y3;
  93. y0=*y++;
  94. y1=*y++;
  95. y2=*y++;
  96. y3=*y++;
  97. for (j=0;j<len;j+=4)
  98. {
  99. spx_word32_t part1, part2, part3, part4, x0;
  100. spx_word32_t dead1;
  101. __asm__ __volatile__ (
  102. #ifdef SHORTCUTS
  103. "\tldrsh %10, [%8], #4 \n"
  104. "\tmul %4, %10, %0 \n"
  105. "\tldrsh %15, [%8], #4 \n"
  106. "\tmul %5, %10, %1 \n"
  107. "\tldrsh %0, [%9], #2 \n"
  108. "\tmul %6, %10, %2 \n"
  109. "\tldrsh %1, [%9], #2 \n"
  110. "\tmul %7, %10, %3 \n"
  111. "\tmla %4, %15, %2, %4 \n"
  112. "\tldrsh %2, [%9], #2 \n"
  113. "\tmla %5, %15, %3, %5 \n"
  114. "\tldrsh %3, [%9], #2 \n"
  115. "\tmla %6, %15, %0, %6 \n"
  116. "\tmla %7, %15, %1, %7 \n"
  117. #else
  118. "\tldrsh %10, [%8], #2 \n"
  119. "\tmul %4, %10, %0 \n"
  120. "\tmul %5, %10, %1 \n"
  121. "\tmul %6, %10, %2 \n"
  122. "\tmul %7, %10, %3 \n"
  123. "\tldrsh %10, [%8], #2 \n"
  124. "\tldrsh %0, [%9], #2 \n"
  125. "\tmla %4, %10, %1, %4 \n"
  126. "\tmla %5, %10, %2, %5 \n"
  127. "\tmla %6, %10, %3, %6 \n"
  128. "\tmla %7, %10, %0, %7 \n"
  129. "\tldrsh %10, [%8], #2 \n"
  130. "\tldrsh %1, [%9], #2 \n"
  131. "\tmla %4, %10, %2, %4 \n"
  132. "\tmla %5, %10, %3, %5 \n"
  133. "\tmla %6, %10, %0, %6 \n"
  134. "\tmla %7, %10, %1, %7 \n"
  135. "\tldrsh %10, [%8], #2 \n"
  136. "\tldrsh %2, [%9], #2 \n"
  137. "\tmla %4, %10, %3, %4 \n"
  138. "\tmla %5, %10, %0, %5 \n"
  139. "\tmla %6, %10, %1, %6 \n"
  140. "\tmla %7, %10, %2, %7 \n"
  141. "\tldrsh %3, [%9], #2 \n"
  142. #endif
  143. "\tldr %10, %11 \n"
  144. "\tldr %15, %12 \n"
  145. "\tadd %4, %10, %4, asr #6 \n"
  146. "\tstr %4, %11 \n"
  147. "\tldr %10, %13 \n"
  148. "\tadd %5, %15, %5, asr #6 \n"
  149. "\tstr %5, %12 \n"
  150. "\tldr %15, %14 \n"
  151. "\tadd %6, %10, %6, asr #6 \n"
  152. "\tadd %7, %15, %7, asr #6 \n"
  153. "\tstr %6, %13 \n"
  154. "\tstr %7, %14 \n"
  155. : "+r" (y0), "+r" (y1), "+r" (y2), "+r" (y3),
  156. "=r" (part1), "=r" (part2), "=r" (part3), "=r" (part4),
  157. "+r" (x), "+r" (y), "=r" (x0), "+m" (sum1),
  158. "+m" (sum2), "+m" (sum3), "+m" (sum4), "=r" (dead1)
  159. :
  160. : "cc", "memory"
  161. );
  162. }
  163. corr[nb_pitch-1-i]=sum1;
  164. corr[nb_pitch-2-i]=sum2;
  165. corr[nb_pitch-3-i]=sum3;
  166. corr[nb_pitch-4-i]=sum4;
  167. }
  168. }