macros_armv4.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /***********************************************************************
  2. Copyright (C) 2013 Xiph.Org Foundation and contributors.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions
  5. are met:
  6. - Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. - Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. - Neither the name of Internet Society, IETF or IETF Trust, nor the
  12. names of specific contributors, may be used to endorse or promote
  13. products derived from this software without specific prior written
  14. permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  19. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. POSSIBILITY OF SUCH DAMAGE.
  26. ***********************************************************************/
  27. #ifndef SILK_MACROS_ARMv4_H
  28. #define SILK_MACROS_ARMv4_H
  29. /* This macro only avoids the undefined behaviour from a left shift of
  30. a negative value. It should only be used in macros that can't include
  31. SigProc_FIX.h. In other cases, use silk_LSHIFT32(). */
  32. #define SAFE_SHL(a,b) ((opus_int32)((opus_uint32)(a) << (b)))
  33. /* (a32 * (opus_int32)((opus_int16)(b32))) >> 16 output have to be 32bit int */
  34. #undef silk_SMULWB
  35. static OPUS_INLINE opus_int32 silk_SMULWB_armv4(opus_int32 a, opus_int16 b)
  36. {
  37. unsigned rd_lo;
  38. int rd_hi;
  39. __asm__(
  40. "#silk_SMULWB\n\t"
  41. "smull %0, %1, %2, %3\n\t"
  42. : "=&r"(rd_lo), "=&r"(rd_hi)
  43. : "%r"(a), "r"(SAFE_SHL(b,16))
  44. );
  45. return rd_hi;
  46. }
  47. #define silk_SMULWB(a, b) (silk_SMULWB_armv4(a, b))
  48. /* a32 + (b32 * (opus_int32)((opus_int16)(c32))) >> 16 output have to be 32bit int */
  49. #undef silk_SMLAWB
  50. #define silk_SMLAWB(a, b, c) ((a) + silk_SMULWB(b, c))
  51. /* (a32 * (b32 >> 16)) >> 16 */
  52. #undef silk_SMULWT
  53. static OPUS_INLINE opus_int32 silk_SMULWT_armv4(opus_int32 a, opus_int32 b)
  54. {
  55. unsigned rd_lo;
  56. int rd_hi;
  57. __asm__(
  58. "#silk_SMULWT\n\t"
  59. "smull %0, %1, %2, %3\n\t"
  60. : "=&r"(rd_lo), "=&r"(rd_hi)
  61. : "%r"(a), "r"(b&~0xFFFF)
  62. );
  63. return rd_hi;
  64. }
  65. #define silk_SMULWT(a, b) (silk_SMULWT_armv4(a, b))
  66. /* a32 + (b32 * (c32 >> 16)) >> 16 */
  67. #undef silk_SMLAWT
  68. #define silk_SMLAWT(a, b, c) ((a) + silk_SMULWT(b, c))
  69. /* (a32 * b32) >> 16 */
  70. #undef silk_SMULWW
  71. static OPUS_INLINE opus_int32 silk_SMULWW_armv4(opus_int32 a, opus_int32 b)
  72. {
  73. unsigned rd_lo;
  74. int rd_hi;
  75. __asm__(
  76. "#silk_SMULWW\n\t"
  77. "smull %0, %1, %2, %3\n\t"
  78. : "=&r"(rd_lo), "=&r"(rd_hi)
  79. : "%r"(a), "r"(b)
  80. );
  81. return SAFE_SHL(rd_hi,16)+(rd_lo>>16);
  82. }
  83. #define silk_SMULWW(a, b) (silk_SMULWW_armv4(a, b))
  84. #undef silk_SMLAWW
  85. static OPUS_INLINE opus_int32 silk_SMLAWW_armv4(opus_int32 a, opus_int32 b,
  86. opus_int32 c)
  87. {
  88. unsigned rd_lo;
  89. int rd_hi;
  90. __asm__(
  91. "#silk_SMLAWW\n\t"
  92. "smull %0, %1, %2, %3\n\t"
  93. : "=&r"(rd_lo), "=&r"(rd_hi)
  94. : "%r"(b), "r"(c)
  95. );
  96. return a+SAFE_SHL(rd_hi,16)+(rd_lo>>16);
  97. }
  98. #define silk_SMLAWW(a, b, c) (silk_SMLAWW_armv4(a, b, c))
  99. #undef SAFE_SHL
  100. #endif /* SILK_MACROS_ARMv4_H */