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_rms_q15.c 00009 * 00010 * Description: Root Mean Square of the elements of a Q15 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 00057 void arm_rms_q15( 00058 q15_t * pSrc, 00059 uint32_t blockSize, 00060 q15_t * pResult) 00061 { 00062 q63_t sum = 0; /* accumulator */ 00063 q31_t in1; /* temporary variable to store the input value */ 00064 q15_t in; /* temporary variable to store the input value */ 00065 uint32_t blkCnt; /* loop counter */ 00066 q31_t in2, in3, in4; /* temporary variabels to store input valeus */ 00067 00068 /* loop Unrolling */ 00069 blkCnt = blockSize >> 3u; 00070 00071 /* First part of the processing with loop unrolling. Compute 8 outputs at a time. 00072 ** a second loop below computes the remaining 1 to 7 samples. */ 00073 while(blkCnt > 0u) 00074 { 00075 /* C = (A[0] * A[0] + A[1] * A[1] + ... + A[blockSize-1] * A[blockSize-1]) */ 00076 /* Compute sum of the squares and then store the results in a temporary variable, sum */ 00077 /* read two samples from source buffer */ 00078 in1 = _SIMD32_OFFSET(pSrc); 00079 in2 = _SIMD32_OFFSET(pSrc + 2); 00080 00081 /* calculate power and accumulate to accumulator */ 00082 sum = __SMLALD(in1, in1, sum); 00083 00084 /* read two samples from source buffer */ 00085 in3 = _SIMD32_OFFSET(pSrc + 4); 00086 00087 /* calculate power and accumulate to accumulator */ 00088 sum = __SMLALD(in2, in2, sum); 00089 00090 /* read two samples from source buffer */ 00091 in4 = _SIMD32_OFFSET(pSrc + 6); 00092 00093 /* calculate power and accumulate to accumulator */ 00094 sum = __SMLALD(in3, in3, sum); 00095 sum = __SMLALD(in4, in4, sum); 00096 00097 /* update source buffer to process next sampels */ 00098 pSrc += 8u; 00099 00100 /* Decrement the loop counter */ 00101 blkCnt--; 00102 } 00103 00104 /* If the blockSize is not a multiple of 8, compute any remaining output samples here. 00105 ** No loop unrolling is used. */ 00106 blkCnt = blockSize % 0x8u; 00107 00108 while(blkCnt > 0u) 00109 { 00110 /* C = (A[0] * A[0] + A[1] * A[1] + ... + A[blockSize-1] * A[blockSize-1]) */ 00111 /* Compute sum of the squares and then store the results in a temporary variable, sum */ 00112 in = *pSrc++; 00113 sum = __SMLALD(in, in, sum); 00114 00115 /* Decrement the loop counter */ 00116 blkCnt--; 00117 } 00118 00119 /* Truncating and saturating the accumulator to 1.15 format */ 00120 #ifdef CCS 00121 sum = __SSATA((q31_t) (sum), 15, 16); 00122 #else 00123 sum = __SSAT((q31_t) (sum >> 15), 16); 00124 #endif 00125 00126 in1 = (q15_t) (sum / blockSize); 00127 00128 /* Store the result in the destination */ 00129 arm_sqrt_q15(in1, pResult); 00130 } 00131