1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_mat_trans_q31.c
4 * Description: Q31 matrix transpose
6 * $Date: 27. January 2017
9 * Target Processor: Cortex-M cores
10 * -------------------------------------------------------------------- */
12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
14 * SPDX-License-Identifier: Apache-2.0
16 * Licensed under the Apache License, Version 2.0 (the License); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
20 * www.apache.org/licenses/LICENSE-2.0
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
32 * @ingroup groupMatrix
36 * @addtogroup MatrixTrans
41 * @brief Q31 matrix transpose.
42 * @param[in] *pSrc points to the input matrix
43 * @param[out] *pDst points to the output matrix
44 * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
45 * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
48 arm_status
arm_mat_trans_q31(
49 const arm_matrix_instance_q31
* pSrc
,
50 arm_matrix_instance_q31
* pDst
)
52 q31_t
*pIn
= pSrc
->pData
; /* input data matrix pointer */
53 q31_t
*pOut
= pDst
->pData
; /* output data matrix pointer */
54 q31_t
*px
; /* Temporary output data matrix pointer */
55 uint16_t nRows
= pSrc
->numRows
; /* number of nRows */
56 uint16_t nColumns
= pSrc
->numCols
; /* number of nColumns */
58 #if defined (ARM_MATH_DSP)
60 /* Run the below code for Cortex-M4 and Cortex-M3 */
62 uint16_t blkCnt
, i
= 0U, row
= nRows
; /* loop counters */
63 arm_status status
; /* status of matrix transpose */
66 #ifdef ARM_MATH_MATRIX_CHECK
69 /* Check for matrix mismatch condition */
70 if ((pSrc
->numRows
!= pDst
->numCols
) || (pSrc
->numCols
!= pDst
->numRows
))
72 /* Set status as ARM_MATH_SIZE_MISMATCH */
73 status
= ARM_MATH_SIZE_MISMATCH
;
76 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
79 /* Matrix transpose by exchanging the rows with columns */
83 /* Apply loop unrolling and exchange the columns with row elements */
84 blkCnt
= nColumns
>> 2U;
86 /* The pointer px is set to starting address of the column being processed */
89 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
90 ** a second loop below computes the remaining 1 to 3 samples. */
93 /* Read and store the input element in the destination */
96 /* Update the pointer px to point to the next row of the transposed matrix */
99 /* Read and store the input element in the destination */
102 /* Update the pointer px to point to the next row of the transposed matrix */
105 /* Read and store the input element in the destination */
108 /* Update the pointer px to point to the next row of the transposed matrix */
111 /* Read and store the input element in the destination */
114 /* Update the pointer px to point to the next row of the transposed matrix */
117 /* Decrement the column loop counter */
121 /* Perform matrix transpose for last 3 samples here. */
122 blkCnt
= nColumns
% 0x4U
;
126 /* Read and store the input element in the destination */
129 /* Update the pointer px to point to the next row of the transposed matrix */
132 /* Decrement the column loop counter */
138 /* Run the below code for Cortex-M0 */
140 uint16_t col
, i
= 0U, row
= nRows
; /* loop counters */
141 arm_status status
; /* status of matrix transpose */
144 #ifdef ARM_MATH_MATRIX_CHECK
146 /* Check for matrix mismatch condition */
147 if ((pSrc
->numRows
!= pDst
->numCols
) || (pSrc
->numCols
!= pDst
->numRows
))
149 /* Set status as ARM_MATH_SIZE_MISMATCH */
150 status
= ARM_MATH_SIZE_MISMATCH
;
153 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
156 /* Matrix transpose by exchanging the rows with columns */
160 /* The pointer px is set to starting address of the column being processed */
163 /* Initialize column loop counter */
168 /* Read and store the input element in the destination */
171 /* Update the pointer px to point to the next row of the transposed matrix */
174 /* Decrement the column loop counter */
178 #endif /* #if defined (ARM_MATH_DSP) */
182 /* Decrement the row loop counter */
186 while (row
> 0U); /* row loop end */
188 /* set status as ARM_MATH_SUCCESS */
189 status
= ARM_MATH_SUCCESS
;
192 /* Return to application */
197 * @} end of MatrixTrans group