00001 /* ---------------------------------------------------------------------- 00002 * Copyright (C) 2011 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 15. December 2011 00005 * $Revision: V2.0.0 00006 * 00007 * Project: Cortex-R DSP Library 00008 * Title: arm_cmplx_mag_squared_f32.c 00009 * 00010 * Description: Floating-point complex magnitude squared. 00011 * 00012 * Target Processor: Cortex-R4/R5 00013 * 00014 * Version 1.0.0 2011/03/08 00015 * Alpha release. 00016 * 00017 * Version 1.0.1 2011/09/30 00018 * Beta release. 00019 * 00020 * Version 2.0.0 2011/12/15 00021 * Final release. 00022 * 00023 * ---------------------------------------------------------------------------- */ 00024 #include "arm_math.h" 00025 00068 void arm_cmplx_mag_squared_f32( 00069 float32_t * pSrc, 00070 float32_t * pDst, 00071 uint32_t numSamples) 00072 { 00073 uint32_t blkCnt; /* loop counter */ 00074 float32_t real1, real2, real3, real4; /* Temporary variables to hold real values */ 00075 float32_t imag1, imag2, imag3, imag4; /* Temporary variables to hold imaginary values */ 00076 float32_t mul1, mul2, mul3, mul4; /* Temporary variables */ 00077 float32_t mul5, mul6, mul7, mul8; /* Temporary variables */ 00078 float32_t out1, out2, out3, out4; /* Temporary variables to hold output values */ 00079 00080 /*loop Unrolling */ 00081 blkCnt = numSamples >> 2u; 00082 00083 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00084 ** a second loop below computes the remaining 1 to 3 samples. */ 00085 while(blkCnt > 0u) 00086 { 00087 /* C[0] = (A[0] * A[0] + A[1] * A[1]) */ 00088 /* read real input sample from source buffer */ 00089 real1 = pSrc[0]; 00090 /* read imaginary input sample from source buffer */ 00091 imag1 = pSrc[1]; 00092 00093 /* calculate power of real value */ 00094 mul1 = real1 * real1; 00095 00096 /* read real input sample from source buffer */ 00097 real2 = pSrc[2]; 00098 00099 /* calculate power of imaginary value */ 00100 mul2 = imag1 * imag1; 00101 00102 /* read imaginary input sample from source buffer */ 00103 imag2 = pSrc[3]; 00104 00105 /* calculate power of real value */ 00106 mul3 = real2 * real2; 00107 00108 /* read real input sample from source buffer */ 00109 real3 = pSrc[4]; 00110 00111 /* calculate power of imaginary value */ 00112 mul4 = imag2 * imag2; 00113 00114 /* read imaginary input sample from source buffer */ 00115 imag3 = pSrc[5]; 00116 00117 /* calculate power of real value */ 00118 mul5 = real3 * real3; 00119 /* calculate power of imaginary value */ 00120 mul6 = imag3 * imag3; 00121 00122 /* read real input sample from source buffer */ 00123 real4 = pSrc[6]; 00124 00125 /* accumulate real and imaginary powers */ 00126 out1 = mul1 + mul2; 00127 00128 /* read imaginary input sample from source buffer */ 00129 imag4 = pSrc[7]; 00130 00131 /* accumulate real and imaginary powers */ 00132 out2 = mul3 + mul4; 00133 00134 /* calculate power of real value */ 00135 mul7 = real4 * real4; 00136 /* calculate power of imaginary value */ 00137 mul8 = imag4 * imag4; 00138 00139 /* store output to destination */ 00140 pDst[0] = out1; 00141 00142 /* accumulate real and imaginary powers */ 00143 out3 = mul5 + mul6; 00144 00145 /* store output to destination */ 00146 pDst[1] = out2; 00147 00148 /* accumulate real and imaginary powers */ 00149 out4 = mul7 + mul8; 00150 00151 /* store output to destination */ 00152 pDst[2] = out3; 00153 00154 /* increment destination pointer by 8 to process next samples */ 00155 pSrc += 8u; 00156 00157 /* store output to destination */ 00158 pDst[3] = out4; 00159 00160 /* increment destination pointer by 4 to process next samples */ 00161 pDst += 4u; 00162 00163 /* Decrement the loop counter */ 00164 blkCnt--; 00165 } 00166 00167 /* If the numSamples is not a multiple of 4, compute any remaining output samples here. 00168 ** No loop unrolling is used. */ 00169 blkCnt = numSamples % 0x4u; 00170 00171 while(blkCnt > 0u) 00172 { 00173 /* C[0] = (A[0] * A[0] + A[1] * A[1]) */ 00174 real1 = *pSrc++; 00175 imag1 = *pSrc++; 00176 /* store the result in the destination buffer. */ 00177 *pDst++ = (real1 * real1) + (imag1 * imag1); 00178 00179 /* Decrement the loop counter */ 00180 blkCnt--; 00181 } 00182 } 00183