vq_bfin.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Copyright (C) 2005 Analog Devices */
  2. /**
  3. @file vq_bfin.h
  4. @author Jean-Marc Valin
  5. @brief Blackfin-optimized vq routine
  6. */
  7. /*
  8. Redistribution and use in source and binary forms, with or without
  9. modification, are permitted provided that the following conditions
  10. are met:
  11. - Redistributions of source code must retain the above copyright
  12. notice, this list of conditions and the following disclaimer.
  13. - Redistributions in binary form must reproduce the above copyright
  14. notice, this list of conditions and the following disclaimer in the
  15. documentation and/or other materials provided with the distribution.
  16. - Neither the name of the Xiph.org Foundation nor the names of its
  17. contributors may be used to endorse or promote products derived from
  18. this software without specific prior written permission.
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  23. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #define OVERRIDE_VQ_NBEST
  32. 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)
  33. {
  34. if (N==1)
  35. {
  36. best_dist[0] = 2147483647;
  37. {
  38. spx_word32_t dist;
  39. __asm__ __volatile__
  40. (
  41. "LC0 = %8;\n\t"
  42. "R2 = 0;\n\t"
  43. "I0 = %6;\n\t"
  44. "B0 = %6;\n\t"
  45. "L0 = %9;\n\t"
  46. "LOOP entries_loop%= LC0;\n\t"
  47. "LOOP_BEGIN entries_loop%=;\n\t"
  48. "%0 = [%4++];\n\t"
  49. "%0 >>= 1;\n\t"
  50. "A0 = %0;\n\t"
  51. "R0.L = W[%1++%7] || R1.L = W[I0++];\n\t"
  52. "LOOP vq_loop%= LC1 = %5;\n\t"
  53. "LOOP_BEGIN vq_loop%=;\n\t"
  54. "%0 = (A0 -= R0.L*R1.L) (IS) || R0.L = W[%1++%7] || R1.L = W[I0++];\n\t"
  55. "LOOP_END vq_loop%=;\n\t"
  56. "%0 = (A0 -= R0.L*R1.L) (IS);\n\t"
  57. "cc = %0 < %2;\n\t"
  58. "if cc %2 = %0;\n\t"
  59. "if cc %3 = R2;\n\t"
  60. "R2 += 1;\n\t"
  61. "LOOP_END entries_loop%=;\n\t"
  62. : "=&D" (dist), "=&a" (codebook), "=&d" (best_dist[0]), "=&d" (nbest[0]), "=&a" (E)
  63. : "a" (len-1), "a" (in), "a" (2), "d" (entries), "d" (len<<1), "1" (codebook), "4" (E), "2" (best_dist[0]), "3" (nbest[0])
  64. : "R0", "R1", "R2", "I0", "L0", "B0", "A0", "cc", "memory"
  65. );
  66. }
  67. } else {
  68. int i,k,used;
  69. used = 0;
  70. for (i=0;i<entries;i++)
  71. {
  72. spx_word32_t dist;
  73. __asm__
  74. (
  75. "%0 >>= 1;\n\t"
  76. "A0 = %0;\n\t"
  77. "I0 = %3;\n\t"
  78. "L0 = 0;\n\t"
  79. "R0.L = W[%1++%4] || R1.L = W[I0++];\n\t"
  80. "LOOP vq_loop%= LC0 = %2;\n\t"
  81. "LOOP_BEGIN vq_loop%=;\n\t"
  82. "%0 = (A0 -= R0.L*R1.L) (IS) || R0.L = W[%1++%4] || R1.L = W[I0++];\n\t"
  83. "LOOP_END vq_loop%=;\n\t"
  84. "%0 = (A0 -= R0.L*R1.L) (IS);\n\t"
  85. : "=D" (dist), "=a" (codebook)
  86. : "a" (len-1), "a" (in), "a" (2), "1" (codebook), "0" (E[i])
  87. : "R0", "R1", "I0", "L0", "A0"
  88. );
  89. if (i<N || dist<best_dist[N-1])
  90. {
  91. for (k=N-1; (k >= 1) && (k > used || dist < best_dist[k-1]); k--)
  92. {
  93. best_dist[k]=best_dist[k-1];
  94. nbest[k] = nbest[k-1];
  95. }
  96. best_dist[k]=dist;
  97. nbest[k]=i;
  98. used++;
  99. }
  100. }
  101. }
  102. }