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