1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_mat_cmplx_mult_f32.c
4 * Description: Floating-point matrix multiplication
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 * @defgroup CmplxMatrixMult Complex Matrix Multiplication
38 * Complex Matrix multiplication is only defined if the number of columns of the
39 * first matrix equals the number of rows of the second matrix.
40 * Multiplying an <code>M x N</code> matrix with an <code>N x P</code> matrix results
41 * in an <code>M x P</code> matrix.
42 * When matrix size checking is enabled, the functions check: (1) that the inner dimensions of
43 * <code>pSrcA</code> and <code>pSrcB</code> are equal; and (2) that the size of the output
44 * matrix equals the outer dimensions of <code>pSrcA</code> and <code>pSrcB</code>.
49 * @addtogroup CmplxMatrixMult
54 * @brief Floating-point Complex matrix multiplication.
55 * @param[in] *pSrcA points to the first input complex matrix structure
56 * @param[in] *pSrcB points to the second input complex matrix structure
57 * @param[out] *pDst points to output complex matrix structure
58 * @return The function returns either
59 * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
62 arm_status
arm_mat_cmplx_mult_f32(
63 const arm_matrix_instance_f32
* pSrcA
,
64 const arm_matrix_instance_f32
* pSrcB
,
65 arm_matrix_instance_f32
* pDst
)
67 float32_t
*pIn1
= pSrcA
->pData
; /* input data matrix pointer A */
68 float32_t
*pIn2
= pSrcB
->pData
; /* input data matrix pointer B */
69 float32_t
*pInA
= pSrcA
->pData
; /* input data matrix pointer A */
70 float32_t
*pOut
= pDst
->pData
; /* output data matrix pointer */
71 float32_t
*px
; /* Temporary output data matrix pointer */
72 uint16_t numRowsA
= pSrcA
->numRows
; /* number of rows of input matrix A */
73 uint16_t numColsB
= pSrcB
->numCols
; /* number of columns of input matrix B */
74 uint16_t numColsA
= pSrcA
->numCols
; /* number of columns of input matrix A */
75 float32_t sumReal1
, sumImag1
; /* accumulator */
76 float32_t a0
, b0
, c0
, d0
;
77 float32_t a1
, b1
, c1
, d1
;
78 float32_t sumReal2
, sumImag2
; /* accumulator */
81 /* Run the below code for Cortex-M4 and Cortex-M3 */
83 uint16_t col
, i
= 0U, j
, row
= numRowsA
, colCnt
; /* loop counters */
84 arm_status status
; /* status of matrix multiplication */
86 #ifdef ARM_MATH_MATRIX_CHECK
89 /* Check for matrix mismatch condition */
90 if ((pSrcA
->numCols
!= pSrcB
->numRows
) ||
91 (pSrcA
->numRows
!= pDst
->numRows
) || (pSrcB
->numCols
!= pDst
->numCols
))
94 /* Set status as ARM_MATH_SIZE_MISMATCH */
95 status
= ARM_MATH_SIZE_MISMATCH
;
98 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
101 /* The following loop performs the dot-product of each row in pSrcA with each column in pSrcB */
105 /* Output pointer is set to starting address of the row being processed */
108 /* For every row wise process, the column loop counter is to be initiated */
111 /* For every row wise process, the pIn2 pointer is set
112 ** to the starting address of the pSrcB data */
120 /* Set the variable sum, that acts as accumulator, to zero */
127 /* Initiate the pointer pIn1 to point to the starting address of the column being processed */
130 /* Apply loop unrolling and compute 4 MACs simultaneously. */
131 colCnt
= numColsA
>> 2;
133 /* matrix multiplication */
137 /* Reading real part of complex matrix A */
140 /* Reading real part of complex matrix B */
143 /* Reading imaginary part of complex matrix A */
146 /* Reading imaginary part of complex matrix B */
153 pIn2
+= 2 * numColsB
;
158 /* c(m,n) = a(1,1)*b(1,1) + a(1,2) * b(2,1) + .... + a(m,p)*b(p,n) */
170 pIn2
+= 2 * numColsB
;
185 pIn2
+= 2 * numColsB
;
190 /* c(m,n) = a(1,1)*b(1,1) + a(1,2) * b(2,1) + .... + a(m,p)*b(p,n) */
202 pIn2
+= 2 * numColsB
;
207 /* Decrement the loop count */
211 /* If the columns of pSrcA is not a multiple of 4, compute any remaining MACs here.
212 ** No loop unrolling is used. */
213 colCnt
= numColsA
% 0x4U
;
217 /* c(m,n) = a(1,1)*b(1,1) + a(1,2) * b(2,1) + .... + a(m,p)*b(p,n) */
228 pIn2
+= 2 * numColsB
;
233 /* Decrement the loop counter */
237 sumReal1
+= sumReal2
;
238 sumImag1
+= sumImag2
;
240 /* Store the result in the destination buffer */
244 /* Update the pointer pIn2 to point to the starting address of the next column */
246 pIn2
= pSrcB
->pData
+ 2U * j
;
248 /* Decrement the column loop counter */
253 /* Update the pointer pInA to point to the starting address of the next row */
255 pInA
= pInA
+ 2 * numColsA
;
257 /* Decrement the row loop counter */
262 /* Set status as ARM_MATH_SUCCESS */
263 status
= ARM_MATH_SUCCESS
;
266 /* Return to application */
271 * @} end of MatrixMult group