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