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_power_q7.c
00001 /* ---------------------------------------------------------------------- 00002 * Project: CMSIS DSP Library 00003 * Title: arm_power_q7.c 00004 * Description: Sum of the squares of the elements of a Q7 vector 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 groupStats 00033 */ 00034 00035 /** 00036 * @addtogroup power 00037 * @{ 00038 */ 00039 00040 /** 00041 * @brief Sum of the squares of the elements of a Q7 vector. 00042 * @param[in] *pSrc points to the input vector 00043 * @param[in] blockSize length of the input vector 00044 * @param[out] *pResult sum of the squares value returned here 00045 * @return none. 00046 * 00047 * @details 00048 * <b>Scaling and Overflow Behavior:</b> 00049 * 00050 * \par 00051 * The function is implemented using a 32-bit internal accumulator. 00052 * The input is represented in 1.7 format. 00053 * Intermediate multiplication yields a 2.14 format, and this 00054 * result is added without saturation to an accumulator in 18.14 format. 00055 * With 17 guard bits in the accumulator, there is no risk of overflow, and the 00056 * full precision of the intermediate multiplication is preserved. 00057 * Finally, the return result is in 18.14 format. 00058 * 00059 */ 00060 00061 void arm_power_q7( 00062 q7_t * pSrc, 00063 uint32_t blockSize, 00064 q31_t * pResult) 00065 { 00066 q31_t sum = 0; /* Temporary result storage */ 00067 q7_t in; /* Temporary variable to store input */ 00068 uint32_t blkCnt; /* loop counter */ 00069 00070 #if defined (ARM_MATH_DSP) 00071 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00072 00073 q31_t input1; /* Temporary variable to store packed input */ 00074 q31_t in1, in2; /* Temporary variables to store input */ 00075 00076 /*loop Unrolling */ 00077 blkCnt = blockSize >> 2U; 00078 00079 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00080 ** a second loop below computes the remaining 1 to 3 samples. */ 00081 while (blkCnt > 0U) 00082 { 00083 /* Reading two inputs of pSrc vector and packing */ 00084 input1 = *__SIMD32(pSrc)++; 00085 00086 in1 = __SXTB16(__ROR(input1, 8)); 00087 in2 = __SXTB16(input1); 00088 00089 /* C = A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + ... + A[blockSize-1] * A[blockSize-1] */ 00090 /* calculate power and accumulate to accumulator */ 00091 sum = __SMLAD(in1, in1, sum); 00092 sum = __SMLAD(in2, in2, sum); 00093 00094 /* Decrement the loop counter */ 00095 blkCnt--; 00096 } 00097 00098 /* If the blockSize is not a multiple of 4, compute any remaining output samples here. 00099 ** No loop unrolling is used. */ 00100 blkCnt = blockSize % 0x4U; 00101 00102 #else 00103 /* Run the below code for Cortex-M0 */ 00104 00105 /* Loop over blockSize number of values */ 00106 blkCnt = blockSize; 00107 00108 #endif /* #if defined (ARM_MATH_DSP) */ 00109 00110 while (blkCnt > 0U) 00111 { 00112 /* C = A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + ... + A[blockSize-1] * A[blockSize-1] */ 00113 /* Compute Power and then store the result in a temporary variable, sum. */ 00114 in = *pSrc++; 00115 sum += ((q15_t) in * in); 00116 00117 /* Decrement the loop counter */ 00118 blkCnt--; 00119 } 00120 00121 /* Store the result in 18.14 format */ 00122 *pResult = sum; 00123 } 00124 00125 /** 00126 * @} end of power group 00127 */ 00128
Generated on Tue Jul 12 2022 16:47:27 by
