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_mean_f32.c 00009 * 00010 * Description: Mean value 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 00058 void arm_mean_f32( 00059 float32_t * pSrc, 00060 uint32_t blockSize, 00061 float32_t * pResult) 00062 { 00063 float32_t sum1 = 0.0f; /* Temporary result storage */ 00064 float32_t sum2 = 0.0f; /* Temporary result storage */ 00065 uint32_t blkCnt; /* loop counter */ 00066 float32_t in1, in2, in3, in4; /* Temporary variabels to hold input data */ 00067 float32_t in5, in6, in7, in8; /* Temporary variabels to hold input data */ 00068 00069 /*loop Unrolling */ 00070 blkCnt = blockSize >> 3u; 00071 00072 /* First part of the processing with loop unrolling. Compute 8 outputs at a time. 00073 ** a second loop below computes the remaining 1 to 7 samples. */ 00074 while(blkCnt > 0u) 00075 { 00076 /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */ 00077 /* read inputs from source buffer */ 00078 in1 = pSrc[0]; 00079 in2 = pSrc[1]; 00080 in3 = pSrc[2]; 00081 00082 /* accumulate to sum1 */ 00083 sum1 += in1; 00084 00085 /* read input from source buffer */ 00086 in4 = pSrc[3]; 00087 00088 /* accumulate to sum2 */ 00089 sum2 += in2; 00090 00091 /* read input from source buffer */ 00092 in5 = pSrc[4]; 00093 00094 /* accumulate to sum1 */ 00095 sum1 += in3; 00096 00097 /* read input from source buffer */ 00098 in6 = pSrc[5]; 00099 00100 /* accumulate to sum1 */ 00101 sum2 += in4; 00102 00103 /* read input from source buffer */ 00104 in7 = pSrc[6]; 00105 00106 /* accumulate to sum1 */ 00107 sum1 += in5; 00108 00109 /* read input from source buffer */ 00110 in8 = pSrc[7]; 00111 00112 /* update source buffer to process next sampels */ 00113 pSrc += 8u; 00114 00115 /* accumulate to sum2 */ 00116 sum2 += in6; 00117 00118 /* accumulate to sum1 */ 00119 sum1 += in7; 00120 00121 /* accumulate to sum2 */ 00122 sum2 += in8; 00123 00124 /* Decrement the loop counter */ 00125 blkCnt--; 00126 } 00127 00128 /* add two accumulators */ 00129 sum1 = sum2 + sum1; 00130 00131 /* If the blockSize is not a multiple of 8, compute any remaining output samples here. 00132 ** No loop unrolling is used. */ 00133 blkCnt = blockSize % 0x8u; 00134 00135 while(blkCnt > 0u) 00136 { 00137 /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */ 00138 sum1 += *pSrc++; 00139 00140 /* Decrement the loop counter */ 00141 blkCnt--; 00142 } 00143 00144 /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) / blockSize */ 00145 /* Store the result to the destination */ 00146 *pResult = sum1 / (float32_t) blockSize; 00147 } 00148