Aded CMSIS5 DSP and NN folder. Needs some work
Embed:
(wiki syntax)
Show/hide line numbers
arm_scale_q31.c
00001 /* ---------------------------------------------------------------------- 00002 * Project: CMSIS DSP Library 00003 * Title: arm_scale_q31.c 00004 * Description: Multiplies a Q31 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 Q31 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.31 format. 00052 * These are multiplied to yield a 2.62 intermediate result and this is shifted with saturation to 1.31 format. 00053 */ 00054 00055 void arm_scale_q31( 00056 q31_t * pSrc, 00057 q31_t scaleFract, 00058 int8_t shift, 00059 q31_t * pDst, 00060 uint32_t blockSize) 00061 { 00062 int8_t kShift = shift + 1; /* Shift to apply after scaling */ 00063 int8_t sign = (kShift & 0x80); 00064 uint32_t blkCnt; /* loop counter */ 00065 q31_t in, out; 00066 00067 #if defined (ARM_MATH_DSP) 00068 00069 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00070 00071 q31_t in1, in2, in3, in4; /* temporary input variables */ 00072 q31_t out1, out2, out3, out4; /* temporary output variabels */ 00073 00074 00075 /*loop Unrolling */ 00076 blkCnt = blockSize >> 2U; 00077 00078 if (sign == 0U) 00079 { 00080 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00081 ** a second loop below computes the remaining 1 to 3 samples. */ 00082 while (blkCnt > 0U) 00083 { 00084 /* read four inputs from source */ 00085 in1 = *pSrc; 00086 in2 = *(pSrc + 1); 00087 in3 = *(pSrc + 2); 00088 in4 = *(pSrc + 3); 00089 00090 /* multiply input with scaler value */ 00091 in1 = ((q63_t) in1 * scaleFract) >> 32; 00092 in2 = ((q63_t) in2 * scaleFract) >> 32; 00093 in3 = ((q63_t) in3 * scaleFract) >> 32; 00094 in4 = ((q63_t) in4 * scaleFract) >> 32; 00095 00096 /* apply shifting */ 00097 out1 = in1 << kShift; 00098 out2 = in2 << kShift; 00099 00100 /* saturate the results. */ 00101 if (in1 != (out1 >> kShift)) 00102 out1 = 0x7FFFFFFF ^ (in1 >> 31); 00103 00104 if (in2 != (out2 >> kShift)) 00105 out2 = 0x7FFFFFFF ^ (in2 >> 31); 00106 00107 out3 = in3 << kShift; 00108 out4 = in4 << kShift; 00109 00110 *pDst = out1; 00111 *(pDst + 1) = out2; 00112 00113 if (in3 != (out3 >> kShift)) 00114 out3 = 0x7FFFFFFF ^ (in3 >> 31); 00115 00116 if (in4 != (out4 >> kShift)) 00117 out4 = 0x7FFFFFFF ^ (in4 >> 31); 00118 00119 /* Store result destination */ 00120 *(pDst + 2) = out3; 00121 *(pDst + 3) = out4; 00122 00123 /* Update pointers to process next sampels */ 00124 pSrc += 4U; 00125 pDst += 4U; 00126 00127 /* Decrement the loop counter */ 00128 blkCnt--; 00129 } 00130 00131 } 00132 else 00133 { 00134 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00135 ** a second loop below computes the remaining 1 to 3 samples. */ 00136 while (blkCnt > 0U) 00137 { 00138 /* read four inputs from source */ 00139 in1 = *pSrc; 00140 in2 = *(pSrc + 1); 00141 in3 = *(pSrc + 2); 00142 in4 = *(pSrc + 3); 00143 00144 /* multiply input with scaler value */ 00145 in1 = ((q63_t) in1 * scaleFract) >> 32; 00146 in2 = ((q63_t) in2 * scaleFract) >> 32; 00147 in3 = ((q63_t) in3 * scaleFract) >> 32; 00148 in4 = ((q63_t) in4 * scaleFract) >> 32; 00149 00150 /* apply shifting */ 00151 out1 = in1 >> -kShift; 00152 out2 = in2 >> -kShift; 00153 00154 out3 = in3 >> -kShift; 00155 out4 = in4 >> -kShift; 00156 00157 /* Store result destination */ 00158 *pDst = out1; 00159 *(pDst + 1) = out2; 00160 00161 *(pDst + 2) = out3; 00162 *(pDst + 3) = out4; 00163 00164 /* Update pointers to process next sampels */ 00165 pSrc += 4U; 00166 pDst += 4U; 00167 00168 /* Decrement the loop counter */ 00169 blkCnt--; 00170 } 00171 } 00172 /* If the blockSize is not a multiple of 4, compute any remaining output samples here. 00173 ** No loop unrolling is used. */ 00174 blkCnt = blockSize % 0x4U; 00175 00176 #else 00177 00178 /* Run the below code for Cortex-M0 */ 00179 00180 /* Initialize blkCnt with number of samples */ 00181 blkCnt = blockSize; 00182 00183 #endif /* #if defined (ARM_MATH_DSP) */ 00184 00185 if (sign == 0) 00186 { 00187 while (blkCnt > 0U) 00188 { 00189 /* C = A * scale */ 00190 /* Scale the input and then store the result in the destination buffer. */ 00191 in = *pSrc++; 00192 in = ((q63_t) in * scaleFract) >> 32; 00193 00194 out = in << kShift; 00195 00196 if (in != (out >> kShift)) 00197 out = 0x7FFFFFFF ^ (in >> 31); 00198 00199 *pDst++ = out; 00200 00201 /* Decrement the loop counter */ 00202 blkCnt--; 00203 } 00204 } 00205 else 00206 { 00207 while (blkCnt > 0U) 00208 { 00209 /* C = A * scale */ 00210 /* Scale the input and then store the result in the destination buffer. */ 00211 in = *pSrc++; 00212 in = ((q63_t) in * scaleFract) >> 32; 00213 00214 out = in >> -kShift; 00215 00216 *pDst++ = out; 00217 00218 /* Decrement the loop counter */ 00219 blkCnt--; 00220 } 00221 00222 } 00223 } 00224 00225 /** 00226 * @} end of scale group 00227 */ 00228
Generated on Tue Jul 12 2022 16:47:28 by 1.7.2