PageRenderTime 27ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/CMSIS/DSP_Lib/Source/BasicMathFunctions/arm_shift_q15.c

https://gitlab.com/locsonpham/demeter_weatherstation
C | 243 lines | 97 code | 52 blank | 94 comment | 4 complexity | 4e0921855206da24a437d2f2a78d1db8 MD5 | raw file
  1. /* ----------------------------------------------------------------------
  2. * Copyright (C) 2010 ARM Limited. All rights reserved.
  3. *
  4. * $Date: 15. February 2012
  5. * $Revision: V1.1.0
  6. *
  7. * Project: CMSIS DSP Library
  8. * Title: arm_shift_q15.c
  9. *
  10. * Description: Shifts the elements of a Q15 vector by a specified number of bits.
  11. *
  12. * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
  13. *
  14. * Version 1.1.0 2012/02/15
  15. * Updated with more optimizations, bug fixes and minor API changes.
  16. *
  17. * Version 1.0.10 2011/7/15
  18. * Big Endian support added and Merged M0 and M3/M4 Source code.
  19. *
  20. * Version 1.0.3 2010/11/29
  21. * Re-organized the CMSIS folders and updated documentation.
  22. *
  23. * Version 1.0.2 2010/11/11
  24. * Documentation updated.
  25. *
  26. * Version 1.0.1 2010/10/05
  27. * Production release and review comments incorporated.
  28. *
  29. * Version 1.0.0 2010/09/20
  30. * Production release and review comments incorporated.
  31. *
  32. * Version 0.0.7 2010/06/10
  33. * Misra-C changes done
  34. * -------------------------------------------------------------------- */
  35. #include "arm_math.h"
  36. /**
  37. * @ingroup groupMath
  38. */
  39. /**
  40. * @addtogroup shift
  41. * @{
  42. */
  43. /**
  44. * @brief Shifts the elements of a Q15 vector a specified number of bits.
  45. * @param[in] *pSrc points to the input vector
  46. * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right.
  47. * @param[out] *pDst points to the output vector
  48. * @param[in] blockSize number of samples in the vector
  49. * @return none.
  50. *
  51. * <b>Scaling and Overflow Behavior:</b>
  52. * \par
  53. * The function uses saturating arithmetic.
  54. * Results outside of the allowable Q15 range [0x8000 0x7FFF] will be saturated.
  55. */
  56. void arm_shift_q15(
  57. q15_t * pSrc,
  58. int8_t shiftBits,
  59. q15_t * pDst,
  60. uint32_t blockSize)
  61. {
  62. uint32_t blkCnt; /* loop counter */
  63. uint8_t sign; /* Sign of shiftBits */
  64. #ifndef ARM_MATH_CM0
  65. /* Run the below code for Cortex-M4 and Cortex-M3 */
  66. q15_t in1, in2; /* Temporary variables */
  67. /*loop Unrolling */
  68. blkCnt = blockSize >> 2u;
  69. /* Getting the sign of shiftBits */
  70. sign = (shiftBits & 0x80);
  71. /* If the shift value is positive then do right shift else left shift */
  72. if(sign == 0u)
  73. {
  74. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  75. ** a second loop below computes the remaining 1 to 3 samples. */
  76. while(blkCnt > 0u)
  77. {
  78. /* Read 2 inputs */
  79. in1 = *pSrc++;
  80. in2 = *pSrc++;
  81. /* C = A << shiftBits */
  82. /* Shift the inputs and then store the results in the destination buffer. */
  83. #ifndef ARM_MATH_BIG_ENDIAN
  84. *__SIMD32(pDst)++ = __PKHBT(__SSAT((in1 << shiftBits), 16),
  85. __SSAT((in2 << shiftBits), 16), 16);
  86. #else
  87. *__SIMD32(pDst)++ = __PKHBT(__SSAT((in2 << shiftBits), 16),
  88. __SSAT((in1 << shiftBits), 16), 16);
  89. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  90. in1 = *pSrc++;
  91. in2 = *pSrc++;
  92. #ifndef ARM_MATH_BIG_ENDIAN
  93. *__SIMD32(pDst)++ = __PKHBT(__SSAT((in1 << shiftBits), 16),
  94. __SSAT((in2 << shiftBits), 16), 16);
  95. #else
  96. *__SIMD32(pDst)++ = __PKHBT(__SSAT((in2 << shiftBits), 16),
  97. __SSAT((in1 << shiftBits), 16), 16);
  98. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  99. /* Decrement the loop counter */
  100. blkCnt--;
  101. }
  102. /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
  103. ** No loop unrolling is used. */
  104. blkCnt = blockSize % 0x4u;
  105. while(blkCnt > 0u)
  106. {
  107. /* C = A << shiftBits */
  108. /* Shift and then store the results in the destination buffer. */
  109. *pDst++ = __SSAT((*pSrc++ << shiftBits), 16);
  110. /* Decrement the loop counter */
  111. blkCnt--;
  112. }
  113. }
  114. else
  115. {
  116. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  117. ** a second loop below computes the remaining 1 to 3 samples. */
  118. while(blkCnt > 0u)
  119. {
  120. /* Read 2 inputs */
  121. in1 = *pSrc++;
  122. in2 = *pSrc++;
  123. /* C = A >> shiftBits */
  124. /* Shift the inputs and then store the results in the destination buffer. */
  125. #ifndef ARM_MATH_BIG_ENDIAN
  126. *__SIMD32(pDst)++ = __PKHBT((in1 >> -shiftBits),
  127. (in2 >> -shiftBits), 16);
  128. #else
  129. *__SIMD32(pDst)++ = __PKHBT((in2 >> -shiftBits),
  130. (in1 >> -shiftBits), 16);
  131. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  132. in1 = *pSrc++;
  133. in2 = *pSrc++;
  134. #ifndef ARM_MATH_BIG_ENDIAN
  135. *__SIMD32(pDst)++ = __PKHBT((in1 >> -shiftBits),
  136. (in2 >> -shiftBits), 16);
  137. #else
  138. *__SIMD32(pDst)++ = __PKHBT((in2 >> -shiftBits),
  139. (in1 >> -shiftBits), 16);
  140. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  141. /* Decrement the loop counter */
  142. blkCnt--;
  143. }
  144. /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
  145. ** No loop unrolling is used. */
  146. blkCnt = blockSize % 0x4u;
  147. while(blkCnt > 0u)
  148. {
  149. /* C = A >> shiftBits */
  150. /* Shift the inputs and then store the results in the destination buffer. */
  151. *pDst++ = (*pSrc++ >> -shiftBits);
  152. /* Decrement the loop counter */
  153. blkCnt--;
  154. }
  155. }
  156. #else
  157. /* Run the below code for Cortex-M0 */
  158. /* Getting the sign of shiftBits */
  159. sign = (shiftBits & 0x80);
  160. /* If the shift value is positive then do right shift else left shift */
  161. if(sign == 0u)
  162. {
  163. /* Initialize blkCnt with number of samples */
  164. blkCnt = blockSize;
  165. while(blkCnt > 0u)
  166. {
  167. /* C = A << shiftBits */
  168. /* Shift and then store the results in the destination buffer. */
  169. *pDst++ = __SSAT(((q31_t) * pSrc++ << shiftBits), 16);
  170. /* Decrement the loop counter */
  171. blkCnt--;
  172. }
  173. }
  174. else
  175. {
  176. /* Initialize blkCnt with number of samples */
  177. blkCnt = blockSize;
  178. while(blkCnt > 0u)
  179. {
  180. /* C = A >> shiftBits */
  181. /* Shift the inputs and then store the results in the destination buffer. */
  182. *pDst++ = (*pSrc++ >> -shiftBits);
  183. /* Decrement the loop counter */
  184. blkCnt--;
  185. }
  186. }
  187. #endif /* #ifndef ARM_MATH_CM0 */
  188. }
  189. /**
  190. * @} end of shift group
  191. */