vq_mipsr1.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #define OVERRIDE_vq_exp_rotation1
  33. static void exp_rotation1(celt_norm *X, int len, int stride, opus_val16 c, opus_val16 s)
  34. {
  35. int i;
  36. opus_val16 ms;
  37. celt_norm *Xptr;
  38. Xptr = X;
  39. ms = NEG16(s);
  40. for (i=0;i<len-stride;i++)
  41. {
  42. celt_norm x1, x2;
  43. x1 = Xptr[0];
  44. x2 = Xptr[stride];
  45. Xptr[stride] = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x2), s, x1), 15));
  46. *Xptr++ = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x1), ms, x2), 15));
  47. }
  48. Xptr = &X[len-2*stride-1];
  49. for (i=len-2*stride-1;i>=0;i--)
  50. {
  51. celt_norm x1, x2;
  52. x1 = Xptr[0];
  53. x2 = Xptr[stride];
  54. Xptr[stride] = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x2), s, x1), 15));
  55. *Xptr-- = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x1), ms, x2), 15));
  56. }
  57. }
  58. #define OVERRIDE_renormalise_vector
  59. void renormalise_vector(celt_norm *X, int N, opus_val16 gain, int arch)
  60. {
  61. int i;
  62. #ifdef FIXED_POINT
  63. int k;
  64. #endif
  65. opus_val32 E = EPSILON;
  66. opus_val16 g;
  67. opus_val32 t;
  68. celt_norm *xptr = X;
  69. int X0, X1;
  70. (void)arch;
  71. asm volatile("mult $ac1, $0, $0");
  72. asm volatile("MTLO %0, $ac1" : :"r" (E));
  73. /*if(N %4)
  74. printf("error");*/
  75. for (i=0;i<N-2;i+=2)
  76. {
  77. X0 = (int)*xptr++;
  78. asm volatile("MADD $ac1, %0, %1" : : "r" (X0), "r" (X0));
  79. X1 = (int)*xptr++;
  80. asm volatile("MADD $ac1, %0, %1" : : "r" (X1), "r" (X1));
  81. }
  82. for (;i<N;i++)
  83. {
  84. X0 = (int)*xptr++;
  85. asm volatile("MADD $ac1, %0, %1" : : "r" (X0), "r" (X0));
  86. }
  87. asm volatile("MFLO %0, $ac1" : "=r" (E));
  88. #ifdef FIXED_POINT
  89. k = celt_ilog2(E)>>1;
  90. #endif
  91. t = VSHR32(E, 2*(k-7));
  92. g = MULT16_16_P15(celt_rsqrt_norm(t),gain);
  93. xptr = X;
  94. for (i=0;i<N;i++)
  95. {
  96. *xptr = EXTRACT16(PSHR32(MULT16_16(g, *xptr), k+1));
  97. xptr++;
  98. }
  99. /*return celt_sqrt(E);*/
  100. }
  101. #endif /* __VQ_MIPSR1_H__ */