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_add_q15.c 00009 * 00010 * Description: Q15 vector addition 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 00053 void arm_add_q15( 00054 q15_t * pSrcA, 00055 q15_t * pSrcB, 00056 q15_t * pDst, 00057 uint32_t blockSize) 00058 { 00059 uint32_t blkCnt; /* loop counter */ 00060 q31_t inA1, inA2; /* temporary input variables */ 00061 q31_t inB1, inB2; /* temporary input variabels */ 00062 q31_t out1, out2, out3, out4; /* temporary output variables */ 00063 00064 /*loop Unrolling */ 00065 blkCnt = blockSize >> 3u; 00066 00067 /* First part of the processing with loop unrolling. Compute 8 outputs at a time. 00068 ** a second loop below computes the remaining 1 to 7 samples. */ 00069 while(blkCnt > 0u) 00070 { 00071 /* C = A + B */ 00072 /* Add and then store the results in the destination buffer. */ 00073 /* read two samples at a time from sourceA buffer */ 00074 inA1 = _SIMD32_OFFSET(pSrcA); 00075 /* read two samples at a time from sourceB buffer */ 00076 inB1 = _SIMD32_OFFSET(pSrcB); 00077 /* read two samples at a time from sourceA buffer */ 00078 inA2 = _SIMD32_OFFSET(pSrcA + 2); 00079 00080 /* add, saturate and store two samples to destination at a time*/ 00081 out1 = __QADD16(inA1, inB1); 00082 00083 /* read two samples at a time from sourceB buffer */ 00084 inB2 = _SIMD32_OFFSET(pSrcB + 2); 00085 00086 /* store two output samples at a time to destination */ 00087 _SIMD32_OFFSET(pDst) = out1; 00088 00089 /* add, saturate and store two samples to destination at a time*/ 00090 out2 = __QADD16(inA2, inB2); 00091 00092 /* read two samples at a time from sourceA buffer */ 00093 inA1 = _SIMD32_OFFSET(pSrcA + 4); 00094 /* read two samples at a time from sourceB buffer */ 00095 inB1 = _SIMD32_OFFSET(pSrcB + 4); 00096 /* read two samples at a time from sourceA buffer */ 00097 inA2 = _SIMD32_OFFSET(pSrcA + 6); 00098 00099 /* add, saturate and store two samples to destination at a time*/ 00100 out3 = __QADD16(inA1, inB1); 00101 00102 /* read two samples at a time from sourceB buffer */ 00103 inB2 = _SIMD32_OFFSET(pSrcB + 6); 00104 00105 /* increment sourceA pointer by 8 */ 00106 pSrcA += 8u; 00107 00108 /* store two output samples at a time to destination */ 00109 _SIMD32_OFFSET(pDst + 2) = out2; 00110 00111 /* add, saturate and store two samples to destination at a time*/ 00112 out4 = __QADD16(inA2, inB2); 00113 00114 /* store two output samples at a time to destination */ 00115 _SIMD32_OFFSET(pDst + 4) = out3; 00116 00117 /* increment sourceB pointer by 8 */ 00118 pSrcB += 8u; 00119 00120 /* store two output samples at a time to destination */ 00121 _SIMD32_OFFSET(pDst + 6) = out4; 00122 00123 /* increment destination pointer by 8 */ 00124 pDst += 8u; 00125 00126 /* Decrement the loop counter */ 00127 blkCnt--; 00128 } 00129 00130 /* If the blockSize is not a multiple of 8, compute any remaining output samples here. 00131 ** No loop unrolling is used. */ 00132 blkCnt = blockSize % 0x8u; 00133 00134 while(blkCnt > 0u) 00135 { 00136 /* C = A + B */ 00137 /* Add and then store the results in the destination buffer. */ 00138 *pDst++ = (q15_t) __QADD16(*pSrcA++, *pSrcB++); 00139 00140 /* Decrement the loop counter */ 00141 blkCnt--; 00142 } 00143 00144 } 00145