Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dsp by
arm_mat_add_f32.c
00001 /* ---------------------------------------------------------------------------- 00002 * Copyright (C) 2010-2013 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 17. January 2013 00005 * $Revision: V1.4.1 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/Cortex-M0 00013 * 00014 * Redistribution and use in source and binary forms, with or without 00015 * modification, are permitted provided that the following conditions 00016 * are met: 00017 * - Redistributions of source code must retain the above copyright 00018 * notice, this list of conditions and the following disclaimer. 00019 * - Redistributions in binary form must reproduce the above copyright 00020 * notice, this list of conditions and the following disclaimer in 00021 * the documentation and/or other materials provided with the 00022 * distribution. 00023 * - Neither the name of ARM LIMITED nor the names of its contributors 00024 * may be used to endorse or promote products derived from this 00025 * software without specific prior written permission. 00026 * 00027 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00028 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00029 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00030 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00031 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00032 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00033 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00034 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00035 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00036 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00037 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00038 * POSSIBILITY OF SUCH DAMAGE. 00039 * -------------------------------------------------------------------------- */ 00040 00041 #include "arm_math.h" 00042 00043 /** 00044 * @ingroup groupMatrix 00045 */ 00046 00047 /** 00048 * @defgroup MatrixAdd Matrix Addition 00049 * 00050 * Adds two matrices. 00051 * \image html MatrixAddition.gif "Addition of two 3 x 3 matrices" 00052 * 00053 * The functions check to make sure that 00054 * <code>pSrcA</code>, <code>pSrcB</code>, and <code>pDst</code> have the same 00055 * number of rows and columns. 00056 */ 00057 00058 /** 00059 * @addtogroup MatrixAdd 00060 * @{ 00061 */ 00062 00063 00064 /** 00065 * @brief Floating-point matrix addition. 00066 * @param[in] *pSrcA points to the first input matrix structure 00067 * @param[in] *pSrcB points to the second input matrix structure 00068 * @param[out] *pDst points to output matrix structure 00069 * @return The function returns either 00070 * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. 00071 */ 00072 00073 arm_status arm_mat_add_f32( 00074 const arm_matrix_instance_f32 * pSrcA, 00075 const arm_matrix_instance_f32 * pSrcB, 00076 arm_matrix_instance_f32 * pDst) 00077 { 00078 float32_t *pIn1 = pSrcA->pData; /* input data matrix pointer A */ 00079 float32_t *pIn2 = pSrcB->pData; /* input data matrix pointer B */ 00080 float32_t *pOut = pDst->pData; /* output data matrix pointer */ 00081 00082 #ifndef ARM_MATH_CM0_FAMILY 00083 00084 float32_t inA1, inA2, inB1, inB2, out1, out2; /* temporary variables */ 00085 00086 #endif // #ifndef ARM_MATH_CM0_FAMILY 00087 00088 uint32_t numSamples; /* total number of elements in the matrix */ 00089 uint32_t blkCnt; /* loop counters */ 00090 arm_status status; /* status of matrix addition */ 00091 00092 #ifdef ARM_MATH_MATRIX_CHECK 00093 /* Check for matrix mismatch condition */ 00094 if((pSrcA->numRows != pSrcB->numRows) || 00095 (pSrcA->numCols != pSrcB->numCols) || 00096 (pSrcA->numRows != pDst->numRows) || (pSrcA->numCols != pDst->numCols)) 00097 { 00098 /* Set status as ARM_MATH_SIZE_MISMATCH */ 00099 status = ARM_MATH_SIZE_MISMATCH; 00100 } 00101 else 00102 #endif 00103 { 00104 00105 /* Total number of samples in the input matrix */ 00106 numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols; 00107 00108 #ifndef ARM_MATH_CM0_FAMILY 00109 00110 /* Loop unrolling */ 00111 blkCnt = numSamples >> 2u; 00112 00113 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00114 ** a second loop below computes the remaining 1 to 3 samples. */ 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 /* Read values from source A */ 00120 inA1 = pIn1[0]; 00121 00122 /* Read values from source B */ 00123 inB1 = pIn2[0]; 00124 00125 /* Read values from source A */ 00126 inA2 = pIn1[1]; 00127 00128 /* out = sourceA + sourceB */ 00129 out1 = inA1 + inB1; 00130 00131 /* Read values from source B */ 00132 inB2 = pIn2[1]; 00133 00134 /* Read values from source A */ 00135 inA1 = pIn1[2]; 00136 00137 /* out = sourceA + sourceB */ 00138 out2 = inA2 + inB2; 00139 00140 /* Read values from source B */ 00141 inB1 = pIn2[2]; 00142 00143 /* Store result in destination */ 00144 pOut[0] = out1; 00145 pOut[1] = out2; 00146 00147 /* Read values from source A */ 00148 inA2 = pIn1[3]; 00149 00150 /* Read values from source B */ 00151 inB2 = pIn2[3]; 00152 00153 /* out = sourceA + sourceB */ 00154 out1 = inA1 + inB1; 00155 00156 /* out = sourceA + sourceB */ 00157 out2 = inA2 + inB2; 00158 00159 /* Store result in destination */ 00160 pOut[2] = out1; 00161 00162 /* Store result in destination */ 00163 pOut[3] = out2; 00164 00165 00166 /* update pointers to process next sampels */ 00167 pIn1 += 4u; 00168 pIn2 += 4u; 00169 pOut += 4u; 00170 /* Decrement the loop counter */ 00171 blkCnt--; 00172 } 00173 00174 /* If the numSamples is not a multiple of 4, compute any remaining output samples here. 00175 ** No loop unrolling is used. */ 00176 blkCnt = numSamples % 0x4u; 00177 00178 #else 00179 00180 /* Run the below code for Cortex-M0 */ 00181 00182 /* Initialize blkCnt with number of samples */ 00183 blkCnt = numSamples; 00184 00185 #endif /* #ifndef ARM_MATH_CM0_FAMILY */ 00186 00187 while(blkCnt > 0u) 00188 { 00189 /* C(m,n) = A(m,n) + B(m,n) */ 00190 /* Add and then store the results in the destination buffer. */ 00191 *pOut++ = (*pIn1++) + (*pIn2++); 00192 00193 /* Decrement the loop counter */ 00194 blkCnt--; 00195 } 00196 00197 /* set status as ARM_MATH_SUCCESS */ 00198 status = ARM_MATH_SUCCESS; 00199 00200 } 00201 00202 /* Return to application */ 00203 return (status); 00204 } 00205 00206 /** 00207 * @} end of MatrixAdd group 00208 */
Generated on Tue Jul 12 2022 18:44:09 by
1.7.2
