Added all the F4 libraries to the project
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / BasicMathFunctions / arm_mult_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_mult_q7.c   
9 *   
10 * Description:  Q7 vector multiplication.   
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 * Version 0.0.5  2010/04/26    
33 *    incorporated review comments and updated with latest CMSIS layer   
34 *   
35 * Version 0.0.3  2010/03/10 DP   
36 *    Initial version   
37 * -------------------------------------------------------------------- */
38
39 #include "arm_math.h"
40
41 /**   
42  * @ingroup groupMath   
43  */
44
45 /**   
46  * @addtogroup BasicMult   
47  * @{   
48  */
49
50 /**   
51  * @brief           Q7 vector multiplication   
52  * @param[in]       *pSrcA points to the first input vector   
53  * @param[in]       *pSrcB points to the second input vector   
54  * @param[out]      *pDst points to the output vector   
55  * @param[in]       blockSize number of samples in each vector   
56  * @return none.   
57  *   
58  * <b>Scaling and Overflow Behavior:</b>   
59  * \par   
60  * The function uses saturating arithmetic.   
61  * Results outside of the allowable Q7 range [0x80 0x7F] will be saturated.   
62  */
63
64 void arm_mult_q7(
65   q7_t * pSrcA,
66   q7_t * pSrcB,
67   q7_t * pDst,
68   uint32_t blockSize)
69 {
70   uint32_t blkCnt;                               /* loop counters */
71
72 #ifndef ARM_MATH_CM0
73
74 /* Run the below code for Cortex-M4 and Cortex-M3 */
75   q7_t out1, out2, out3, out4;                   /* Temporary variables to store the product */
76
77   /* loop Unrolling */
78   blkCnt = blockSize >> 2u;
79
80   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
81    ** a second loop below computes the remaining 1 to 3 samples. */
82   while(blkCnt > 0u)
83   {
84     /* C = A * B */
85     /* Multiply the inputs and store the results in temporary variables */
86     out1 = (q7_t) (((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7);
87     out2 = (q7_t) (((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7);
88     out3 = (q7_t) (((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7);
89     out4 = (q7_t) (((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7);
90
91     /* Store the results of 4 inputs in the destination buffer in single cycle by packing */
92     *__SIMD32(pDst)++ = __PACKq7(out1, out2, out3, out4);
93
94     /* Decrement the blockSize loop counter */
95     blkCnt--;
96   }
97
98   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.   
99    ** No loop unrolling is used. */
100   blkCnt = blockSize % 0x4u;
101
102 #else
103
104   /* Run the below code for Cortex-M0 */
105
106   /* Initialize blkCnt with number of samples */
107   blkCnt = blockSize;
108
109 #endif /* #ifndef ARM_MATH_CM0 */
110
111
112   while(blkCnt > 0u)
113   {
114     /* C = A * B */
115     /* Multiply the inputs and store the result in the destination buffer */
116     *pDst++ = (q7_t) (((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7);
117
118     /* Decrement the blockSize loop counter */
119     blkCnt--;
120   }
121 }
122
123 /**   
124  * @} end of BasicMult group   
125  */