CMSIS DSP Software Library: arm_shift_q7.c Source File

- Main Page
- Modules
- Data Structures
- Files
- Examples

- File List
- Globals

# arm_shift_q7.c

Go to the documentation of this file.

    00001 /* ----------------------------------------------------------------------
    00002 * Copyright (C) 2010 ARM Limited. All rights reserved.
    00003 *
    00004 * $Date:        15. July 2011
    00005 * $Revision:    V1.0.10
    00006 *
    00007 * Project:      CMSIS DSP Library
    00008 * Title:        arm_shift_q7.c
    00009 *
    00010 * Description:  Processing function for the Q7 Shifting
    00011 *
    00012 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
    00013 *
    00014 * Version 1.0.10 2011/7/15
    00015 *    Big Endian support added and Merged M0 and M3/M4 Source code.
    00016 *
    00017 * Version 1.0.3 2010/11/29
    00018 *    Re-organized the CMSIS folders and updated documentation.
    00019 *
    00020 * Version 1.0.2 2010/11/11
    00021 *    Documentation updated.
    00022 *
    00023 * Version 1.0.1 2010/10/05
    00024 *    Production release and review comments incorporated.
    00025 *
    00026 * Version 1.0.0 2010/09/20
    00027 *    Production release and review comments incorporated.
    00028 *
    00029 * Version 0.0.7  2010/06/10
    00030 *    Misra-C changes done
    00031 * -------------------------------------------------------------------- */
    00032
    00033 #include "arm_math.h"
    00034
    00059 void arm_shift_q7(
    00060   q7_t * pSrc,
    00061   int8_t shiftBits,
    00062   q7_t * pDst,
    00063   uint32_t blockSize)
    00064 {
    00065   uint32_t blkCnt;                               /* loop counter */
    00066   uint8_t sign;                                  /* Sign of shiftBits */
    00067
    00068 #ifndef ARM_MATH_CM0
    00069
    00070 /* Run the below code for Cortex-M4 and Cortex-M3 */
    00071   q7_t in1;                                      /* Input value1 */
    00072   q7_t in2;                                      /* Input value2 */
    00073   q7_t in3;                                      /* Input value3 */
    00074   q7_t in4;                                      /* Input value4 */
    00075
    00076
    00077   /*loop Unrolling */
    00078   blkCnt = blockSize >> 2u;
    00079
    00080   /* Getting the sign of shiftBits */
    00081   sign = (shiftBits & 0x80);
    00082
    00083   /* If the shift value is positive then do right shift else left shift */
    00084   if(sign == 0u)
    00085   {
    00086     /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
    00087      ** a second loop below computes the remaining 1 to 3 samples. */
    00088     while(blkCnt > 0u)
    00089     {
    00090       /* C = A << shiftBits */
    00091       /* Read 4 inputs */
    00092       in1 = *pSrc++;
    00093       in2 = *pSrc++;
    00094       in3 = *pSrc++;
    00095       in4 = *pSrc++;
    00096
    00097       /* Store the Shifted result in the destination buffer in single cycle by packing the outputs */
    00098       *__SIMD32(pDst)++ = __PACKq7(__SSAT((in1 << shiftBits), 8),
    00099                                    __SSAT((in2 << shiftBits), 8),
    00100                                    __SSAT((in3 << shiftBits), 8),
    00101                                    __SSAT((in4 << shiftBits), 8));
    00102
    00103       /* Decrement the loop counter */
    00104       blkCnt--;
    00105     }
    00106
    00107     /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
    00108      ** No loop unrolling is used. */
    00109     blkCnt = blockSize % 0x4u;
    00110
    00111     while(blkCnt > 0u)
    00112     {
    00113       /* C = A << shiftBits */
    00114       /* Shift the input and then store the result in the destination buffer. */
    00115       *pDst++ = (q7_t) __SSAT((*pSrc++ << shiftBits), 8);
    00116
    00117       /* Decrement the loop counter */
    00118       blkCnt--;
    00119     }
    00120   }
    00121   else
    00122   {
    00123     /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
    00124      ** a second loop below computes the remaining 1 to 3 samples. */
    00125     while(blkCnt > 0u)
    00126     {
    00127       /* C = A >> shiftBits */
    00128       /* Read 4 inputs */
    00129       in1 = *pSrc++;
    00130       in2 = *pSrc++;
    00131       in3 = *pSrc++;
    00132       in4 = *pSrc++;
    00133
    00134       /* Store the Shifted result in the destination buffer in single cycle by packing the outputs */
    00135       *__SIMD32(pDst)++ = __PACKq7((in1 >> -shiftBits), (in2 >> -shiftBits),
    00136                                    (in3 >> -shiftBits), (in4 >> -shiftBits));
    00137
    00138       /* Decrement the loop counter */
    00139       blkCnt--;
    00140     }
    00141
    00142     /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
    00143      ** No loop unrolling is used. */
    00144     blkCnt = blockSize % 0x4u;
    00145
    00146     while(blkCnt > 0u)
    00147     {
    00148       /* C = A >> shiftBits */
    00149       /* Shift the input and then store the result in the destination buffer. */
    00150       *pDst++ = (*pSrc++ >> -shiftBits);
    00151
    00152       /* Decrement the loop counter */
    00153       blkCnt--;
    00154     }
    00155   }
    00156
    00157 #else
    00158
    00159   /* Run the below code for Cortex-M0 */
    00160
    00161   /* Getting the sign of shiftBits */
    00162   sign = (shiftBits & 0x80);
    00163
    00164   /* If the shift value is positive then do right shift else left shift */
    00165   if(sign == 0u)
    00166   {
    00167     /* Initialize blkCnt with number of samples */
    00168     blkCnt = blockSize;
    00169
    00170     while(blkCnt > 0u)
    00171     {
    00172       /* C = A << shiftBits */
    00173       /* Shift the input and then store the result in the destination buffer. */
    00174       *pDst++ = (q7_t) __SSAT(((q15_t) * pSrc++ << shiftBits), 8);
    00175
    00176       /* Decrement the loop counter */
    00177       blkCnt--;
    00178     }
    00179   }
    00180   else
    00181   {
    00182     /* Initialize blkCnt with number of samples */
    00183     blkCnt = blockSize;
    00184
    00185     while(blkCnt > 0u)
    00186     {
    00187       /* C = A >> shiftBits */
    00188       /* Shift the input and then store the result in the destination buffer. */
    00189       *pDst++ = (*pSrc++ >> -shiftBits);
    00190
    00191       /* Decrement the loop counter */
    00192       blkCnt--;
    00193     }
    00194   }
    00195
    00196 #endif /* #ifndef ARM_MATH_CM0 */
    00197
    00198 }
    00199

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines