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

- File List
- Globals

# arm_cmplx_mag_squared_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_cmplx_mag_squared_q31.c
    00009 *
    00010 * Description:  Q31 complex magnitude squared.
    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
    00030 #include "arm_math.h"
    00031
    00055 void arm_cmplx_mag_squared_q31(
    00056   q31_t * pSrc,
    00057   q31_t * pDst,
    00058   uint32_t numSamples)
    00059 {
    00060   q31_t real, imag;                              /* Temporary variables to store real and imaginary values */
    00061   q31_t acc0, acc1;                              /* Accumulators */
    00062
    00063 #ifndef ARM_MATH_CM0
    00064
    00065   /* Run the below code for Cortex-M4 and Cortex-M3 */
    00066   uint32_t blkCnt;                               /* loop counter */
    00067
    00068   /* loop Unrolling */
    00069   blkCnt = numSamples >> 2u;
    00070
    00071   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
    00072    ** a second loop below computes the remaining 1 to 3 samples. */
    00073   while(blkCnt > 0u)
    00074   {
    00075     /* C[0] = (A[0] * A[0] + A[1] * A[1]) */
    00076     real = *pSrc++;
    00077     imag = *pSrc++;
    00078     acc0 = (q31_t) (((q63_t) real * real) >> 33);
    00079     acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
    00080     /* store the result in 3.29 format in the destination buffer. */
    00081     *pDst++ = acc0 + acc1;
    00082
    00083     real = *pSrc++;
    00084     imag = *pSrc++;
    00085     acc0 = (q31_t) (((q63_t) real * real) >> 33);
    00086     acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
    00087     /* store the result in 3.29 format in the destination buffer. */
    00088     *pDst++ = acc0 + acc1;
    00089
    00090     real = *pSrc++;
    00091     imag = *pSrc++;
    00092     acc0 = (q31_t) (((q63_t) real * real) >> 33);
    00093     acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
    00094     /* store the result in 3.29 format in the destination buffer. */
    00095     *pDst++ = acc0 + acc1;
    00096
    00097     real = *pSrc++;
    00098     imag = *pSrc++;
    00099     acc0 = (q31_t) (((q63_t) real * real) >> 33);
    00100     acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
    00101     /* store the result in 3.29 format in the destination buffer. */
    00102     *pDst++ = acc0 + acc1;
    00103
    00104     /* Decrement the loop counter */
    00105     blkCnt--;
    00106   }
    00107
    00108   /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
    00109    ** No loop unrolling is used. */
    00110   blkCnt = numSamples % 0x4u;
    00111
    00112   while(blkCnt > 0u)
    00113   {
    00114     /* C[0] = (A[0] * A[0] + A[1] * A[1]) */
    00115     real = *pSrc++;
    00116     imag = *pSrc++;
    00117     acc0 = (q31_t) (((q63_t) real * real) >> 33);
    00118     acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
    00119     /* store the result in 3.29 format in the destination buffer. */
    00120     *pDst++ = acc0 + acc1;
    00121
    00122     /* Decrement the loop counter */
    00123     blkCnt--;
    00124   }
    00125
    00126 #else
    00127
    00128   /* Run the below code for Cortex-M0 */
    00129
    00130   while(numSamples > 0u)
    00131   {
    00132     /* out = ((real * real) + (imag * imag)) */
    00133     real = *pSrc++;
    00134     imag = *pSrc++;
    00135     acc0 = (q31_t) (((q63_t) real * real) >> 33);
    00136     acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
    00137     /* store the result in 3.29 format in the destination buffer. */
    00138     *pDst++ = acc0 + acc1;
    00139
    00140     /* Decrement the loop counter */
    00141     numSamples--;
    00142   }
    00143
    00144 #endif /* #ifndef ARM_MATH_CM0 */
    00145
    00146 }
    00147

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines