Added all the F4 libraries to the project
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / MatrixFunctions / arm_mat_trans_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_mat_trans_q31.c   
9 *   
10 * Description:  Q31 matrix transpose.   
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  * @addtogroup MatrixTrans   
44  * @{   
45  */
46
47 /*   
48   * @brief Q31 matrix transpose.   
49   * @param[in]  *pSrc points to the input matrix   
50   * @param[out] *pDst points to the output matrix   
51   * @return     The function returns either  <code>ARM_MATH_SIZE_MISMATCH</code>   
52   * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.   
53  */
54
55 arm_status arm_mat_trans_q31(
56   const arm_matrix_instance_q31 * pSrc,
57   arm_matrix_instance_q31 * pDst)
58 {
59   q31_t *pIn = pSrc->pData;                      /* input data matrix pointer  */
60   q31_t *pOut = pDst->pData;                     /* output data matrix pointer  */
61   q31_t *px;                                     /* Temporary output data matrix pointer */
62   uint16_t nRows = pSrc->numRows;                /* number of nRows */
63   uint16_t nColumns = pSrc->numCols;             /* number of nColumns  */
64
65 #ifndef ARM_MATH_CM0
66
67   /* Run the below code for Cortex-M4 and Cortex-M3 */
68
69   uint16_t blkCnt, i = 0u, row = nRows;          /* loop counters */
70   arm_status status;                             /* status of matrix transpose */
71
72
73 #ifdef ARM_MATH_MATRIX_CHECK
74
75
76   /* Check for matrix mismatch condition */
77   if((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
78   {
79     /* Set status as ARM_MATH_SIZE_MISMATCH */
80     status = ARM_MATH_SIZE_MISMATCH;
81   }
82   else
83 #endif /*    #ifdef ARM_MATH_MATRIX_CHECK    */
84
85   {
86     /* Matrix transpose by exchanging the rows with columns */
87     /* row loop     */
88     do
89     {
90       /* Apply loop unrolling and exchange the columns with row elements */
91       blkCnt = nColumns >> 2u;
92
93       /* The pointer px is set to starting address of the column being processed */
94       px = pOut + i;
95
96       /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
97        ** a second loop below computes the remaining 1 to 3 samples. */
98       while(blkCnt > 0u)
99       {
100         /* Read and store the input element in the destination */
101         *px = *pIn++;
102
103         /* Update the pointer px to point to the next row of the transposed matrix */
104         px += nRows;
105
106         /* Read and store the input element in the destination */
107         *px = *pIn++;
108
109         /* Update the pointer px to point to the next row of the transposed matrix */
110         px += nRows;
111
112         /* Read and store the input element in the destination */
113         *px = *pIn++;
114
115         /* Update the pointer px to point to the next row of the transposed matrix */
116         px += nRows;
117
118         /* Read and store the input element in the destination */
119         *px = *pIn++;
120
121         /* Update the pointer px to point to the next row of the transposed matrix */
122         px += nRows;
123
124         /* Decrement the column loop counter */
125         blkCnt--;
126       }
127
128       /* Perform matrix transpose for last 3 samples here. */
129       blkCnt = nColumns % 0x4u;
130
131       while(blkCnt > 0u)
132       {
133         /* Read and store the input element in the destination */
134         *px = *pIn++;
135
136         /* Update the pointer px to point to the next row of the transposed matrix */
137         px += nRows;
138
139         /* Decrement the column loop counter */
140         blkCnt--;
141       }
142
143 #else
144
145   /* Run the below code for Cortex-M0 */
146
147   uint16_t col, i = 0u, row = nRows;             /* loop counters */
148   arm_status status;                             /* status of matrix transpose */
149
150
151 #ifdef ARM_MATH_MATRIX_CHECK
152
153   /* Check for matrix mismatch condition */
154   if((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
155   {
156     /* Set status as ARM_MATH_SIZE_MISMATCH */
157     status = ARM_MATH_SIZE_MISMATCH;
158   }
159   else
160 #endif /*    #ifdef ARM_MATH_MATRIX_CHECK    */
161
162   {
163     /* Matrix transpose by exchanging the rows with columns */
164     /* row loop     */
165     do
166     {
167       /* The pointer px is set to starting address of the column being processed */
168       px = pOut + i;
169
170       /* Initialize column loop counter */
171       col = nColumns;
172
173       while(col > 0u)
174       {
175         /* Read and store the input element in the destination */
176         *px = *pIn++;
177
178         /* Update the pointer px to point to the next row of the transposed matrix */
179         px += nRows;
180
181         /* Decrement the column loop counter */
182         col--;
183       }
184
185 #endif /* #ifndef ARM_MATH_CM0 */
186
187       i++;
188
189       /* Decrement the row loop counter */
190       row--;
191
192     }
193     while(row > 0u);            /* row loop end */
194
195     /* set status as ARM_MATH_SUCCESS */
196     status = ARM_MATH_SUCCESS;
197   }
198
199   /* Return to application */
200   return (status);
201 }
202
203 /**   
204  * @} end of MatrixTrans group   
205  */