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_power_f32.c 00009 * 00010 * Description: Sum of the squares of the elements of a floating-point vector. 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 00059 void arm_power_f32( 00060 float32_t * pSrc, 00061 uint32_t blockSize, 00062 float32_t * pResult) 00063 { 00064 float32_t in; /* Temporary variable to store input value */ 00065 uint32_t blkCnt; /* loop counter */ 00066 float32_t in1, in2, in3, in4; /* Temporary variables to hold input data */ 00067 float32_t acc1 = 0.0f, acc2 = 0.0f; /* accumulators */ 00068 float32_t acc3 = 0.0f, acc4 = 0.0f; /* accumulators */ 00069 00070 /*loop Unrolling */ 00071 blkCnt = blockSize >> 3u; 00072 00073 /* First part of the processing with loop unrolling. Compute 8 outputs at a time. 00074 ** a second loop below computes the remaining 1 to 7 samples. */ 00075 while(blkCnt > 0u) 00076 { 00077 /* C = A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + ... + A[blockSize-1] * A[blockSize-1] */ 00078 /* Compute Power and then store the result in a temporary variable, acc. */ 00079 /* load four samples from source buffer */ 00080 in1 = pSrc[0]; 00081 in2 = pSrc[1]; 00082 in3 = pSrc[2]; 00083 in4 = pSrc[3]; 00084 00085 /* calculate square of input and accumulate it to accumulator */ 00086 acc1 += in1 * in1; 00087 acc2 += in2 * in2; 00088 acc3 += in3 * in3; 00089 acc4 += in4 * in4; 00090 00091 /* load four samples from source buffer */ 00092 in1 = pSrc[4]; 00093 in2 = pSrc[5]; 00094 in3 = pSrc[6]; 00095 in4 = pSrc[7]; 00096 00097 /* calculate square of input and accumulate it to accumulator */ 00098 acc1 += in1 * in1; 00099 acc2 += in2 * in2; 00100 acc3 += in3 * in3; 00101 acc4 += in4 * in4; 00102 00103 /* update source pointer to process next samples */ 00104 pSrc += 8u; 00105 00106 /* Decrement the loop counter */ 00107 blkCnt--; 00108 } 00109 00110 /* add accumulators */ 00111 acc1 = acc1 + acc2 + acc3 + acc4; 00112 00113 /* If the blockSize is not a multiple of 8, compute any remaining output samples here. 00114 ** No loop unrolling is used. */ 00115 blkCnt = blockSize % 0x8u; 00116 00117 while(blkCnt > 0u) 00118 { 00119 /* C = A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + ... + A[blockSize-1] * A[blockSize-1] */ 00120 /* compute power and then store the result in a temporary variable, acc. */ 00121 in = *pSrc++; 00122 acc1 += in * in; 00123 00124 /* Decrement the loop counter */ 00125 blkCnt--; 00126 } 00127 00128 /* Store the result to the destination */ 00129 *pResult = acc1; 00130 } 00131