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_sub_q31.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_sub_q31.c 00009 * 00010 * Description: Q31 matrix subtraction 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 MatrixSub 00049 * @{ 00050 */ 00051 00052 /** 00053 * @brief Q31 matrix subtraction. 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 00067 arm_status arm_mat_sub_q31( 00068 const arm_matrix_instance_q31 * pSrcA, 00069 const arm_matrix_instance_q31 * pSrcB, 00070 arm_matrix_instance_q31 * pDst) 00071 { 00072 q31_t *pIn1 = pSrcA->pData; /* input data matrix pointer A */ 00073 q31_t *pIn2 = pSrcB->pData; /* input data matrix pointer B */ 00074 q31_t *pOut = pDst->pData; /* output data matrix pointer */ 00075 q31_t inA1, inB1; /* temporary variables */ 00076 00077 #ifndef ARM_MATH_CM0_FAMILY 00078 00079 q31_t inA2, inB2; /* temporary variables */ 00080 q31_t out1, out2; /* temporary variables */ 00081 00082 #endif // #ifndef ARM_MATH_CM0_FAMILY 00083 00084 uint32_t numSamples; /* total number of elements in the matrix */ 00085 uint32_t blkCnt; /* loop counters */ 00086 arm_status status; /* status of matrix subtraction */ 00087 00088 00089 #ifdef ARM_MATH_MATRIX_CHECK 00090 /* Check for matrix mismatch condition */ 00091 if((pSrcA->numRows != pSrcB->numRows) || 00092 (pSrcA->numCols != pSrcB->numCols) || 00093 (pSrcA->numRows != pDst->numRows) || (pSrcA->numCols != pDst->numCols)) 00094 { 00095 /* Set status as ARM_MATH_SIZE_MISMATCH */ 00096 status = ARM_MATH_SIZE_MISMATCH; 00097 } 00098 else 00099 #endif 00100 { 00101 /* Total number of samples in the input matrix */ 00102 numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols; 00103 00104 #ifndef ARM_MATH_CM0_FAMILY 00105 00106 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00107 00108 /* Loop Unrolling */ 00109 blkCnt = numSamples >> 2u; 00110 00111 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00112 ** a second loop below computes the remaining 1 to 3 samples. */ 00113 while(blkCnt > 0u) 00114 { 00115 /* C(m,n) = A(m,n) - B(m,n) */ 00116 /* Subtract, saturate and then store the results in the destination buffer. */ 00117 /* Read values from source A */ 00118 inA1 = pIn1[0]; 00119 00120 /* Read values from source B */ 00121 inB1 = pIn2[0]; 00122 00123 /* Read values from source A */ 00124 inA2 = pIn1[1]; 00125 00126 /* Subtract and saturate */ 00127 out1 = __QSUB(inA1, inB1); 00128 00129 /* Read values from source B */ 00130 inB2 = pIn2[1]; 00131 00132 /* Read values from source A */ 00133 inA1 = pIn1[2]; 00134 00135 /* Subtract and saturate */ 00136 out2 = __QSUB(inA2, inB2); 00137 00138 /* Read values from source B */ 00139 inB1 = pIn2[2]; 00140 00141 /* Store result in destination */ 00142 pOut[0] = out1; 00143 pOut[1] = out2; 00144 00145 /* Read values from source A */ 00146 inA2 = pIn1[3]; 00147 00148 /* Read values from source B */ 00149 inB2 = pIn2[3]; 00150 00151 /* Subtract and saturate */ 00152 out1 = __QSUB(inA1, inB1); 00153 00154 /* Subtract and saturate */ 00155 out2 = __QSUB(inA2, inB2); 00156 00157 /* Store result in destination */ 00158 pOut[2] = out1; 00159 pOut[3] = out2; 00160 00161 /* update pointers to process next samples */ 00162 pIn1 += 4u; 00163 pIn2 += 4u; 00164 pOut += 4u; 00165 00166 /* Decrement the loop counter */ 00167 blkCnt--; 00168 } 00169 00170 /* If the numSamples is not a multiple of 4, compute any remaining output samples here. 00171 ** No loop unrolling is used. */ 00172 blkCnt = numSamples % 0x4u; 00173 00174 #else 00175 00176 /* Run the below code for Cortex-M0 */ 00177 00178 /* Initialize blkCnt with number of samples */ 00179 blkCnt = numSamples; 00180 00181 #endif /* #ifndef ARM_MATH_CM0_FAMILY */ 00182 00183 while(blkCnt > 0u) 00184 { 00185 /* C(m,n) = A(m,n) - B(m,n) */ 00186 /* Subtract, saturate and then store the results in the destination buffer. */ 00187 inA1 = *pIn1++; 00188 inB1 = *pIn2++; 00189 00190 inA1 = __QSUB(inA1, inB1); 00191 00192 *pOut++ = inA1; 00193 00194 /* Decrement the loop counter */ 00195 blkCnt--; 00196 } 00197 00198 /* Set status as ARM_MATH_SUCCESS */ 00199 status = ARM_MATH_SUCCESS; 00200 } 00201 00202 /* Return to application */ 00203 return (status); 00204 } 00205 00206 /** 00207 * @} end of MatrixSub group 00208 */
Generated on Tue Jul 12 2022 18:44:09 by
1.7.2
