]> git.gag.com Git - fw/stlink/blob - exampleF4/CMSIS/DSP_Lib/Source/BasicMathFunctions/arm_mult_q31.c
Added all the F4 libraries to the project
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / BasicMathFunctions / arm_mult_q31.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_q31.c   
9 *   
10 * Description:  Q31 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  * @brief Q31 vector multiplication.   
49  * @param[in]       *pSrcA points to the first input vector   
50  * @param[in]       *pSrcB points to the second input vector   
51  * @param[out]      *pDst points to the output vector   
52  * @param[in]       blockSize number of samples in each vector   
53  * @return none.   
54  *   
55  * <b>Scaling and Overflow Behavior:</b>   
56  * \par   
57  * The function uses saturating arithmetic.   
58  * Results outside of the allowable Q31 range[0x80000000 0x7FFFFFFF] will be saturated.   
59  */
60
61 void arm_mult_q31(
62   q31_t * pSrcA,
63   q31_t * pSrcB,
64   q31_t * pDst,
65   uint32_t blockSize)
66 {
67   uint32_t blkCnt;                               /* loop counters */
68
69 #ifndef ARM_MATH_CM0
70
71 /* Run the below code for Cortex-M4 and Cortex-M3 */
72   /* loop Unrolling */
73   blkCnt = blockSize >> 2u;
74
75   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
76    ** a second loop below computes the remaining 1 to 3 samples. */
77   while(blkCnt > 0u)
78   {
79     /* C = A * B */
80     /* Multiply the inputs and then store the results in the destination buffer. */
81     *pDst++ =
82       (q31_t) clip_q63_to_q31(((q63_t) (*pSrcA++) * (*pSrcB++)) >> 31);
83     *pDst++ =
84       (q31_t) clip_q63_to_q31(((q63_t) (*pSrcA++) * (*pSrcB++)) >> 31);
85     *pDst++ =
86       (q31_t) clip_q63_to_q31(((q63_t) (*pSrcA++) * (*pSrcB++)) >> 31);
87     *pDst++ =
88       (q31_t) clip_q63_to_q31(((q63_t) (*pSrcA++) * (*pSrcB++)) >> 31);
89
90     /* Decrement the blockSize loop counter */
91     blkCnt--;
92   }
93
94   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.   
95    ** No loop unrolling is used. */
96   blkCnt = blockSize % 0x4u;
97
98 #else
99
100   /* Run the below code for Cortex-M0 */
101
102   /* Initialize blkCnt with number of samples */
103   blkCnt = blockSize;
104
105 #endif /* #ifndef ARM_MATH_CM0 */
106
107   while(blkCnt > 0u)
108   {
109     /* C = A * B */
110     /* Multiply the inputs and then store the results in the destination buffer. */
111     *pDst++ =
112       (q31_t) clip_q63_to_q31(((q63_t) (*pSrcA++) * (*pSrcB++)) >> 31);
113
114     /* Decrement the blockSize loop counter */
115     blkCnt--;
116   }
117 }
118
119 /**   
120  * @} end of BasicMult group   
121  */