macros_armv5e.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /***********************************************************************
  2. Copyright (c) 2006-2011, Skype Limited. All rights reserved.
  3. Copyright (c) 2013 Parrot
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. - Redistributions of source code must retain the above copyright notice,
  8. this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. - Neither the name of Internet Society, IETF or IETF Trust, nor the
  13. names of specific contributors, may be used to endorse or promote
  14. products derived from this software without specific prior written
  15. permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  20. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26. POSSIBILITY OF SUCH DAMAGE.
  27. ***********************************************************************/
  28. #ifndef SILK_MACROS_ARMv5E_H
  29. #define SILK_MACROS_ARMv5E_H
  30. /* (a32 * (opus_int32)((opus_int16)(b32))) >> 16 output have to be 32bit int */
  31. #undef silk_SMULWB
  32. static OPUS_INLINE opus_int32 silk_SMULWB_armv5e(opus_int32 a, opus_int16 b)
  33. {
  34. int res;
  35. __asm__(
  36. "#silk_SMULWB\n\t"
  37. "smulwb %0, %1, %2\n\t"
  38. : "=r"(res)
  39. : "r"(a), "r"(b)
  40. );
  41. return res;
  42. }
  43. #define silk_SMULWB(a, b) (silk_SMULWB_armv5e(a, b))
  44. /* a32 + (b32 * (opus_int32)((opus_int16)(c32))) >> 16 output have to be 32bit int */
  45. #undef silk_SMLAWB
  46. static OPUS_INLINE opus_int32 silk_SMLAWB_armv5e(opus_int32 a, opus_int32 b,
  47. opus_int16 c)
  48. {
  49. int res;
  50. __asm__(
  51. "#silk_SMLAWB\n\t"
  52. "smlawb %0, %1, %2, %3\n\t"
  53. : "=r"(res)
  54. : "r"(b), "r"(c), "r"(a)
  55. );
  56. return res;
  57. }
  58. #define silk_SMLAWB(a, b, c) (silk_SMLAWB_armv5e(a, b, c))
  59. /* (a32 * (b32 >> 16)) >> 16 */
  60. #undef silk_SMULWT
  61. static OPUS_INLINE opus_int32 silk_SMULWT_armv5e(opus_int32 a, opus_int32 b)
  62. {
  63. int res;
  64. __asm__(
  65. "#silk_SMULWT\n\t"
  66. "smulwt %0, %1, %2\n\t"
  67. : "=r"(res)
  68. : "r"(a), "r"(b)
  69. );
  70. return res;
  71. }
  72. #define silk_SMULWT(a, b) (silk_SMULWT_armv5e(a, b))
  73. /* a32 + (b32 * (c32 >> 16)) >> 16 */
  74. #undef silk_SMLAWT
  75. static OPUS_INLINE opus_int32 silk_SMLAWT_armv5e(opus_int32 a, opus_int32 b,
  76. opus_int32 c)
  77. {
  78. int res;
  79. __asm__(
  80. "#silk_SMLAWT\n\t"
  81. "smlawt %0, %1, %2, %3\n\t"
  82. : "=r"(res)
  83. : "r"(b), "r"(c), "r"(a)
  84. );
  85. return res;
  86. }
  87. #define silk_SMLAWT(a, b, c) (silk_SMLAWT_armv5e(a, b, c))
  88. /* (opus_int32)((opus_int16)(a3))) * (opus_int32)((opus_int16)(b32)) output have to be 32bit int */
  89. #undef silk_SMULBB
  90. static OPUS_INLINE opus_int32 silk_SMULBB_armv5e(opus_int32 a, opus_int32 b)
  91. {
  92. int res;
  93. __asm__(
  94. "#silk_SMULBB\n\t"
  95. "smulbb %0, %1, %2\n\t"
  96. : "=r"(res)
  97. : "%r"(a), "r"(b)
  98. );
  99. return res;
  100. }
  101. #define silk_SMULBB(a, b) (silk_SMULBB_armv5e(a, b))
  102. /* a32 + (opus_int32)((opus_int16)(b32)) * (opus_int32)((opus_int16)(c32)) output have to be 32bit int */
  103. #undef silk_SMLABB
  104. static OPUS_INLINE opus_int32 silk_SMLABB_armv5e(opus_int32 a, opus_int32 b,
  105. opus_int32 c)
  106. {
  107. int res;
  108. __asm__(
  109. "#silk_SMLABB\n\t"
  110. "smlabb %0, %1, %2, %3\n\t"
  111. : "=r"(res)
  112. : "%r"(b), "r"(c), "r"(a)
  113. );
  114. return res;
  115. }
  116. #define silk_SMLABB(a, b, c) (silk_SMLABB_armv5e(a, b, c))
  117. /* (opus_int32)((opus_int16)(a32)) * (b32 >> 16) */
  118. #undef silk_SMULBT
  119. static OPUS_INLINE opus_int32 silk_SMULBT_armv5e(opus_int32 a, opus_int32 b)
  120. {
  121. int res;
  122. __asm__(
  123. "#silk_SMULBT\n\t"
  124. "smulbt %0, %1, %2\n\t"
  125. : "=r"(res)
  126. : "r"(a), "r"(b)
  127. );
  128. return res;
  129. }
  130. #define silk_SMULBT(a, b) (silk_SMULBT_armv5e(a, b))
  131. /* a32 + (opus_int32)((opus_int16)(b32)) * (c32 >> 16) */
  132. #undef silk_SMLABT
  133. static OPUS_INLINE opus_int32 silk_SMLABT_armv5e(opus_int32 a, opus_int32 b,
  134. opus_int32 c)
  135. {
  136. int res;
  137. __asm__(
  138. "#silk_SMLABT\n\t"
  139. "smlabt %0, %1, %2, %3\n\t"
  140. : "=r"(res)
  141. : "r"(b), "r"(c), "r"(a)
  142. );
  143. return res;
  144. }
  145. #define silk_SMLABT(a, b, c) (silk_SMLABT_armv5e(a, b, c))
  146. /* add/subtract with output saturated */
  147. #undef silk_ADD_SAT32
  148. static OPUS_INLINE opus_int32 silk_ADD_SAT32_armv5e(opus_int32 a, opus_int32 b)
  149. {
  150. int res;
  151. __asm__(
  152. "#silk_ADD_SAT32\n\t"
  153. "qadd %0, %1, %2\n\t"
  154. : "=r"(res)
  155. : "%r"(a), "r"(b)
  156. );
  157. return res;
  158. }
  159. #define silk_ADD_SAT32(a, b) (silk_ADD_SAT32_armv5e(a, b))
  160. #undef silk_SUB_SAT32
  161. static OPUS_INLINE opus_int32 silk_SUB_SAT32_armv5e(opus_int32 a, opus_int32 b)
  162. {
  163. int res;
  164. __asm__(
  165. "#silk_SUB_SAT32\n\t"
  166. "qsub %0, %1, %2\n\t"
  167. : "=r"(res)
  168. : "r"(a), "r"(b)
  169. );
  170. return res;
  171. }
  172. #define silk_SUB_SAT32(a, b) (silk_SUB_SAT32_armv5e(a, b))
  173. #undef silk_CLZ16
  174. static OPUS_INLINE opus_int32 silk_CLZ16_armv5(opus_int16 in16)
  175. {
  176. int res;
  177. __asm__(
  178. "#silk_CLZ16\n\t"
  179. "clz %0, %1;\n"
  180. : "=r"(res)
  181. : "r"(in16<<16|0x8000)
  182. );
  183. return res;
  184. }
  185. #define silk_CLZ16(in16) (silk_CLZ16_armv5(in16))
  186. #undef silk_CLZ32
  187. static OPUS_INLINE opus_int32 silk_CLZ32_armv5(opus_int32 in32)
  188. {
  189. int res;
  190. __asm__(
  191. "#silk_CLZ32\n\t"
  192. "clz %0, %1\n\t"
  193. : "=r"(res)
  194. : "r"(in32)
  195. );
  196. return res;
  197. }
  198. #define silk_CLZ32(in32) (silk_CLZ32_armv5(in32))
  199. #endif /* SILK_MACROS_ARMv5E_H */