Aded CMSIS5 DSP and NN folder. Needs some work
Embed:
(wiki syntax)
Show/hide line numbers
arm_mat_sub_q31.c
00001 /* ---------------------------------------------------------------------- 00002 * Project: CMSIS DSP Library 00003 * Title: arm_mat_sub_q31.c 00004 * Description: Q31 matrix subtraction 00005 * 00006 * $Date: 27. January 2017 00007 * $Revision: V.1.5.1 00008 * 00009 * Target Processor: Cortex-M cores 00010 * -------------------------------------------------------------------- */ 00011 /* 00012 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 00013 * 00014 * SPDX-License-Identifier: Apache-2.0 00015 * 00016 * Licensed under the Apache License, Version 2.0 (the License); you may 00017 * not use this file except in compliance with the License. 00018 * You may obtain a copy of the License at 00019 * 00020 * www.apache.org/licenses/LICENSE-2.0 00021 * 00022 * Unless required by applicable law or agreed to in writing, software 00023 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00024 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00025 * See the License for the specific language governing permissions and 00026 * limitations under the License. 00027 */ 00028 00029 #include "arm_math.h" 00030 00031 /** 00032 * @ingroup groupMatrix 00033 */ 00034 00035 /** 00036 * @addtogroup MatrixSub 00037 * @{ 00038 */ 00039 00040 /** 00041 * @brief Q31 matrix subtraction. 00042 * @param[in] *pSrcA points to the first input matrix structure 00043 * @param[in] *pSrcB points to the second input matrix structure 00044 * @param[out] *pDst points to output matrix structure 00045 * @return The function returns either 00046 * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. 00047 * 00048 * <b>Scaling and Overflow Behavior:</b> 00049 * \par 00050 * The function uses saturating arithmetic. 00051 * Results outside of the allowable Q31 range [0x80000000 0x7FFFFFFF] will be saturated. 00052 */ 00053 00054 00055 arm_status arm_mat_sub_q31( 00056 const arm_matrix_instance_q31 * pSrcA, 00057 const arm_matrix_instance_q31 * pSrcB, 00058 arm_matrix_instance_q31 * pDst) 00059 { 00060 q31_t *pIn1 = pSrcA->pData; /* input data matrix pointer A */ 00061 q31_t *pIn2 = pSrcB->pData; /* input data matrix pointer B */ 00062 q31_t *pOut = pDst->pData; /* output data matrix pointer */ 00063 q31_t inA1, inB1; /* temporary variables */ 00064 00065 #if defined (ARM_MATH_DSP) 00066 00067 q31_t inA2, inB2; /* temporary variables */ 00068 q31_t out1, out2; /* temporary variables */ 00069 00070 #endif // #if defined (ARM_MATH_DSP) 00071 00072 uint32_t numSamples; /* total number of elements in the matrix */ 00073 uint32_t blkCnt; /* loop counters */ 00074 arm_status status; /* status of matrix subtraction */ 00075 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 /* Total number of samples in the input matrix */ 00090 numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols; 00091 00092 #if defined (ARM_MATH_DSP) 00093 00094 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00095 00096 /* Loop Unrolling */ 00097 blkCnt = numSamples >> 2U; 00098 00099 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00100 ** a second loop below computes the remaining 1 to 3 samples. */ 00101 while (blkCnt > 0U) 00102 { 00103 /* C(m,n) = A(m,n) - B(m,n) */ 00104 /* Subtract, saturate and then store the results in the destination buffer. */ 00105 /* Read values from source A */ 00106 inA1 = pIn1[0]; 00107 00108 /* Read values from source B */ 00109 inB1 = pIn2[0]; 00110 00111 /* Read values from source A */ 00112 inA2 = pIn1[1]; 00113 00114 /* Subtract and saturate */ 00115 out1 = __QSUB(inA1, inB1); 00116 00117 /* Read values from source B */ 00118 inB2 = pIn2[1]; 00119 00120 /* Read values from source A */ 00121 inA1 = pIn1[2]; 00122 00123 /* Subtract and saturate */ 00124 out2 = __QSUB(inA2, inB2); 00125 00126 /* Read values from source B */ 00127 inB1 = pIn2[2]; 00128 00129 /* Store result in destination */ 00130 pOut[0] = out1; 00131 pOut[1] = out2; 00132 00133 /* Read values from source A */ 00134 inA2 = pIn1[3]; 00135 00136 /* Read values from source B */ 00137 inB2 = pIn2[3]; 00138 00139 /* Subtract and saturate */ 00140 out1 = __QSUB(inA1, inB1); 00141 00142 /* Subtract and saturate */ 00143 out2 = __QSUB(inA2, inB2); 00144 00145 /* Store result in destination */ 00146 pOut[2] = out1; 00147 pOut[3] = out2; 00148 00149 /* update pointers to process next samples */ 00150 pIn1 += 4U; 00151 pIn2 += 4U; 00152 pOut += 4U; 00153 00154 /* Decrement the loop counter */ 00155 blkCnt--; 00156 } 00157 00158 /* If the numSamples is not a multiple of 4, compute any remaining output samples here. 00159 ** No loop unrolling is used. */ 00160 blkCnt = numSamples % 0x4U; 00161 00162 #else 00163 00164 /* Run the below code for Cortex-M0 */ 00165 00166 /* Initialize blkCnt with number of samples */ 00167 blkCnt = numSamples; 00168 00169 #endif /* #if defined (ARM_MATH_DSP) */ 00170 00171 while (blkCnt > 0U) 00172 { 00173 /* C(m,n) = A(m,n) - B(m,n) */ 00174 /* Subtract, saturate and then store the results in the destination buffer. */ 00175 inA1 = *pIn1++; 00176 inB1 = *pIn2++; 00177 00178 inA1 = __QSUB(inA1, inB1); 00179 00180 *pOut++ = inA1; 00181 00182 /* Decrement the loop counter */ 00183 blkCnt--; 00184 } 00185 00186 /* Set status as ARM_MATH_SUCCESS */ 00187 status = ARM_MATH_SUCCESS; 00188 } 00189 00190 /* Return to application */ 00191 return (status); 00192 } 00193 00194 /** 00195 * @} end of MatrixSub group 00196 */ 00197
Generated on Tue Jul 12 2022 16:47:27 by 1.7.2