Aded CMSIS5 DSP and NN folder. Needs some work
Embed:
(wiki syntax)
Show/hide line numbers
arm_abs_q7.c
00001 /* ---------------------------------------------------------------------- 00002 * Project: CMSIS DSP Library 00003 * Title: arm_abs_q7.c 00004 * Description: Q7 vector absolute value 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 groupMath 00033 */ 00034 00035 /** 00036 * @addtogroup BasicAbs 00037 * @{ 00038 */ 00039 00040 /** 00041 * @brief Q7 vector absolute value. 00042 * @param[in] *pSrc points to the input buffer 00043 * @param[out] *pDst points to the output buffer 00044 * @param[in] blockSize number of samples in each vector 00045 * @return none. 00046 * 00047 * \par Conditions for optimum performance 00048 * Input and output buffers should be aligned by 32-bit 00049 * 00050 * 00051 * <b>Scaling and Overflow Behavior:</b> 00052 * \par 00053 * The function uses saturating arithmetic. 00054 * The Q7 value -1 (0x80) will be saturated to the maximum allowable positive value 0x7F. 00055 */ 00056 00057 void arm_abs_q7( 00058 q7_t * pSrc, 00059 q7_t * pDst, 00060 uint32_t blockSize) 00061 { 00062 uint32_t blkCnt; /* loop counter */ 00063 q7_t in; /* Input value1 */ 00064 00065 #if defined (ARM_MATH_DSP) 00066 00067 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00068 q31_t in1, in2, in3, in4; /* temporary input variables */ 00069 q31_t out1, out2, out3, out4; /* temporary output variables */ 00070 00071 /*loop Unrolling */ 00072 blkCnt = blockSize >> 2U; 00073 00074 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00075 ** a second loop below computes the remaining 1 to 3 samples. */ 00076 while (blkCnt > 0U) 00077 { 00078 /* C = |A| */ 00079 /* Read inputs */ 00080 in1 = (q31_t) * pSrc; 00081 in2 = (q31_t) * (pSrc + 1); 00082 in3 = (q31_t) * (pSrc + 2); 00083 00084 /* find absolute value */ 00085 out1 = (in1 > 0) ? in1 : (q31_t)__QSUB8(0, in1); 00086 00087 /* read input */ 00088 in4 = (q31_t) * (pSrc + 3); 00089 00090 /* find absolute value */ 00091 out2 = (in2 > 0) ? in2 : (q31_t)__QSUB8(0, in2); 00092 00093 /* store result to destination */ 00094 *pDst = (q7_t) out1; 00095 00096 /* find absolute value */ 00097 out3 = (in3 > 0) ? in3 : (q31_t)__QSUB8(0, in3); 00098 00099 /* find absolute value */ 00100 out4 = (in4 > 0) ? in4 : (q31_t)__QSUB8(0, in4); 00101 00102 /* store result to destination */ 00103 *(pDst + 1) = (q7_t) out2; 00104 00105 /* store result to destination */ 00106 *(pDst + 2) = (q7_t) out3; 00107 00108 /* store result to destination */ 00109 *(pDst + 3) = (q7_t) out4; 00110 00111 /* update pointers to process next samples */ 00112 pSrc += 4U; 00113 pDst += 4U; 00114 00115 /* Decrement the loop counter */ 00116 blkCnt--; 00117 } 00118 00119 /* If the blockSize is not a multiple of 4, compute any remaining output samples here. 00120 ** No loop unrolling is used. */ 00121 blkCnt = blockSize % 0x4U; 00122 #else 00123 00124 /* Run the below code for Cortex-M0 */ 00125 blkCnt = blockSize; 00126 00127 #endif /* #define ARM_MATH_CM0_FAMILY */ 00128 00129 while (blkCnt > 0U) 00130 { 00131 /* C = |A| */ 00132 /* Read the input */ 00133 in = *pSrc++; 00134 00135 /* Store the Absolute result in the destination buffer */ 00136 *pDst++ = (in > 0) ? in : ((in == (q7_t) 0x80) ? 0x7f : -in); 00137 00138 /* Decrement the loop counter */ 00139 blkCnt--; 00140 } 00141 } 00142 00143 /** 00144 * @} end of BasicAbs group 00145 */ 00146
Generated on Tue Jul 12 2022 16:46:22 by 1.7.2