]> git.gag.com Git - fw/stlink/blob - exampleF4/CMSIS/DSP_Lib/Source/MatrixFunctions/arm_mat_scale_f32.c
Added all the F4 libraries to the project
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / MatrixFunctions / arm_mat_scale_f32.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_mat_scale_f32.c   
9 *   
10 * Description:  Multiplies a floating-point matrix 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.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 groupMatrix   
40  */
41
42 /**   
43  * @defgroup MatrixScale Matrix Scale   
44  *   
45  * Multiplies a matrix by a scalar.  This is accomplished by multiplying each element in the   
46  * matrix by the scalar.  For example:   
47  * \image html MatrixScale.gif "Matrix Scaling of a 3 x 3 matrix"   
48  *   
49  * The function checks to make sure that the input and output matrices are of the same size.   
50  *   
51  * In the fixed-point Q15 and Q31 functions, <code>scale</code> is represented by   
52  * a fractional multiplication <code>scaleFract</code> and an arithmetic shift <code>shift</code>.   
53  * The shift allows the gain of the scaling operation to exceed 1.0.   
54  * The overall scale factor applied to the fixed-point data is   
55  * <pre>   
56  *     scale = scaleFract * 2^shift.   
57  * </pre>   
58  */
59
60 /**   
61  * @addtogroup MatrixScale   
62  * @{   
63  */
64
65 /**   
66  * @brief Floating-point matrix scaling.   
67  * @param[in]       *pSrc points to input matrix structure   
68  * @param[in]       scale scale factor to be applied    
69  * @param[out]      *pDst points to output matrix structure   
70  * @return              The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>    
71  * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.   
72  *   
73  */
74
75 arm_status arm_mat_scale_f32(
76   const arm_matrix_instance_f32 * pSrc,
77   float32_t scale,
78   arm_matrix_instance_f32 * pDst)
79 {
80   float32_t *pIn = pSrc->pData;                  /* input data matrix pointer */
81   float32_t *pOut = pDst->pData;                 /* output data matrix pointer */
82   uint32_t numSamples;                           /* total number of elements in the matrix */
83   uint32_t blkCnt;                               /* loop counters */
84   arm_status status;                             /* status of matrix scaling     */
85
86 #ifdef ARM_MATH_MATRIX_CHECK
87
88
89   /* Check for matrix mismatch condition */
90   if((pSrc->numRows != pDst->numRows) || (pSrc->numCols != pDst->numCols))
91   {
92     /* Set status as ARM_MATH_SIZE_MISMATCH */
93     status = ARM_MATH_SIZE_MISMATCH;
94   }
95   else
96 #endif /*    #ifdef ARM_MATH_MATRIX_CHECK    */
97
98   {
99     /* Total number of samples in the input matrix */
100     numSamples = (uint32_t) pSrc->numRows * pSrc->numCols;
101
102 #ifndef ARM_MATH_CM0
103
104     /* Run the below code for Cortex-M4 and Cortex-M3 */
105
106     /* Loop Unrolling */
107     blkCnt = numSamples >> 2;
108
109     /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
110      ** a second loop below computes the remaining 1 to 3 samples. */
111     while(blkCnt > 0u)
112     {
113       /* C(m,n) = A(m,n) * scale */
114       /* Scaling and results are stored in the destination buffer. */
115       *pOut++ = (*pIn++) * scale;
116       *pOut++ = (*pIn++) * scale;
117       *pOut++ = (*pIn++) * scale;
118       *pOut++ = (*pIn++) * scale;
119
120       /* Decrement the numSamples loop counter */
121       blkCnt--;
122     }
123
124     /* If the numSamples is not a multiple of 4, compute any remaining output samples here.   
125      ** No loop unrolling is used. */
126     blkCnt = numSamples % 0x4u;
127
128 #else
129
130     /* Run the below code for Cortex-M0 */
131
132     /* Initialize blkCnt with number of samples */
133     blkCnt = numSamples;
134
135 #endif /* #ifndef ARM_MATH_CM0 */
136
137     while(blkCnt > 0u)
138     {
139       /* C(m,n) = A(m,n) * scale */
140       /* The results are stored in the destination buffer. */
141       *pOut++ = (*pIn++) * scale;
142
143       /* Decrement the loop counter */
144       blkCnt--;
145     }
146     /* Set status as ARM_MATH_SUCCESS */
147     status = ARM_MATH_SUCCESS;
148   }
149
150   /* Return to application */
151   return (status);
152 }
153
154 /**   
155  * @} end of MatrixScale group   
156  */