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