F1 and F3 HAL / LL libraries
[betaflight.git] / lib / main / STM32F3 / Drivers / CMSIS / DSP_Lib / Source / MatrixFunctions / arm_mat_trans_q15.c
blobc4656bbd8a75a7bc631bf016cf423a162b19d465
1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
3 *
4 * $Date: 19. March 2015
5 * $Revision: V.1.4.5
6 *
7 * Project: CMSIS DSP Library
8 * Title: arm_mat_trans_q15.c
9 *
10 * Description: Q15 matrix transpose.
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
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.
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 * -------------------------------------------------------------------- */
41 #include "arm_math.h"
43 /**
44 * @ingroup groupMatrix
47 /**
48 * @addtogroup MatrixTrans
49 * @{
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.
60 arm_status arm_mat_trans_q15(
61 const arm_matrix_instance_q15 * pSrc,
62 arm_matrix_instance_q15 * pDst)
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 */
71 #ifndef ARM_MATH_CM0_FAMILY
73 /* Run the below code for Cortex-M4 and Cortex-M3 */
74 #ifndef UNALIGNED_SUPPORT_DISABLE
76 q31_t in; /* variable to hold temporary output */
78 #else
80 q15_t in;
82 #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */
84 #ifdef ARM_MATH_MATRIX_CHECK
87 /* Check for matrix mismatch condition */
88 if((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
90 /* Set status as ARM_MATH_SIZE_MISMATCH */
91 status = ARM_MATH_SIZE_MISMATCH;
93 else
94 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
97 /* Matrix transpose by exchanging the rows with columns */
98 /* row loop */
102 /* Apply loop unrolling and exchange the columns with row elements */
103 col = nColumns >> 2u;
105 /* The pointer pOut is set to starting address of the column being processed */
106 pOut = pDst->pData + i;
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)
112 #ifndef UNALIGNED_SUPPORT_DISABLE
114 /* Read two elements from the row */
115 in = *__SIMD32(pSrcA)++;
117 /* Unpack and store one element in the destination */
118 #ifndef ARM_MATH_BIG_ENDIAN
120 *pOut = (q15_t) in;
122 #else
124 *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
126 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
128 /* Update the pointer pOut to point to the next row of the transposed matrix */
129 pOut += nRows;
131 /* Unpack and store the second element in the destination */
133 #ifndef ARM_MATH_BIG_ENDIAN
135 *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
137 #else
139 *pOut = (q15_t) in;
141 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
143 /* Update the pointer pOut to point to the next row of the transposed matrix */
144 pOut += nRows;
146 /* Read two elements from the row */
147 #ifndef ARM_MATH_BIG_ENDIAN
149 in = *__SIMD32(pSrcA)++;
151 #else
153 in = *__SIMD32(pSrcA)++;
155 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
157 /* Unpack and store one element in the destination */
158 #ifndef ARM_MATH_BIG_ENDIAN
160 *pOut = (q15_t) in;
162 #else
164 *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
166 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
168 /* Update the pointer pOut to point to the next row of the transposed matrix */
169 pOut += nRows;
171 /* Unpack and store the second element in the destination */
172 #ifndef ARM_MATH_BIG_ENDIAN
174 *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
176 #else
178 *pOut = (q15_t) in;
180 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
182 #else
183 /* Read one element from the row */
184 in = *pSrcA++;
186 /* Store one element in the destination */
187 *pOut = in;
189 /* Update the pointer px to point to the next row of the transposed matrix */
190 pOut += nRows;
192 /* Read one element from the row */
193 in = *pSrcA++;
195 /* Store one element in the destination */
196 *pOut = in;
198 /* Update the pointer px to point to the next row of the transposed matrix */
199 pOut += nRows;
201 /* Read one element from the row */
202 in = *pSrcA++;
204 /* Store one element in the destination */
205 *pOut = in;
207 /* Update the pointer px to point to the next row of the transposed matrix */
208 pOut += nRows;
210 /* Read one element from the row */
211 in = *pSrcA++;
213 /* Store one element in the destination */
214 *pOut = in;
216 #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */
218 /* Update the pointer pOut to point to the next row of the transposed matrix */
219 pOut += nRows;
221 /* Decrement the column loop counter */
222 col--;
225 /* Perform matrix transpose for last 3 samples here. */
226 col = nColumns % 0x4u;
228 #else
230 /* Run the below code for Cortex-M0 */
232 #ifdef ARM_MATH_MATRIX_CHECK
234 /* Check for matrix mismatch condition */
235 if((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
237 /* Set status as ARM_MATH_SIZE_MISMATCH */
238 status = ARM_MATH_SIZE_MISMATCH;
240 else
241 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
244 /* Matrix transpose by exchanging the rows with columns */
245 /* row loop */
248 /* The pointer pOut is set to starting address of the column being processed */
249 pOut = pDst->pData + i;
251 /* Initialize column loop counter */
252 col = nColumns;
254 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
256 while(col > 0u)
258 /* Read and store the input element in the destination */
259 *pOut = *pSrcA++;
261 /* Update the pointer pOut to point to the next row of the transposed matrix */
262 pOut += nRows;
264 /* Decrement the column loop counter */
265 col--;
268 i++;
270 /* Decrement the row loop counter */
271 row--;
273 } while(row > 0u);
275 /* set status as ARM_MATH_SUCCESS */
276 status = ARM_MATH_SUCCESS;
278 /* Return to application */
279 return (status);
282 /**
283 * @} end of MatrixTrans group