quant_lsp_bfin.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* Copyright (C) 2006 David Rowe */
  2. /**
  3. @file quant_lsp_bfin.h
  4. @author David Rowe
  5. @brief Various compatibility routines for Speex (Blackfin version)
  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_LSP_QUANT
  32. #ifdef OVERRIDE_LSP_QUANT
  33. /*
  34. Note http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html
  35. well tell you all the magic resgister constraints used below
  36. for gcc in-line asm.
  37. */
  38. static int lsp_quant(
  39. spx_word16_t *x,
  40. const signed char *cdbk,
  41. int nbVec,
  42. int nbDim
  43. )
  44. {
  45. int j;
  46. spx_word32_t best_dist=1<<30;
  47. int best_id=0;
  48. __asm__ __volatile__
  49. (
  50. " %0 = 1 (X);\n\t" /* %0: best_dist */
  51. " %0 <<= 30;\n\t"
  52. " %1 = 0 (X);\n\t" /* %1: best_i */
  53. " P2 = %3\n\t" /* P2: ptr to cdbk */
  54. " R5 = 0;\n\t" /* R5: best cb entry */
  55. " R0 = %5;\n\t" /* set up circ addr */
  56. " R0 <<= 1;\n\t"
  57. " L0 = R0;\n\t"
  58. " I0 = %2;\n\t" /* %2: &x[0] */
  59. " B0 = %2;\n\t"
  60. " R2.L = W [I0++];\n\t"
  61. " LSETUP (1f, 2f) LC0 = %4;\n\t"
  62. "1: R3 = 0;\n\t" /* R3: dist */
  63. " LSETUP (3f, 4f) LC1 = %5;\n\t"
  64. "3: R1 = B [P2++] (X);\n\t"
  65. " R1 <<= 5;\n\t"
  66. " R0.L = R2.L - R1.L || R2.L = W [I0++];\n\t"
  67. " R0 = R0.L*R0.L;\n\t"
  68. "4: R3 = R3 + R0;\n\t"
  69. " cc =R3<%0;\n\t"
  70. " if cc %0=R3;\n\t"
  71. " if cc %1=R5;\n\t"
  72. "2: R5 += 1;\n\t"
  73. " L0 = 0;\n\t"
  74. : "=&d" (best_dist), "=&d" (best_id)
  75. : "a" (x), "b" (cdbk), "a" (nbVec), "a" (nbDim)
  76. : "I0", "P2", "R0", "R1", "R2", "R3", "R5", "L0", "B0", "A0"
  77. );
  78. for (j=0;j<nbDim;j++) {
  79. x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
  80. }
  81. return best_id;
  82. }
  83. #endif
  84. #define OVERRIDE_LSP_WEIGHT_QUANT
  85. #ifdef OVERRIDE_LSP_WEIGHT_QUANT
  86. /*
  87. Note http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html
  88. well tell you all the magic resgister constraints used below
  89. for gcc in-line asm.
  90. */
  91. static int lsp_weight_quant(
  92. spx_word16_t *x,
  93. spx_word16_t *weight,
  94. const signed char *cdbk,
  95. int nbVec,
  96. int nbDim
  97. )
  98. {
  99. int j;
  100. spx_word32_t best_dist=1<<30;
  101. int best_id=0;
  102. __asm__ __volatile__
  103. (
  104. " %0 = 1 (X);\n\t" /* %0: best_dist */
  105. " %0 <<= 30;\n\t"
  106. " %1 = 0 (X);\n\t" /* %1: best_i */
  107. " P2 = %4\n\t" /* P2: ptr to cdbk */
  108. " R5 = 0;\n\t" /* R5: best cb entry */
  109. " R0 = %6;\n\t" /* set up circ addr */
  110. " R0 <<= 1;\n\t"
  111. " L0 = R0;\n\t"
  112. " L1 = R0;\n\t"
  113. " I0 = %2;\n\t" /* %2: &x[0] */
  114. " I1 = %3;\n\t" /* %3: &weight[0] */
  115. " B0 = %2;\n\t"
  116. " B1 = %3;\n\t"
  117. " LSETUP (1f, 2f) LC0 = %5;\n\t"
  118. "1: R3 = 0 (X);\n\t" /* R3: dist */
  119. " LSETUP (3f, 4f) LC1 = %6;\n\t"
  120. "3: R0.L = W [I0++] || R2.L = W [I1++];\n\t"
  121. " R1 = B [P2++] (X);\n\t"
  122. " R1 <<= 5;\n\t"
  123. " R0.L = R0.L - R1.L;\n\t"
  124. " R0 = R0.L*R0.L;\n\t"
  125. " A1 = R2.L*R0.L (M,IS);\n\t"
  126. " A1 = A1 >>> 16;\n\t"
  127. " R1 = (A1 += R2.L*R0.H) (IS);\n\t"
  128. "4: R3 = R3 + R1;\n\t"
  129. " cc =R3<%0;\n\t"
  130. " if cc %0=R3;\n\t"
  131. " if cc %1=R5;\n\t"
  132. "2: R5 += 1;\n\t"
  133. " L0 = 0;\n\t"
  134. " L1 = 0;\n\t"
  135. : "=&d" (best_dist), "=&d" (best_id)
  136. : "a" (x), "a" (weight), "b" (cdbk), "a" (nbVec), "a" (nbDim)
  137. : "I0", "I1", "P2", "R0", "R1", "R2", "R3", "R5", "A1",
  138. "L0", "L1", "B0", "B1"
  139. );
  140. for (j=0;j<nbDim;j++) {
  141. x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
  142. }
  143. return best_id;
  144. }
  145. #endif