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