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-os by
arm_mat_add_q31.c
00001 /* ---------------------------------------------------------------------- 00002 * Copyright (C) 2010-2014 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 19. March 2015 00005 * $Revision: V.1.4.5 00006 * 00007 * Project: CMSIS DSP Library 00008 * Title: arm_mat_add_q31.c 00009 * 00010 * Description: Q31 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 * @addtogroup MatrixAdd 00049 * @{ 00050 */ 00051 00052 /** 00053 * @brief Q31 matrix addition. 00054 * @param[in] *pSrcA points to the first input matrix structure 00055 * @param[in] *pSrcB points to the second input matrix structure 00056 * @param[out] *pDst points to output matrix structure 00057 * @return The function returns either 00058 * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. 00059 * 00060 * <b>Scaling and Overflow Behavior:</b> 00061 * \par 00062 * The function uses saturating arithmetic. 00063 * Results outside of the allowable Q31 range [0x80000000 0x7FFFFFFF] will be saturated. 00064 */ 00065 00066 arm_status arm_mat_add_q31( 00067 const arm_matrix_instance_q31 * pSrcA, 00068 const arm_matrix_instance_q31 * pSrcB, 00069 arm_matrix_instance_q31 * pDst) 00070 { 00071 q31_t *pIn1 = pSrcA->pData; /* input data matrix pointer A */ 00072 q31_t *pIn2 = pSrcB->pData; /* input data matrix pointer B */ 00073 q31_t *pOut = pDst->pData; /* output data matrix pointer */ 00074 q31_t inA1, inB1; /* temporary variables */ 00075 00076 #ifndef ARM_MATH_CM0_FAMILY 00077 00078 q31_t inA2, inB2; /* temporary variables */ 00079 q31_t out1, out2; /* temporary variables */ 00080 00081 #endif // #ifndef ARM_MATH_CM0_FAMILY 00082 00083 uint32_t numSamples; /* total number of elements in the matrix */ 00084 uint32_t blkCnt; /* loop counters */ 00085 arm_status status; /* status of matrix addition */ 00086 00087 #ifdef ARM_MATH_MATRIX_CHECK 00088 /* Check for matrix mismatch condition */ 00089 if((pSrcA->numRows != pSrcB->numRows) || 00090 (pSrcA->numCols != pSrcB->numCols) || 00091 (pSrcA->numRows != pDst->numRows) || (pSrcA->numCols != pDst->numCols)) 00092 { 00093 /* Set status as ARM_MATH_SIZE_MISMATCH */ 00094 status = ARM_MATH_SIZE_MISMATCH; 00095 } 00096 else 00097 #endif 00098 { 00099 /* Total number of samples in the input matrix */ 00100 numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols; 00101 00102 #ifndef ARM_MATH_CM0_FAMILY 00103 00104 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00105 00106 /* Loop Unrolling */ 00107 blkCnt = numSamples >> 2u; 00108 00109 00110 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00111 ** a second loop below computes the remaining 1 to 3 samples. */ 00112 while(blkCnt > 0u) 00113 { 00114 /* C(m,n) = A(m,n) + B(m,n) */ 00115 /* Add, saturate and then store the results in the destination buffer. */ 00116 /* Read values from source A */ 00117 inA1 = pIn1[0]; 00118 00119 /* Read values from source B */ 00120 inB1 = pIn2[0]; 00121 00122 /* Read values from source A */ 00123 inA2 = pIn1[1]; 00124 00125 /* Add and saturate */ 00126 out1 = __QADD(inA1, inB1); 00127 00128 /* Read values from source B */ 00129 inB2 = pIn2[1]; 00130 00131 /* Read values from source A */ 00132 inA1 = pIn1[2]; 00133 00134 /* Add and saturate */ 00135 out2 = __QADD(inA2, inB2); 00136 00137 /* Read values from source B */ 00138 inB1 = pIn2[2]; 00139 00140 /* Store result in destination */ 00141 pOut[0] = out1; 00142 pOut[1] = out2; 00143 00144 /* Read values from source A */ 00145 inA2 = pIn1[3]; 00146 00147 /* Read values from source B */ 00148 inB2 = pIn2[3]; 00149 00150 /* Add and saturate */ 00151 out1 = __QADD(inA1, inB1); 00152 out2 = __QADD(inA2, inB2); 00153 00154 /* Store result in destination */ 00155 pOut[2] = out1; 00156 pOut[3] = out2; 00157 00158 /* update pointers to process next sampels */ 00159 pIn1 += 4u; 00160 pIn2 += 4u; 00161 pOut += 4u; 00162 00163 /* Decrement the loop counter */ 00164 blkCnt--; 00165 } 00166 00167 /* If the numSamples is not a multiple of 4, compute any remaining output samples here. 00168 ** No loop unrolling is used. */ 00169 blkCnt = numSamples % 0x4u; 00170 00171 #else 00172 00173 /* Run the below code for Cortex-M0 */ 00174 00175 /* Initialize blkCnt with number of samples */ 00176 blkCnt = numSamples; 00177 00178 00179 #endif /* #ifndef ARM_MATH_CM0_FAMILY */ 00180 00181 while(blkCnt > 0u) 00182 { 00183 /* C(m,n) = A(m,n) + B(m,n) */ 00184 /* Add, saturate and then store the results in the destination buffer. */ 00185 inA1 = *pIn1++; 00186 inB1 = *pIn2++; 00187 00188 inA1 = __QADD(inA1, inB1); 00189 00190 /* Decrement the loop counter */ 00191 blkCnt--; 00192 00193 *pOut++ = inA1; 00194 00195 } 00196 00197 /* set status as ARM_MATH_SUCCESS */ 00198 status = ARM_MATH_SUCCESS; 00199 } 00200 00201 /* Return to application */ 00202 return (status); 00203 } 00204 00205 /** 00206 * @} end of MatrixAdd group 00207 */
Generated on Tue Jul 12 2022 13:15:25 by
