before merging master
[inav.git] / lib / main / CMSIS / DSP / Source / BasicMathFunctions / arm_dot_prod_f32.c
blob0cd0afc4626e84646c7af8bf0256ec0eb0c3b2cd
1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_dot_prod_f32.c
4 * Description: Floating-point dot product
6 * $Date: 27. January 2017
7 * $Revision: V.1.5.1
9 * Target Processor: Cortex-M cores
10 * -------------------------------------------------------------------- */
12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
14 * SPDX-License-Identifier: Apache-2.0
16 * Licensed under the Apache License, Version 2.0 (the License); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
20 * www.apache.org/licenses/LICENSE-2.0
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
29 #include "arm_math.h"
31 /**
32 * @ingroup groupMath
35 /**
36 * @defgroup dot_prod Vector Dot Product
38 * Computes the dot product of two vectors.
39 * The vectors are multiplied element-by-element and then summed.
41 * <pre>
42 * sum = pSrcA[0]*pSrcB[0] + pSrcA[1]*pSrcB[1] + ... + pSrcA[blockSize-1]*pSrcB[blockSize-1]
43 * </pre>
45 * There are separate functions for floating-point, Q7, Q15, and Q31 data types.
48 /**
49 * @addtogroup dot_prod
50 * @{
53 /**
54 * @brief Dot product of floating-point vectors.
55 * @param[in] *pSrcA points to the first input vector
56 * @param[in] *pSrcB points to the second input vector
57 * @param[in] blockSize number of samples in each vector
58 * @param[out] *result output result returned here
59 * @return none.
63 void arm_dot_prod_f32(
64 float32_t * pSrcA,
65 float32_t * pSrcB,
66 uint32_t blockSize,
67 float32_t * result)
69 float32_t sum = 0.0f; /* Temporary result storage */
70 uint32_t blkCnt; /* loop counter */
73 #if defined (ARM_MATH_DSP)
75 /* Run the below code for Cortex-M4 and Cortex-M3 */
76 /*loop Unrolling */
77 blkCnt = blockSize >> 2U;
79 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
80 ** a second loop below computes the remaining 1 to 3 samples. */
81 while (blkCnt > 0U)
83 /* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */
84 /* Calculate dot product and then store the result in a temporary buffer */
85 sum += (*pSrcA++) * (*pSrcB++);
86 sum += (*pSrcA++) * (*pSrcB++);
87 sum += (*pSrcA++) * (*pSrcB++);
88 sum += (*pSrcA++) * (*pSrcB++);
90 /* Decrement the loop counter */
91 blkCnt--;
94 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
95 ** No loop unrolling is used. */
96 blkCnt = blockSize % 0x4U;
98 #else
100 /* Run the below code for Cortex-M0 */
102 /* Initialize blkCnt with number of samples */
103 blkCnt = blockSize;
105 #endif /* #if defined (ARM_MATH_DSP) */
108 while (blkCnt > 0U)
110 /* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */
111 /* Calculate dot product and then store the result in a temporary buffer. */
112 sum += (*pSrcA++) * (*pSrcB++);
114 /* Decrement the loop counter */
115 blkCnt--;
117 /* Store the result back in the destination buffer */
118 *result = sum;
122 * @} end of dot_prod group