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