Aded CMSIS5 DSP and NN folder. Needs some work
Embed:
(wiki syntax)
Show/hide line numbers
arm_dot_prod_q31.c
00001 /* ---------------------------------------------------------------------- 00002 * Project: CMSIS DSP Library 00003 * Title: arm_dot_prod_q31.c 00004 * Description: Q31 dot product 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 dot_prod 00037 * @{ 00038 */ 00039 00040 /** 00041 * @brief Dot product of Q31 vectors. 00042 * @param[in] *pSrcA points to the first input vector 00043 * @param[in] *pSrcB points to the second input vector 00044 * @param[in] blockSize number of samples in each vector 00045 * @param[out] *result output result returned here 00046 * @return none. 00047 * 00048 * <b>Scaling and Overflow Behavior:</b> 00049 * \par 00050 * The intermediate multiplications are in 1.31 x 1.31 = 2.62 format and these 00051 * are truncated to 2.48 format by discarding the lower 14 bits. 00052 * The 2.48 result is then added without saturation to a 64-bit accumulator in 16.48 format. 00053 * There are 15 guard bits in the accumulator and there is no risk of overflow as long as 00054 * the length of the vectors is less than 2^16 elements. 00055 * The return result is in 16.48 format. 00056 */ 00057 00058 void arm_dot_prod_q31( 00059 q31_t * pSrcA, 00060 q31_t * pSrcB, 00061 uint32_t blockSize, 00062 q63_t * result) 00063 { 00064 q63_t sum = 0; /* Temporary result storage */ 00065 uint32_t blkCnt; /* loop counter */ 00066 00067 00068 #if defined (ARM_MATH_DSP) 00069 00070 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00071 q31_t inA1, inA2, inA3, inA4; 00072 q31_t inB1, inB2, inB3, inB4; 00073 00074 /*loop Unrolling */ 00075 blkCnt = blockSize >> 2U; 00076 00077 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00078 ** a second loop below computes the remaining 1 to 3 samples. */ 00079 while (blkCnt > 0U) 00080 { 00081 /* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */ 00082 /* Calculate dot product and then store the result in a temporary buffer. */ 00083 inA1 = *pSrcA++; 00084 inA2 = *pSrcA++; 00085 inA3 = *pSrcA++; 00086 inA4 = *pSrcA++; 00087 inB1 = *pSrcB++; 00088 inB2 = *pSrcB++; 00089 inB3 = *pSrcB++; 00090 inB4 = *pSrcB++; 00091 00092 sum += ((q63_t) inA1 * inB1) >> 14U; 00093 sum += ((q63_t) inA2 * inB2) >> 14U; 00094 sum += ((q63_t) inA3 * inB3) >> 14U; 00095 sum += ((q63_t) inA4 * inB4) >> 14U; 00096 00097 /* Decrement the loop counter */ 00098 blkCnt--; 00099 } 00100 00101 /* If the blockSize is not a multiple of 4, compute any remaining output samples here. 00102 ** No loop unrolling is used. */ 00103 blkCnt = blockSize % 0x4U; 00104 00105 #else 00106 00107 /* Run the below code for Cortex-M0 */ 00108 00109 /* Initialize blkCnt with number of samples */ 00110 blkCnt = blockSize; 00111 00112 #endif /* #if defined (ARM_MATH_DSP) */ 00113 00114 00115 while (blkCnt > 0U) 00116 { 00117 /* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */ 00118 /* Calculate dot product and then store the result in a temporary buffer. */ 00119 sum += ((q63_t) * pSrcA++ * *pSrcB++) >> 14U; 00120 00121 /* Decrement the loop counter */ 00122 blkCnt--; 00123 } 00124 00125 /* Store the result in the destination buffer in 16.48 format */ 00126 *result = sum; 00127 } 00128 00129 /** 00130 * @} end of dot_prod group 00131 */ 00132
Generated on Tue Jul 12 2022 16:47:27 by 1.7.2