vq_arm4.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* Copyright (C) 2004 Jean-Marc Valin */
  2. /**
  3. @file vq_arm4.h
  4. @brief ARM4-optimized vq routine
  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_VQ_NBEST
  31. void vq_nbest(spx_word16_t *in, const spx_word16_t *codebook, int len, int entries, spx_word32_t *E, int N, int *nbest, spx_word32_t *best_dist, char *stack)
  32. {
  33. int i,j;
  34. for (i=0;i<entries;i+=4)
  35. {
  36. #if 1
  37. spx_word32_t dist1, dist2, dist3, dist4;
  38. int dead1, dead2, dead3, dead4, dead5, dead6, dead7, dead8;
  39. __asm__ __volatile__ (
  40. "mov %0, #0 \n\t"
  41. "mov %1, #0 \n\t"
  42. "mov %2, #0 \n\t"
  43. "mov %3, #0 \n\t"
  44. "mov %10, %4 \n\t"
  45. "add %4, %4, %4\n\t"
  46. ".vqloop%=:\n\t"
  47. "ldrsh %7, [%5], #2 \n\t"
  48. "ldrsh %8, [%6] \n\t"
  49. "mov %9, %6 \n\t"
  50. "mla %0, %7, %8, %0 \n\t"
  51. "ldrsh %8, [%9, %4]! \n\t"
  52. "mla %1, %7, %8, %1 \n\t"
  53. "ldrsh %8, [%9, %4]!\n\t"
  54. "mla %2, %7, %8, %2 \n\t"
  55. "ldrsh %8, [%9, %4]! \n\t"
  56. "mla %3, %7, %8, %3 \n\t"
  57. "subs %10, %10, #1 \n\t"
  58. "add %6, %6, #2 \n\t"
  59. "bne .vqloop%="
  60. : "=r" (dist1), "=r" (dist2), "=r" (dist3), "=r" (dist4),
  61. "=r" (dead1), "=r" (dead2), "=r" (codebook), "=r" (dead4),
  62. "=r" (dead5), "=r" (dead6), "=r" (dead7)
  63. : "4" (len), "5" (in), "6" (codebook)
  64. : "cc");
  65. #else
  66. dist1=dist2=dist3=dist4=0;
  67. /* spx_word32_t dist1=0;
  68. spx_word32_t dist2=0;
  69. spx_word32_t dist3=0;
  70. spx_word32_t dist4=0;*/
  71. for (j=0;j<2;j++)
  72. {
  73. const spx_word16_t *code = codebook;
  74. dist1 = MAC16_16(dist1,in[j],*code);
  75. code += len;
  76. dist2 = MAC16_16(dist2,in[j],*code);
  77. code += len;
  78. dist3 = MAC16_16(dist3,in[j],*code);
  79. code += len;
  80. dist4 = MAC16_16(dist4,in[j],*code);
  81. codebook++;
  82. }
  83. #endif
  84. dist1=SUB32(SHR(*E++,1),dist1);
  85. if (dist1<*best_dist || i==0)
  86. {
  87. *best_dist=dist1;
  88. *nbest=i;
  89. }
  90. dist2=SUB32(SHR(*E++,1),dist2);
  91. if (dist2<*best_dist)
  92. {
  93. *best_dist=dist2;
  94. *nbest=i+1;
  95. }
  96. dist3=SUB32(SHR(*E++,1),dist3);
  97. if (dist3<*best_dist)
  98. {
  99. *best_dist=dist3;
  100. *nbest=i+2;
  101. }
  102. dist4=SUB32(SHR(*E++,1),dist4);
  103. if (dist4<*best_dist)
  104. {
  105. *best_dist=dist4;
  106. *nbest=i+3;
  107. }
  108. codebook += 3*len;
  109. }
  110. }