CMSIS DSP Library from CMSIS 2.0. See http://www.onarm.com/cmsis/ for full details

Dependents:   K22F_DSP_Matrix_least_square BNO055-ELEC3810 1BNO055 ECE4180Project--Slave2 ... more

Committer:
simon
Date:
Thu Mar 10 15:07:50 2011 +0000
Revision:
0:1014af42efd9

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:1014af42efd9 1 /* ----------------------------------------------------------------------
simon 0:1014af42efd9 2 * Copyright (C) 2010 ARM Limited. All rights reserved.
simon 0:1014af42efd9 3 *
simon 0:1014af42efd9 4 * $Date: 29. November 2010
simon 0:1014af42efd9 5 * $Revision: V1.0.3
simon 0:1014af42efd9 6 *
simon 0:1014af42efd9 7 * Project: CMSIS DSP Library
simon 0:1014af42efd9 8 * Title: arm_shift_q7.c
simon 0:1014af42efd9 9 *
simon 0:1014af42efd9 10 * Description: Processing function for the Q7 Shifting
simon 0:1014af42efd9 11 *
simon 0:1014af42efd9 12 * Target Processor: Cortex-M4/Cortex-M3
simon 0:1014af42efd9 13 *
simon 0:1014af42efd9 14 * Version 1.0.3 2010/11/29
simon 0:1014af42efd9 15 * Re-organized the CMSIS folders and updated documentation.
simon 0:1014af42efd9 16 *
simon 0:1014af42efd9 17 * Version 1.0.2 2010/11/11
simon 0:1014af42efd9 18 * Documentation updated.
simon 0:1014af42efd9 19 *
simon 0:1014af42efd9 20 * Version 1.0.1 2010/10/05
simon 0:1014af42efd9 21 * Production release and review comments incorporated.
simon 0:1014af42efd9 22 *
simon 0:1014af42efd9 23 * Version 1.0.0 2010/09/20
simon 0:1014af42efd9 24 * Production release and review comments incorporated.
simon 0:1014af42efd9 25 *
simon 0:1014af42efd9 26 * Version 0.0.7 2010/06/10
simon 0:1014af42efd9 27 * Misra-C changes done
simon 0:1014af42efd9 28 * -------------------------------------------------------------------- */
simon 0:1014af42efd9 29
simon 0:1014af42efd9 30 #include "arm_math.h"
simon 0:1014af42efd9 31
simon 0:1014af42efd9 32 /**
simon 0:1014af42efd9 33 * @ingroup groupMath
simon 0:1014af42efd9 34 */
simon 0:1014af42efd9 35
simon 0:1014af42efd9 36 /**
simon 0:1014af42efd9 37 * @addtogroup shift
simon 0:1014af42efd9 38 * @{
simon 0:1014af42efd9 39 */
simon 0:1014af42efd9 40
simon 0:1014af42efd9 41
simon 0:1014af42efd9 42 /**
simon 0:1014af42efd9 43 * @brief Shifts the elements of a Q7 vector a specified number of bits.
simon 0:1014af42efd9 44 * @param *pSrc points to the input vector
simon 0:1014af42efd9 45 * @param shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right.
simon 0:1014af42efd9 46 * @param *pDst points to the output vector
simon 0:1014af42efd9 47 * @param blockSize number of samples in the vector
simon 0:1014af42efd9 48 * @return none.
simon 0:1014af42efd9 49 *
simon 0:1014af42efd9 50 * <b>Scaling and Overflow Behavior:</b>
simon 0:1014af42efd9 51 * \par
simon 0:1014af42efd9 52 * The function uses saturating arithmetic.
simon 0:1014af42efd9 53 * Results outside of the allowable Q7 range [0x8 0x7F] will be saturated.
simon 0:1014af42efd9 54 */
simon 0:1014af42efd9 55
simon 0:1014af42efd9 56 void arm_shift_q7(
simon 0:1014af42efd9 57 q7_t * pSrc,
simon 0:1014af42efd9 58 int8_t shiftBits,
simon 0:1014af42efd9 59 q7_t * pDst,
simon 0:1014af42efd9 60 uint32_t blockSize)
simon 0:1014af42efd9 61 {
simon 0:1014af42efd9 62 uint32_t blkCnt; /* loop counter */
simon 0:1014af42efd9 63 uint8_t sign; /* Sign of shiftBits */
simon 0:1014af42efd9 64 q7_t in1; /* Input value1 */
simon 0:1014af42efd9 65 q7_t in2; /* Input value2 */
simon 0:1014af42efd9 66 q7_t in3; /* Input value3 */
simon 0:1014af42efd9 67 q7_t in4; /* Input value4 */
simon 0:1014af42efd9 68
simon 0:1014af42efd9 69
simon 0:1014af42efd9 70 /*loop Unrolling */
simon 0:1014af42efd9 71 blkCnt = blockSize >> 2u;
simon 0:1014af42efd9 72
simon 0:1014af42efd9 73 /* Getting the sign of shiftBits */
simon 0:1014af42efd9 74 sign = (shiftBits & 0x80);
simon 0:1014af42efd9 75
simon 0:1014af42efd9 76 /* If the shift value is positive then do right shift else left shift */
simon 0:1014af42efd9 77 if(sign == 0u)
simon 0:1014af42efd9 78 {
simon 0:1014af42efd9 79 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
simon 0:1014af42efd9 80 ** a second loop below computes the remaining 1 to 3 samples. */
simon 0:1014af42efd9 81 while(blkCnt > 0u)
simon 0:1014af42efd9 82 {
simon 0:1014af42efd9 83 /* C = A << shiftBits */
simon 0:1014af42efd9 84 /* Read 4 inputs */
simon 0:1014af42efd9 85 in1 = *pSrc++;
simon 0:1014af42efd9 86 in2 = *pSrc++;
simon 0:1014af42efd9 87 in3 = *pSrc++;
simon 0:1014af42efd9 88 in4 = *pSrc++;
simon 0:1014af42efd9 89
simon 0:1014af42efd9 90 /* Store the Shifted result in the destination buffer in single cycle by packing the outputs */
simon 0:1014af42efd9 91 *__SIMD32(pDst)++ = __PACKq7(__SSAT((in1 << shiftBits), 8),
simon 0:1014af42efd9 92 __SSAT((in2 << shiftBits), 8),
simon 0:1014af42efd9 93 __SSAT((in3 << shiftBits), 8),
simon 0:1014af42efd9 94 __SSAT((in4 << shiftBits), 8));
simon 0:1014af42efd9 95
simon 0:1014af42efd9 96 /* Decrement the loop counter */
simon 0:1014af42efd9 97 blkCnt--;
simon 0:1014af42efd9 98 }
simon 0:1014af42efd9 99
simon 0:1014af42efd9 100 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
simon 0:1014af42efd9 101 ** No loop unrolling is used. */
simon 0:1014af42efd9 102 blkCnt = blockSize % 0x4u;
simon 0:1014af42efd9 103
simon 0:1014af42efd9 104 while(blkCnt > 0u)
simon 0:1014af42efd9 105 {
simon 0:1014af42efd9 106 /* C = A << shiftBits */
simon 0:1014af42efd9 107 /* Shift the input and then store the result in the destination buffer. */
simon 0:1014af42efd9 108 *pDst++ = (q7_t) __SSAT((*pSrc++ << shiftBits), 8);
simon 0:1014af42efd9 109
simon 0:1014af42efd9 110 /* Decrement the loop counter */
simon 0:1014af42efd9 111 blkCnt--;
simon 0:1014af42efd9 112 }
simon 0:1014af42efd9 113 }
simon 0:1014af42efd9 114 else
simon 0:1014af42efd9 115 {
simon 0:1014af42efd9 116 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
simon 0:1014af42efd9 117 ** a second loop below computes the remaining 1 to 3 samples. */
simon 0:1014af42efd9 118 while(blkCnt > 0u)
simon 0:1014af42efd9 119 {
simon 0:1014af42efd9 120 /* C = A >> shiftBits */
simon 0:1014af42efd9 121 /* Read 4 inputs */
simon 0:1014af42efd9 122 in1 = *pSrc++;
simon 0:1014af42efd9 123 in2 = *pSrc++;
simon 0:1014af42efd9 124 in3 = *pSrc++;
simon 0:1014af42efd9 125 in4 = *pSrc++;
simon 0:1014af42efd9 126
simon 0:1014af42efd9 127 /* Store the Shifted result in the destination buffer in single cycle by packing the outputs */
simon 0:1014af42efd9 128 *__SIMD32(pDst)++ = __PACKq7((in1 >> -shiftBits), (in2 >> -shiftBits),
simon 0:1014af42efd9 129 (in3 >> -shiftBits), (in4 >> -shiftBits));
simon 0:1014af42efd9 130
simon 0:1014af42efd9 131 /* Decrement the loop counter */
simon 0:1014af42efd9 132 blkCnt--;
simon 0:1014af42efd9 133 }
simon 0:1014af42efd9 134
simon 0:1014af42efd9 135 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
simon 0:1014af42efd9 136 ** No loop unrolling is used. */
simon 0:1014af42efd9 137 blkCnt = blockSize % 0x4u;
simon 0:1014af42efd9 138
simon 0:1014af42efd9 139 while(blkCnt > 0u)
simon 0:1014af42efd9 140 {
simon 0:1014af42efd9 141 /* C = A >> shiftBits */
simon 0:1014af42efd9 142 /* Shift the input and then store the result in the destination buffer. */
simon 0:1014af42efd9 143 *pDst++ = (*pSrc++ >> -shiftBits);
simon 0:1014af42efd9 144
simon 0:1014af42efd9 145 /* Decrement the loop counter */
simon 0:1014af42efd9 146 blkCnt--;
simon 0:1014af42efd9 147 }
simon 0:1014af42efd9 148 }
simon 0:1014af42efd9 149 }
simon 0:1014af42efd9 150
simon 0:1014af42efd9 151 /**
simon 0:1014af42efd9 152 * @} end of shift group
simon 0:1014af42efd9 153 */