Added all the F4 libraries to the project
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / ComplexMathFunctions / arm_cmplx_mult_real_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_cmplx_mult_real_q15.c   
9 *   
10 * Description:  Q15 complex by real 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
30 #include "arm_math.h"
31
32 /**   
33  * @ingroup groupCmplxMath   
34  */
35
36 /**   
37  * @addtogroup CmplxByRealMult   
38  * @{   
39  */
40
41
42 /**   
43  * @brief  Q15 complex-by-real multiplication   
44  * @param[in]  *pSrcCmplx points to the complex input vector   
45  * @param[in]  *pSrcReal points to the real input vector   
46  * @param[out]  *pCmplxDst points to the complex output vector   
47  * @param[in]  numSamples number of samples in each vector   
48  * @return none.   
49  *   
50  * <b>Scaling and Overflow Behavior:</b>   
51  * \par   
52  * The function uses saturating arithmetic.   
53  * Results outside of the allowable Q15 range [0x8000 0x7FFF] will be saturated.   
54  */
55
56 void arm_cmplx_mult_real_q15(
57   q15_t * pSrcCmplx,
58   q15_t * pSrcReal,
59   q15_t * pCmplxDst,
60   uint32_t numSamples)
61 {
62   q15_t in;                                      /* Temporary variable to store input value */
63
64 #ifndef ARM_MATH_CM0
65
66   /* Run the below code for Cortex-M4 and Cortex-M3 */
67   uint32_t blkCnt;                               /* loop counters */
68
69   /* loop Unrolling */
70   blkCnt = numSamples >> 2u;
71
72   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
73    ** a second loop below computes the remaining 1 to 3 samples. */
74   while(blkCnt > 0u)
75   {
76     /* C[2 * i] = A[2 * i] * B[i].            */
77     /* C[2 * i + 1] = A[2 * i + 1] * B[i].        */
78     in = *pSrcReal++;
79     /* store the result in the destination buffer. */
80     *pCmplxDst++ =
81       (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16);
82     *pCmplxDst++ =
83       (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16);
84
85     in = *pSrcReal++;
86     *pCmplxDst++ =
87       (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16);
88     *pCmplxDst++ =
89       (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16);
90
91     in = *pSrcReal++;
92     *pCmplxDst++ =
93       (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16);
94     *pCmplxDst++ =
95       (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16);
96
97     in = *pSrcReal++;
98     *pCmplxDst++ =
99       (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16);
100     *pCmplxDst++ =
101       (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16);
102
103     /* Decrement the numSamples loop counter */
104     blkCnt--;
105   }
106
107   /* If the numSamples is not a multiple of 4, compute any remaining output samples here.   
108    ** No loop unrolling is used. */
109   blkCnt = numSamples % 0x4u;
110
111   while(blkCnt > 0u)
112   {
113     /* C[2 * i] = A[2 * i] * B[i].            */
114     /* C[2 * i + 1] = A[2 * i + 1] * B[i].        */
115     in = *pSrcReal++;
116     /* store the result in the destination buffer. */
117     *pCmplxDst++ =
118       (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16);
119     *pCmplxDst++ =
120       (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16);
121
122     /* Decrement the numSamples loop counter */
123     blkCnt--;
124   }
125
126 #else
127
128   /* Run the below code for Cortex-M0 */
129
130   while(numSamples > 0u)
131   {
132     /* realOut = realA * realB.            */
133     /* imagOut = imagA * realB.                */
134     in = *pSrcReal++;
135     /* store the result in the destination buffer. */
136     *pCmplxDst++ =
137       (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16);
138     *pCmplxDst++ =
139       (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16);
140
141     /* Decrement the numSamples loop counter */
142     numSamples--;
143   }
144
145 #endif /* #ifndef ARM_MATH_CM0 */
146
147 }
148
149 /**   
150  * @} end of CmplxByRealMult group   
151  */