Subversion Repositories testOled

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/* ----------------------------------------------------------------------
2
 * Project:      CMSIS DSP Library
3
 * Title:        arm_dot_prod_f32.c
4
 * Description:  Floating-point dot product
5
 *
6
 * $Date:        27. January 2017
7
 * $Revision:    V.1.5.1
8
 *
9
 * Target Processor: Cortex-M cores
10
 * -------------------------------------------------------------------- */
11
/*
12
 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
13
 *
14
 * SPDX-License-Identifier: Apache-2.0
15
 *
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
19
 *
20
 * www.apache.org/licenses/LICENSE-2.0
21
 *
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.
27
 */
28
 
29
#include "arm_math.h"
30
 
31
/**
32
 * @ingroup groupMath
33
 */
34
 
35
/**
36
 * @defgroup dot_prod Vector Dot Product
37
 *
38
 * Computes the dot product of two vectors.
39
 * The vectors are multiplied element-by-element and then summed.
40
 *
41
 * <pre>
42
 *     sum = pSrcA[0]*pSrcB[0] + pSrcA[1]*pSrcB[1] + ... + pSrcA[blockSize-1]*pSrcB[blockSize-1]
43
 * </pre>
44
 *
45
 * There are separate functions for floating-point, Q7, Q15, and Q31 data types.
46
 */
47
 
48
/**
49
 * @addtogroup dot_prod
50
 * @{
51
 */
52
 
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.
60
 */
61
 
62
 
63
void arm_dot_prod_f32(
64
  float32_t * pSrcA,
65
  float32_t * pSrcB,
66
  uint32_t blockSize,
67
  float32_t * result)
68
{
69
  float32_t sum = 0.0f;                          /* Temporary result storage */
70
  uint32_t blkCnt;                               /* loop counter */
71
 
72
 
73
#if defined (ARM_MATH_DSP)
74
 
75
/* Run the below code for Cortex-M4 and Cortex-M3 */
76
  /*loop Unrolling */
77
  blkCnt = blockSize >> 2U;
78
 
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)
82
  {
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++);
89
 
90
    /* Decrement the loop counter */
91
    blkCnt--;
92
  }
93
 
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;
97
 
98
#else
99
 
100
  /* Run the below code for Cortex-M0 */
101
 
102
  /* Initialize blkCnt with number of samples */
103
  blkCnt = blockSize;
104
 
105
#endif /* #if defined (ARM_MATH_DSP) */
106
 
107
 
108
  while (blkCnt > 0U)
109
  {
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++);
113
 
114
    /* Decrement the loop counter */
115
    blkCnt--;
116
  }
117
  /* Store the result back in the destination buffer */
118
  *result = sum;
119
}
120
 
121
/**
122
 * @} end of dot_prod group
123
 */