Simon Ford / dsp

Dependents:   K22F_DSP_Matrix_least_square BNO055-ELEC3810 1BNO055 ECE4180Project--Slave2 ... more

Committer:
simon
Date:
Thu Mar 10 15:07:50 2011 +0000
Revision:
0:1014af42efd9

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:1014af42efd9 1 /* ----------------------------------------------------------------------------
simon 0:1014af42efd9 2 * Copyright (C) 2010 ARM Limited. All rights reserved.
simon 0:1014af42efd9 3 *
simon 0:1014af42efd9 4 * $Date: 29. November 2010
simon 0:1014af42efd9 5 * $Revision: V1.0.3
simon 0:1014af42efd9 6 *
simon 0:1014af42efd9 7 * Project: CMSIS DSP Library
simon 0:1014af42efd9 8 * Title: arm_mat_add_f32.c
simon 0:1014af42efd9 9 *
simon 0:1014af42efd9 10 * Description: Floating-point matrix addition
simon 0:1014af42efd9 11 *
simon 0:1014af42efd9 12 * Target Processor: Cortex-M4/Cortex-M3
simon 0:1014af42efd9 13 *
simon 0:1014af42efd9 14 * Version 1.0.3 2010/11/29
simon 0:1014af42efd9 15 * Re-organized the CMSIS folders and updated documentation.
simon 0:1014af42efd9 16 *
simon 0:1014af42efd9 17 * Version 1.0.2 2010/11/11
simon 0:1014af42efd9 18 * Documentation updated.
simon 0:1014af42efd9 19 *
simon 0:1014af42efd9 20 * Version 1.0.1 2010/10/05
simon 0:1014af42efd9 21 * Production release and review comments incorporated.
simon 0:1014af42efd9 22 *
simon 0:1014af42efd9 23 * Version 1.0.0 2010/09/20
simon 0:1014af42efd9 24 * Production release and review comments incorporated.
simon 0:1014af42efd9 25 *
simon 0:1014af42efd9 26 * Version 0.0.5 2010/04/26
simon 0:1014af42efd9 27 * incorporated review comments and updated with latest CMSIS layer
simon 0:1014af42efd9 28 *
simon 0:1014af42efd9 29 * Version 0.0.3 2010/03/10
simon 0:1014af42efd9 30 * Initial version
simon 0:1014af42efd9 31 * -------------------------------------------------------------------------- */
simon 0:1014af42efd9 32
simon 0:1014af42efd9 33 #include "arm_math.h"
simon 0:1014af42efd9 34
simon 0:1014af42efd9 35 /**
simon 0:1014af42efd9 36 * @ingroup groupMatrix
simon 0:1014af42efd9 37 */
simon 0:1014af42efd9 38
simon 0:1014af42efd9 39 /**
simon 0:1014af42efd9 40 * @defgroup MatrixAdd Matrix Addition
simon 0:1014af42efd9 41 *
simon 0:1014af42efd9 42 * Adds two matrices.
simon 0:1014af42efd9 43 * \image html MatrixAddition.gif "Addition of two 3 x 3 matrices"
simon 0:1014af42efd9 44 *
simon 0:1014af42efd9 45 * The functions check to make sure that
simon 0:1014af42efd9 46 * <code>pSrcA</code>, <code>pSrcB</code>, and <code>pDst</code> have the same
simon 0:1014af42efd9 47 * number of rows and columns.
simon 0:1014af42efd9 48 */
simon 0:1014af42efd9 49
simon 0:1014af42efd9 50 /**
simon 0:1014af42efd9 51 * @addtogroup MatrixAdd
simon 0:1014af42efd9 52 * @{
simon 0:1014af42efd9 53 */
simon 0:1014af42efd9 54
simon 0:1014af42efd9 55
simon 0:1014af42efd9 56 /**
simon 0:1014af42efd9 57 * @brief Floating-point matrix addition.
simon 0:1014af42efd9 58 * @param[in] *pSrcA points to the first input matrix structure
simon 0:1014af42efd9 59 * @param[in] *pSrcB points to the second input matrix structure
simon 0:1014af42efd9 60 * @param[out] *pDst points to output matrix structure
simon 0:1014af42efd9 61 * @return The function returns either
simon 0:1014af42efd9 62 * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
simon 0:1014af42efd9 63 */
simon 0:1014af42efd9 64
simon 0:1014af42efd9 65 arm_status arm_mat_add_f32(
simon 0:1014af42efd9 66 const arm_matrix_instance_f32 * pSrcA,
simon 0:1014af42efd9 67 const arm_matrix_instance_f32 * pSrcB,
simon 0:1014af42efd9 68 arm_matrix_instance_f32 * pDst)
simon 0:1014af42efd9 69 {
simon 0:1014af42efd9 70 float32_t *pIn1 = pSrcA->pData; /* input data matrix pointer A */
simon 0:1014af42efd9 71 float32_t *pIn2 = pSrcB->pData; /* input data matrix pointer B */
simon 0:1014af42efd9 72 float32_t *pOut = pDst->pData; /* output data matrix pointer */
simon 0:1014af42efd9 73 uint32_t numSamples; /* total number of elements in the matrix */
simon 0:1014af42efd9 74 uint32_t blkCnt; /* loop counters */
simon 0:1014af42efd9 75 arm_status status; /* status of matrix addition */
simon 0:1014af42efd9 76
simon 0:1014af42efd9 77 #ifdef ARM_MATH_MATRIX_CHECK
simon 0:1014af42efd9 78 /* Check for matrix mismatch condition */
simon 0:1014af42efd9 79 if((pSrcA->numRows != pSrcB->numRows) ||
simon 0:1014af42efd9 80 (pSrcA->numCols != pSrcB->numCols) ||
simon 0:1014af42efd9 81 (pSrcA->numRows != pDst->numRows) || (pSrcA->numCols != pDst->numCols))
simon 0:1014af42efd9 82 {
simon 0:1014af42efd9 83 /* Set status as ARM_MATH_SIZE_MISMATCH */
simon 0:1014af42efd9 84 status = ARM_MATH_SIZE_MISMATCH;
simon 0:1014af42efd9 85 }
simon 0:1014af42efd9 86 else
simon 0:1014af42efd9 87 #endif
simon 0:1014af42efd9 88 {
simon 0:1014af42efd9 89
simon 0:1014af42efd9 90 /* Total number of samples in the input matrix */
simon 0:1014af42efd9 91 numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols;
simon 0:1014af42efd9 92
simon 0:1014af42efd9 93 /* Loop unrolling */
simon 0:1014af42efd9 94 blkCnt = numSamples >> 2u;
simon 0:1014af42efd9 95
simon 0:1014af42efd9 96 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
simon 0:1014af42efd9 97 ** a second loop below computes the remaining 1 to 3 samples. */
simon 0:1014af42efd9 98 while(blkCnt > 0u)
simon 0:1014af42efd9 99 {
simon 0:1014af42efd9 100 /* C(m,n) = A(m,n) + B(m,n) */
simon 0:1014af42efd9 101 /* Add and then store the results in the destination buffer. */
simon 0:1014af42efd9 102 *pOut++ = (*pIn1++) + (*pIn2++);
simon 0:1014af42efd9 103 *pOut++ = (*pIn1++) + (*pIn2++);
simon 0:1014af42efd9 104 *pOut++ = (*pIn1++) + (*pIn2++);
simon 0:1014af42efd9 105 *pOut++ = (*pIn1++) + (*pIn2++);
simon 0:1014af42efd9 106
simon 0:1014af42efd9 107 /* Decrement the loop counter */
simon 0:1014af42efd9 108 blkCnt--;
simon 0:1014af42efd9 109 }
simon 0:1014af42efd9 110
simon 0:1014af42efd9 111 /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
simon 0:1014af42efd9 112 ** No loop unrolling is used. */
simon 0:1014af42efd9 113 blkCnt = numSamples % 0x4u;
simon 0:1014af42efd9 114
simon 0:1014af42efd9 115 while(blkCnt > 0u)
simon 0:1014af42efd9 116 {
simon 0:1014af42efd9 117 /* C(m,n) = A(m,n) + B(m,n) */
simon 0:1014af42efd9 118 /* Add and then store the results in the destination buffer. */
simon 0:1014af42efd9 119 *pOut++ = (*pIn1++) + (*pIn2++);
simon 0:1014af42efd9 120
simon 0:1014af42efd9 121 /* Decrement the loop counter */
simon 0:1014af42efd9 122 blkCnt--;
simon 0:1014af42efd9 123 }
simon 0:1014af42efd9 124
simon 0:1014af42efd9 125 /* set status as ARM_MATH_SUCCESS */
simon 0:1014af42efd9 126 status = ARM_MATH_SUCCESS;
simon 0:1014af42efd9 127
simon 0:1014af42efd9 128 }
simon 0:1014af42efd9 129
simon 0:1014af42efd9 130 /* Return to application */
simon 0:1014af42efd9 131 return (status);
simon 0:1014af42efd9 132 }
simon 0:1014af42efd9 133
simon 0:1014af42efd9 134 /**
simon 0:1014af42efd9 135 * @} end of MatrixAdd group
simon 0:1014af42efd9 136 */