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_scale_q7.c
00001 /* ---------------------------------------------------------------------- 00002 * Project: CMSIS DSP Library 00003 * Title: arm_scale_q7.c 00004 * Description: Multiplies a Q7 vector by a scalar 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 scale 00037 * @{ 00038 */ 00039 00040 /** 00041 * @brief Multiplies a Q7 vector by a scalar. 00042 * @param[in] *pSrc points to the input vector 00043 * @param[in] scaleFract fractional portion of the scale value 00044 * @param[in] shift number of bits to shift the result by 00045 * @param[out] *pDst points to the output vector 00046 * @param[in] blockSize number of samples in the vector 00047 * @return none. 00048 * 00049 * <b>Scaling and Overflow Behavior:</b> 00050 * \par 00051 * The input data <code>*pSrc</code> and <code>scaleFract</code> are in 1.7 format. 00052 * These are multiplied to yield a 2.14 intermediate result and this is shifted with saturation to 1.7 format. 00053 */ 00054 00055 void arm_scale_q7( 00056 q7_t * pSrc, 00057 q7_t scaleFract, 00058 int8_t shift, 00059 q7_t * pDst, 00060 uint32_t blockSize) 00061 { 00062 int8_t kShift = 7 - shift; /* shift to apply after scaling */ 00063 uint32_t blkCnt; /* loop counter */ 00064 00065 #if defined (ARM_MATH_DSP) 00066 00067 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00068 q7_t in1, in2, in3, in4, out1, out2, out3, out4; /* Temporary variables to store input & output */ 00069 00070 00071 /*loop Unrolling */ 00072 blkCnt = blockSize >> 2U; 00073 00074 00075 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00076 ** a second loop below computes the remaining 1 to 3 samples. */ 00077 while (blkCnt > 0U) 00078 { 00079 /* Reading 4 inputs from memory */ 00080 in1 = *pSrc++; 00081 in2 = *pSrc++; 00082 in3 = *pSrc++; 00083 in4 = *pSrc++; 00084 00085 /* C = A * scale */ 00086 /* Scale the inputs and then store the results in the temporary variables. */ 00087 out1 = (q7_t) (__SSAT(((in1) * scaleFract) >> kShift, 8)); 00088 out2 = (q7_t) (__SSAT(((in2) * scaleFract) >> kShift, 8)); 00089 out3 = (q7_t) (__SSAT(((in3) * scaleFract) >> kShift, 8)); 00090 out4 = (q7_t) (__SSAT(((in4) * scaleFract) >> kShift, 8)); 00091 00092 /* Packing the individual outputs into 32bit and storing in 00093 * destination buffer in single write */ 00094 *__SIMD32(pDst)++ = __PACKq7(out1, out2, out3, out4); 00095 00096 /* Decrement the loop counter */ 00097 blkCnt--; 00098 } 00099 00100 /* If the blockSize is not a multiple of 4, compute any remaining output samples here. 00101 ** No loop unrolling is used. */ 00102 blkCnt = blockSize % 0x4U; 00103 00104 while (blkCnt > 0U) 00105 { 00106 /* C = A * scale */ 00107 /* Scale the input and then store the result in the destination buffer. */ 00108 *pDst++ = (q7_t) (__SSAT(((*pSrc++) * scaleFract) >> kShift, 8)); 00109 00110 /* Decrement the loop counter */ 00111 blkCnt--; 00112 } 00113 00114 #else 00115 00116 /* Run the below code for Cortex-M0 */ 00117 00118 /* Initialize blkCnt with number of samples */ 00119 blkCnt = blockSize; 00120 00121 while (blkCnt > 0U) 00122 { 00123 /* C = A * scale */ 00124 /* Scale the input and then store the result in the destination buffer. */ 00125 *pDst++ = (q7_t) (__SSAT((((q15_t) * pSrc++ * scaleFract) >> kShift), 8)); 00126 00127 /* Decrement the loop counter */ 00128 blkCnt--; 00129 } 00130 00131 #endif /* #if defined (ARM_MATH_DSP) */ 00132 00133 } 00134 00135 /** 00136 * @} end of scale group 00137 */ 00138
Generated on Tue Jul 12 2022 16:47:28 by
1.7.2