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

- File List
- Globals

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

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines