]> git.gag.com Git - fw/stlink/blob - exampleF4/CMSIS/DSP_Lib/Source/BasicMathFunctions/arm_add_q15.c
Added all the F4 libraries to the project
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / BasicMathFunctions / arm_add_q15.c
1 /* ----------------------------------------------------------------------   
2 * Copyright (C) 2010 ARM Limited. All rights reserved.   
3 *   
4 * $Date:        15. July 2011  
5 * $Revision:    V1.0.10  
6 *   
7 * Project:          CMSIS DSP Library   
8 * Title:                arm_add_q15.c   
9 *   
10 * Description:  Q15 vector addition   
11 *   
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
13 *  
14 * Version 1.0.10 2011/7/15 
15 *    Big Endian support added and Merged M0 and M3/M4 Source code.  
16 *   
17 * Version 1.0.3 2010/11/29  
18 *    Re-organized the CMSIS folders and updated documentation.   
19 *    
20 * Version 1.0.2 2010/11/11   
21 *    Documentation updated.    
22 *   
23 * Version 1.0.1 2010/10/05    
24 *    Production release and review comments incorporated.   
25 *   
26 * Version 1.0.0 2010/09/20    
27 *    Production release and review comments incorporated.   
28 *   
29 * Version 0.0.7  2010/06/10    
30 *    Misra-C changes done   
31 * -------------------------------------------------------------------- */
32
33 #include "arm_math.h"
34
35 /**   
36  * @ingroup groupMath   
37  */
38
39 /**   
40  * @addtogroup BasicAdd   
41  * @{   
42  */
43
44 /**   
45  * @brief Q15 vector addition.   
46  * @param[in]       *pSrcA points to the first input vector   
47  * @param[in]       *pSrcB points to the second input vector   
48  * @param[out]      *pDst points to the output vector   
49  * @param[in]       blockSize number of samples in each vector   
50  * @return none.   
51  *   
52  * <b>Scaling and Overflow Behavior:</b>   
53  * \par   
54  * The function uses saturating arithmetic.   
55  * Results outside of the allowable Q15 range [0x8000 0x7FFF] will be saturated.   
56  */
57
58 void arm_add_q15(
59   q15_t * pSrcA,
60   q15_t * pSrcB,
61   q15_t * pDst,
62   uint32_t blockSize)
63 {
64   uint32_t blkCnt;                               /* loop counter */
65
66 #ifndef ARM_MATH_CM0
67
68 /* Run the below code for Cortex-M4 and Cortex-M3 */
69
70
71   /*loop Unrolling */
72   blkCnt = blockSize >> 2u;
73
74   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
75    ** a second loop below computes the remaining 1 to 3 samples. */
76   while(blkCnt > 0u)
77   {
78     /* C = A + B */
79     /* Add and then store the results in the destination buffer. */
80     *__SIMD32(pDst)++ = __QADD16(*__SIMD32(pSrcA)++, *__SIMD32(pSrcB)++);
81     *__SIMD32(pDst)++ = __QADD16(*__SIMD32(pSrcA)++, *__SIMD32(pSrcB)++);
82
83     /* Decrement the loop counter */
84     blkCnt--;
85   }
86
87   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.   
88    ** No loop unrolling is used. */
89   blkCnt = blockSize % 0x4u;
90
91   while(blkCnt > 0u)
92   {
93     /* C = A + B */
94     /* Add and then store the results in the destination buffer. */
95     *pDst++ = (q15_t) __QADD16(*pSrcA++, *pSrcB++);
96
97     /* Decrement the loop counter */
98     blkCnt--;
99   }
100
101 #else
102
103   /* Run the below code for Cortex-M0 */
104
105
106
107   /* Initialize blkCnt with number of samples */
108   blkCnt = blockSize;
109
110   while(blkCnt > 0u)
111   {
112     /* C = A + B */
113     /* Add and then store the results in the destination buffer. */
114     *pDst++ = (q15_t) __SSAT(((q31_t) * pSrcA++ + *pSrcB++), 16);
115
116     /* Decrement the loop counter */
117     blkCnt--;
118   }
119
120 #endif /* #ifndef ARM_MATH_CM0 */
121
122
123 }
124
125 /**   
126  * @} end of BasicAdd group   
127  */