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_q7.c 00009 * 00010 * Description: Sum of the squares of the elements 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 00060 void arm_power_q7( 00061 q7_t * pSrc, 00062 uint32_t blockSize, 00063 q31_t * pResult) 00064 { 00065 q31_t acc = 0; /* Temporary result storage */ 00066 q31_t input1; /* Temporary variable to store packed input */ 00067 q7_t in; /* Temporary variable to store input */ 00068 uint32_t blkCnt; /* loop counter */ 00069 q31_t inA1, inA2; /* Temporary variables to hold intermiediate data */ 00070 q31_t acc1 = 0; 00071 00072 00073 /*loop Unrolling */ 00074 blkCnt = blockSize >> 3u; 00075 00076 /* First part of the processing with loop unrolling. Compute 8 outputs at a time. 00077 ** a second loop below computes the remaining 1 to 7 samples. */ 00078 while(blkCnt > 0u) 00079 { 00080 /* read four samples at a time from soruce buffer */ 00081 input1 = _SIMD32_OFFSET(pSrc); 00082 00083 /* extend two q7_t values to q15_t values */ 00084 #ifdef CCS 00085 00086 inA1 = __SXTB16(input1, 8); 00087 inA2 = __SXTB16(input1, 0); 00088 00089 #else 00090 00091 inA1 = __SXTB16(__ROR(input1, 8)); 00092 inA2 = __SXTB16(input1); 00093 00094 #endif // #ifdef CCS 00095 00096 /* calculate power and accumulate to accumulator */ 00097 acc = __SMLAD(inA1, inA1, acc); 00098 00099 /* read four samples at a time from soruce buffer */ 00100 input1 = _SIMD32_OFFSET(pSrc + 4); 00101 00102 #ifdef CCS 00103 00104 /* extend two q7_t values to q15_t values */ 00105 inA1 = __SXTB16(input1, 8); 00106 00107 /* calculate power and accumulate to accumulator */ 00108 acc1 = __SMLAD(inA2, inA2, acc1); 00109 00110 /* extend two q7_t values to q15_t values */ 00111 inA2 = __SXTB16(input1, 0); 00112 00113 #else 00114 00115 /* extend two q7_t values to q15_t values */ 00116 inA1 = __SXTB16(__ROR(input1, 8)); 00117 00118 /* calculate power and accumulate to accumulator */ 00119 acc1 = __SMLAD(inA2, inA2, acc1); 00120 00121 /* extend two q7_t values to q15_t values */ 00122 inA2 = __SXTB16(input1); 00123 00124 #endif // #ifdef CCS 00125 00126 /* calculate power and accumulate to accumulator */ 00127 acc = __SMLAD(inA1, inA1, acc); 00128 acc1 = __SMLAD(inA2, inA2, acc1); 00129 00130 /* update source buffer to process next samples */ 00131 pSrc += 8u; 00132 00133 /* Decrement the loop counter */ 00134 blkCnt--; 00135 } 00136 00137 /* add accumulators */ 00138 acc = acc + acc1; 00139 00140 /* If the blockSize is not a multiple of 8, compute any remaining output samples here. 00141 ** No loop unrolling is used. */ 00142 blkCnt = blockSize % 0x8u; 00143 00144 while(blkCnt > 0u) 00145 { 00146 /* C = A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + ... + A[blockSize-1] * A[blockSize-1] */ 00147 /* Compute Power and then store the result in a temporary variable, acc. */ 00148 in = *pSrc++; 00149 acc += ((q15_t) in * in); 00150 00151 /* Decrement the loop counter */ 00152 blkCnt--; 00153 } 00154 00155 /* Store the result in 18.14 format */ 00156 *pResult = acc; 00157 } 00158