1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_mat_cmplx_trans_f16.c
4  * Description:  Floating-point complex matrix transpose
5  *
6  * $Date:        23 April 2021
7  * $Revision:    V1.9.0
8  *
9  * Target Processor: Cortex-M and Cortex-A cores
10  * -------------------------------------------------------------------- */
11 /*
12  * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
13  *
14  * SPDX-License-Identifier: Apache-2.0
15  *
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
19  *
20  * www.apache.org/licenses/LICENSE-2.0
21  *
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.
27  */
28 
29 #include "dsp/matrix_functions_f16.h"
30 
31 #if defined(ARM_FLOAT16_SUPPORTED)
32 
33 
34 /**
35   @ingroup groupMatrix
36  */
37 
38 
39 /**
40   @addtogroup MatrixComplexTrans
41   @{
42  */
43 
44 /**
45   @brief         Floating-point matrix transpose.
46   @param[in]     pSrc      points to input matrix
47   @param[out]    pDst      points to output matrix
48   @return        execution status
49                    - \ref ARM_MATH_SUCCESS       : Operation successful
50                    - \ref ARM_MATH_SIZE_MISMATCH : Matrix size check failed
51  */
52 #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
53 
54 #include "arm_helium_utils.h"
55 
arm_mat_cmplx_trans_f16(const arm_matrix_instance_f16 * pSrc,arm_matrix_instance_f16 * pDst)56 arm_status arm_mat_cmplx_trans_f16(const arm_matrix_instance_f16 * pSrc, arm_matrix_instance_f16 * pDst)
57 {
58     return arm_mat_cmplx_trans_16bit(pSrc->numRows, pSrc->numCols, (uint16_t *) pSrc->pData,
59                                    pDst->numRows, pDst->numCols, (uint16_t *) pDst->pData);
60 }
61 
62 #else
arm_mat_cmplx_trans_f16(const arm_matrix_instance_f16 * pSrc,arm_matrix_instance_f16 * pDst)63 arm_status arm_mat_cmplx_trans_f16(
64   const arm_matrix_instance_f16 * pSrc,
65   arm_matrix_instance_f16 * pDst)
66 {
67   float16_t *pIn = pSrc->pData;                  /* input data matrix pointer */
68   float16_t *pOut = pDst->pData;                 /* output data matrix pointer */
69   float16_t *px;                                 /* Temporary output data matrix pointer */
70   uint16_t nRows = pSrc->numRows;                /* number of rows */
71   uint16_t nColumns = pSrc->numCols;             /* number of columns */
72   uint16_t col, i = 0U, row = nRows;             /* loop counters */
73   arm_status status;                             /* status of matrix transpose  */
74 
75 
76 #ifdef ARM_MATH_MATRIX_CHECK
77 
78   /* Check for matrix mismatch condition */
79   if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
80   {
81     /* Set status as ARM_MATH_SIZE_MISMATCH */
82     status = ARM_MATH_SIZE_MISMATCH;
83   }
84   else
85 #endif /*      #ifdef ARM_MATH_MATRIX_CHECK    */
86 
87   {
88     /* Matrix transpose by exchanging the rows with columns */
89     /* row loop     */
90     do
91     {
92       /* The pointer px is set to starting address of the column being processed */
93       px = pOut + CMPLX_DIM * i;
94 
95       /* Initialize column loop counter */
96       col = nColumns;
97 
98       while (col > 0U)
99       {
100         /* Read and store the input element in the destination */
101         px[0] = *pIn++; // real
102         px[1] = *pIn++; // imag
103 
104         /* Update the pointer px to point to the next row of the transposed matrix */
105         px += CMPLX_DIM * nRows;
106 
107         /* Decrement the column loop counter */
108         col--;
109       }
110       i++;
111 
112       /* Decrement the row loop counter */
113       row--;
114 
115     } while (row > 0U);          /* row loop end  */
116 
117     /* Set status as ARM_MATH_SUCCESS */
118     status = ARM_MATH_SUCCESS;
119   }
120 
121   /* Return to application */
122   return (status);
123 }
124 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
125 
126 /**
127  * @} end of MatrixTrans group
128  */
129 
130 #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
131 
132