Added all the F4 libraries to the project
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / BasicMathFunctions / arm_dot_prod_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_dot_prod_q15.c   
9 *   
10 * Description:  Q15 dot product.   
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 dot_prod   
41  * @{   
42  */
43
44 /**   
45  * @brief Dot product of Q15 vectors.   
46  * @param[in]       *pSrcA points to the first input vector   
47  * @param[in]       *pSrcB points to the second input vector   
48  * @param[in]       blockSize number of samples in each vector   
49  * @param[out]      *result output result returned here   
50  * @return none.   
51  *   
52  * <b>Scaling and Overflow Behavior:</b>   
53  * \par   
54  * The intermediate multiplications are in 1.15 x 1.15 = 2.30 format and these   
55  * results are added to a 64-bit accumulator in 34.30 format.   
56  * Nonsaturating additions are used and given that there are 33 guard bits in the accumulator   
57  * there is no risk of overflow.   
58  * The return result is in 34.30 format.   
59  */
60
61 void arm_dot_prod_q15(
62   q15_t * pSrcA,
63   q15_t * pSrcB,
64   uint32_t blockSize,
65   q63_t * result)
66 {
67   q63_t sum = 0;                                 /* Temporary result storage */
68   uint32_t blkCnt;                               /* loop counter */
69
70 #ifndef ARM_MATH_CM0
71
72 /* Run the below code for Cortex-M4 and Cortex-M3 */
73
74
75   /*loop Unrolling */
76   blkCnt = blockSize >> 2u;
77
78   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
79    ** a second loop below computes the remaining 1 to 3 samples. */
80   while(blkCnt > 0u)
81   {
82     /* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */
83     /* Calculate dot product and then store the result in a temporary buffer. */
84     sum = __SMLALD(*__SIMD32(pSrcA)++, *__SIMD32(pSrcB)++, sum);
85     sum = __SMLALD(*__SIMD32(pSrcA)++, *__SIMD32(pSrcB)++, sum);
86
87     /* Decrement the loop counter */
88     blkCnt--;
89   }
90
91   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.   
92    ** No loop unrolling is used. */
93   blkCnt = blockSize % 0x4u;
94
95   while(blkCnt > 0u)
96   {
97     /* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */
98     /* Calculate dot product and then store the results in a temporary buffer. */
99     sum = __SMLALD(*pSrcA++, *pSrcB++, sum);
100
101     /* Decrement the loop counter */
102     blkCnt--;
103   }
104
105
106 #else
107
108   /* Run the below code for Cortex-M0 */
109
110   /* Initialize blkCnt with number of samples */
111   blkCnt = blockSize;
112
113   while(blkCnt > 0u)
114   {
115     /* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */
116     /* Calculate dot product and then store the results in a temporary buffer. */
117     sum += (q63_t) ((q31_t) * pSrcA++ * *pSrcB++);
118
119     /* Decrement the loop counter */
120     blkCnt--;
121   }
122
123 #endif /* #ifndef ARM_MATH_CM0 */
124
125   /* Store the result in the destination buffer in 34.30 format */
126   *result = sum;
127
128 }
129
130 /**   
131  * @} end of dot_prod group   
132  */