cb_search_bfin.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* Copyright (C) 2005 Analog Devices */
  2. /**
  3. @author Jean-Marc Valin
  4. @file cb_search_bfin.h
  5. @brief Fixed codebook functions (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. #include "bfin.h"
  32. #define OVERRIDE_COMPUTE_WEIGHTED_CODEBOOK
  33. void compute_weighted_codebook(const signed char *shape_cb, const spx_word16_t *r, spx_word16_t *resp, spx_word16_t *resp2, spx_word32_t *E, int shape_cb_size, int subvect_size, char *stack)
  34. {
  35. int i;
  36. for (i=0;i<shape_cb_size;i++)
  37. {
  38. __asm__ __volatile__ (
  39. "P0 = %0;\n\t"
  40. "LC0 = P0;\n\t"
  41. "P1 = %1;\n\t"
  42. "P2 = %2;\n\t"
  43. "P3 = %3;\n\t"
  44. "P0 = 1;\n\t"
  45. "L0 = 0;\n\t"
  46. "L1 = 0;\n\t"
  47. "R2 = 0;\n\t"
  48. "A1 = 0;\n\t"
  49. "LOOP outer%= LC0;\n\t"
  50. "LOOP_BEGIN outer%=;\n\t"
  51. "A0 = 0;\n\t"
  52. "P4 = P1;\n\t"
  53. "I1 = P2;\n\t"
  54. "R0 = B[P4++] (X) || R1.L = W[I1--];\n\t"
  55. "LOOP inner%= LC1 = P0;\n\t"
  56. "LOOP_BEGIN inner%=;\n\t"
  57. "A0 += R0.L*R1.L (IS) || R0 = B[P4++] (X) || R1.L = W[I1--];\n\t"
  58. "LOOP_END inner%=;\n\t"
  59. "R0 = A0;\n\t"
  60. "R0 >>>= 13;\n\t"
  61. "A1 += R0.L*R0.L (IS);\n\t"
  62. "W[P3++] = R0;\n\t"
  63. "P0 += 1;\n\t"
  64. "P2 += 2;\n\t"
  65. "LOOP_END outer%=;\n\t"
  66. "P4 = %4;\n\t"
  67. "R1 = A1;\n\t"
  68. "[P4] = R1;\n\t"
  69. :
  70. : "m" (subvect_size), "m" (shape_cb), "m" (r), "m" (resp), "m" (E)
  71. : "A0", "P0", "P1", "P2", "P3", "P4", "R0", "R1", "R2", "I0", "I1", "L0",
  72. "L1", "A0", "A1", "memory", "ASTAT" BFIN_HWLOOP0_REGS BFIN_HWLOOP1_REGS
  73. );
  74. shape_cb += subvect_size;
  75. resp += subvect_size;
  76. E++;
  77. }
  78. }
  79. #define OVERRIDE_TARGET_UPDATE
  80. static inline void target_update(spx_word16_t *t, spx_word16_t g, spx_word16_t *r, int len)
  81. {
  82. if (!len)
  83. return;
  84. __asm__ __volatile__
  85. (
  86. "I0 = %0;\n\t"
  87. "I1 = %1;\n\t"
  88. "L0 = 0;\n\t"
  89. "L1 = 0;\n\t"
  90. "R2 = 4096;\n\t"
  91. "LOOP tupdate%= LC0 = %3;\n\t"
  92. "LOOP_BEGIN tupdate%=;\n\t"
  93. "R0.L = W[I0] || R1.L = W[I1++];\n\t"
  94. "R1 = (A1 = R1.L*%2.L) (IS);\n\t"
  95. "R1 = R1 + R2;\n\t"
  96. "R1 >>>= 13;\n\t"
  97. "R0.L = R0.L - R1.L;\n\t"
  98. "W[I0++] = R0.L;\n\t"
  99. "LOOP_END tupdate%=;\n\t"
  100. :
  101. : "a" (t), "a" (r), "d" (g), "a" (len)
  102. : "R0", "R1", "R2", "A1", "I0", "I1", "L0", "L1", "ASTAT" BFIN_HWLOOP0_REGS
  103. );
  104. }