1 
2 /* ----------------------------------------------------------------------
3  * Project:      CMSIS DSP Library
4  * Title:        arm_euclidean_distance_f64.c
5  * Description:  Euclidean distance between two vectors
6  *
7  * $Date:        10 August 2022
8  * $Revision:    V1.10.1
9  *
10  * Target Processor: Cortex-M and Cortex-A cores
11  * -------------------------------------------------------------------- */
12 /*
13  * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
14  *
15  * SPDX-License-Identifier: Apache-2.0
16  *
17  * Licensed under the Apache License, Version 2.0 (the License); you may
18  * not use this file except in compliance with the License.
19  * You may obtain a copy of the License at
20  *
21  * www.apache.org/licenses/LICENSE-2.0
22  *
23  * Unless required by applicable law or agreed to in writing, software
24  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
25  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26  * See the License for the specific language governing permissions and
27  * limitations under the License.
28  */
29 
30 #include "dsp/distance_functions.h"
31 #include <limits.h>
32 #include <math.h>
33 
34 
35 
36 /**
37   @addtogroup Euclidean
38   @{
39  */
40 
41 
42 /**
43  * @brief        Euclidean distance between two vectors
44  * @param[in]    pA         First vector
45  * @param[in]    pB         Second vector
46  * @param[in]    blockSize  vector length
47  * @return distance
48  *
49  */
arm_euclidean_distance_f64(const float64_t * pA,const float64_t * pB,uint32_t blockSize)50 ARM_DSP_ATTRIBUTE float64_t arm_euclidean_distance_f64(const float64_t *pA,const float64_t *pB, uint32_t blockSize)
51 {
52     float64_t accum=0.,tmp;
53     uint32_t blkCnt;
54 #if defined(ARM_MATH_NEON) && defined(__aarch64__)
55     float64x2_t accumV,tmpV , pAV ,pBV;
56     accumV = vdupq_n_f64(0.0);
57     blkCnt = blockSize >> 1U;
58     while(blkCnt > 0U)
59     {
60         pAV = vld1q_f64(pA);
61         pBV = vld1q_f64(pB);
62         tmpV = vsubq_f64(pAV, pBV);
63         accumV = vmlaq_f64(accumV, tmpV, tmpV);
64         pA+=2;
65         pB+=2;
66         blkCnt--;
67     }
68     accum = vaddvq_f64(accumV);
69     blkCnt = blockSize & 1;
70 #else
71     blkCnt = blockSize;
72 #endif
73     while(blkCnt > 0)
74     {
75         tmp = *pA++ - *pB++;
76         accum += ARM_SQ(tmp);
77         blkCnt --;
78     }
79     tmp = sqrt(accum);
80     return(tmp);
81 }
82 
83 /**
84  * @} end of Euclidean group
85  */
86