]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/dsp/cmsis_dsp/MatrixFunctions/arm_mat_trans_q15.c
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / dsp / cmsis_dsp / MatrixFunctions / arm_mat_trans_q15.c
1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010-2013 ARM Limited. All rights reserved.
3 *
4 * $Date: 17. January 2013
5 * $Revision: V1.4.1
6 *
7 * Project: CMSIS DSP Library
8 * Title: arm_mat_trans_q15.c
9 *
10 * Description: Q15 matrix transpose.
11 *
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * - Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * - Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided with the
22 * distribution.
23 * - Neither the name of ARM LIMITED nor the names of its contributors
24 * may be used to endorse or promote products derived from this
25 * software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 * -------------------------------------------------------------------- */
40
41 #include "arm_math.h"
42
43 /**
44 * @ingroup groupMatrix
45 */
46
47 /**
48 * @addtogroup MatrixTrans
49 * @{
50 */
51
52 /*
53 * @brief Q15 matrix transpose.
54 * @param[in] *pSrc points to the input matrix
55 * @param[out] *pDst points to the output matrix
56 * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
57 * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
58 */
59
60 arm_status arm_mat_trans_q15(
61 const arm_matrix_instance_q15 * pSrc,
62 arm_matrix_instance_q15 * pDst)
63 {
64 q15_t *pSrcA = pSrc->pData; /* input data matrix pointer */
65 q15_t *pOut = pDst->pData; /* output data matrix pointer */
66 uint16_t nRows = pSrc->numRows; /* number of nRows */
67 uint16_t nColumns = pSrc->numCols; /* number of nColumns */
68 uint16_t col, row = nRows, i = 0u; /* row and column loop counters */
69 arm_status status; /* status of matrix transpose */
70
71 #ifndef ARM_MATH_CM0_FAMILY
72
73 /* Run the below code for Cortex-M4 and Cortex-M3 */
74 #ifndef UNALIGNED_SUPPORT_DISABLE
75
76 q31_t in; /* variable to hold temporary output */
77
78 #else
79
80 q15_t in;
81
82 #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */
83
84 #ifdef ARM_MATH_MATRIX_CHECK
85
86
87 /* Check for matrix mismatch condition */
88 if((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
89 {
90 /* Set status as ARM_MATH_SIZE_MISMATCH */
91 status = ARM_MATH_SIZE_MISMATCH;
92 }
93 else
94 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
95
96 {
97 /* Matrix transpose by exchanging the rows with columns */
98 /* row loop */
99 do
100 {
101
102 /* Apply loop unrolling and exchange the columns with row elements */
103 col = nColumns >> 2u;
104
105 /* The pointer pOut is set to starting address of the column being processed */
106 pOut = pDst->pData + i;
107
108 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
109 ** a second loop below computes the remaining 1 to 3 samples. */
110 while(col > 0u)
111 {
112 #ifndef UNALIGNED_SUPPORT_DISABLE
113
114 /* Read two elements from the row */
115 in = *__SIMD32(pSrcA)++;
116
117 /* Unpack and store one element in the destination */
118 #ifndef ARM_MATH_BIG_ENDIAN
119
120 *pOut = (q15_t) in;
121
122 #else
123
124 *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
125
126 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
127
128 /* Update the pointer pOut to point to the next row of the transposed matrix */
129 pOut += nRows;
130
131 /* Unpack and store the second element in the destination */
132
133 #ifndef ARM_MATH_BIG_ENDIAN
134
135 *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
136
137 #else
138
139 *pOut = (q15_t) in;
140
141 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
142
143 /* Update the pointer pOut to point to the next row of the transposed matrix */
144 pOut += nRows;
145
146 /* Read two elements from the row */
147 #ifndef ARM_MATH_BIG_ENDIAN
148
149 in = *__SIMD32(pSrcA)++;
150
151 #else
152
153 in = *__SIMD32(pSrcA)++;
154
155 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
156
157 /* Unpack and store one element in the destination */
158 #ifndef ARM_MATH_BIG_ENDIAN
159
160 *pOut = (q15_t) in;
161
162 #else
163
164 *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
165
166 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
167
168 /* Update the pointer pOut to point to the next row of the transposed matrix */
169 pOut += nRows;
170
171 /* Unpack and store the second element in the destination */
172 #ifndef ARM_MATH_BIG_ENDIAN
173
174 *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
175
176 #else
177
178 *pOut = (q15_t) in;
179
180 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
181
182 #else
183 /* Read one element from the row */
184 in = *pSrcA++;
185
186 /* Store one element in the destination */
187 *pOut = in;
188
189 /* Update the pointer px to point to the next row of the transposed matrix */
190 pOut += nRows;
191
192 /* Read one element from the row */
193 in = *pSrcA++;
194
195 /* Store one element in the destination */
196 *pOut = in;
197
198 /* Update the pointer px to point to the next row of the transposed matrix */
199 pOut += nRows;
200
201 /* Read one element from the row */
202 in = *pSrcA++;
203
204 /* Store one element in the destination */
205 *pOut = in;
206
207 /* Update the pointer px to point to the next row of the transposed matrix */
208 pOut += nRows;
209
210 /* Read one element from the row */
211 in = *pSrcA++;
212
213 /* Store one element in the destination */
214 *pOut = in;
215
216 #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */
217
218 /* Update the pointer pOut to point to the next row of the transposed matrix */
219 pOut += nRows;
220
221 /* Decrement the column loop counter */
222 col--;
223 }
224
225 /* Perform matrix transpose for last 3 samples here. */
226 col = nColumns % 0x4u;
227
228 #else
229
230 /* Run the below code for Cortex-M0 */
231
232 #ifdef ARM_MATH_MATRIX_CHECK
233
234 /* Check for matrix mismatch condition */
235 if((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
236 {
237 /* Set status as ARM_MATH_SIZE_MISMATCH */
238 status = ARM_MATH_SIZE_MISMATCH;
239 }
240 else
241 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
242
243 {
244 /* Matrix transpose by exchanging the rows with columns */
245 /* row loop */
246 do
247 {
248 /* The pointer pOut is set to starting address of the column being processed */
249 pOut = pDst->pData + i;
250
251 /* Initialize column loop counter */
252 col = nColumns;
253
254 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
255
256 while(col > 0u)
257 {
258 /* Read and store the input element in the destination */
259 *pOut = *pSrcA++;
260
261 /* Update the pointer pOut to point to the next row of the transposed matrix */
262 pOut += nRows;
263
264 /* Decrement the column loop counter */
265 col--;
266 }
267
268 i++;
269
270 /* Decrement the row loop counter */
271 row--;
272
273 } while(row > 0u);
274
275 /* set status as ARM_MATH_SUCCESS */
276 status = ARM_MATH_SUCCESS;
277 }
278 /* Return to application */
279 return (status);
280 }
281
282 /**
283 * @} end of MatrixTrans group
284 */
Imprint / Impressum