CMSIS DSP Library from CMSIS 2.0. See http://www.onarm.com/cmsis/ for full details

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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_mat_add_f32.c Source File

arm_mat_add_f32.c

00001 /* ----------------------------------------------------------------------------  
00002 * Copyright (C) 2010 ARM Limited. All rights reserved.  
00003 *  
00004 * $Date:        29. November 2010  
00005 * $Revision:    V1.0.3  
00006 *  
00007 * Project:      CMSIS DSP Library  
00008 * Title:        arm_mat_add_f32.c  
00009 *  
00010 * Description:  Floating-point matrix addition  
00011 *  
00012 * Target Processor: Cortex-M4/Cortex-M3
00013 *  
00014 * Version 1.0.3 2010/11/29 
00015 *    Re-organized the CMSIS folders and updated documentation.  
00016 *   
00017 * Version 1.0.2 2010/11/11  
00018 *    Documentation updated.   
00019 *  
00020 * Version 1.0.1 2010/10/05   
00021 *    Production release and review comments incorporated.  
00022 *  
00023 * Version 1.0.0 2010/09/20   
00024 *    Production release and review comments incorporated.  
00025 *  
00026 * Version 0.0.5  2010/04/26   
00027 *    incorporated review comments and updated with latest CMSIS layer  
00028 *  
00029 * Version 0.0.3  2010/03/10   
00030 *    Initial version  
00031 * -------------------------------------------------------------------------- */ 
00032  
00033 #include "arm_math.h" 
00034  
00035 /**  
00036  * @ingroup groupMatrix  
00037  */ 
00038  
00039 /**  
00040  * @defgroup MatrixAdd Matrix Addition  
00041  *  
00042  * Adds two matrices.  
00043  * \image html MatrixAddition.gif "Addition of two 3 x 3 matrices"  
00044  *  
00045  * The functions check to make sure that  
00046  * <code>pSrcA</code>, <code>pSrcB</code>, and <code>pDst</code> have the same  
00047  * number of rows and columns.  
00048  */ 
00049  
00050 /**  
00051  * @addtogroup MatrixAdd  
00052  * @{  
00053  */ 
00054  
00055  
00056 /**  
00057  * @brief Floating-point matrix addition.  
00058  * @param[in]       *pSrcA points to the first input matrix structure  
00059  * @param[in]       *pSrcB points to the second input matrix structure  
00060  * @param[out]      *pDst points to output matrix structure  
00061  * @return          The function returns either  
00062  * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.  
00063  */ 
00064  
00065 arm_status arm_mat_add_f32( 
00066   const arm_matrix_instance_f32 * pSrcA, 
00067   const arm_matrix_instance_f32 * pSrcB, 
00068   arm_matrix_instance_f32 * pDst) 
00069 { 
00070   float32_t *pIn1 = pSrcA->pData;                /* input data matrix pointer A  */ 
00071   float32_t *pIn2 = pSrcB->pData;                /* input data matrix pointer B  */ 
00072   float32_t *pOut = pDst->pData;                 /* output data matrix pointer   */ 
00073   uint32_t numSamples;                           /* total number of elements in the matrix  */ 
00074   uint32_t blkCnt;                               /* loop counters */ 
00075   arm_status status;                             /* status of matrix addition */ 
00076  
00077 #ifdef ARM_MATH_MATRIX_CHECK 
00078   /* Check for matrix mismatch condition */ 
00079   if((pSrcA->numRows != pSrcB->numRows) || 
00080      (pSrcA->numCols != pSrcB->numCols) || 
00081      (pSrcA->numRows != pDst->numRows) || (pSrcA->numCols != pDst->numCols)) 
00082   { 
00083     /* Set status as ARM_MATH_SIZE_MISMATCH */ 
00084     status = ARM_MATH_SIZE_MISMATCH; 
00085   } 
00086   else 
00087 #endif 
00088   { 
00089  
00090     /* Total number of samples in the input matrix */ 
00091     numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols; 
00092  
00093     /* Loop unrolling */ 
00094     blkCnt = numSamples >> 2u; 
00095  
00096     /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.  
00097      ** a second loop below computes the remaining 1 to 3 samples. */ 
00098     while(blkCnt > 0u) 
00099     { 
00100       /* C(m,n) = A(m,n) + B(m,n) */ 
00101       /* Add and then store the results in the destination buffer. */ 
00102       *pOut++ = (*pIn1++) + (*pIn2++); 
00103       *pOut++ = (*pIn1++) + (*pIn2++); 
00104       *pOut++ = (*pIn1++) + (*pIn2++); 
00105       *pOut++ = (*pIn1++) + (*pIn2++); 
00106  
00107       /* Decrement the loop counter */ 
00108       blkCnt--; 
00109     } 
00110  
00111     /* If the numSamples is not a multiple of 4, compute any remaining output samples here.  
00112      ** No loop unrolling is used. */ 
00113     blkCnt = numSamples % 0x4u; 
00114  
00115     while(blkCnt > 0u) 
00116     { 
00117       /* C(m,n) = A(m,n) + B(m,n) */ 
00118       /* Add and then store the results in the destination buffer. */ 
00119       *pOut++ = (*pIn1++) + (*pIn2++); 
00120  
00121       /* Decrement the loop counter */ 
00122       blkCnt--; 
00123     } 
00124  
00125     /* set status as ARM_MATH_SUCCESS */ 
00126     status = ARM_MATH_SUCCESS; 
00127  
00128   } 
00129  
00130   /* Return to application */ 
00131   return (status); 
00132 } 
00133  
00134 /**  
00135  * @} end of MatrixAdd group  
00136  */