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.
arm_abs_q31.c
00001 /* ---------------------------------------------------------------------- 00002 * Project: CMSIS DSP Library 00003 * Title: arm_abs_q31.c 00004 * Description: Q31 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 /** 00042 * @brief Q31 vector absolute value. 00043 * @param[in] *pSrc points to the input buffer 00044 * @param[out] *pDst points to the output buffer 00045 * @param[in] blockSize number of samples in each vector 00046 * @return none. 00047 * 00048 * <b>Scaling and Overflow Behavior:</b> 00049 * \par 00050 * The function uses saturating arithmetic. 00051 * The Q31 value -1 (0x80000000) will be saturated to the maximum allowable positive value 0x7FFFFFFF. 00052 */ 00053 00054 void arm_abs_q31( 00055 q31_t * pSrc, 00056 q31_t * pDst, 00057 uint32_t blockSize) 00058 { 00059 uint32_t blkCnt; /* loop counter */ 00060 q31_t in; /* Input value */ 00061 00062 #if defined (ARM_MATH_DSP) 00063 00064 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00065 q31_t in1, in2, in3, in4; 00066 00067 /*loop Unrolling */ 00068 blkCnt = blockSize >> 2U; 00069 00070 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00071 ** a second loop below computes the remaining 1 to 3 samples. */ 00072 while (blkCnt > 0U) 00073 { 00074 /* C = |A| */ 00075 /* Calculate absolute of input (if -1 then saturated to 0x7fffffff) and then store the results in the destination buffer. */ 00076 in1 = *pSrc++; 00077 in2 = *pSrc++; 00078 in3 = *pSrc++; 00079 in4 = *pSrc++; 00080 00081 *pDst++ = (in1 > 0) ? in1 : (q31_t)__QSUB(0, in1); 00082 *pDst++ = (in2 > 0) ? in2 : (q31_t)__QSUB(0, in2); 00083 *pDst++ = (in3 > 0) ? in3 : (q31_t)__QSUB(0, in3); 00084 *pDst++ = (in4 > 0) ? in4 : (q31_t)__QSUB(0, in4); 00085 00086 /* Decrement the loop counter */ 00087 blkCnt--; 00088 } 00089 00090 /* If the blockSize is not a multiple of 4, compute any remaining output samples here. 00091 ** No loop unrolling is used. */ 00092 blkCnt = blockSize % 0x4U; 00093 00094 #else 00095 00096 /* Run the below code for Cortex-M0 */ 00097 00098 /* Initialize blkCnt with number of samples */ 00099 blkCnt = blockSize; 00100 00101 #endif /* #if defined (ARM_MATH_DSP) */ 00102 00103 while (blkCnt > 0U) 00104 { 00105 /* C = |A| */ 00106 /* Calculate absolute value of the input (if -1 then saturated to 0x7fffffff) and then store the results in the destination buffer. */ 00107 in = *pSrc++; 00108 *pDst++ = (in > 0) ? in : ((in == INT32_MIN) ? INT32_MAX : -in); 00109 00110 /* Decrement the loop counter */ 00111 blkCnt--; 00112 } 00113 00114 } 00115 00116 /** 00117 * @} end of BasicAbs group 00118 */ 00119
Generated on Tue Jul 12 2022 16:46:22 by
