macros_armv5e.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. /* This macro only avoids the undefined behaviour from a left shift of
  31. a negative value. It should only be used in macros that can't include
  32. SigProc_FIX.h. In other cases, use silk_LSHIFT32(). */
  33. #define SAFE_SHL(a,b) ((opus_int32)((opus_uint32)(a) << (b)))
  34. /* (a32 * (opus_int32)((opus_int16)(b32))) >> 16 output have to be 32bit int */
  35. #undef silk_SMULWB
  36. static OPUS_INLINE opus_int32 silk_SMULWB_armv5e(opus_int32 a, opus_int16 b)
  37. {
  38. int res;
  39. __asm__(
  40. "#silk_SMULWB\n\t"
  41. "smulwb %0, %1, %2\n\t"
  42. : "=r"(res)
  43. : "r"(a), "r"(b)
  44. );
  45. return res;
  46. }
  47. #define silk_SMULWB(a, b) (silk_SMULWB_armv5e(a, b))
  48. /* a32 + (b32 * (opus_int32)((opus_int16)(c32))) >> 16 output have to be 32bit int */
  49. #undef silk_SMLAWB
  50. static OPUS_INLINE opus_int32 silk_SMLAWB_armv5e(opus_int32 a, opus_int32 b,
  51. opus_int16 c)
  52. {
  53. int res;
  54. __asm__(
  55. "#silk_SMLAWB\n\t"
  56. "smlawb %0, %1, %2, %3\n\t"
  57. : "=r"(res)
  58. : "r"(b), "r"(c), "r"(a)
  59. );
  60. return res;
  61. }
  62. #define silk_SMLAWB(a, b, c) (silk_SMLAWB_armv5e(a, b, c))
  63. /* (a32 * (b32 >> 16)) >> 16 */
  64. #undef silk_SMULWT
  65. static OPUS_INLINE opus_int32 silk_SMULWT_armv5e(opus_int32 a, opus_int32 b)
  66. {
  67. int res;
  68. __asm__(
  69. "#silk_SMULWT\n\t"
  70. "smulwt %0, %1, %2\n\t"
  71. : "=r"(res)
  72. : "r"(a), "r"(b)
  73. );
  74. return res;
  75. }
  76. #define silk_SMULWT(a, b) (silk_SMULWT_armv5e(a, b))
  77. /* a32 + (b32 * (c32 >> 16)) >> 16 */
  78. #undef silk_SMLAWT
  79. static OPUS_INLINE opus_int32 silk_SMLAWT_armv5e(opus_int32 a, opus_int32 b,
  80. opus_int32 c)
  81. {
  82. int res;
  83. __asm__(
  84. "#silk_SMLAWT\n\t"
  85. "smlawt %0, %1, %2, %3\n\t"
  86. : "=r"(res)
  87. : "r"(b), "r"(c), "r"(a)
  88. );
  89. return res;
  90. }
  91. #define silk_SMLAWT(a, b, c) (silk_SMLAWT_armv5e(a, b, c))
  92. /* (opus_int32)((opus_int16)(a3))) * (opus_int32)((opus_int16)(b32)) output have to be 32bit int */
  93. #undef silk_SMULBB
  94. static OPUS_INLINE opus_int32 silk_SMULBB_armv5e(opus_int32 a, opus_int32 b)
  95. {
  96. int res;
  97. __asm__(
  98. "#silk_SMULBB\n\t"
  99. "smulbb %0, %1, %2\n\t"
  100. : "=r"(res)
  101. : "%r"(a), "r"(b)
  102. );
  103. return res;
  104. }
  105. #define silk_SMULBB(a, b) (silk_SMULBB_armv5e(a, b))
  106. /* a32 + (opus_int32)((opus_int16)(b32)) * (opus_int32)((opus_int16)(c32)) output have to be 32bit int */
  107. #undef silk_SMLABB
  108. static OPUS_INLINE opus_int32 silk_SMLABB_armv5e(opus_int32 a, opus_int32 b,
  109. opus_int32 c)
  110. {
  111. int res;
  112. __asm__(
  113. "#silk_SMLABB\n\t"
  114. "smlabb %0, %1, %2, %3\n\t"
  115. : "=r"(res)
  116. : "%r"(b), "r"(c), "r"(a)
  117. );
  118. return res;
  119. }
  120. #define silk_SMLABB(a, b, c) (silk_SMLABB_armv5e(a, b, c))
  121. /* (opus_int32)((opus_int16)(a32)) * (b32 >> 16) */
  122. #undef silk_SMULBT
  123. static OPUS_INLINE opus_int32 silk_SMULBT_armv5e(opus_int32 a, opus_int32 b)
  124. {
  125. int res;
  126. __asm__(
  127. "#silk_SMULBT\n\t"
  128. "smulbt %0, %1, %2\n\t"
  129. : "=r"(res)
  130. : "r"(a), "r"(b)
  131. );
  132. return res;
  133. }
  134. #define silk_SMULBT(a, b) (silk_SMULBT_armv5e(a, b))
  135. /* a32 + (opus_int32)((opus_int16)(b32)) * (c32 >> 16) */
  136. #undef silk_SMLABT
  137. static OPUS_INLINE opus_int32 silk_SMLABT_armv5e(opus_int32 a, opus_int32 b,
  138. opus_int32 c)
  139. {
  140. int res;
  141. __asm__(
  142. "#silk_SMLABT\n\t"
  143. "smlabt %0, %1, %2, %3\n\t"
  144. : "=r"(res)
  145. : "r"(b), "r"(c), "r"(a)
  146. );
  147. return res;
  148. }
  149. #define silk_SMLABT(a, b, c) (silk_SMLABT_armv5e(a, b, c))
  150. /* add/subtract with output saturated */
  151. #undef silk_ADD_SAT32
  152. static OPUS_INLINE opus_int32 silk_ADD_SAT32_armv5e(opus_int32 a, opus_int32 b)
  153. {
  154. int res;
  155. __asm__(
  156. "#silk_ADD_SAT32\n\t"
  157. "qadd %0, %1, %2\n\t"
  158. : "=r"(res)
  159. : "%r"(a), "r"(b)
  160. );
  161. return res;
  162. }
  163. #define silk_ADD_SAT32(a, b) (silk_ADD_SAT32_armv5e(a, b))
  164. #undef silk_SUB_SAT32
  165. static OPUS_INLINE opus_int32 silk_SUB_SAT32_armv5e(opus_int32 a, opus_int32 b)
  166. {
  167. int res;
  168. __asm__(
  169. "#silk_SUB_SAT32\n\t"
  170. "qsub %0, %1, %2\n\t"
  171. : "=r"(res)
  172. : "r"(a), "r"(b)
  173. );
  174. return res;
  175. }
  176. #define silk_SUB_SAT32(a, b) (silk_SUB_SAT32_armv5e(a, b))
  177. #undef silk_CLZ16
  178. static OPUS_INLINE opus_int32 silk_CLZ16_armv5(opus_int16 in16)
  179. {
  180. int res;
  181. __asm__(
  182. "#silk_CLZ16\n\t"
  183. "clz %0, %1;\n"
  184. : "=r"(res)
  185. : "r"(SAFE_SHL(in16,16)|0x8000)
  186. );
  187. return res;
  188. }
  189. #define silk_CLZ16(in16) (silk_CLZ16_armv5(in16))
  190. #undef silk_CLZ32
  191. static OPUS_INLINE opus_int32 silk_CLZ32_armv5(opus_int32 in32)
  192. {
  193. int res;
  194. __asm__(
  195. "#silk_CLZ32\n\t"
  196. "clz %0, %1\n\t"
  197. : "=r"(res)
  198. : "r"(in32)
  199. );
  200. return res;
  201. }
  202. #define silk_CLZ32(in32) (silk_CLZ32_armv5(in32))
  203. #undef SAFE_SHL
  204. #endif /* SILK_MACROS_ARMv5E_H */