1 /* ----------------------------------------------------------------------------
2 * Copyright (C) 2010 ARM Limited. All rights reserved.
7 * Project: CMSIS DSP Library
8 * Title: arm_mat_add_f32.c
10 * Description: Floating-point matrix addition
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
14 * Version 1.0.10 2011/7/15
15 * Big Endian support added and Merged M0 and M3/M4 Source code.
17 * Version 1.0.3 2010/11/29
18 * Re-organized the CMSIS folders and updated documentation.
20 * Version 1.0.2 2010/11/11
21 * Documentation updated.
23 * Version 1.0.1 2010/10/05
24 * Production release and review comments incorporated.
26 * Version 1.0.0 2010/09/20
27 * Production release and review comments incorporated.
29 * Version 0.0.5 2010/04/26
30 * incorporated review comments and updated with latest CMSIS layer
32 * Version 0.0.3 2010/03/10
34 * -------------------------------------------------------------------------- */
39 * @ingroup groupMatrix
43 * @defgroup MatrixAdd Matrix Addition
46 * \image html MatrixAddition.gif "Addition of two 3 x 3 matrices"
48 * The functions check to make sure that
49 * <code>pSrcA</code>, <code>pSrcB</code>, and <code>pDst</code> have the same
50 * number of rows and columns.
54 * @addtogroup MatrixAdd
60 * @brief Floating-point matrix addition.
61 * @param[in] *pSrcA points to the first input matrix structure
62 * @param[in] *pSrcB points to the second input matrix structure
63 * @param[out] *pDst points to output matrix structure
64 * @return The function returns either
65 * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
68 arm_status arm_mat_add_f32(
69 const arm_matrix_instance_f32 * pSrcA,
70 const arm_matrix_instance_f32 * pSrcB,
71 arm_matrix_instance_f32 * pDst)
73 float32_t *pIn1 = pSrcA->pData; /* input data matrix pointer A */
74 float32_t *pIn2 = pSrcB->pData; /* input data matrix pointer B */
75 float32_t *pOut = pDst->pData; /* output data matrix pointer */
76 uint32_t numSamples; /* total number of elements in the matrix */
77 uint32_t blkCnt; /* loop counters */
78 arm_status status; /* status of matrix addition */
80 #ifdef ARM_MATH_MATRIX_CHECK
83 /* Check for matrix mismatch condition */
84 if((pSrcA->numRows != pSrcB->numRows) ||
85 (pSrcA->numCols != pSrcB->numCols) ||
86 (pSrcA->numRows != pDst->numRows) || (pSrcA->numCols != pDst->numCols))
88 /* Set status as ARM_MATH_SIZE_MISMATCH */
89 status = ARM_MATH_SIZE_MISMATCH;
92 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
96 /* Total number of samples in the input matrix */
97 numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols;
101 /* Run the below code for Cortex-M4 and Cortex-M3 */
104 blkCnt = numSamples >> 2u;
106 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
107 ** a second loop below computes the remaining 1 to 3 samples. */
110 /* C(m,n) = A(m,n) + B(m,n) */
111 /* Add and then store the results in the destination buffer. */
112 *pOut++ = (*pIn1++) + (*pIn2++);
113 *pOut++ = (*pIn1++) + (*pIn2++);
114 *pOut++ = (*pIn1++) + (*pIn2++);
115 *pOut++ = (*pIn1++) + (*pIn2++);
117 /* Decrement the loop counter */
121 /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
122 ** No loop unrolling is used. */
123 blkCnt = numSamples % 0x4u;
127 /* Run the below code for Cortex-M0 */
129 /* Initialize blkCnt with number of samples */
132 #endif /* #ifndef ARM_MATH_CM0 */
136 /* C(m,n) = A(m,n) + B(m,n) */
137 /* Add and then store the results in the destination buffer. */
138 *pOut++ = (*pIn1++) + (*pIn2++);
140 /* Decrement the loop counter */
143 /* set status as ARM_MATH_SUCCESS */
144 status = ARM_MATH_SUCCESS;
148 /* Return to application */
153 * @} end of MatrixAdd group