2
0

fixed_generic_mipsr1.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* Copyright (C) 2007-2009 Xiph.Org Foundation
  2. Copyright (C) 2003-2008 Jean-Marc Valin
  3. Copyright (C) 2007-2008 CSIRO */
  4. /**
  5. @file fixed_generic.h
  6. @brief Generic fixed-point operations
  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 CELT_FIXED_GENERIC_MIPSR1_H
  30. #define CELT_FIXED_GENERIC_MIPSR1_H
  31. #undef MULT16_32_Q15_ADD
  32. static inline int MULT16_32_Q15_ADD(int a, int b, int c, int d) {
  33. int m;
  34. asm volatile("MULT $ac1, %0, %1" : : "r" ((int)a), "r" ((int)b));
  35. asm volatile("madd $ac1, %0, %1" : : "r" ((int)c), "r" ((int)d));
  36. asm volatile("EXTR.W %0,$ac1, %1" : "=r" (m): "i" (15));
  37. return m;
  38. }
  39. #undef MULT16_32_Q15_SUB
  40. static inline int MULT16_32_Q15_SUB(int a, int b, int c, int d) {
  41. int m;
  42. asm volatile("MULT $ac1, %0, %1" : : "r" ((int)a), "r" ((int)b));
  43. asm volatile("msub $ac1, %0, %1" : : "r" ((int)c), "r" ((int)d));
  44. asm volatile("EXTR.W %0,$ac1, %1" : "=r" (m): "i" (15));
  45. return m;
  46. }
  47. #undef MULT16_16_Q15_ADD
  48. static inline int MULT16_16_Q15_ADD(int a, int b, int c, int d) {
  49. int m;
  50. asm volatile("MULT $ac1, %0, %1" : : "r" ((int)a), "r" ((int)b));
  51. asm volatile("madd $ac1, %0, %1" : : "r" ((int)c), "r" ((int)d));
  52. asm volatile("EXTR.W %0,$ac1, %1" : "=r" (m): "i" (15));
  53. return m;
  54. }
  55. #undef MULT16_16_Q15_SUB
  56. static inline int MULT16_16_Q15_SUB(int a, int b, int c, int d) {
  57. int m;
  58. asm volatile("MULT $ac1, %0, %1" : : "r" ((int)a), "r" ((int)b));
  59. asm volatile("msub $ac1, %0, %1" : : "r" ((int)c), "r" ((int)d));
  60. asm volatile("EXTR.W %0,$ac1, %1" : "=r" (m): "i" (15));
  61. return m;
  62. }
  63. #undef MULT16_32_Q16
  64. static inline int MULT16_32_Q16(int a, int b)
  65. {
  66. int c;
  67. asm volatile("MULT $ac1,%0, %1" : : "r" (a), "r" (b));
  68. asm volatile("EXTR.W %0,$ac1, %1" : "=r" (c): "i" (16));
  69. return c;
  70. }
  71. #undef MULT16_32_P16
  72. static inline int MULT16_32_P16(int a, int b)
  73. {
  74. int c;
  75. asm volatile("MULT $ac1, %0, %1" : : "r" (a), "r" (b));
  76. asm volatile("EXTR_R.W %0,$ac1, %1" : "=r" (c): "i" (16));
  77. return c;
  78. }
  79. #undef MULT16_32_Q15
  80. static inline int MULT16_32_Q15(int a, int b)
  81. {
  82. int c;
  83. asm volatile("MULT $ac1, %0, %1" : : "r" (a), "r" (b));
  84. asm volatile("EXTR.W %0,$ac1, %1" : "=r" (c): "i" (15));
  85. return c;
  86. }
  87. #undef MULT32_32_Q31
  88. static inline int MULT32_32_Q31(int a, int b)
  89. {
  90. int r;
  91. asm volatile("MULT $ac1, %0, %1" : : "r" (a), "r" (b));
  92. asm volatile("EXTR.W %0,$ac1, %1" : "=r" (r): "i" (31));
  93. return r;
  94. }
  95. #undef PSHR32
  96. static inline int PSHR32(int a, int shift)
  97. {
  98. int r;
  99. asm volatile ("SHRAV_R.W %0, %1, %2" :"=r" (r): "r" (a), "r" (shift));
  100. return r;
  101. }
  102. #undef MULT16_16_P15
  103. static inline int MULT16_16_P15(int a, int b)
  104. {
  105. int r;
  106. asm volatile ("mul %0, %1, %2" :"=r" (r): "r" (a), "r" (b));
  107. asm volatile ("SHRA_R.W %0, %1, %2" : "+r" (r): "0" (r), "i"(15));
  108. return r;
  109. }
  110. #endif /* CELT_FIXED_GENERIC_MIPSR1_H */