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_dot_prod_q7.c 00009 * 00010 * Description: Q7 dot product. 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 00056 void arm_dot_prod_q7( 00057 q7_t * pSrcA, 00058 q7_t * pSrcB, 00059 uint32_t blockSize, 00060 q31_t * result) 00061 { 00062 q31_t input1, input2; /* Temporary variables to store input */ 00063 q31_t sum = 0; /* Temporary variables to store output */ 00064 uint32_t blkCnt; /* loop counter */ 00065 q31_t inA1, inB1, inA2, inB2; 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 /* read 4 samples at a time from sourceA */ 00075 input1 = *__SIMD32(pSrcA)++; 00076 /* read 4 samples at a time from sourceB */ 00077 input2 = *__SIMD32(pSrcB)++; 00078 00079 #ifdef CCS 00080 00081 /* extract two q7_t samples to q15_t samples */ 00082 inA1 = __SXTB16(input1, 8); 00083 /* extract reminaing two samples */ 00084 inA2 = __SXTB16(input1, 0); 00085 /* extract two q7_t samples to q15_t samples */ 00086 inB1 = __SXTB16(input2, 8); 00087 /* extract reminaing two samples */ 00088 inB2 = __SXTB16(input2, 0); 00089 00090 #else 00091 00092 /* extract two q7_t samples to q15_t samples */ 00093 inA1 = __SXTB16(__ROR(input1, 8)); 00094 /* extract reminaing two samples */ 00095 inA2 = __SXTB16(input1); 00096 /* extract two q7_t samples to q15_t samples */ 00097 inB1 = __SXTB16(__ROR(input2, 8)); 00098 /* extract reminaing two samples */ 00099 inB2 = __SXTB16(input2); 00100 00101 #endif 00102 00103 /* multiply and accumulate two samples at a time */ 00104 sum = __SMLAD(inA1, inB1, sum); 00105 sum = __SMLAD(inA2, inB2, sum); 00106 00107 /* read 4 samples at a time from sourceA */ 00108 input1 = *__SIMD32(pSrcA)++; 00109 /* read 4 samples at a time from sourceB */ 00110 input2 = *__SIMD32(pSrcB)++; 00111 00112 #ifdef CCS 00113 00114 /* extract two q7_t samples to q15_t samples */ 00115 inA1 = __SXTB16(input1, 8); 00116 /* extract reminaing two samples */ 00117 inA2 = __SXTB16(input1, 0); 00118 /* extract two q7_t samples to q15_t samples */ 00119 inB1 = __SXTB16(input2, 8); 00120 /* extract reminaing two samples */ 00121 inB2 = __SXTB16(input2, 0); 00122 00123 #else 00124 00125 /* extract two q7_t samples to q15_t samples */ 00126 inA1 = __SXTB16(__ROR(input1, 8)); 00127 /* extract reminaing two samples */ 00128 inA2 = __SXTB16(input1); 00129 /* extract two q7_t samples to q15_t samples */ 00130 inB1 = __SXTB16(__ROR(input2, 8)); 00131 /* extract reminaing two samples */ 00132 inB2 = __SXTB16(input2); 00133 00134 #endif 00135 00136 /* multiply and accumulate two samples at a time */ 00137 sum = __SMLAD(inA1, inB1, sum); 00138 sum = __SMLAD(inA2, inB2, sum); 00139 00140 /* Decrement the loop counter */ 00141 blkCnt--; 00142 } 00143 00144 /* If the blockSize is not a multiple of 8, compute any remaining output samples here. 00145 ** No loop unrolling is used. */ 00146 blkCnt = blockSize % 0x8u; 00147 00148 while(blkCnt > 0u) 00149 { 00150 /* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */ 00151 /* Dot product and then store the results in a temporary buffer. */ 00152 sum = __SMLAD(*pSrcA++, *pSrcB++, sum); 00153 00154 /* Decrement the loop counter */ 00155 blkCnt--; 00156 } 00157 00158 /* Store the result in the destination buffer in 18.14 format */ 00159 *result = sum; 00160 } 00161