The CMSIS DSP 5 library

Dependents:   Nucleo-Heart-Rate ejercicioVrms2 PROYECTOFINAL ejercicioVrms ... more

Committer:
xorjoep
Date:
Thu Jun 21 11:56:27 2018 +0000
Revision:
3:4098b9d3d571
Parent:
1:24714b45cd1b
headers is a folder not a library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xorjoep 1:24714b45cd1b 1 /* ----------------------------------------------------------------------
xorjoep 1:24714b45cd1b 2 * Project: CMSIS DSP Library
xorjoep 1:24714b45cd1b 3 * Title: arm_mat_cmplx_mult_f32.c
xorjoep 1:24714b45cd1b 4 * Description: Floating-point matrix multiplication
xorjoep 1:24714b45cd1b 5 *
xorjoep 1:24714b45cd1b 6 * $Date: 27. January 2017
xorjoep 1:24714b45cd1b 7 * $Revision: V.1.5.1
xorjoep 1:24714b45cd1b 8 *
xorjoep 1:24714b45cd1b 9 * Target Processor: Cortex-M cores
xorjoep 1:24714b45cd1b 10 * -------------------------------------------------------------------- */
xorjoep 1:24714b45cd1b 11 /*
xorjoep 1:24714b45cd1b 12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
xorjoep 1:24714b45cd1b 13 *
xorjoep 1:24714b45cd1b 14 * SPDX-License-Identifier: Apache-2.0
xorjoep 1:24714b45cd1b 15 *
xorjoep 1:24714b45cd1b 16 * Licensed under the Apache License, Version 2.0 (the License); you may
xorjoep 1:24714b45cd1b 17 * not use this file except in compliance with the License.
xorjoep 1:24714b45cd1b 18 * You may obtain a copy of the License at
xorjoep 1:24714b45cd1b 19 *
xorjoep 1:24714b45cd1b 20 * www.apache.org/licenses/LICENSE-2.0
xorjoep 1:24714b45cd1b 21 *
xorjoep 1:24714b45cd1b 22 * Unless required by applicable law or agreed to in writing, software
xorjoep 1:24714b45cd1b 23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
xorjoep 1:24714b45cd1b 24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
xorjoep 1:24714b45cd1b 25 * See the License for the specific language governing permissions and
xorjoep 1:24714b45cd1b 26 * limitations under the License.
xorjoep 1:24714b45cd1b 27 */
xorjoep 1:24714b45cd1b 28
xorjoep 1:24714b45cd1b 29 #include "arm_math.h"
xorjoep 1:24714b45cd1b 30
xorjoep 1:24714b45cd1b 31 /**
xorjoep 1:24714b45cd1b 32 * @ingroup groupMatrix
xorjoep 1:24714b45cd1b 33 */
xorjoep 1:24714b45cd1b 34
xorjoep 1:24714b45cd1b 35 /**
xorjoep 1:24714b45cd1b 36 * @defgroup CmplxMatrixMult Complex Matrix Multiplication
xorjoep 1:24714b45cd1b 37 *
xorjoep 1:24714b45cd1b 38 * Complex Matrix multiplication is only defined if the number of columns of the
xorjoep 1:24714b45cd1b 39 * first matrix equals the number of rows of the second matrix.
xorjoep 1:24714b45cd1b 40 * Multiplying an <code>M x N</code> matrix with an <code>N x P</code> matrix results
xorjoep 1:24714b45cd1b 41 * in an <code>M x P</code> matrix.
xorjoep 1:24714b45cd1b 42 * When matrix size checking is enabled, the functions check: (1) that the inner dimensions of
xorjoep 1:24714b45cd1b 43 * <code>pSrcA</code> and <code>pSrcB</code> are equal; and (2) that the size of the output
xorjoep 1:24714b45cd1b 44 * matrix equals the outer dimensions of <code>pSrcA</code> and <code>pSrcB</code>.
xorjoep 1:24714b45cd1b 45 */
xorjoep 1:24714b45cd1b 46
xorjoep 1:24714b45cd1b 47
xorjoep 1:24714b45cd1b 48 /**
xorjoep 1:24714b45cd1b 49 * @addtogroup CmplxMatrixMult
xorjoep 1:24714b45cd1b 50 * @{
xorjoep 1:24714b45cd1b 51 */
xorjoep 1:24714b45cd1b 52
xorjoep 1:24714b45cd1b 53 /**
xorjoep 1:24714b45cd1b 54 * @brief Floating-point Complex matrix multiplication.
xorjoep 1:24714b45cd1b 55 * @param[in] *pSrcA points to the first input complex matrix structure
xorjoep 1:24714b45cd1b 56 * @param[in] *pSrcB points to the second input complex matrix structure
xorjoep 1:24714b45cd1b 57 * @param[out] *pDst points to output complex matrix structure
xorjoep 1:24714b45cd1b 58 * @return The function returns either
xorjoep 1:24714b45cd1b 59 * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
xorjoep 1:24714b45cd1b 60 */
xorjoep 1:24714b45cd1b 61
xorjoep 1:24714b45cd1b 62 arm_status arm_mat_cmplx_mult_f32(
xorjoep 1:24714b45cd1b 63 const arm_matrix_instance_f32 * pSrcA,
xorjoep 1:24714b45cd1b 64 const arm_matrix_instance_f32 * pSrcB,
xorjoep 1:24714b45cd1b 65 arm_matrix_instance_f32 * pDst)
xorjoep 1:24714b45cd1b 66 {
xorjoep 1:24714b45cd1b 67 float32_t *pIn1 = pSrcA->pData; /* input data matrix pointer A */
xorjoep 1:24714b45cd1b 68 float32_t *pIn2 = pSrcB->pData; /* input data matrix pointer B */
xorjoep 1:24714b45cd1b 69 float32_t *pInA = pSrcA->pData; /* input data matrix pointer A */
xorjoep 1:24714b45cd1b 70 float32_t *pOut = pDst->pData; /* output data matrix pointer */
xorjoep 1:24714b45cd1b 71 float32_t *px; /* Temporary output data matrix pointer */
xorjoep 1:24714b45cd1b 72 uint16_t numRowsA = pSrcA->numRows; /* number of rows of input matrix A */
xorjoep 1:24714b45cd1b 73 uint16_t numColsB = pSrcB->numCols; /* number of columns of input matrix B */
xorjoep 1:24714b45cd1b 74 uint16_t numColsA = pSrcA->numCols; /* number of columns of input matrix A */
xorjoep 1:24714b45cd1b 75 float32_t sumReal1, sumImag1; /* accumulator */
xorjoep 1:24714b45cd1b 76 float32_t a0, b0, c0, d0;
xorjoep 1:24714b45cd1b 77 float32_t a1, b1, c1, d1;
xorjoep 1:24714b45cd1b 78 float32_t sumReal2, sumImag2; /* accumulator */
xorjoep 1:24714b45cd1b 79
xorjoep 1:24714b45cd1b 80
xorjoep 1:24714b45cd1b 81 /* Run the below code for Cortex-M4 and Cortex-M3 */
xorjoep 1:24714b45cd1b 82
xorjoep 1:24714b45cd1b 83 uint16_t col, i = 0U, j, row = numRowsA, colCnt; /* loop counters */
xorjoep 1:24714b45cd1b 84 arm_status status; /* status of matrix multiplication */
xorjoep 1:24714b45cd1b 85
xorjoep 1:24714b45cd1b 86 #ifdef ARM_MATH_MATRIX_CHECK
xorjoep 1:24714b45cd1b 87
xorjoep 1:24714b45cd1b 88
xorjoep 1:24714b45cd1b 89 /* Check for matrix mismatch condition */
xorjoep 1:24714b45cd1b 90 if ((pSrcA->numCols != pSrcB->numRows) ||
xorjoep 1:24714b45cd1b 91 (pSrcA->numRows != pDst->numRows) || (pSrcB->numCols != pDst->numCols))
xorjoep 1:24714b45cd1b 92 {
xorjoep 1:24714b45cd1b 93
xorjoep 1:24714b45cd1b 94 /* Set status as ARM_MATH_SIZE_MISMATCH */
xorjoep 1:24714b45cd1b 95 status = ARM_MATH_SIZE_MISMATCH;
xorjoep 1:24714b45cd1b 96 }
xorjoep 1:24714b45cd1b 97 else
xorjoep 1:24714b45cd1b 98 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
xorjoep 1:24714b45cd1b 99
xorjoep 1:24714b45cd1b 100 {
xorjoep 1:24714b45cd1b 101 /* The following loop performs the dot-product of each row in pSrcA with each column in pSrcB */
xorjoep 1:24714b45cd1b 102 /* row loop */
xorjoep 1:24714b45cd1b 103 do
xorjoep 1:24714b45cd1b 104 {
xorjoep 1:24714b45cd1b 105 /* Output pointer is set to starting address of the row being processed */
xorjoep 1:24714b45cd1b 106 px = pOut + 2 * i;
xorjoep 1:24714b45cd1b 107
xorjoep 1:24714b45cd1b 108 /* For every row wise process, the column loop counter is to be initiated */
xorjoep 1:24714b45cd1b 109 col = numColsB;
xorjoep 1:24714b45cd1b 110
xorjoep 1:24714b45cd1b 111 /* For every row wise process, the pIn2 pointer is set
xorjoep 1:24714b45cd1b 112 ** to the starting address of the pSrcB data */
xorjoep 1:24714b45cd1b 113 pIn2 = pSrcB->pData;
xorjoep 1:24714b45cd1b 114
xorjoep 1:24714b45cd1b 115 j = 0U;
xorjoep 1:24714b45cd1b 116
xorjoep 1:24714b45cd1b 117 /* column loop */
xorjoep 1:24714b45cd1b 118 do
xorjoep 1:24714b45cd1b 119 {
xorjoep 1:24714b45cd1b 120 /* Set the variable sum, that acts as accumulator, to zero */
xorjoep 1:24714b45cd1b 121 sumReal1 = 0.0f;
xorjoep 1:24714b45cd1b 122 sumImag1 = 0.0f;
xorjoep 1:24714b45cd1b 123
xorjoep 1:24714b45cd1b 124 sumReal2 = 0.0f;
xorjoep 1:24714b45cd1b 125 sumImag2 = 0.0f;
xorjoep 1:24714b45cd1b 126
xorjoep 1:24714b45cd1b 127 /* Initiate the pointer pIn1 to point to the starting address of the column being processed */
xorjoep 1:24714b45cd1b 128 pIn1 = pInA;
xorjoep 1:24714b45cd1b 129
xorjoep 1:24714b45cd1b 130 /* Apply loop unrolling and compute 4 MACs simultaneously. */
xorjoep 1:24714b45cd1b 131 colCnt = numColsA >> 2;
xorjoep 1:24714b45cd1b 132
xorjoep 1:24714b45cd1b 133 /* matrix multiplication */
xorjoep 1:24714b45cd1b 134 while (colCnt > 0U)
xorjoep 1:24714b45cd1b 135 {
xorjoep 1:24714b45cd1b 136
xorjoep 1:24714b45cd1b 137 /* Reading real part of complex matrix A */
xorjoep 1:24714b45cd1b 138 a0 = *pIn1;
xorjoep 1:24714b45cd1b 139
xorjoep 1:24714b45cd1b 140 /* Reading real part of complex matrix B */
xorjoep 1:24714b45cd1b 141 c0 = *pIn2;
xorjoep 1:24714b45cd1b 142
xorjoep 1:24714b45cd1b 143 /* Reading imaginary part of complex matrix A */
xorjoep 1:24714b45cd1b 144 b0 = *(pIn1 + 1U);
xorjoep 1:24714b45cd1b 145
xorjoep 1:24714b45cd1b 146 /* Reading imaginary part of complex matrix B */
xorjoep 1:24714b45cd1b 147 d0 = *(pIn2 + 1U);
xorjoep 1:24714b45cd1b 148
xorjoep 1:24714b45cd1b 149 sumReal1 += a0 * c0;
xorjoep 1:24714b45cd1b 150 sumImag1 += b0 * c0;
xorjoep 1:24714b45cd1b 151
xorjoep 1:24714b45cd1b 152 pIn1 += 2U;
xorjoep 1:24714b45cd1b 153 pIn2 += 2 * numColsB;
xorjoep 1:24714b45cd1b 154
xorjoep 1:24714b45cd1b 155 sumReal2 -= b0 * d0;
xorjoep 1:24714b45cd1b 156 sumImag2 += a0 * d0;
xorjoep 1:24714b45cd1b 157
xorjoep 1:24714b45cd1b 158 /* c(m,n) = a(1,1)*b(1,1) + a(1,2) * b(2,1) + .... + a(m,p)*b(p,n) */
xorjoep 1:24714b45cd1b 159
xorjoep 1:24714b45cd1b 160 a1 = *pIn1;
xorjoep 1:24714b45cd1b 161 c1 = *pIn2;
xorjoep 1:24714b45cd1b 162
xorjoep 1:24714b45cd1b 163 b1 = *(pIn1 + 1U);
xorjoep 1:24714b45cd1b 164 d1 = *(pIn2 + 1U);
xorjoep 1:24714b45cd1b 165
xorjoep 1:24714b45cd1b 166 sumReal1 += a1 * c1;
xorjoep 1:24714b45cd1b 167 sumImag1 += b1 * c1;
xorjoep 1:24714b45cd1b 168
xorjoep 1:24714b45cd1b 169 pIn1 += 2U;
xorjoep 1:24714b45cd1b 170 pIn2 += 2 * numColsB;
xorjoep 1:24714b45cd1b 171
xorjoep 1:24714b45cd1b 172 sumReal2 -= b1 * d1;
xorjoep 1:24714b45cd1b 173 sumImag2 += a1 * d1;
xorjoep 1:24714b45cd1b 174
xorjoep 1:24714b45cd1b 175 a0 = *pIn1;
xorjoep 1:24714b45cd1b 176 c0 = *pIn2;
xorjoep 1:24714b45cd1b 177
xorjoep 1:24714b45cd1b 178 b0 = *(pIn1 + 1U);
xorjoep 1:24714b45cd1b 179 d0 = *(pIn2 + 1U);
xorjoep 1:24714b45cd1b 180
xorjoep 1:24714b45cd1b 181 sumReal1 += a0 * c0;
xorjoep 1:24714b45cd1b 182 sumImag1 += b0 * c0;
xorjoep 1:24714b45cd1b 183
xorjoep 1:24714b45cd1b 184 pIn1 += 2U;
xorjoep 1:24714b45cd1b 185 pIn2 += 2 * numColsB;
xorjoep 1:24714b45cd1b 186
xorjoep 1:24714b45cd1b 187 sumReal2 -= b0 * d0;
xorjoep 1:24714b45cd1b 188 sumImag2 += a0 * d0;
xorjoep 1:24714b45cd1b 189
xorjoep 1:24714b45cd1b 190 /* c(m,n) = a(1,1)*b(1,1) + a(1,2) * b(2,1) + .... + a(m,p)*b(p,n) */
xorjoep 1:24714b45cd1b 191
xorjoep 1:24714b45cd1b 192 a1 = *pIn1;
xorjoep 1:24714b45cd1b 193 c1 = *pIn2;
xorjoep 1:24714b45cd1b 194
xorjoep 1:24714b45cd1b 195 b1 = *(pIn1 + 1U);
xorjoep 1:24714b45cd1b 196 d1 = *(pIn2 + 1U);
xorjoep 1:24714b45cd1b 197
xorjoep 1:24714b45cd1b 198 sumReal1 += a1 * c1;
xorjoep 1:24714b45cd1b 199 sumImag1 += b1 * c1;
xorjoep 1:24714b45cd1b 200
xorjoep 1:24714b45cd1b 201 pIn1 += 2U;
xorjoep 1:24714b45cd1b 202 pIn2 += 2 * numColsB;
xorjoep 1:24714b45cd1b 203
xorjoep 1:24714b45cd1b 204 sumReal2 -= b1 * d1;
xorjoep 1:24714b45cd1b 205 sumImag2 += a1 * d1;
xorjoep 1:24714b45cd1b 206
xorjoep 1:24714b45cd1b 207 /* Decrement the loop count */
xorjoep 1:24714b45cd1b 208 colCnt--;
xorjoep 1:24714b45cd1b 209 }
xorjoep 1:24714b45cd1b 210
xorjoep 1:24714b45cd1b 211 /* If the columns of pSrcA is not a multiple of 4, compute any remaining MACs here.
xorjoep 1:24714b45cd1b 212 ** No loop unrolling is used. */
xorjoep 1:24714b45cd1b 213 colCnt = numColsA % 0x4U;
xorjoep 1:24714b45cd1b 214
xorjoep 1:24714b45cd1b 215 while (colCnt > 0U)
xorjoep 1:24714b45cd1b 216 {
xorjoep 1:24714b45cd1b 217 /* c(m,n) = a(1,1)*b(1,1) + a(1,2) * b(2,1) + .... + a(m,p)*b(p,n) */
xorjoep 1:24714b45cd1b 218 a1 = *pIn1;
xorjoep 1:24714b45cd1b 219 c1 = *pIn2;
xorjoep 1:24714b45cd1b 220
xorjoep 1:24714b45cd1b 221 b1 = *(pIn1 + 1U);
xorjoep 1:24714b45cd1b 222 d1 = *(pIn2 + 1U);
xorjoep 1:24714b45cd1b 223
xorjoep 1:24714b45cd1b 224 sumReal1 += a1 * c1;
xorjoep 1:24714b45cd1b 225 sumImag1 += b1 * c1;
xorjoep 1:24714b45cd1b 226
xorjoep 1:24714b45cd1b 227 pIn1 += 2U;
xorjoep 1:24714b45cd1b 228 pIn2 += 2 * numColsB;
xorjoep 1:24714b45cd1b 229
xorjoep 1:24714b45cd1b 230 sumReal2 -= b1 * d1;
xorjoep 1:24714b45cd1b 231 sumImag2 += a1 * d1;
xorjoep 1:24714b45cd1b 232
xorjoep 1:24714b45cd1b 233 /* Decrement the loop counter */
xorjoep 1:24714b45cd1b 234 colCnt--;
xorjoep 1:24714b45cd1b 235 }
xorjoep 1:24714b45cd1b 236
xorjoep 1:24714b45cd1b 237 sumReal1 += sumReal2;
xorjoep 1:24714b45cd1b 238 sumImag1 += sumImag2;
xorjoep 1:24714b45cd1b 239
xorjoep 1:24714b45cd1b 240 /* Store the result in the destination buffer */
xorjoep 1:24714b45cd1b 241 *px++ = sumReal1;
xorjoep 1:24714b45cd1b 242 *px++ = sumImag1;
xorjoep 1:24714b45cd1b 243
xorjoep 1:24714b45cd1b 244 /* Update the pointer pIn2 to point to the starting address of the next column */
xorjoep 1:24714b45cd1b 245 j++;
xorjoep 1:24714b45cd1b 246 pIn2 = pSrcB->pData + 2U * j;
xorjoep 1:24714b45cd1b 247
xorjoep 1:24714b45cd1b 248 /* Decrement the column loop counter */
xorjoep 1:24714b45cd1b 249 col--;
xorjoep 1:24714b45cd1b 250
xorjoep 1:24714b45cd1b 251 } while (col > 0U);
xorjoep 1:24714b45cd1b 252
xorjoep 1:24714b45cd1b 253 /* Update the pointer pInA to point to the starting address of the next row */
xorjoep 1:24714b45cd1b 254 i = i + numColsB;
xorjoep 1:24714b45cd1b 255 pInA = pInA + 2 * numColsA;
xorjoep 1:24714b45cd1b 256
xorjoep 1:24714b45cd1b 257 /* Decrement the row loop counter */
xorjoep 1:24714b45cd1b 258 row--;
xorjoep 1:24714b45cd1b 259
xorjoep 1:24714b45cd1b 260 } while (row > 0U);
xorjoep 1:24714b45cd1b 261
xorjoep 1:24714b45cd1b 262 /* Set status as ARM_MATH_SUCCESS */
xorjoep 1:24714b45cd1b 263 status = ARM_MATH_SUCCESS;
xorjoep 1:24714b45cd1b 264 }
xorjoep 1:24714b45cd1b 265
xorjoep 1:24714b45cd1b 266 /* Return to application */
xorjoep 1:24714b45cd1b 267 return (status);
xorjoep 1:24714b45cd1b 268 }
xorjoep 1:24714b45cd1b 269
xorjoep 1:24714b45cd1b 270 /**
xorjoep 1:24714b45cd1b 271 * @} end of MatrixMult group
xorjoep 1:24714b45cd1b 272 */