CMSIS DSP Software Library: arm_fir_sparse_q31.c Source File

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

- File List
- Globals

# arm_fir_sparse_q31.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_fir_sparse_q31.c
    00009 *
    00010 * Description:  Q31 sparse FIR filter processing function.
    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 #include "arm_math.h"
    00033
    00034
    00058 void arm_fir_sparse_q31(
    00059   arm_fir_sparse_instance_q31 * S,
    00060   q31_t * pSrc,
    00061   q31_t * pDst,
    00062   q31_t * pScratchIn,
    00063   uint32_t blockSize)
    00064 {
    00065
    00066   q31_t *pState = S->pState;                     /* State pointer */
    00067   q31_t *pCoeffs = S->pCoeffs;                   /* Coefficient pointer */
    00068   q31_t *px;                                     /* Scratch buffer pointer */
    00069   q31_t *py = pState;                            /* Temporary pointers for state buffer */
    00070   q31_t *pb = pScratchIn;                        /* Temporary pointers for scratch buffer */
    00071   q31_t *pOut;                                   /* Destination pointer */
    00072   q63_t out;                                     /* Temporary output variable */
    00073   int32_t *pTapDelay = S->pTapDelay;             /* Pointer to the array containing offset of the non-zero tap values. */
    00074   uint32_t delaySize = S->maxDelay + blockSize;  /* state length */
    00075   uint16_t numTaps = S->numTaps;                 /* Filter order */
    00076   int32_t readIndex;                             /* Read index of the state buffer */
    00077   uint32_t tapCnt, blkCnt;                       /* loop counters */
    00078   q31_t coeff = *pCoeffs++;                      /* Read the first coefficient value */
    00079   q31_t in;
    00080
    00081
    00082   /* BlockSize of Input samples are copied into the state buffer */
    00083   /* StateIndex points to the starting position to write in the state buffer */
    00084   arm_circularWrite_f32((int32_t *) py, delaySize, &S->stateIndex, 1,
    00085                         (int32_t *) pSrc, 1, blockSize);
    00086
    00087   /* Read Index, from where the state buffer should be read, is calculated. */
    00088   readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++;
    00089
    00090   /* Wraparound of readIndex */
    00091   if(readIndex < 0)
    00092   {
    00093     readIndex += (int32_t) delaySize;
    00094   }
    00095
    00096   /* Working pointer for state buffer is updated */
    00097   py = pState;
    00098
    00099   /* blockSize samples are read from the state buffer */
    00100   arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1,
    00101                        (int32_t *) pb, (int32_t *) pb, blockSize, 1,
    00102                        blockSize);
    00103
    00104   /* Working pointer for the scratch buffer of state values */
    00105   px = pb;
    00106
    00107   /* Working pointer for scratch buffer of output values */
    00108   pOut = pDst;
    00109
    00110
    00111 #ifndef ARM_MATH_CM0
    00112
    00113   /* Run the below code for Cortex-M4 and Cortex-M3 */
    00114
    00115   /* Loop over the blockSize. Unroll by a factor of 4.
    00116    * Compute 4 Multiplications at a time. */
    00117   blkCnt = blockSize >> 2;
    00118
    00119   while(blkCnt > 0u)
    00120   {
    00121     /* Perform Multiplications and store in the destination buffer */
    00122     *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32);
    00123     *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32);
    00124     *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32);
    00125     *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32);
    00126
    00127     /* Decrement the loop counter */
    00128     blkCnt--;
    00129   }
    00130
    00131   /* If the blockSize is not a multiple of 4,
    00132    * compute the remaining samples */
    00133   blkCnt = blockSize % 0x4u;
    00134
    00135   while(blkCnt > 0u)
    00136   {
    00137     /* Perform Multiplications and store in the destination buffer */
    00138     *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32);
    00139
    00140     /* Decrement the loop counter */
    00141     blkCnt--;
    00142   }
    00143
    00144   /* Load the coefficient value and
    00145    * increment the coefficient buffer for the next set of state values */
    00146   coeff = *pCoeffs++;
    00147
    00148   /* Read Index, from where the state buffer should be read, is calculated. */
    00149   readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++;
    00150
    00151   /* Wraparound of readIndex */
    00152   if(readIndex < 0)
    00153   {
    00154     readIndex += (int32_t) delaySize;
    00155   }
    00156
    00157   /* Loop over the number of taps. */
    00158   tapCnt = (uint32_t) numTaps - 1u;
    00159
    00160   while(tapCnt > 0u)
    00161   {
    00162     /* Working pointer for state buffer is updated */
    00163     py = pState;
    00164
    00165     /* blockSize samples are read from the state buffer */
    00166     arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1,
    00167                          (int32_t *) pb, (int32_t *) pb, blockSize, 1,
    00168                          blockSize);
    00169
    00170     /* Working pointer for the scratch buffer of state values */
    00171     px = pb;
    00172
    00173     /* Working pointer for scratch buffer of output values */
    00174     pOut = pDst;
    00175
    00176     /* Loop over the blockSize. Unroll by a factor of 4.
    00177      * Compute 4 MACS at a time. */
    00178     blkCnt = blockSize >> 2;
    00179
    00180     while(blkCnt > 0u)
    00181     {
    00182       out = *pOut;
    00183       out += ((q63_t) * px++ * coeff) >> 32;
    00184       *pOut++ = (q31_t) (out);
    00185
    00186       out = *pOut;
    00187       out += ((q63_t) * px++ * coeff) >> 32;
    00188       *pOut++ = (q31_t) (out);
    00189
    00190       out = *pOut;
    00191       out += ((q63_t) * px++ * coeff) >> 32;
    00192       *pOut++ = (q31_t) (out);
    00193
    00194       out = *pOut;
    00195       out += ((q63_t) * px++ * coeff) >> 32;
    00196       *pOut++ = (q31_t) (out);
    00197
    00198       /* Decrement the loop counter */
    00199       blkCnt--;
    00200     }
    00201
    00202     /* If the blockSize is not a multiple of 4,
    00203      * compute the remaining samples */
    00204     blkCnt = blockSize % 0x4u;
    00205
    00206     while(blkCnt > 0u)
    00207     {
    00208       /* Perform Multiply-Accumulate */
    00209       out = *pOut;
    00210       out += ((q63_t) * px++ * coeff) >> 32;
    00211       *pOut++ = (q31_t) (out);
    00212
    00213       /* Decrement the loop counter */
    00214       blkCnt--;
    00215     }
    00216
    00217     /* Load the coefficient value and
    00218      * increment the coefficient buffer for the next set of state values */
    00219     coeff = *pCoeffs++;
    00220
    00221     /* Read Index, from where the state buffer should be read, is calculated. */
    00222     readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++;
    00223
    00224     /* Wraparound of readIndex */
    00225     if(readIndex < 0)
    00226     {
    00227       readIndex += (int32_t) delaySize;
    00228     }
    00229
    00230     /* Decrement the tap loop counter */
    00231     tapCnt--;
    00232   }
    00233
    00234   /* Working output pointer is updated */
    00235   pOut = pDst;
    00236
    00237   /* Output is converted into 1.31 format. */
    00238   /* Loop over the blockSize. Unroll by a factor of 4.
    00239    * process 4 output samples at a time. */
    00240   blkCnt = blockSize >> 2;
    00241
    00242   while(blkCnt > 0u)
    00243   {
    00244     in = *pOut << 1;
    00245     *pOut++ = in;
    00246     in = *pOut << 1;
    00247     *pOut++ = in;
    00248     in = *pOut << 1;
    00249     *pOut++ = in;
    00250     in = *pOut << 1;
    00251     *pOut++ = in;
    00252
    00253     /* Decrement the loop counter */
    00254     blkCnt--;
    00255   }
    00256
    00257   /* If the blockSize is not a multiple of 4,
    00258    * process the remaining output samples */
    00259   blkCnt = blockSize % 0x4u;
    00260
    00261   while(blkCnt > 0u)
    00262   {
    00263     in = *pOut << 1;
    00264     *pOut++ = in;
    00265
    00266     /* Decrement the loop counter */
    00267     blkCnt--;
    00268   }
    00269
    00270 #else
    00271
    00272   /* Run the below code for Cortex-M0 */
    00273   blkCnt = blockSize;
    00274
    00275   while(blkCnt > 0u)
    00276   {
    00277     /* Perform Multiplications and store in the destination buffer */
    00278     *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32);
    00279
    00280     /* Decrement the loop counter */
    00281     blkCnt--;
    00282   }
    00283
    00284   /* Load the coefficient value and
    00285    * increment the coefficient buffer for the next set of state values */
    00286   coeff = *pCoeffs++;
    00287
    00288   /* Read Index, from where the state buffer should be read, is calculated. */
    00289   readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++;
    00290
    00291   /* Wraparound of readIndex */
    00292   if(readIndex < 0)
    00293   {
    00294     readIndex += (int32_t) delaySize;
    00295   }
    00296
    00297   /* Loop over the number of taps. */
    00298   tapCnt = (uint32_t) numTaps - 1u;
    00299
    00300   while(tapCnt > 0u)
    00301   {
    00302     /* Working pointer for state buffer is updated */
    00303     py = pState;
    00304
    00305     /* blockSize samples are read from the state buffer */
    00306     arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1,
    00307                          (int32_t *) pb, (int32_t *) pb, blockSize, 1,
    00308                          blockSize);
    00309
    00310     /* Working pointer for the scratch buffer of state values */
    00311     px = pb;
    00312
    00313     /* Working pointer for scratch buffer of output values */
    00314     pOut = pDst;
    00315
    00316     blkCnt = blockSize;
    00317
    00318     while(blkCnt > 0u)
    00319     {
    00320       /* Perform Multiply-Accumulate */
    00321       out = *pOut;
    00322       out += ((q63_t) * px++ * coeff) >> 32;
    00323       *pOut++ = (q31_t) (out);
    00324
    00325       /* Decrement the loop counter */
    00326       blkCnt--;
    00327     }
    00328
    00329     /* Load the coefficient value and
    00330      * increment the coefficient buffer for the next set of state values */
    00331     coeff = *pCoeffs++;
    00332
    00333     /* Read Index, from where the state buffer should be read, is calculated. */
    00334     readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++;
    00335
    00336     /* Wraparound of readIndex */
    00337     if(readIndex < 0)
    00338     {
    00339       readIndex += (int32_t) delaySize;
    00340     }
    00341
    00342     /* Decrement the tap loop counter */
    00343     tapCnt--;
    00344   }
    00345
    00346   /* Working output pointer is updated */
    00347   pOut = pDst;
    00348
    00349   /* Output is converted into 1.31 format. */
    00350   blkCnt = blockSize;
    00351
    00352   while(blkCnt > 0u)
    00353   {
    00354     in = *pOut << 1;
    00355     *pOut++ = in;
    00356
    00357     /* Decrement the loop counter */
    00358     blkCnt--;
    00359   }
    00360
    00361 #endif /*   #ifndef ARM_MATH_CM0 */
    00362
    00363 }
    00364

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines