fixed_arm5e.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* Copyright (C) 2003 Jean-Marc Valin */
  2. /**
  3. @file fixed_arm5e.h
  4. @brief ARM-tuned fixed-point operations
  5. */
  6. /*
  7. Redistribution and use in source and binary forms, with or without
  8. modification, are permitted provided that the following conditions
  9. are met:
  10. - Redistributions of source code must retain the above copyright
  11. notice, this list of conditions and the following disclaimer.
  12. - Redistributions in binary form must reproduce the above copyright
  13. notice, this list of conditions and the following disclaimer in the
  14. documentation and/or other materials provided with the distribution.
  15. - Neither the name of the Xiph.org Foundation nor the names of its
  16. contributors may be used to endorse or promote products derived from
  17. this software without specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  22. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  26. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef FIXED_ARM5E_H
  31. #define FIXED_ARM5E_H
  32. #undef MULT16_16
  33. static inline spx_word32_t MULT16_16(spx_word16_t x, spx_word16_t y) {
  34. int res;
  35. asm ("smulbb %0,%1,%2;\n"
  36. : "=&r"(res)
  37. : "%r"(x),"r"(y));
  38. return(res);
  39. }
  40. #undef MAC16_16
  41. static inline spx_word32_t MAC16_16(spx_word32_t a, spx_word16_t x, spx_word32_t y) {
  42. int res;
  43. asm ("smlabb %0,%1,%2,%3;\n"
  44. : "=&r"(res)
  45. : "%r"(x),"r"(y),"r"(a));
  46. return(res);
  47. }
  48. #undef MULT16_32_Q15
  49. static inline spx_word32_t MULT16_32_Q15(spx_word16_t x, spx_word32_t y) {
  50. int res;
  51. asm ("smulwb %0,%1,%2;\n"
  52. : "=&r"(res)
  53. : "%r"(y<<1),"r"(x));
  54. return(res);
  55. }
  56. #undef MAC16_32_Q15
  57. static inline spx_word32_t MAC16_32_Q15(spx_word32_t a, spx_word16_t x, spx_word32_t y) {
  58. int res;
  59. asm ("smlawb %0,%1,%2,%3;\n"
  60. : "=&r"(res)
  61. : "%r"(y<<1),"r"(x),"r"(a));
  62. return(res);
  63. }
  64. #undef MULT16_32_Q11
  65. static inline spx_word32_t MULT16_32_Q11(spx_word16_t x, spx_word32_t y) {
  66. int res;
  67. asm ("smulwb %0,%1,%2;\n"
  68. : "=&r"(res)
  69. : "%r"(y<<5),"r"(x));
  70. return(res);
  71. }
  72. #undef MAC16_32_Q11
  73. static inline spx_word32_t MAC16_32_Q11(spx_word32_t a, spx_word16_t x, spx_word32_t y) {
  74. int res;
  75. asm ("smlawb %0,%1,%2,%3;\n"
  76. : "=&r"(res)
  77. : "%r"(y<<5),"r"(x),"r"(a));
  78. return(res);
  79. }
  80. #undef DIV32_16
  81. static inline short DIV32_16(int a, int b)
  82. {
  83. int res=0;
  84. int dead1, dead2, dead3, dead4, dead5;
  85. __asm__ __volatile__ (
  86. "\teor %5, %0, %1\n"
  87. "\tmovs %4, %0\n"
  88. "\trsbmi %0, %0, #0 \n"
  89. "\tmovs %4, %1\n"
  90. "\trsbmi %1, %1, #0 \n"
  91. "\tmov %4, #1\n"
  92. "\tsubs %3, %0, %1, asl #14 \n"
  93. "\torrpl %2, %2, %4, asl #14 \n"
  94. "\tmovpl %0, %3 \n"
  95. "\tsubs %3, %0, %1, asl #13 \n"
  96. "\torrpl %2, %2, %4, asl #13 \n"
  97. "\tmovpl %0, %3 \n"
  98. "\tsubs %3, %0, %1, asl #12 \n"
  99. "\torrpl %2, %2, %4, asl #12 \n"
  100. "\tmovpl %0, %3 \n"
  101. "\tsubs %3, %0, %1, asl #11 \n"
  102. "\torrpl %2, %2, %4, asl #11 \n"
  103. "\tmovpl %0, %3 \n"
  104. "\tsubs %3, %0, %1, asl #10 \n"
  105. "\torrpl %2, %2, %4, asl #10 \n"
  106. "\tmovpl %0, %3 \n"
  107. "\tsubs %3, %0, %1, asl #9 \n"
  108. "\torrpl %2, %2, %4, asl #9 \n"
  109. "\tmovpl %0, %3 \n"
  110. "\tsubs %3, %0, %1, asl #8 \n"
  111. "\torrpl %2, %2, %4, asl #8 \n"
  112. "\tmovpl %0, %3 \n"
  113. "\tsubs %3, %0, %1, asl #7 \n"
  114. "\torrpl %2, %2, %4, asl #7 \n"
  115. "\tmovpl %0, %3 \n"
  116. "\tsubs %3, %0, %1, asl #6 \n"
  117. "\torrpl %2, %2, %4, asl #6 \n"
  118. "\tmovpl %0, %3 \n"
  119. "\tsubs %3, %0, %1, asl #5 \n"
  120. "\torrpl %2, %2, %4, asl #5 \n"
  121. "\tmovpl %0, %3 \n"
  122. "\tsubs %3, %0, %1, asl #4 \n"
  123. "\torrpl %2, %2, %4, asl #4 \n"
  124. "\tmovpl %0, %3 \n"
  125. "\tsubs %3, %0, %1, asl #3 \n"
  126. "\torrpl %2, %2, %4, asl #3 \n"
  127. "\tmovpl %0, %3 \n"
  128. "\tsubs %3, %0, %1, asl #2 \n"
  129. "\torrpl %2, %2, %4, asl #2 \n"
  130. "\tmovpl %0, %3 \n"
  131. "\tsubs %3, %0, %1, asl #1 \n"
  132. "\torrpl %2, %2, %4, asl #1 \n"
  133. "\tmovpl %0, %3 \n"
  134. "\tsubs %3, %0, %1 \n"
  135. "\torrpl %2, %2, %4 \n"
  136. "\tmovpl %0, %3 \n"
  137. "\tmovs %5, %5, lsr #31 \n"
  138. "\trsbne %2, %2, #0 \n"
  139. : "=r" (dead1), "=r" (dead2), "=r" (res),
  140. "=r" (dead3), "=r" (dead4), "=r" (dead5)
  141. : "0" (a), "1" (b), "2" (res)
  142. : "memory", "cc"
  143. );
  144. return res;
  145. }
  146. #endif