Added all the F4 libraries to the project
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / BasicMathFunctions / arm_scale_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_scale_q15.c   
9 *   
10 * Description:  Multiplies a Q15 vector by a scalar.   
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 scale   
41  * @{   
42  */
43
44 /**   
45  * @brief Multiplies a Q15 vector by a scalar.   
46  * @param[in]       *pSrc points to the input vector   
47  * @param[in]       scaleFract fractional portion of the scale value   
48  * @param[in]       shift number of bits to shift the result by   
49  * @param[out]      *pDst points to the output vector   
50  * @param[in]       blockSize number of samples in the vector   
51  * @return none.   
52  *   
53  * <b>Scaling and Overflow Behavior:</b>   
54  * \par   
55  * The input data <code>*pSrc</code> and <code>scaleFract</code> are in 1.15 format.   
56  * These are multiplied to yield a 2.30 intermediate result and this is shifted with saturation to 1.15 format.   
57  */
58
59
60 void arm_scale_q15(
61   q15_t * pSrc,
62   q15_t scaleFract,
63   int8_t shift,
64   q15_t * pDst,
65   uint32_t blockSize)
66 {
67   int8_t kShift = 15 - shift;                    /* shift to apply after scaling */
68   uint32_t blkCnt;                               /* loop counter */
69
70 #ifndef ARM_MATH_CM0
71
72 /* Run the below code for Cortex-M4 and Cortex-M3 */
73
74   q15_t in1, in2;                                /* Temporary variables */
75
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     /* Reading 2 inputs from memory */
85     in1 = *pSrc++;
86     in2 = *pSrc++;
87     /* C = A * scale */
88     /* Scale the inputs and then store the 2 results in the destination buffer   
89      * in single cycle by packing the outputs */
90 #ifndef  ARM_MATH_BIG_ENDIAN
91
92     *__SIMD32(pDst)++ =
93       __PKHBT(__SSAT((in1 * scaleFract) >> kShift, 16),
94               __SSAT((in2 * scaleFract) >> kShift, 16), 16);
95
96 #else
97
98     *__SIMD32(pDst)++ =
99       __PKHBT(__SSAT((in2 * scaleFract) >> kShift, 16),
100               __SSAT((in1 * scaleFract) >> kShift, 16), 16);
101
102 #endif /* #ifndef  ARM_MATH_BIG_ENDIAN    */
103
104     in1 = *pSrc++;
105     in2 = *pSrc++;
106
107 #ifndef  ARM_MATH_BIG_ENDIAN
108
109     *__SIMD32(pDst)++ =
110       __PKHBT(__SSAT((in1 * scaleFract) >> kShift, 16),
111               __SSAT((in2 * scaleFract) >> kShift, 16), 16);
112
113 #else
114
115     *__SIMD32(pDst)++ =
116       __PKHBT(__SSAT((in2 * scaleFract) >> kShift, 16),
117               __SSAT((in1 * scaleFract) >> kShift, 16), 16);
118
119 #endif /* #ifndef  ARM_MATH_BIG_ENDIAN    */
120
121     /* Decrement the loop counter */
122     blkCnt--;
123   }
124
125   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.   
126    ** No loop unrolling is used. */
127   blkCnt = blockSize % 0x4u;
128
129   while(blkCnt > 0u)
130   {
131     /* C = A * scale */
132     /* Scale the input and then store the result in the destination buffer. */
133     *pDst++ = (q15_t) (__SSAT(((*pSrc++) * scaleFract) >> kShift, 16));
134
135     /* Decrement the loop counter */
136     blkCnt--;
137   }
138
139 #else
140
141   /* Run the below code for Cortex-M0 */
142
143   /* Initialize blkCnt with number of samples */
144   blkCnt = blockSize;
145
146   while(blkCnt > 0u)
147   {
148     /* C = A * scale */
149     /* Scale the input and then store the result in the destination buffer. */
150     *pDst++ = (q15_t) (__SSAT(((q31_t) * pSrc++ * scaleFract) >> kShift, 16));
151
152     /* Decrement the loop counter */
153     blkCnt--;
154   }
155
156 #endif /* #ifndef ARM_MATH_CM0 */
157
158 }
159
160 /**   
161  * @} end of scale group   
162  */