]>
git.gir.st - tmk_keyboard.git/blob - 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.
4 * $Date: 17. January 2013
7 * Project: CMSIS DSP Library
8 * Title: arm_mat_trans_q15.c
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
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
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 * -------------------------------------------------------------------- */
44 * @ingroup groupMatrix
48 * @addtogroup MatrixTrans
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 */
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
;
94 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
97 /* Matrix transpose by exchanging the rows with columns */
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. */
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
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 */
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);
141 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
143 /* Update the pointer pOut to point to the next row of the transposed matrix */
146 /* Read two elements from the row */
147 #ifndef ARM_MATH_BIG_ENDIAN
149 in
= *__SIMD32(pSrcA
)++;
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
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 */
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);
180 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
183 /* Read one element from the row */
186 /* Store one element in the destination */
189 /* Update the pointer px to point to the next row of the transposed matrix */
192 /* Read one element from the row */
195 /* Store one element in the destination */
198 /* Update the pointer px to point to the next row of the transposed matrix */
201 /* Read one element from the row */
204 /* Store one element in the destination */
207 /* Update the pointer px to point to the next row of the transposed matrix */
210 /* Read one element from the row */
213 /* Store one element in the destination */
216 #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */
218 /* Update the pointer pOut to point to the next row of the transposed matrix */
221 /* Decrement the column loop counter */
225 /* Perform matrix transpose for last 3 samples here. */
226 col
= nColumns
% 0x4u
;
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
;
241 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
244 /* Matrix transpose by exchanging the rows with columns */
248 /* The pointer pOut is set to starting address of the column being processed */
249 pOut
= pDst
->pData
+ i
;
251 /* Initialize column loop counter */
254 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
258 /* Read and store the input element in the destination */
261 /* Update the pointer pOut to point to the next row of the transposed matrix */
264 /* Decrement the column loop counter */
270 /* Decrement the row loop counter */
275 /* set status as ARM_MATH_SUCCESS */
276 status
= ARM_MATH_SUCCESS
;
278 /* Return to application */
283 * @} end of MatrixTrans group