Added all the F4 libraries to the project
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / BasicMathFunctions / arm_scale_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_scale_q31.c   
9 *   
10 * Description:  Multiplies a Q31 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 Q31 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.31 format.   
56  * These are multiplied to yield a 2.62 intermediate result and this is shifted with saturation to 1.31 format.   
57  */
58
59 void arm_scale_q31(
60   q31_t * pSrc,
61   q31_t scaleFract,
62   int8_t shift,
63   q31_t * pDst,
64   uint32_t blockSize)
65 {
66   int8_t kShift = 31 - shift;                    /* Shift to apply after scaling */
67   uint32_t blkCnt;                               /* loop counter */
68
69 #ifndef ARM_MATH_CM0
70
71 /* Run the below code for Cortex-M4 and Cortex-M3 */
72
73   /*loop Unrolling */
74   blkCnt = blockSize >> 2u;
75
76   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
77    ** a second loop below computes the remaining 1 to 3 samples. */
78   while(blkCnt > 0u)
79   {
80     /* C = A * scale */
81     /* Scale the input and then store the results in the destination buffer. */
82     *pDst++ = clip_q63_to_q31(((q63_t) * pSrc++ * scaleFract) >> kShift);
83     *pDst++ = clip_q63_to_q31(((q63_t) * pSrc++ * scaleFract) >> kShift);
84     *pDst++ = clip_q63_to_q31(((q63_t) * pSrc++ * scaleFract) >> kShift);
85     *pDst++ = clip_q63_to_q31(((q63_t) * pSrc++ * scaleFract) >> kShift);
86
87     /* Decrement the loop counter */
88     blkCnt--;
89   }
90
91   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.   
92    ** No loop unrolling is used. */
93   blkCnt = blockSize % 0x4u;
94
95 #else
96
97   /* Run the below code for Cortex-M0 */
98
99   /* Initialize blkCnt with number of samples */
100   blkCnt = blockSize;
101
102 #endif /* #ifndef ARM_MATH_CM0 */
103
104   while(blkCnt > 0u)
105   {
106     /* C = A * scale */
107     /* Scale the input and then store the result in the destination buffer. */
108     *pDst++ = clip_q63_to_q31(((q63_t) * pSrc++ * scaleFract) >> kShift);
109
110     /* Decrement the loop counter */
111     blkCnt--;
112   }
113 }
114
115 /**   
116  * @} end of scale group   
117  */