vq_mipsr1.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* Copyright (c) 2007-2008 CSIRO
  2. Copyright (c) 2007-2009 Xiph.Org Foundation
  3. Written by Jean-Marc Valin */
  4. /*
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions
  7. are met:
  8. - Redistributions of source code must retain the above copyright
  9. notice, this list of conditions and the following disclaimer.
  10. - Redistributions in binary form must reproduce the above copyright
  11. notice, this list of conditions and the following disclaimer in the
  12. documentation and/or other materials provided with the distribution.
  13. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  14. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  15. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  16. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  17. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  21. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef __VQ_MIPSR1_H__
  26. #define __VQ_MIPSR1_H__
  27. #ifdef HAVE_CONFIG_H
  28. #include "config.h"
  29. #endif
  30. #include "mathops.h"
  31. #include "arch.h"
  32. static unsigned extract_collapse_mask(int *iy, int N, int B);
  33. static void normalise_residual(int * OPUS_RESTRICT iy, celt_norm * OPUS_RESTRICT X, int N, opus_val32 Ryy, opus_val16 gain);
  34. static void exp_rotation(celt_norm *X, int len, int dir, int stride, int K, int spread);
  35. static void renormalise_vector_mips(celt_norm *X, int N, opus_val16 gain, int arch);
  36. #define OVERRIDE_vq_exp_rotation1
  37. static void exp_rotation1(celt_norm *X, int len, int stride, opus_val16 c, opus_val16 s)
  38. {
  39. int i;
  40. opus_val16 ms;
  41. celt_norm *Xptr;
  42. Xptr = X;
  43. ms = NEG16(s);
  44. for (i=0;i<len-stride;i++)
  45. {
  46. celt_norm x1, x2;
  47. x1 = Xptr[0];
  48. x2 = Xptr[stride];
  49. Xptr[stride] = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x2), s, x1), 15));
  50. *Xptr++ = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x1), ms, x2), 15));
  51. }
  52. Xptr = &X[len-2*stride-1];
  53. for (i=len-2*stride-1;i>=0;i--)
  54. {
  55. celt_norm x1, x2;
  56. x1 = Xptr[0];
  57. x2 = Xptr[stride];
  58. Xptr[stride] = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x2), s, x1), 15));
  59. *Xptr-- = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x1), ms, x2), 15));
  60. }
  61. }
  62. #define OVERRIDE_renormalise_vector
  63. #define renormalise_vector(X, N, gain, arch) \
  64. (renormalise_vector_mips(X, N, gain, arch))
  65. void renormalise_vector_mips(celt_norm *X, int N, opus_val16 gain, int arch)
  66. {
  67. int i;
  68. #ifdef FIXED_POINT
  69. int k;
  70. #endif
  71. opus_val32 E = EPSILON;
  72. opus_val16 g;
  73. opus_val32 t;
  74. celt_norm *xptr = X;
  75. int X0, X1;
  76. (void)arch;
  77. asm volatile("mult $ac1, $0, $0");
  78. asm volatile("MTLO %0, $ac1" : :"r" (E));
  79. /*if(N %4)
  80. printf("error");*/
  81. for (i=0;i<N-2;i+=2)
  82. {
  83. X0 = (int)*xptr++;
  84. asm volatile("MADD $ac1, %0, %1" : : "r" (X0), "r" (X0));
  85. X1 = (int)*xptr++;
  86. asm volatile("MADD $ac1, %0, %1" : : "r" (X1), "r" (X1));
  87. }
  88. for (;i<N;i++)
  89. {
  90. X0 = (int)*xptr++;
  91. asm volatile("MADD $ac1, %0, %1" : : "r" (X0), "r" (X0));
  92. }
  93. asm volatile("MFLO %0, $ac1" : "=r" (E));
  94. #ifdef FIXED_POINT
  95. k = celt_ilog2(E)>>1;
  96. #endif
  97. t = VSHR32(E, 2*(k-7));
  98. g = MULT16_16_P15(celt_rsqrt_norm(t),gain);
  99. xptr = X;
  100. for (i=0;i<N;i++)
  101. {
  102. *xptr = EXTRACT16(PSHR32(MULT16_16(g, *xptr), k+1));
  103. xptr++;
  104. }
  105. /*return celt_sqrt(E);*/
  106. }
  107. #endif /* __VQ_MIPSR1_H__ */