pitch_mipsr1.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* Copyright (c) 2007-2008 CSIRO
  2. Copyright (c) 2007-2009 Xiph.Org Foundation
  3. Written by Jean-Marc Valin */
  4. /**
  5. @file pitch.h
  6. @brief Pitch analysis
  7. */
  8. /*
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions
  11. are met:
  12. - Redistributions of source code must retain the above copyright
  13. notice, this list of conditions and the following disclaimer.
  14. - Redistributions in binary form must reproduce the above copyright
  15. notice, this list of conditions and the following disclaimer in the
  16. documentation and/or other materials provided with the distribution.
  17. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  21. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  25. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef PITCH_MIPSR1_H
  30. #define PITCH_MIPSR1_H
  31. #define OVERRIDE_DUAL_INNER_PROD
  32. static inline void dual_inner_prod(const opus_val16 *x, const opus_val16 *y01, const opus_val16 *y02,
  33. int N, opus_val32 *xy1, opus_val32 *xy2, int arch)
  34. {
  35. int j;
  36. opus_val32 xy01=0;
  37. opus_val32 xy02=0;
  38. (void)arch;
  39. asm volatile("MULT $ac1, $0, $0");
  40. asm volatile("MULT $ac2, $0, $0");
  41. /* Compute the norm of X+Y and X-Y as |X|^2 + |Y|^2 +/- sum(xy) */
  42. for (j=0;j<N;j++)
  43. {
  44. asm volatile("MADD $ac1, %0, %1" : : "r" ((int)x[j]), "r" ((int)y01[j]));
  45. asm volatile("MADD $ac2, %0, %1" : : "r" ((int)x[j]), "r" ((int)y02[j]));
  46. ++j;
  47. asm volatile("MADD $ac1, %0, %1" : : "r" ((int)x[j]), "r" ((int)y01[j]));
  48. asm volatile("MADD $ac2, %0, %1" : : "r" ((int)x[j]), "r" ((int)y02[j]));
  49. }
  50. asm volatile ("mflo %0, $ac1": "=r"(xy01));
  51. asm volatile ("mflo %0, $ac2": "=r"(xy02));
  52. *xy1 = xy01;
  53. *xy2 = xy02;
  54. }
  55. static inline void xcorr_kernel_mips(const opus_val16 * x,
  56. const opus_val16 * y, opus_val32 sum[4], int len)
  57. {
  58. int j;
  59. opus_val16 y_0, y_1, y_2, y_3;
  60. opus_int64 sum_0, sum_1, sum_2, sum_3;
  61. sum_0 = (opus_int64)sum[0];
  62. sum_1 = (opus_int64)sum[1];
  63. sum_2 = (opus_int64)sum[2];
  64. sum_3 = (opus_int64)sum[3];
  65. y_3=0; /* gcc doesn't realize that y_3 can't be used uninitialized */
  66. y_0=*y++;
  67. y_1=*y++;
  68. y_2=*y++;
  69. for (j=0;j<len-3;j+=4)
  70. {
  71. opus_val16 tmp;
  72. tmp = *x++;
  73. y_3=*y++;
  74. sum_0 = __builtin_mips_madd( sum_0, tmp, y_0);
  75. sum_1 = __builtin_mips_madd( sum_1, tmp, y_1);
  76. sum_2 = __builtin_mips_madd( sum_2, tmp, y_2);
  77. sum_3 = __builtin_mips_madd( sum_3, tmp, y_3);
  78. tmp=*x++;
  79. y_0=*y++;
  80. sum_0 = __builtin_mips_madd( sum_0, tmp, y_1 );
  81. sum_1 = __builtin_mips_madd( sum_1, tmp, y_2 );
  82. sum_2 = __builtin_mips_madd( sum_2, tmp, y_3);
  83. sum_3 = __builtin_mips_madd( sum_3, tmp, y_0);
  84. tmp=*x++;
  85. y_1=*y++;
  86. sum_0 = __builtin_mips_madd( sum_0, tmp, y_2 );
  87. sum_1 = __builtin_mips_madd( sum_1, tmp, y_3 );
  88. sum_2 = __builtin_mips_madd( sum_2, tmp, y_0);
  89. sum_3 = __builtin_mips_madd( sum_3, tmp, y_1);
  90. tmp=*x++;
  91. y_2=*y++;
  92. sum_0 = __builtin_mips_madd( sum_0, tmp, y_3 );
  93. sum_1 = __builtin_mips_madd( sum_1, tmp, y_0 );
  94. sum_2 = __builtin_mips_madd( sum_2, tmp, y_1);
  95. sum_3 = __builtin_mips_madd( sum_3, tmp, y_2);
  96. }
  97. if (j++<len)
  98. {
  99. opus_val16 tmp = *x++;
  100. y_3=*y++;
  101. sum_0 = __builtin_mips_madd( sum_0, tmp, y_0 );
  102. sum_1 = __builtin_mips_madd( sum_1, tmp, y_1 );
  103. sum_2 = __builtin_mips_madd( sum_2, tmp, y_2);
  104. sum_3 = __builtin_mips_madd( sum_3, tmp, y_3);
  105. }
  106. if (j++<len)
  107. {
  108. opus_val16 tmp=*x++;
  109. y_0=*y++;
  110. sum_0 = __builtin_mips_madd( sum_0, tmp, y_1 );
  111. sum_1 = __builtin_mips_madd( sum_1, tmp, y_2 );
  112. sum_2 = __builtin_mips_madd( sum_2, tmp, y_3);
  113. sum_3 = __builtin_mips_madd( sum_3, tmp, y_0);
  114. }
  115. if (j<len)
  116. {
  117. opus_val16 tmp=*x++;
  118. y_1=*y++;
  119. sum_0 = __builtin_mips_madd( sum_0, tmp, y_2 );
  120. sum_1 = __builtin_mips_madd( sum_1, tmp, y_3 );
  121. sum_2 = __builtin_mips_madd( sum_2, tmp, y_0);
  122. sum_3 = __builtin_mips_madd( sum_3, tmp, y_1);
  123. }
  124. sum[0] = (opus_val32)sum_0;
  125. sum[1] = (opus_val32)sum_1;
  126. sum[2] = (opus_val32)sum_2;
  127. sum[3] = (opus_val32)sum_3;
  128. }
  129. #define OVERRIDE_XCORR_KERNEL
  130. #define xcorr_kernel(x, y, sum, len, arch) \
  131. ((void)(arch), xcorr_kernel_mips(x, y, sum, len))
  132. #endif /* PITCH_MIPSR1_H */