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