SKP_Silk_macros.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /***********************************************************************
  2. Copyright (c) 2006-2012, Skype Limited. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, (subject to the limitations in the disclaimer below)
  5. are permitted provided that the following conditions 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 Skype Limited, nor the names of specific
  12. contributors, may be used to endorse or promote products derived from
  13. this software without specific prior written permission.
  14. NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
  15. BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  16. CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
  17. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  18. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  19. COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  22. USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  23. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. ***********************************************************************/
  27. #ifndef _SKP_SILK_API_C_H_
  28. #define _SKP_SILK_API_C_H_
  29. // This is an inline header file for general platform.
  30. // (a32 * (SKP_int32)((SKP_int16)(b32))) >> 16 output have to be 32bit int
  31. #define SKP_SMULWB(a32, b32) ((((a32) >> 16) * (SKP_int32)((SKP_int16)(b32))) + ((((a32) & 0x0000FFFF) * (SKP_int32)((SKP_int16)(b32))) >> 16))
  32. // a32 + (b32 * (SKP_int32)((SKP_int16)(c32))) >> 16 output have to be 32bit int
  33. #define SKP_SMLAWB(a32, b32, c32) ((a32) + ((((b32) >> 16) * (SKP_int32)((SKP_int16)(c32))) + ((((b32) & 0x0000FFFF) * (SKP_int32)((SKP_int16)(c32))) >> 16)))
  34. // (a32 * (b32 >> 16)) >> 16
  35. #define SKP_SMULWT(a32, b32) (((a32) >> 16) * ((b32) >> 16) + ((((a32) & 0x0000FFFF) * ((b32) >> 16)) >> 16))
  36. // a32 + (b32 * (c32 >> 16)) >> 16
  37. #define SKP_SMLAWT(a32, b32, c32) ((a32) + (((b32) >> 16) * ((c32) >> 16)) + ((((b32) & 0x0000FFFF) * ((c32) >> 16)) >> 16))
  38. // (SKP_int32)((SKP_int16)(a3))) * (SKP_int32)((SKP_int16)(b32)) output have to be 32bit int
  39. #define SKP_SMULBB(a32, b32) ((SKP_int32)((SKP_int16)(a32)) * (SKP_int32)((SKP_int16)(b32)))
  40. // a32 + (SKP_int32)((SKP_int16)(b32)) * (SKP_int32)((SKP_int16)(c32)) output have to be 32bit int
  41. #define SKP_SMLABB(a32, b32, c32) ((a32) + ((SKP_int32)((SKP_int16)(b32))) * (SKP_int32)((SKP_int16)(c32)))
  42. // (SKP_int32)((SKP_int16)(a32)) * (b32 >> 16)
  43. #define SKP_SMULBT(a32, b32) ((SKP_int32)((SKP_int16)(a32)) * ((b32) >> 16))
  44. // a32 + (SKP_int32)((SKP_int16)(b32)) * (c32 >> 16)
  45. #define SKP_SMLABT(a32, b32, c32) ((a32) + ((SKP_int32)((SKP_int16)(b32))) * ((c32) >> 16))
  46. // a64 + (b32 * c32)
  47. #define SKP_SMLAL(a64, b32, c32) (SKP_ADD64((a64), ((SKP_int64)(b32) * (SKP_int64)(c32))))
  48. // (a32 * b32) >> 16
  49. #define SKP_SMULWW(a32, b32) SKP_MLA(SKP_SMULWB((a32), (b32)), (a32), SKP_RSHIFT_ROUND((b32), 16))
  50. // a32 + ((b32 * c32) >> 16)
  51. #define SKP_SMLAWW(a32, b32, c32) SKP_MLA(SKP_SMLAWB((a32), (b32), (c32)), (b32), SKP_RSHIFT_ROUND((c32), 16))
  52. // (SKP_int32)(((SKP_int64)a32 * b32) >> 32)
  53. #define SKP_SMMUL(a32, b32) (SKP_int32)SKP_RSHIFT64(SKP_SMULL((a32), (b32)), 32)
  54. /* add/subtract with output saturated */
  55. #define SKP_ADD_SAT32(a, b) ((((a) + (b)) & 0x80000000) == 0 ? \
  56. ((((a) & (b)) & 0x80000000) != 0 ? SKP_int32_MIN : (a)+(b)) : \
  57. ((((a) | (b)) & 0x80000000) == 0 ? SKP_int32_MAX : (a)+(b)) )
  58. #define SKP_SUB_SAT32(a, b) ((((a)-(b)) & 0x80000000) == 0 ? \
  59. (( (a) & ((b)^0x80000000) & 0x80000000) ? SKP_int32_MIN : (a)-(b)) : \
  60. ((((a)^0x80000000) & (b) & 0x80000000) ? SKP_int32_MAX : (a)-(b)) )
  61. SKP_INLINE SKP_int32 SKP_Silk_CLZ16(SKP_int16 in16)
  62. {
  63. SKP_int32 out32 = 0;
  64. if( in16 == 0 ) {
  65. return 16;
  66. }
  67. /* test nibbles */
  68. if( in16 & 0xFF00 ) {
  69. if( in16 & 0xF000 ) {
  70. in16 >>= 12;
  71. } else {
  72. out32 += 4;
  73. in16 >>= 8;
  74. }
  75. } else {
  76. if( in16 & 0xFFF0 ) {
  77. out32 += 8;
  78. in16 >>= 4;
  79. } else {
  80. out32 += 12;
  81. }
  82. }
  83. /* test bits and return */
  84. if( in16 & 0xC ) {
  85. if( in16 & 0x8 )
  86. return out32 + 0;
  87. else
  88. return out32 + 1;
  89. } else {
  90. if( in16 & 0xE )
  91. return out32 + 2;
  92. else
  93. return out32 + 3;
  94. }
  95. }
  96. SKP_INLINE SKP_int32 SKP_Silk_CLZ32(SKP_int32 in32)
  97. {
  98. /* test highest 16 bits and convert to SKP_int16 */
  99. if( in32 & 0xFFFF0000 ) {
  100. return SKP_Silk_CLZ16((SKP_int16)(in32 >> 16));
  101. } else {
  102. return SKP_Silk_CLZ16((SKP_int16)in32) + 16;
  103. }
  104. }
  105. #endif //_SKP_SILK_API_C_H_