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

- File List
- Globals

# arm_fir_lattice_q15.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_lattice_q15.c
    00009 *
    00010 * Description:  Q15 FIR lattice 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
    00033 #include "arm_math.h"
    00034
    00054 void arm_fir_lattice_q15(
    00055   const arm_fir_lattice_instance_q15 * S,
    00056   q15_t * pSrc,
    00057   q15_t * pDst,
    00058   uint32_t blockSize)
    00059 {
    00060   q15_t *pState;                                 /* State pointer */
    00061   q15_t *pCoeffs = S->pCoeffs;                   /* Coefficient pointer */
    00062   q15_t *px;                                     /* temporary state pointer */
    00063   q15_t *pk;                                     /* temporary coefficient pointer */
    00064
    00065
    00066 #ifndef ARM_MATH_CM0
    00067
    00068   /* Run the below code for Cortex-M4 and Cortex-M3 */
    00069
    00070   q31_t fcurnt1, fnext1, gcurnt1 = 0, gnext1;    /* temporary variables for first sample in loop unrolling */
    00071   q31_t fcurnt2, fnext2, gnext2;                 /* temporary variables for second sample in loop unrolling */
    00072   q31_t fcurnt3, fnext3, gnext3;                 /* temporary variables for third sample in loop unrolling */
    00073   q31_t fcurnt4, fnext4, gnext4;                 /* temporary variables for fourth sample in loop unrolling */
    00074   uint32_t numStages = S->numStages;             /* Number of stages in the filter */
    00075   uint32_t blkCnt, stageCnt;                     /* temporary variables for counts */
    00076
    00077   pState = &S->pState[0];
    00078
    00079   blkCnt = blockSize >> 2u;
    00080
    00081   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
    00082    ** a second loop below computes the remaining 1 to 3 samples. */
    00083   while(blkCnt > 0u)
    00084   {
    00085
    00086     /* Read two samples from input buffer */
    00087     /* f0(n) = x(n) */
    00088     fcurnt1 = *pSrc++;
    00089     fcurnt2 = *pSrc++;
    00090
    00091     /* Initialize coeff pointer */
    00092     pk = (pCoeffs);
    00093
    00094     /* Initialize state pointer */
    00095     px = pState;
    00096
    00097     /* Read g0(n-1) from state */
    00098     gcurnt1 = *px;
    00099
    00100     /* Process first sample for first tap */
    00101     /* f1(n) = f0(n) +  K1 * g0(n-1) */
    00102     fnext1 = (q31_t) ((gcurnt1 * (*pk)) >> 15u) + fcurnt1;
    00103     fnext1 = __SSAT(fnext1, 16);
    00104
    00105     /* g1(n) = f0(n) * K1  +  g0(n-1) */
    00106     gnext1 = (q31_t) ((fcurnt1 * (*pk)) >> 15u) + gcurnt1;
    00107     gnext1 = __SSAT(gnext1, 16);
    00108
    00109     /* Process second sample for first tap */
    00110     /* for sample 2 processing */
    00111     fnext2 = (q31_t) ((fcurnt1 * (*pk)) >> 15u) + fcurnt2;
    00112     fnext2 = __SSAT(fnext2, 16);
    00113
    00114     gnext2 = (q31_t) ((fcurnt2 * (*pk)) >> 15u) + fcurnt1;
    00115     gnext2 = __SSAT(gnext2, 16);
    00116
    00117
    00118     /* Read next two samples from input buffer */
    00119     /* f0(n+2) = x(n+2) */
    00120     fcurnt3 = *pSrc++;
    00121     fcurnt4 = *pSrc++;
    00122
    00123     /* Copy only last input samples into the state buffer
    00124        which is used for next four samples processing */
    00125     *px++ = (q15_t) fcurnt4;
    00126
    00127     /* Process third sample for first tap */
    00128     fnext3 = (q31_t) ((fcurnt2 * (*pk)) >> 15u) + fcurnt3;
    00129     fnext3 = __SSAT(fnext3, 16);
    00130     gnext3 = (q31_t) ((fcurnt3 * (*pk)) >> 15u) + fcurnt2;
    00131     gnext3 = __SSAT(gnext3, 16);
    00132
    00133     /* Process fourth sample for first tap */
    00134     fnext4 = (q31_t) ((fcurnt3 * (*pk)) >> 15u) + fcurnt4;
    00135     fnext4 = __SSAT(fnext4, 16);
    00136     gnext4 = (q31_t) ((fcurnt4 * (*pk++)) >> 15u) + fcurnt3;
    00137     gnext4 = __SSAT(gnext4, 16);
    00138
    00139     /* Update of f values for next coefficient set processing */
    00140     fcurnt1 = fnext1;
    00141     fcurnt2 = fnext2;
    00142     fcurnt3 = fnext3;
    00143     fcurnt4 = fnext4;
    00144
    00145
    00146     /* Loop unrolling.  Process 4 taps at a time . */
    00147     stageCnt = (numStages - 1u) >> 2;
    00148
    00149
    00150     /* Loop over the number of taps.  Unroll by a factor of 4.
    00151      ** Repeat until we've computed numStages-3 coefficients. */
    00152
    00153     /* Process 2nd, 3rd, 4th and 5th taps ... here */
    00154     while(stageCnt > 0u)
    00155     {
    00156       /* Read g1(n-1), g3(n-1) .... from state */
    00157       gcurnt1 = *px;
    00158
    00159       /* save g1(n) in state buffer */
    00160       *px++ = (q15_t) gnext4;
    00161
    00162       /* Process first sample for 2nd, 6th .. tap */
    00163       /* Sample processing for K2, K6.... */
    00164       /* f1(n) = f0(n) +  K1 * g0(n-1) */
    00165       fnext1 = (q31_t) ((gcurnt1 * (*pk)) >> 15u) + fcurnt1;
    00166       fnext1 = __SSAT(fnext1, 16);
    00167
    00168
    00169       /* Process second sample for 2nd, 6th .. tap */
    00170       /* for sample 2 processing */
    00171       fnext2 = (q31_t) ((gnext1 * (*pk)) >> 15u) + fcurnt2;
    00172       fnext2 = __SSAT(fnext2, 16);
    00173       /* Process third sample for 2nd, 6th .. tap */
    00174       fnext3 = (q31_t) ((gnext2 * (*pk)) >> 15u) + fcurnt3;
    00175       fnext3 = __SSAT(fnext3, 16);
    00176       /* Process fourth sample for 2nd, 6th .. tap */
    00177       /* fnext4 = fcurnt4 + (*pk) * gnext3; */
    00178       fnext4 = (q31_t) ((gnext3 * (*pk)) >> 15u) + fcurnt4;
    00179       fnext4 = __SSAT(fnext4, 16);
    00180
    00181       /* g1(n) = f0(n) * K1  +  g0(n-1) */
    00182       /* Calculation of state values for next stage */
    00183       gnext4 = (q31_t) ((fcurnt4 * (*pk)) >> 15u) + gnext3;
    00184       gnext4 = __SSAT(gnext4, 16);
    00185       gnext3 = (q31_t) ((fcurnt3 * (*pk)) >> 15u) + gnext2;
    00186       gnext3 = __SSAT(gnext3, 16);
    00187
    00188       gnext2 = (q31_t) ((fcurnt2 * (*pk)) >> 15u) + gnext1;
    00189       gnext2 = __SSAT(gnext2, 16);
    00190
    00191       gnext1 = (q31_t) ((fcurnt1 * (*pk++)) >> 15u) + gcurnt1;
    00192       gnext1 = __SSAT(gnext1, 16);
    00193
    00194
    00195       /* Read g2(n-1), g4(n-1) .... from state */
    00196       gcurnt1 = *px;
    00197
    00198       /* save g1(n) in state buffer */
    00199       *px++ = (q15_t) gnext4;
    00200
    00201       /* Sample processing for K3, K7.... */
    00202       /* Process first sample for 3rd, 7th .. tap */
    00203       /* f3(n) = f2(n) +  K3 * g2(n-1) */
    00204       fcurnt1 = (q31_t) ((gcurnt1 * (*pk)) >> 15u) + fnext1;
    00205       fcurnt1 = __SSAT(fcurnt1, 16);
    00206
    00207       /* Process second sample for 3rd, 7th .. tap */
    00208       fcurnt2 = (q31_t) ((gnext1 * (*pk)) >> 15u) + fnext2;
    00209       fcurnt2 = __SSAT(fcurnt2, 16);
    00210
    00211       /* Process third sample for 3rd, 7th .. tap */
    00212       fcurnt3 = (q31_t) ((gnext2 * (*pk)) >> 15u) + fnext3;
    00213       fcurnt3 = __SSAT(fcurnt3, 16);
    00214
    00215       /* Process fourth sample for 3rd, 7th .. tap */
    00216       fcurnt4 = (q31_t) ((gnext3 * (*pk)) >> 15u) + fnext4;
    00217       fcurnt4 = __SSAT(fcurnt4, 16);
    00218
    00219       /* Calculation of state values for next stage */
    00220       /* g3(n) = f2(n) * K3  +  g2(n-1) */
    00221       gnext4 = (q31_t) ((fnext4 * (*pk)) >> 15u) + gnext3;
    00222       gnext4 = __SSAT(gnext4, 16);
    00223
    00224       gnext3 = (q31_t) ((fnext3 * (*pk)) >> 15u) + gnext2;
    00225       gnext3 = __SSAT(gnext3, 16);
    00226
    00227       gnext2 = (q31_t) ((fnext2 * (*pk)) >> 15u) + gnext1;
    00228       gnext2 = __SSAT(gnext2, 16);
    00229
    00230       gnext1 = (q31_t) ((fnext1 * (*pk++)) >> 15u) + gcurnt1;
    00231       gnext1 = __SSAT(gnext1, 16);
    00232
    00233       /* Read g1(n-1), g3(n-1) .... from state */
    00234       gcurnt1 = *px;
    00235
    00236       /* save g1(n) in state buffer */
    00237       *px++ = (q15_t) gnext4;
    00238
    00239       /* Sample processing for K4, K8.... */
    00240       /* Process first sample for 4th, 8th .. tap */
    00241       /* f4(n) = f3(n) +  K4 * g3(n-1) */
    00242       fnext1 = (q31_t) ((gcurnt1 * (*pk)) >> 15u) + fcurnt1;
    00243       fnext1 = __SSAT(fnext1, 16);
    00244
    00245       /* Process second sample for 4th, 8th .. tap */
    00246       /* for sample 2 processing */
    00247       fnext2 = (q31_t) ((gnext1 * (*pk)) >> 15u) + fcurnt2;
    00248       fnext2 = __SSAT(fnext2, 16);
    00249
    00250       /* Process third sample for 4th, 8th .. tap */
    00251       fnext3 = (q31_t) ((gnext2 * (*pk)) >> 15u) + fcurnt3;
    00252       fnext3 = __SSAT(fnext3, 16);
    00253
    00254       /* Process fourth sample for 4th, 8th .. tap */
    00255       fnext4 = (q31_t) ((gnext3 * (*pk)) >> 15u) + fcurnt4;
    00256       fnext4 = __SSAT(fnext4, 16);
    00257
    00258       /* g4(n) = f3(n) * K4  +  g3(n-1) */
    00259       /* Calculation of state values for next stage */
    00260       gnext4 = (q31_t) ((fcurnt4 * (*pk)) >> 15u) + gnext3;
    00261       gnext4 = __SSAT(gnext4, 16);
    00262
    00263       gnext3 = (q31_t) ((fcurnt3 * (*pk)) >> 15u) + gnext2;
    00264       gnext3 = __SSAT(gnext3, 16);
    00265
    00266       gnext2 = (q31_t) ((fcurnt2 * (*pk)) >> 15u) + gnext1;
    00267       gnext2 = __SSAT(gnext2, 16);
    00268       gnext1 = (q31_t) ((fcurnt1 * (*pk++)) >> 15u) + gcurnt1;
    00269       gnext1 = __SSAT(gnext1, 16);
    00270
    00271
    00272       /* Read g2(n-1), g4(n-1) .... from state */
    00273       gcurnt1 = *px;
    00274
    00275       /* save g4(n) in state buffer */
    00276       *px++ = (q15_t) gnext4;
    00277
    00278       /* Sample processing for K5, K9.... */
    00279       /* Process first sample for 5th, 9th .. tap */
    00280       /* f5(n) = f4(n) +  K5 * g4(n-1) */
    00281       fcurnt1 = (q31_t) ((gcurnt1 * (*pk)) >> 15u) + fnext1;
    00282       fcurnt1 = __SSAT(fcurnt1, 16);
    00283
    00284       /* Process second sample for 5th, 9th .. tap */
    00285       fcurnt2 = (q31_t) ((gnext1 * (*pk)) >> 15u) + fnext2;
    00286       fcurnt2 = __SSAT(fcurnt2, 16);
    00287
    00288       /* Process third sample for 5th, 9th .. tap */
    00289       fcurnt3 = (q31_t) ((gnext2 * (*pk)) >> 15u) + fnext3;
    00290       fcurnt3 = __SSAT(fcurnt3, 16);
    00291
    00292       /* Process fourth sample for 5th, 9th .. tap */
    00293       fcurnt4 = (q31_t) ((gnext3 * (*pk)) >> 15u) + fnext4;
    00294       fcurnt4 = __SSAT(fcurnt4, 16);
    00295
    00296       /* Calculation of state values for next stage */
    00297       /* g5(n) = f4(n) * K5  +  g4(n-1) */
    00298       gnext4 = (q31_t) ((fnext4 * (*pk)) >> 15u) + gnext3;
    00299       gnext4 = __SSAT(gnext4, 16);
    00300       gnext3 = (q31_t) ((fnext3 * (*pk)) >> 15u) + gnext2;
    00301       gnext3 = __SSAT(gnext3, 16);
    00302       gnext2 = (q31_t) ((fnext2 * (*pk)) >> 15u) + gnext1;
    00303       gnext2 = __SSAT(gnext2, 16);
    00304       gnext1 = (q31_t) ((fnext1 * (*pk++)) >> 15u) + gcurnt1;
    00305       gnext1 = __SSAT(gnext1, 16);
    00306
    00307       stageCnt--;
    00308     }
    00309
    00310     /* If the (filter length -1) is not a multiple of 4, compute the remaining filter taps */
    00311     stageCnt = (numStages - 1u) % 0x4u;
    00312
    00313     while(stageCnt > 0u)
    00314     {
    00315       gcurnt1 = *px;
    00316
    00317       /* save g value in state buffer */
    00318       *px++ = (q15_t) gnext4;
    00319
    00320       /* Process four samples for last three taps here */
    00321       fnext1 = (q31_t) ((gcurnt1 * (*pk)) >> 15u) + fcurnt1;
    00322       fnext1 = __SSAT(fnext1, 16);
    00323       fnext2 = (q31_t) ((gnext1 * (*pk)) >> 15u) + fcurnt2;
    00324       fnext2 = __SSAT(fnext2, 16);
    00325
    00326       fnext3 = (q31_t) ((gnext2 * (*pk)) >> 15u) + fcurnt3;
    00327       fnext3 = __SSAT(fnext3, 16);
    00328
    00329       fnext4 = (q31_t) ((gnext3 * (*pk)) >> 15u) + fcurnt4;
    00330       fnext4 = __SSAT(fnext4, 16);
    00331
    00332       /* g1(n) = f0(n) * K1  +  g0(n-1) */
    00333       gnext4 = (q31_t) ((fcurnt4 * (*pk)) >> 15u) + gnext3;
    00334       gnext4 = __SSAT(gnext4, 16);
    00335       gnext3 = (q31_t) ((fcurnt3 * (*pk)) >> 15u) + gnext2;
    00336       gnext3 = __SSAT(gnext3, 16);
    00337       gnext2 = (q31_t) ((fcurnt2 * (*pk)) >> 15u) + gnext1;
    00338       gnext2 = __SSAT(gnext2, 16);
    00339       gnext1 = (q31_t) ((fcurnt1 * (*pk++)) >> 15u) + gcurnt1;
    00340       gnext1 = __SSAT(gnext1, 16);
    00341
    00342       /* Update of f values for next coefficient set processing */
    00343       fcurnt1 = fnext1;
    00344       fcurnt2 = fnext2;
    00345       fcurnt3 = fnext3;
    00346       fcurnt4 = fnext4;
    00347
    00348       stageCnt--;
    00349
    00350     }
    00351
    00352     /* The results in the 4 accumulators, store in the destination buffer. */
    00353     /* y(n) = fN(n) */
    00354
    00355 #ifndef  ARM_MATH_BIG_ENDIAN
    00356
    00357     *__SIMD32(pDst)++ = __PKHBT(fcurnt1, fcurnt2, 16);
    00358     *__SIMD32(pDst)++ = __PKHBT(fcurnt3, fcurnt4, 16);
    00359
    00360 #else
    00361
    00362     *__SIMD32(pDst)++ = __PKHBT(fcurnt2, fcurnt1, 16);
    00363     *__SIMD32(pDst)++ = __PKHBT(fcurnt4, fcurnt3, 16);
    00364
    00365 #endif /*      #ifndef  ARM_MATH_BIG_ENDIAN    */
    00366
    00367     blkCnt--;
    00368   }
    00369
    00370   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
    00371    ** No loop unrolling is used. */
    00372   blkCnt = blockSize % 0x4u;
    00373
    00374   while(blkCnt > 0u)
    00375   {
    00376     /* f0(n) = x(n) */
    00377     fcurnt1 = *pSrc++;
    00378
    00379     /* Initialize coeff pointer */
    00380     pk = (pCoeffs);
    00381
    00382     /* Initialize state pointer */
    00383     px = pState;
    00384
    00385     /* read g2(n) from state buffer */
    00386     gcurnt1 = *px;
    00387
    00388     /* for sample 1 processing */
    00389     /* f1(n) = f0(n) +  K1 * g0(n-1) */
    00390     fnext1 = (((q31_t) gcurnt1 * (*pk)) >> 15u) + fcurnt1;
    00391     fnext1 = __SSAT(fnext1, 16);
    00392
    00393
    00394     /* g1(n) = f0(n) * K1  +  g0(n-1) */
    00395     gnext1 = (((q31_t) fcurnt1 * (*pk++)) >> 15u) + gcurnt1;
    00396     gnext1 = __SSAT(gnext1, 16);
    00397
    00398     /* save g1(n) in state buffer */
    00399     *px++ = (q15_t) fcurnt1;
    00400
    00401     /* f1(n) is saved in fcurnt1
    00402        for next stage processing */
    00403     fcurnt1 = fnext1;
    00404
    00405     stageCnt = (numStages - 1u);
    00406
    00407     /* stage loop */
    00408     while(stageCnt > 0u)
    00409     {
    00410       /* read g2(n) from state buffer */
    00411       gcurnt1 = *px;
    00412
    00413       /* save g1(n) in state buffer */
    00414       *px++ = (q15_t) gnext1;
    00415
    00416       /* Sample processing for K2, K3.... */
    00417       /* f2(n) = f1(n) +  K2 * g1(n-1) */
    00418       fnext1 = (((q31_t) gcurnt1 * (*pk)) >> 15u) + fcurnt1;
    00419       fnext1 = __SSAT(fnext1, 16);
    00420
    00421       /* g2(n) = f1(n) * K2  +  g1(n-1) */
    00422       gnext1 = (((q31_t) fcurnt1 * (*pk++)) >> 15u) + gcurnt1;
    00423       gnext1 = __SSAT(gnext1, 16);
    00424
    00425
    00426       /* f1(n) is saved in fcurnt1
    00427          for next stage processing */
    00428       fcurnt1 = fnext1;
    00429
    00430       stageCnt--;
    00431
    00432     }
    00433
    00434     /* y(n) = fN(n) */
    00435     *pDst++ = __SSAT(fcurnt1, 16);
    00436
    00437
    00438     blkCnt--;
    00439
    00440   }
    00441
    00442 #else
    00443
    00444   /* Run the below code for Cortex-M0 */
    00445
    00446   q31_t fcurnt, fnext, gcurnt, gnext;            /* temporary variables */
    00447   uint32_t numStages = S->numStages;             /* Length of the filter */
    00448   uint32_t blkCnt, stageCnt;                     /* temporary variables for counts */
    00449
    00450   pState = &S->pState[0];
    00451
    00452   blkCnt = blockSize;
    00453
    00454   while(blkCnt > 0u)
    00455   {
    00456     /* f0(n) = x(n) */
    00457     fcurnt = *pSrc++;
    00458
    00459     /* Initialize coeff pointer */
    00460     pk = (pCoeffs);
    00461
    00462     /* Initialize state pointer */
    00463     px = pState;
    00464
    00465     /* read g0(n-1) from state buffer */
    00466     gcurnt = *px;
    00467
    00468     /* for sample 1 processing */
    00469     /* f1(n) = f0(n) +  K1 * g0(n-1) */
    00470     fnext = ((gcurnt * (*pk)) >> 15u) + fcurnt;
    00471     fnext = __SSAT(fnext, 16);
    00472
    00473
    00474     /* g1(n) = f0(n) * K1  +  g0(n-1) */
    00475     gnext = ((fcurnt * (*pk++)) >> 15u) + gcurnt;
    00476     gnext = __SSAT(gnext, 16);
    00477
    00478     /* save f0(n) in state buffer */
    00479     *px++ = (q15_t) fcurnt;
    00480
    00481     /* f1(n) is saved in fcurnt
    00482        for next stage processing */
    00483     fcurnt = fnext;
    00484
    00485     stageCnt = (numStages - 1u);
    00486
    00487     /* stage loop */
    00488     while(stageCnt > 0u)
    00489     {
    00490       /* read g1(n-1) from state buffer */
    00491       gcurnt = *px;
    00492
    00493       /* save g0(n-1) in state buffer */
    00494       *px++ = (q15_t) gnext;
    00495
    00496       /* Sample processing for K2, K3.... */
    00497       /* f2(n) = f1(n) +  K2 * g1(n-1) */
    00498       fnext = ((gcurnt * (*pk)) >> 15u) + fcurnt;
    00499       fnext = __SSAT(fnext, 16);
    00500
    00501       /* g2(n) = f1(n) * K2  +  g1(n-1) */
    00502       gnext = ((fcurnt * (*pk++)) >> 15u) + gcurnt;
    00503       gnext = __SSAT(gnext, 16);
    00504
    00505
    00506       /* f1(n) is saved in fcurnt
    00507          for next stage processing */
    00508       fcurnt = fnext;
    00509
    00510       stageCnt--;
    00511
    00512     }
    00513
    00514     /* y(n) = fN(n) */
    00515     *pDst++ = __SSAT(fcurnt, 16);
    00516
    00517
    00518     blkCnt--;
    00519
    00520   }
    00521
    00522 #endif /*   #ifndef ARM_MATH_CM0 */
    00523
    00524 }
    00525

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines