]> git.gag.com Git - fw/stlink/blob - exampleF4/CMSIS/DSP_Lib/Source/BasicMathFunctions/arm_dot_prod_q7.c
Added all the F4 libraries to the project
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / BasicMathFunctions / arm_dot_prod_q7.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_q7.c   
9 *   
10 * Description:  Q7 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 Q7 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.7 x 1.7 = 2.14 format and these   
55  * results are added to an accumulator in 18.14 format.   
56  * Nonsaturating additions are used and there is no danger of wrap around as long as   
57  * the vectors are less than 2^18 elements long.   
58  * The return result is in 18.14 format.   
59  */
60
61 void arm_dot_prod_q7(
62   q7_t * pSrcA,
63   q7_t * pSrcB,
64   uint32_t blockSize,
65   q31_t * result)
66 {
67   uint32_t blkCnt;                               /* loop counter */
68
69   q31_t sum = 0;                                 /* Temporary variables to store output */
70
71 #ifndef ARM_MATH_CM0
72
73 /* Run the below code for Cortex-M4 and Cortex-M3 */
74
75   q31_t input1, input2;                          /* Temporary variables to store input */
76   q15_t in1, in2;                                /* Temporary variables to store input */
77
78
79
80   /*loop Unrolling */
81   blkCnt = blockSize >> 2u;
82
83   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
84    ** a second loop below computes the remaining 1 to 3 samples. */
85   while(blkCnt > 0u)
86   {
87     /* Reading two inputs of SrcA buffer and packing */
88     in1 = (q15_t) * pSrcA++;
89     in2 = (q15_t) * pSrcA++;
90     input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16);
91
92     /* Reading two inputs of SrcB buffer and packing */
93     in1 = (q15_t) * pSrcB++;
94     in2 = (q15_t) * pSrcB++;
95     input2 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16);
96
97     /* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */
98     /* Perform Dot product of 2 packed inputs using SMLALD and store the result in a temporary variable. */
99     sum = __SMLAD(input1, input2, sum);
100
101     /* Reading two inputs of SrcA buffer and packing */
102     in1 = (q15_t) * pSrcA++;
103     in2 = (q15_t) * pSrcA++;
104     input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16);
105
106     /* Reading two inputs of SrcB buffer and packing */
107     in1 = (q15_t) * pSrcB++;
108     in2 = (q15_t) * pSrcB++;
109     input2 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16);
110
111     /* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */
112     /* Perform Dot product of 2 packed inputs using SMLALD and store the result in a temporary variable. */
113     sum = __SMLAD(input1, input2, sum);
114
115
116
117     /* Decrement the loop counter */
118     blkCnt--;
119   }
120
121   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.   
122    ** No loop unrolling is used. */
123   blkCnt = blockSize % 0x4u;
124
125   while(blkCnt > 0u)
126   {
127     /* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */
128     /* Dot product and then store the results in a temporary buffer. */
129     sum = __SMLAD(*pSrcA++, *pSrcB++, sum);
130
131     /* Decrement the loop counter */
132     blkCnt--;
133   }
134
135 #else
136
137   /* Run the below code for Cortex-M0 */
138
139
140
141   /* Initialize blkCnt with number of samples */
142   blkCnt = blockSize;
143
144   while(blkCnt > 0u)
145   {
146     /* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */
147     /* Dot product and then store the results in a temporary buffer. */
148     sum += (q31_t) ((q15_t) * pSrcA++ * *pSrcB++);
149
150     /* Decrement the loop counter */
151     blkCnt--;
152   }
153
154 #endif /* #ifndef ARM_MATH_CM0 */
155
156
157   /* Store the result in the destination buffer in 18.14 format */
158   *result = sum;
159 }
160
161 /**   
162  * @} end of dot_prod group   
163  */