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_q7.c 00009 * 00010 * Description: Mean value of a Q7 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_mean_q7( 00060 q7_t * pSrc, 00061 uint32_t blockSize, 00062 q7_t * pResult) 00063 { 00064 q31_t sum = 0; /* Temporary result storage */ 00065 uint32_t blkCnt; /* loop counter */ 00066 q7_t in1, in2, in3, in4; 00067 q31_t sum1 = 0; 00068 00069 /*loop Unrolling */ 00070 blkCnt = blockSize >> 3u; 00071 00072 /* First part of the processing with loop unrolling. Compute 16 outputs at a time. 00073 ** a second loop below computes the remaining 1 to 15 samples. */ 00074 while(blkCnt > 0u) 00075 { 00076 /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */ 00077 /* read four samples from source buffer */ 00078 in1 = pSrc[0]; 00079 in2 = pSrc[1]; 00080 in3 = pSrc[2]; 00081 in4 = pSrc[3]; 00082 00083 /* calculate sum of inputs */ 00084 sum += in1; 00085 sum += in2; 00086 sum += in3; 00087 sum += in4; 00088 00089 /* read four samples from source buffer */ 00090 in1 = pSrc[4]; 00091 in2 = pSrc[5]; 00092 in3 = pSrc[6]; 00093 in4 = pSrc[7]; 00094 00095 /* calculate sum of inputs */ 00096 sum += in1; 00097 sum += in2; 00098 sum += in3; 00099 sum += in4; 00100 00101 /* update source pointer to process next sampels */ 00102 pSrc += 8u; 00103 00104 /* Decrement the loop counter */ 00105 blkCnt--; 00106 } 00107 00108 /* add accumulators */ 00109 sum = sum + sum1; 00110 00111 /* If the blockSize is not a multiple of 16, compute any remaining output samples here. 00112 ** No loop unrolling is used. */ 00113 blkCnt = blockSize % 0x8u; 00114 00115 while(blkCnt > 0u) 00116 { 00117 /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */ 00118 sum += *pSrc++; 00119 00120 /* Decrement the loop counter */ 00121 blkCnt--; 00122 } 00123 00124 /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) / blockSize */ 00125 /* Store the result to the destination */ 00126 *pResult = (q7_t) (sum / (int32_t) blockSize); 00127 } 00128