1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_dot_prod_f32.c
4 * Description: Floating-point dot product
6 * $Date: 27. January 2017
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.
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.
42 * sum = pSrcA[0]*pSrcB[0] + pSrcA[1]*pSrcB[1] + ... + pSrcA[blockSize-1]*pSrcB[blockSize-1]
45 * There are separate functions for floating-point, Q7, Q15, and Q31 data types.
49 * @addtogroup dot_prod
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
63 void arm_dot_prod_f32(
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 */
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. */
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 */
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
;
100 /* Run the below code for Cortex-M0 */
102 /* Initialize blkCnt with number of samples */
105 #endif /* #if defined (ARM_MATH_DSP) */
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 */
117 /* Store the result back in the destination buffer */
122 * @} end of dot_prod group