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_q15.c 00009 * 00010 * Description: Sum of the squares 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 00060 void arm_power_q15( 00061 q15_t * pSrc, 00062 uint32_t blockSize, 00063 q63_t * pResult) 00064 { 00065 q63_t acc = 0; /* Temporary result storage */ 00066 q15_t in16; /* Temporary variable to store input value */ 00067 uint32_t blkCnt; /* loop counter */ 00068 q31_t in1, in2, in3, in4; /* Temporary variable to store input value */ 00069 00070 00071 /* loop Unrolling */ 00072 blkCnt = blockSize >> 3u; 00073 00074 /* First part of the processing with loop unrolling. Compute 8 outputs at a time. 00075 ** a second loop below computes the remaining 1 to 7 samples. */ 00076 while(blkCnt > 0u) 00077 { 00078 /* C = A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + ... + A[blockSize-1] * A[blockSize-1] */ 00079 /* Compute Power and then store the result in a temporary variable, acc. */ 00080 /* read two inputs at a time from source */ 00081 in1 = _SIMD32_OFFSET(pSrc); 00082 in2 = _SIMD32_OFFSET(pSrc + 2); 00083 00084 /* caluculate power and accumulate it ot accumulator */ 00085 acc = __SMLALD(in1, in1, acc); 00086 00087 /* read two inputs at a time from source */ 00088 in3 = _SIMD32_OFFSET(pSrc + 4); 00089 00090 /* caluculate power and accumulate it ot accumulator */ 00091 acc = __SMLALD(in2, in2, acc); 00092 00093 /* read two inputs at a time from source */ 00094 in4 = _SIMD32_OFFSET(pSrc + 6); 00095 00096 /* caluculate power and accumulate it ot accumulator */ 00097 acc = __SMLALD(in3, in3, acc); 00098 acc = __SMLALD(in4, in4, acc); 00099 00100 /* update source pointer to process next sampels */ 00101 pSrc += 8u; 00102 00103 /* Decrement the loop counter */ 00104 blkCnt--; 00105 } 00106 00107 /* If the blockSize is not a multiple of 8, compute any remaining output samples here. 00108 ** No loop unrolling is used. */ 00109 blkCnt = blockSize % 0x8u; 00110 00111 while(blkCnt > 0u) 00112 { 00113 /* C = A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + ... + A[blockSize-1] * A[blockSize-1] */ 00114 /* Compute Power and then store the result in a temporary variable, acc. */ 00115 in16 = *pSrc++; 00116 acc = __SMLALD(in16, in16, acc); 00117 00118 /* Decrement the loop counter */ 00119 blkCnt--; 00120 } 00121 00122 /* Store the results in 34.30 format */ 00123 *pResult = acc; 00124 } 00125