V4.0.1 of the ARM CMSIS DSP libraries. Note that arm_bitreversal2.s, arm_cfft_f32.c and arm_rfft_fast_f32.c had to be removed. arm_bitreversal2.s will not assemble with the online tools. So, the fast f32 FFT functions are not yet available. All the other FFT functions are available.

Dependents:   MPU9150_Example fir_f32 fir_f32 MPU9150_nucleo_noni2cdev ... more

Committer:
emh203
Date:
Mon Jul 28 15:03:15 2014 +0000
Revision:
0:3d9c67d97d6f
1st working commit.   Had to remove arm_bitreversal2.s     arm_cfft_f32.c and arm_rfft_fast_f32.c.    The .s will not assemble.      For now I removed these functions so we could at least have a library for the other functions.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emh203 0:3d9c67d97d6f 1 /* ----------------------------------------------------------------------
emh203 0:3d9c67d97d6f 2 * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
emh203 0:3d9c67d97d6f 3 *
emh203 0:3d9c67d97d6f 4 * $Date: 12. March 2014
emh203 0:3d9c67d97d6f 5 * $Revision: V1.4.3
emh203 0:3d9c67d97d6f 6 *
emh203 0:3d9c67d97d6f 7 * Project: CMSIS DSP Library
emh203 0:3d9c67d97d6f 8 * Title: arm_mat_mult_q15.c
emh203 0:3d9c67d97d6f 9 *
emh203 0:3d9c67d97d6f 10 * Description: Q15 matrix multiplication.
emh203 0:3d9c67d97d6f 11 *
emh203 0:3d9c67d97d6f 12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
emh203 0:3d9c67d97d6f 13 *
emh203 0:3d9c67d97d6f 14 * Redistribution and use in source and binary forms, with or without
emh203 0:3d9c67d97d6f 15 * modification, are permitted provided that the following conditions
emh203 0:3d9c67d97d6f 16 * are met:
emh203 0:3d9c67d97d6f 17 * - Redistributions of source code must retain the above copyright
emh203 0:3d9c67d97d6f 18 * notice, this list of conditions and the following disclaimer.
emh203 0:3d9c67d97d6f 19 * - Redistributions in binary form must reproduce the above copyright
emh203 0:3d9c67d97d6f 20 * notice, this list of conditions and the following disclaimer in
emh203 0:3d9c67d97d6f 21 * the documentation and/or other materials provided with the
emh203 0:3d9c67d97d6f 22 * distribution.
emh203 0:3d9c67d97d6f 23 * - Neither the name of ARM LIMITED nor the names of its contributors
emh203 0:3d9c67d97d6f 24 * may be used to endorse or promote products derived from this
emh203 0:3d9c67d97d6f 25 * software without specific prior written permission.
emh203 0:3d9c67d97d6f 26 *
emh203 0:3d9c67d97d6f 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
emh203 0:3d9c67d97d6f 28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
emh203 0:3d9c67d97d6f 29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
emh203 0:3d9c67d97d6f 30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
emh203 0:3d9c67d97d6f 31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
emh203 0:3d9c67d97d6f 32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
emh203 0:3d9c67d97d6f 33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
emh203 0:3d9c67d97d6f 34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
emh203 0:3d9c67d97d6f 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
emh203 0:3d9c67d97d6f 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
emh203 0:3d9c67d97d6f 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
emh203 0:3d9c67d97d6f 38 * POSSIBILITY OF SUCH DAMAGE.
emh203 0:3d9c67d97d6f 39 * -------------------------------------------------------------------- */
emh203 0:3d9c67d97d6f 40
emh203 0:3d9c67d97d6f 41 #include "arm_math.h"
emh203 0:3d9c67d97d6f 42
emh203 0:3d9c67d97d6f 43 /**
emh203 0:3d9c67d97d6f 44 * @ingroup groupMatrix
emh203 0:3d9c67d97d6f 45 */
emh203 0:3d9c67d97d6f 46
emh203 0:3d9c67d97d6f 47 /**
emh203 0:3d9c67d97d6f 48 * @addtogroup MatrixMult
emh203 0:3d9c67d97d6f 49 * @{
emh203 0:3d9c67d97d6f 50 */
emh203 0:3d9c67d97d6f 51
emh203 0:3d9c67d97d6f 52
emh203 0:3d9c67d97d6f 53 /**
emh203 0:3d9c67d97d6f 54 * @brief Q15 matrix multiplication
emh203 0:3d9c67d97d6f 55 * @param[in] *pSrcA points to the first input matrix structure
emh203 0:3d9c67d97d6f 56 * @param[in] *pSrcB points to the second input matrix structure
emh203 0:3d9c67d97d6f 57 * @param[out] *pDst points to output matrix structure
emh203 0:3d9c67d97d6f 58 * @param[in] *pState points to the array for storing intermediate results
emh203 0:3d9c67d97d6f 59 * @return The function returns either
emh203 0:3d9c67d97d6f 60 * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
emh203 0:3d9c67d97d6f 61 *
emh203 0:3d9c67d97d6f 62 * @details
emh203 0:3d9c67d97d6f 63 * <b>Scaling and Overflow Behavior:</b>
emh203 0:3d9c67d97d6f 64 *
emh203 0:3d9c67d97d6f 65 * \par
emh203 0:3d9c67d97d6f 66 * The function is implemented using a 64-bit internal accumulator. The inputs to the
emh203 0:3d9c67d97d6f 67 * multiplications are in 1.15 format and multiplications yield a 2.30 result.
emh203 0:3d9c67d97d6f 68 * The 2.30 intermediate
emh203 0:3d9c67d97d6f 69 * results are accumulated in a 64-bit accumulator in 34.30 format. This approach
emh203 0:3d9c67d97d6f 70 * provides 33 guard bits and there is no risk of overflow. The 34.30 result is then
emh203 0:3d9c67d97d6f 71 * truncated to 34.15 format by discarding the low 15 bits and then saturated to
emh203 0:3d9c67d97d6f 72 * 1.15 format.
emh203 0:3d9c67d97d6f 73 *
emh203 0:3d9c67d97d6f 74 * \par
emh203 0:3d9c67d97d6f 75 * Refer to <code>arm_mat_mult_fast_q15()</code> for a faster but less precise version of this function for Cortex-M3 and Cortex-M4.
emh203 0:3d9c67d97d6f 76 *
emh203 0:3d9c67d97d6f 77 */
emh203 0:3d9c67d97d6f 78
emh203 0:3d9c67d97d6f 79 arm_status arm_mat_mult_q15(
emh203 0:3d9c67d97d6f 80 const arm_matrix_instance_q15 * pSrcA,
emh203 0:3d9c67d97d6f 81 const arm_matrix_instance_q15 * pSrcB,
emh203 0:3d9c67d97d6f 82 arm_matrix_instance_q15 * pDst,
emh203 0:3d9c67d97d6f 83 q15_t * pState CMSIS_UNUSED)
emh203 0:3d9c67d97d6f 84 {
emh203 0:3d9c67d97d6f 85 q63_t sum; /* accumulator */
emh203 0:3d9c67d97d6f 86
emh203 0:3d9c67d97d6f 87 #ifndef ARM_MATH_CM0_FAMILY
emh203 0:3d9c67d97d6f 88
emh203 0:3d9c67d97d6f 89 /* Run the below code for Cortex-M4 and Cortex-M3 */
emh203 0:3d9c67d97d6f 90
emh203 0:3d9c67d97d6f 91 q15_t *pSrcBT = pState; /* input data matrix pointer for transpose */
emh203 0:3d9c67d97d6f 92 q15_t *pInA = pSrcA->pData; /* input data matrix pointer A of Q15 type */
emh203 0:3d9c67d97d6f 93 q15_t *pInB = pSrcB->pData; /* input data matrix pointer B of Q15 type */
emh203 0:3d9c67d97d6f 94 q15_t *px; /* Temporary output data matrix pointer */
emh203 0:3d9c67d97d6f 95 uint16_t numRowsA = pSrcA->numRows; /* number of rows of input matrix A */
emh203 0:3d9c67d97d6f 96 uint16_t numColsB = pSrcB->numCols; /* number of columns of input matrix B */
emh203 0:3d9c67d97d6f 97 uint16_t numColsA = pSrcA->numCols; /* number of columns of input matrix A */
emh203 0:3d9c67d97d6f 98 uint16_t numRowsB = pSrcB->numRows; /* number of rows of input matrix A */
emh203 0:3d9c67d97d6f 99 uint16_t col, i = 0u, row = numRowsB, colCnt; /* loop counters */
emh203 0:3d9c67d97d6f 100 arm_status status; /* status of matrix multiplication */
emh203 0:3d9c67d97d6f 101
emh203 0:3d9c67d97d6f 102 #ifndef UNALIGNED_SUPPORT_DISABLE
emh203 0:3d9c67d97d6f 103
emh203 0:3d9c67d97d6f 104 q31_t in; /* Temporary variable to hold the input value */
emh203 0:3d9c67d97d6f 105 q31_t pSourceA1, pSourceB1, pSourceA2, pSourceB2;
emh203 0:3d9c67d97d6f 106
emh203 0:3d9c67d97d6f 107 #else
emh203 0:3d9c67d97d6f 108
emh203 0:3d9c67d97d6f 109 q15_t in; /* Temporary variable to hold the input value */
emh203 0:3d9c67d97d6f 110 q15_t inA1, inB1, inA2, inB2;
emh203 0:3d9c67d97d6f 111
emh203 0:3d9c67d97d6f 112 #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */
emh203 0:3d9c67d97d6f 113
emh203 0:3d9c67d97d6f 114 #ifdef ARM_MATH_MATRIX_CHECK
emh203 0:3d9c67d97d6f 115 /* Check for matrix mismatch condition */
emh203 0:3d9c67d97d6f 116 if((pSrcA->numCols != pSrcB->numRows) ||
emh203 0:3d9c67d97d6f 117 (pSrcA->numRows != pDst->numRows) || (pSrcB->numCols != pDst->numCols))
emh203 0:3d9c67d97d6f 118 {
emh203 0:3d9c67d97d6f 119 /* Set status as ARM_MATH_SIZE_MISMATCH */
emh203 0:3d9c67d97d6f 120 status = ARM_MATH_SIZE_MISMATCH;
emh203 0:3d9c67d97d6f 121 }
emh203 0:3d9c67d97d6f 122 else
emh203 0:3d9c67d97d6f 123 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
emh203 0:3d9c67d97d6f 124 {
emh203 0:3d9c67d97d6f 125 /* Matrix transpose */
emh203 0:3d9c67d97d6f 126 do
emh203 0:3d9c67d97d6f 127 {
emh203 0:3d9c67d97d6f 128 /* Apply loop unrolling and exchange the columns with row elements */
emh203 0:3d9c67d97d6f 129 col = numColsB >> 2;
emh203 0:3d9c67d97d6f 130
emh203 0:3d9c67d97d6f 131 /* The pointer px is set to starting address of the column being processed */
emh203 0:3d9c67d97d6f 132 px = pSrcBT + i;
emh203 0:3d9c67d97d6f 133
emh203 0:3d9c67d97d6f 134 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
emh203 0:3d9c67d97d6f 135 ** a second loop below computes the remaining 1 to 3 samples. */
emh203 0:3d9c67d97d6f 136 while(col > 0u)
emh203 0:3d9c67d97d6f 137 {
emh203 0:3d9c67d97d6f 138 #ifndef UNALIGNED_SUPPORT_DISABLE
emh203 0:3d9c67d97d6f 139
emh203 0:3d9c67d97d6f 140 /* Read two elements from the row */
emh203 0:3d9c67d97d6f 141 in = *__SIMD32(pInB)++;
emh203 0:3d9c67d97d6f 142
emh203 0:3d9c67d97d6f 143 /* Unpack and store one element in the destination */
emh203 0:3d9c67d97d6f 144 #ifndef ARM_MATH_BIG_ENDIAN
emh203 0:3d9c67d97d6f 145
emh203 0:3d9c67d97d6f 146 *px = (q15_t) in;
emh203 0:3d9c67d97d6f 147
emh203 0:3d9c67d97d6f 148 #else
emh203 0:3d9c67d97d6f 149
emh203 0:3d9c67d97d6f 150 *px = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
emh203 0:3d9c67d97d6f 151
emh203 0:3d9c67d97d6f 152 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
emh203 0:3d9c67d97d6f 153
emh203 0:3d9c67d97d6f 154 /* Update the pointer px to point to the next row of the transposed matrix */
emh203 0:3d9c67d97d6f 155 px += numRowsB;
emh203 0:3d9c67d97d6f 156
emh203 0:3d9c67d97d6f 157 /* Unpack and store the second element in the destination */
emh203 0:3d9c67d97d6f 158 #ifndef ARM_MATH_BIG_ENDIAN
emh203 0:3d9c67d97d6f 159
emh203 0:3d9c67d97d6f 160 *px = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
emh203 0:3d9c67d97d6f 161
emh203 0:3d9c67d97d6f 162 #else
emh203 0:3d9c67d97d6f 163
emh203 0:3d9c67d97d6f 164 *px = (q15_t) in;
emh203 0:3d9c67d97d6f 165
emh203 0:3d9c67d97d6f 166 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
emh203 0:3d9c67d97d6f 167
emh203 0:3d9c67d97d6f 168 /* Update the pointer px to point to the next row of the transposed matrix */
emh203 0:3d9c67d97d6f 169 px += numRowsB;
emh203 0:3d9c67d97d6f 170
emh203 0:3d9c67d97d6f 171 /* Read two elements from the row */
emh203 0:3d9c67d97d6f 172 in = *__SIMD32(pInB)++;
emh203 0:3d9c67d97d6f 173
emh203 0:3d9c67d97d6f 174 /* Unpack and store one element in the destination */
emh203 0:3d9c67d97d6f 175 #ifndef ARM_MATH_BIG_ENDIAN
emh203 0:3d9c67d97d6f 176
emh203 0:3d9c67d97d6f 177 *px = (q15_t) in;
emh203 0:3d9c67d97d6f 178
emh203 0:3d9c67d97d6f 179 #else
emh203 0:3d9c67d97d6f 180
emh203 0:3d9c67d97d6f 181 *px = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
emh203 0:3d9c67d97d6f 182
emh203 0:3d9c67d97d6f 183 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
emh203 0:3d9c67d97d6f 184
emh203 0:3d9c67d97d6f 185 /* Update the pointer px to point to the next row of the transposed matrix */
emh203 0:3d9c67d97d6f 186 px += numRowsB;
emh203 0:3d9c67d97d6f 187
emh203 0:3d9c67d97d6f 188 /* Unpack and store the second element in the destination */
emh203 0:3d9c67d97d6f 189
emh203 0:3d9c67d97d6f 190 #ifndef ARM_MATH_BIG_ENDIAN
emh203 0:3d9c67d97d6f 191
emh203 0:3d9c67d97d6f 192 *px = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
emh203 0:3d9c67d97d6f 193
emh203 0:3d9c67d97d6f 194 #else
emh203 0:3d9c67d97d6f 195
emh203 0:3d9c67d97d6f 196 *px = (q15_t) in;
emh203 0:3d9c67d97d6f 197
emh203 0:3d9c67d97d6f 198 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
emh203 0:3d9c67d97d6f 199
emh203 0:3d9c67d97d6f 200 /* Update the pointer px to point to the next row of the transposed matrix */
emh203 0:3d9c67d97d6f 201 px += numRowsB;
emh203 0:3d9c67d97d6f 202
emh203 0:3d9c67d97d6f 203 #else
emh203 0:3d9c67d97d6f 204
emh203 0:3d9c67d97d6f 205 /* Read one element from the row */
emh203 0:3d9c67d97d6f 206 in = *pInB++;
emh203 0:3d9c67d97d6f 207
emh203 0:3d9c67d97d6f 208 /* Store one element in the destination */
emh203 0:3d9c67d97d6f 209 *px = in;
emh203 0:3d9c67d97d6f 210
emh203 0:3d9c67d97d6f 211 /* Update the pointer px to point to the next row of the transposed matrix */
emh203 0:3d9c67d97d6f 212 px += numRowsB;
emh203 0:3d9c67d97d6f 213
emh203 0:3d9c67d97d6f 214 /* Read one element from the row */
emh203 0:3d9c67d97d6f 215 in = *pInB++;
emh203 0:3d9c67d97d6f 216
emh203 0:3d9c67d97d6f 217 /* Store one element in the destination */
emh203 0:3d9c67d97d6f 218 *px = in;
emh203 0:3d9c67d97d6f 219
emh203 0:3d9c67d97d6f 220 /* Update the pointer px to point to the next row of the transposed matrix */
emh203 0:3d9c67d97d6f 221 px += numRowsB;
emh203 0:3d9c67d97d6f 222
emh203 0:3d9c67d97d6f 223 /* Read one element from the row */
emh203 0:3d9c67d97d6f 224 in = *pInB++;
emh203 0:3d9c67d97d6f 225
emh203 0:3d9c67d97d6f 226 /* Store one element in the destination */
emh203 0:3d9c67d97d6f 227 *px = in;
emh203 0:3d9c67d97d6f 228
emh203 0:3d9c67d97d6f 229 /* Update the pointer px to point to the next row of the transposed matrix */
emh203 0:3d9c67d97d6f 230 px += numRowsB;
emh203 0:3d9c67d97d6f 231
emh203 0:3d9c67d97d6f 232 /* Read one element from the row */
emh203 0:3d9c67d97d6f 233 in = *pInB++;
emh203 0:3d9c67d97d6f 234
emh203 0:3d9c67d97d6f 235 /* Store one element in the destination */
emh203 0:3d9c67d97d6f 236 *px = in;
emh203 0:3d9c67d97d6f 237
emh203 0:3d9c67d97d6f 238 /* Update the pointer px to point to the next row of the transposed matrix */
emh203 0:3d9c67d97d6f 239 px += numRowsB;
emh203 0:3d9c67d97d6f 240
emh203 0:3d9c67d97d6f 241 #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */
emh203 0:3d9c67d97d6f 242
emh203 0:3d9c67d97d6f 243 /* Decrement the column loop counter */
emh203 0:3d9c67d97d6f 244 col--;
emh203 0:3d9c67d97d6f 245 }
emh203 0:3d9c67d97d6f 246
emh203 0:3d9c67d97d6f 247 /* If the columns of pSrcB is not a multiple of 4, compute any remaining output samples here.
emh203 0:3d9c67d97d6f 248 ** No loop unrolling is used. */
emh203 0:3d9c67d97d6f 249 col = numColsB % 0x4u;
emh203 0:3d9c67d97d6f 250
emh203 0:3d9c67d97d6f 251 while(col > 0u)
emh203 0:3d9c67d97d6f 252 {
emh203 0:3d9c67d97d6f 253 /* Read and store the input element in the destination */
emh203 0:3d9c67d97d6f 254 *px = *pInB++;
emh203 0:3d9c67d97d6f 255
emh203 0:3d9c67d97d6f 256 /* Update the pointer px to point to the next row of the transposed matrix */
emh203 0:3d9c67d97d6f 257 px += numRowsB;
emh203 0:3d9c67d97d6f 258
emh203 0:3d9c67d97d6f 259 /* Decrement the column loop counter */
emh203 0:3d9c67d97d6f 260 col--;
emh203 0:3d9c67d97d6f 261 }
emh203 0:3d9c67d97d6f 262
emh203 0:3d9c67d97d6f 263 i++;
emh203 0:3d9c67d97d6f 264
emh203 0:3d9c67d97d6f 265 /* Decrement the row loop counter */
emh203 0:3d9c67d97d6f 266 row--;
emh203 0:3d9c67d97d6f 267
emh203 0:3d9c67d97d6f 268 } while(row > 0u);
emh203 0:3d9c67d97d6f 269
emh203 0:3d9c67d97d6f 270 /* Reset the variables for the usage in the following multiplication process */
emh203 0:3d9c67d97d6f 271 row = numRowsA;
emh203 0:3d9c67d97d6f 272 i = 0u;
emh203 0:3d9c67d97d6f 273 px = pDst->pData;
emh203 0:3d9c67d97d6f 274
emh203 0:3d9c67d97d6f 275 /* The following loop performs the dot-product of each row in pSrcA with each column in pSrcB */
emh203 0:3d9c67d97d6f 276 /* row loop */
emh203 0:3d9c67d97d6f 277 do
emh203 0:3d9c67d97d6f 278 {
emh203 0:3d9c67d97d6f 279 /* For every row wise process, the column loop counter is to be initiated */
emh203 0:3d9c67d97d6f 280 col = numColsB;
emh203 0:3d9c67d97d6f 281
emh203 0:3d9c67d97d6f 282 /* For every row wise process, the pIn2 pointer is set
emh203 0:3d9c67d97d6f 283 ** to the starting address of the transposed pSrcB data */
emh203 0:3d9c67d97d6f 284 pInB = pSrcBT;
emh203 0:3d9c67d97d6f 285
emh203 0:3d9c67d97d6f 286 /* column loop */
emh203 0:3d9c67d97d6f 287 do
emh203 0:3d9c67d97d6f 288 {
emh203 0:3d9c67d97d6f 289 /* Set the variable sum, that acts as accumulator, to zero */
emh203 0:3d9c67d97d6f 290 sum = 0;
emh203 0:3d9c67d97d6f 291
emh203 0:3d9c67d97d6f 292 /* Apply loop unrolling and compute 2 MACs simultaneously. */
emh203 0:3d9c67d97d6f 293 colCnt = numColsA >> 2;
emh203 0:3d9c67d97d6f 294
emh203 0:3d9c67d97d6f 295 /* Initiate the pointer pIn1 to point to the starting address of the column being processed */
emh203 0:3d9c67d97d6f 296 pInA = pSrcA->pData + i;
emh203 0:3d9c67d97d6f 297
emh203 0:3d9c67d97d6f 298
emh203 0:3d9c67d97d6f 299 /* matrix multiplication */
emh203 0:3d9c67d97d6f 300 while(colCnt > 0u)
emh203 0:3d9c67d97d6f 301 {
emh203 0:3d9c67d97d6f 302 /* c(m,n) = a(1,1)*b(1,1) + a(1,2) * b(2,1) + .... + a(m,p)*b(p,n) */
emh203 0:3d9c67d97d6f 303 #ifndef UNALIGNED_SUPPORT_DISABLE
emh203 0:3d9c67d97d6f 304
emh203 0:3d9c67d97d6f 305 /* read real and imag values from pSrcA and pSrcB buffer */
emh203 0:3d9c67d97d6f 306 pSourceA1 = *__SIMD32(pInA)++;
emh203 0:3d9c67d97d6f 307 pSourceB1 = *__SIMD32(pInB)++;
emh203 0:3d9c67d97d6f 308
emh203 0:3d9c67d97d6f 309 pSourceA2 = *__SIMD32(pInA)++;
emh203 0:3d9c67d97d6f 310 pSourceB2 = *__SIMD32(pInB)++;
emh203 0:3d9c67d97d6f 311
emh203 0:3d9c67d97d6f 312 /* Multiply and Accumlates */
emh203 0:3d9c67d97d6f 313 sum = __SMLALD(pSourceA1, pSourceB1, sum);
emh203 0:3d9c67d97d6f 314 sum = __SMLALD(pSourceA2, pSourceB2, sum);
emh203 0:3d9c67d97d6f 315
emh203 0:3d9c67d97d6f 316 #else
emh203 0:3d9c67d97d6f 317 /* read real and imag values from pSrcA and pSrcB buffer */
emh203 0:3d9c67d97d6f 318 inA1 = *pInA++;
emh203 0:3d9c67d97d6f 319 inB1 = *pInB++;
emh203 0:3d9c67d97d6f 320 inA2 = *pInA++;
emh203 0:3d9c67d97d6f 321 /* Multiply and Accumlates */
emh203 0:3d9c67d97d6f 322 sum += inA1 * inB1;
emh203 0:3d9c67d97d6f 323 inB2 = *pInB++;
emh203 0:3d9c67d97d6f 324
emh203 0:3d9c67d97d6f 325 inA1 = *pInA++;
emh203 0:3d9c67d97d6f 326 inB1 = *pInB++;
emh203 0:3d9c67d97d6f 327 /* Multiply and Accumlates */
emh203 0:3d9c67d97d6f 328 sum += inA2 * inB2;
emh203 0:3d9c67d97d6f 329 inA2 = *pInA++;
emh203 0:3d9c67d97d6f 330 inB2 = *pInB++;
emh203 0:3d9c67d97d6f 331
emh203 0:3d9c67d97d6f 332 /* Multiply and Accumlates */
emh203 0:3d9c67d97d6f 333 sum += inA1 * inB1;
emh203 0:3d9c67d97d6f 334 sum += inA2 * inB2;
emh203 0:3d9c67d97d6f 335
emh203 0:3d9c67d97d6f 336 #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */
emh203 0:3d9c67d97d6f 337
emh203 0:3d9c67d97d6f 338 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 339 colCnt--;
emh203 0:3d9c67d97d6f 340 }
emh203 0:3d9c67d97d6f 341
emh203 0:3d9c67d97d6f 342 /* process remaining column samples */
emh203 0:3d9c67d97d6f 343 colCnt = numColsA & 3u;
emh203 0:3d9c67d97d6f 344
emh203 0:3d9c67d97d6f 345 while(colCnt > 0u)
emh203 0:3d9c67d97d6f 346 {
emh203 0:3d9c67d97d6f 347 /* c(m,n) = a(1,1)*b(1,1) + a(1,2) * b(2,1) + .... + a(m,p)*b(p,n) */
emh203 0:3d9c67d97d6f 348 sum += *pInA++ * *pInB++;
emh203 0:3d9c67d97d6f 349
emh203 0:3d9c67d97d6f 350 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 351 colCnt--;
emh203 0:3d9c67d97d6f 352 }
emh203 0:3d9c67d97d6f 353
emh203 0:3d9c67d97d6f 354 /* Saturate and store the result in the destination buffer */
emh203 0:3d9c67d97d6f 355 *px = (q15_t) (__SSAT((sum >> 15), 16));
emh203 0:3d9c67d97d6f 356 px++;
emh203 0:3d9c67d97d6f 357
emh203 0:3d9c67d97d6f 358 /* Decrement the column loop counter */
emh203 0:3d9c67d97d6f 359 col--;
emh203 0:3d9c67d97d6f 360
emh203 0:3d9c67d97d6f 361 } while(col > 0u);
emh203 0:3d9c67d97d6f 362
emh203 0:3d9c67d97d6f 363 i = i + numColsA;
emh203 0:3d9c67d97d6f 364
emh203 0:3d9c67d97d6f 365 /* Decrement the row loop counter */
emh203 0:3d9c67d97d6f 366 row--;
emh203 0:3d9c67d97d6f 367
emh203 0:3d9c67d97d6f 368 } while(row > 0u);
emh203 0:3d9c67d97d6f 369
emh203 0:3d9c67d97d6f 370 #else
emh203 0:3d9c67d97d6f 371
emh203 0:3d9c67d97d6f 372 /* Run the below code for Cortex-M0 */
emh203 0:3d9c67d97d6f 373
emh203 0:3d9c67d97d6f 374 q15_t *pIn1 = pSrcA->pData; /* input data matrix pointer A */
emh203 0:3d9c67d97d6f 375 q15_t *pIn2 = pSrcB->pData; /* input data matrix pointer B */
emh203 0:3d9c67d97d6f 376 q15_t *pInA = pSrcA->pData; /* input data matrix pointer A of Q15 type */
emh203 0:3d9c67d97d6f 377 q15_t *pInB = pSrcB->pData; /* input data matrix pointer B of Q15 type */
emh203 0:3d9c67d97d6f 378 q15_t *pOut = pDst->pData; /* output data matrix pointer */
emh203 0:3d9c67d97d6f 379 q15_t *px; /* Temporary output data matrix pointer */
emh203 0:3d9c67d97d6f 380 uint16_t numColsB = pSrcB->numCols; /* number of columns of input matrix B */
emh203 0:3d9c67d97d6f 381 uint16_t numColsA = pSrcA->numCols; /* number of columns of input matrix A */
emh203 0:3d9c67d97d6f 382 uint16_t numRowsA = pSrcA->numRows; /* number of rows of input matrix A */
emh203 0:3d9c67d97d6f 383 uint16_t col, i = 0u, row = numRowsA, colCnt; /* loop counters */
emh203 0:3d9c67d97d6f 384 arm_status status; /* status of matrix multiplication */
emh203 0:3d9c67d97d6f 385
emh203 0:3d9c67d97d6f 386 #ifdef ARM_MATH_MATRIX_CHECK
emh203 0:3d9c67d97d6f 387
emh203 0:3d9c67d97d6f 388 /* Check for matrix mismatch condition */
emh203 0:3d9c67d97d6f 389 if((pSrcA->numCols != pSrcB->numRows) ||
emh203 0:3d9c67d97d6f 390 (pSrcA->numRows != pDst->numRows) || (pSrcB->numCols != pDst->numCols))
emh203 0:3d9c67d97d6f 391 {
emh203 0:3d9c67d97d6f 392 /* Set status as ARM_MATH_SIZE_MISMATCH */
emh203 0:3d9c67d97d6f 393 status = ARM_MATH_SIZE_MISMATCH;
emh203 0:3d9c67d97d6f 394 }
emh203 0:3d9c67d97d6f 395 else
emh203 0:3d9c67d97d6f 396 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
emh203 0:3d9c67d97d6f 397
emh203 0:3d9c67d97d6f 398 {
emh203 0:3d9c67d97d6f 399 /* The following loop performs the dot-product of each row in pSrcA with each column in pSrcB */
emh203 0:3d9c67d97d6f 400 /* row loop */
emh203 0:3d9c67d97d6f 401 do
emh203 0:3d9c67d97d6f 402 {
emh203 0:3d9c67d97d6f 403 /* Output pointer is set to starting address of the row being processed */
emh203 0:3d9c67d97d6f 404 px = pOut + i;
emh203 0:3d9c67d97d6f 405
emh203 0:3d9c67d97d6f 406 /* For every row wise process, the column loop counter is to be initiated */
emh203 0:3d9c67d97d6f 407 col = numColsB;
emh203 0:3d9c67d97d6f 408
emh203 0:3d9c67d97d6f 409 /* For every row wise process, the pIn2 pointer is set
emh203 0:3d9c67d97d6f 410 ** to the starting address of the pSrcB data */
emh203 0:3d9c67d97d6f 411 pIn2 = pSrcB->pData;
emh203 0:3d9c67d97d6f 412
emh203 0:3d9c67d97d6f 413 /* column loop */
emh203 0:3d9c67d97d6f 414 do
emh203 0:3d9c67d97d6f 415 {
emh203 0:3d9c67d97d6f 416 /* Set the variable sum, that acts as accumulator, to zero */
emh203 0:3d9c67d97d6f 417 sum = 0;
emh203 0:3d9c67d97d6f 418
emh203 0:3d9c67d97d6f 419 /* Initiate the pointer pIn1 to point to the starting address of pSrcA */
emh203 0:3d9c67d97d6f 420 pIn1 = pInA;
emh203 0:3d9c67d97d6f 421
emh203 0:3d9c67d97d6f 422 /* Matrix A columns number of MAC operations are to be performed */
emh203 0:3d9c67d97d6f 423 colCnt = numColsA;
emh203 0:3d9c67d97d6f 424
emh203 0:3d9c67d97d6f 425 /* matrix multiplication */
emh203 0:3d9c67d97d6f 426 while(colCnt > 0u)
emh203 0:3d9c67d97d6f 427 {
emh203 0:3d9c67d97d6f 428 /* c(m,n) = a(1,1)*b(1,1) + a(1,2) * b(2,1) + .... + a(m,p)*b(p,n) */
emh203 0:3d9c67d97d6f 429 /* Perform the multiply-accumulates */
emh203 0:3d9c67d97d6f 430 sum += (q31_t) * pIn1++ * *pIn2;
emh203 0:3d9c67d97d6f 431 pIn2 += numColsB;
emh203 0:3d9c67d97d6f 432
emh203 0:3d9c67d97d6f 433 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 434 colCnt--;
emh203 0:3d9c67d97d6f 435 }
emh203 0:3d9c67d97d6f 436
emh203 0:3d9c67d97d6f 437 /* Convert the result from 34.30 to 1.15 format and store the saturated value in destination buffer */
emh203 0:3d9c67d97d6f 438 /* Saturate and store the result in the destination buffer */
emh203 0:3d9c67d97d6f 439 *px++ = (q15_t) __SSAT((sum >> 15), 16);
emh203 0:3d9c67d97d6f 440
emh203 0:3d9c67d97d6f 441 /* Decrement the column loop counter */
emh203 0:3d9c67d97d6f 442 col--;
emh203 0:3d9c67d97d6f 443
emh203 0:3d9c67d97d6f 444 /* Update the pointer pIn2 to point to the starting address of the next column */
emh203 0:3d9c67d97d6f 445 pIn2 = pInB + (numColsB - col);
emh203 0:3d9c67d97d6f 446
emh203 0:3d9c67d97d6f 447 } while(col > 0u);
emh203 0:3d9c67d97d6f 448
emh203 0:3d9c67d97d6f 449 /* Update the pointer pSrcA to point to the starting address of the next row */
emh203 0:3d9c67d97d6f 450 i = i + numColsB;
emh203 0:3d9c67d97d6f 451 pInA = pInA + numColsA;
emh203 0:3d9c67d97d6f 452
emh203 0:3d9c67d97d6f 453 /* Decrement the row loop counter */
emh203 0:3d9c67d97d6f 454 row--;
emh203 0:3d9c67d97d6f 455
emh203 0:3d9c67d97d6f 456 } while(row > 0u);
emh203 0:3d9c67d97d6f 457
emh203 0:3d9c67d97d6f 458 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
emh203 0:3d9c67d97d6f 459 /* set status as ARM_MATH_SUCCESS */
emh203 0:3d9c67d97d6f 460 status = ARM_MATH_SUCCESS;
emh203 0:3d9c67d97d6f 461 }
emh203 0:3d9c67d97d6f 462
emh203 0:3d9c67d97d6f 463 /* Return to application */
emh203 0:3d9c67d97d6f 464 return (status);
emh203 0:3d9c67d97d6f 465 }
emh203 0:3d9c67d97d6f 466
emh203 0:3d9c67d97d6f 467 /**
emh203 0:3d9c67d97d6f 468 * @} end of MatrixMult group
emh203 0:3d9c67d97d6f 469 */