1 
2 /* ----------------------------------------------------------------------
3  * Project:      CMSIS DSP Library
4  * Title:        arm_chebyshev_distance_f64.c
5  * Description:  Chebyshev 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   @addtogroup Chebyshev
37   @{
38  */
39 
40 
41 /**
42  * @brief        Chebyshev distance between two vectors
43  * @param[in]    pA         First vector
44  * @param[in]    pB         Second vector
45  * @param[in]    blockSize  vector length
46  * @return distance
47  *
48  */
arm_chebyshev_distance_f64(const float64_t * pA,const float64_t * pB,uint32_t blockSize)49 ARM_DSP_ATTRIBUTE float64_t arm_chebyshev_distance_f64(const float64_t *pA,const float64_t *pB, uint32_t blockSize)
50 {
51 
52     float64_t diff=0.,  maxVal,tmpA, tmpB;
53     uint32_t blkCnt;
54     maxVal = F64_MIN;
55 #if defined(ARM_MATH_NEON) && defined(__aarch64__)
56     float64x2_t diffV , tmpAV , tmpBV , maxValV ;
57     maxValV = vdupq_n_f64(maxVal);
58     blkCnt = blockSize >> 1U ;
59     while(blkCnt > 0U)
60     {
61         tmpAV = vld1q_f64(pA);
62         tmpBV = vld1q_f64(pB);
63         diffV = vabsq_f64((vsubq_f64(tmpAV, tmpBV)));
64         maxValV = vmaxq_f64(maxValV, diffV);
65         pA+=2;
66         pB+=2;
67         blkCnt--;
68     }
69     maxVal =vgetq_lane_f64(maxValV, 0);
70     if(maxVal < vgetq_lane_f64(maxValV, 1))
71     {
72         maxVal = vgetq_lane_f64(maxValV, 1);
73     }
74     blkCnt = blockSize & 1;
75 
76 
77 #else
78     blkCnt = blockSize;
79 #endif
80 
81     while(blkCnt > 0)
82     {
83         tmpA = *pA++;
84         tmpB = *pB++;
85         diff = fabs(tmpA - tmpB);
86         if (diff > maxVal)
87         {
88             maxVal = diff;
89         }
90         blkCnt --;
91     }
92 
93     return(maxVal);
94 }
95 
96 /**
97  * @} end of Chebyshev group
98  */
99