Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

158 lignes
3.5 KiB

  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cityblock_distance_f32.c
  4. * Description: Cityblock (Manhattan) distance between two vectors
  5. *
  6. * $Date: 23 April 2021
  7. * $Revision: V1.9.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 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. #include "dsp/distance_functions.h"
  29. #include <limits.h>
  30. #include <math.h>
  31. /**
  32. @addtogroup Manhattan
  33. @{
  34. */
  35. /**
  36. * @brief Cityblock (Manhattan) distance between two vectors
  37. * @param[in] pA First vector
  38. * @param[in] pB Second vector
  39. * @param[in] blockSize vector length
  40. * @return distance
  41. *
  42. */
  43. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  44. #include "arm_helium_utils.h"
  45. #include "arm_vec_math.h"
  46. float32_t arm_cityblock_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize)
  47. {
  48. uint32_t blkCnt;
  49. f32x4_t a, b, accumV, tempV;
  50. accumV = vdupq_n_f32(0.0f);
  51. blkCnt = blockSize >> 2;
  52. while (blkCnt > 0U) {
  53. a = vld1q(pA);
  54. b = vld1q(pB);
  55. tempV = vabdq(a, b);
  56. accumV = vaddq(accumV, tempV);
  57. pA += 4;
  58. pB += 4;
  59. blkCnt--;
  60. }
  61. /*
  62. * tail
  63. * (will be merged thru tail predication)
  64. */
  65. blkCnt = blockSize & 3;
  66. if (blkCnt > 0U) {
  67. mve_pred16_t p0 = vctp32q(blkCnt);
  68. a = vldrwq_z_f32(pA, p0);
  69. b = vldrwq_z_f32(pB, p0);
  70. tempV = vabdq(a, b);
  71. accumV = vaddq_m(accumV, accumV, tempV, p0);
  72. }
  73. return vecAddAcrossF32Mve(accumV);
  74. }
  75. #else
  76. #if defined(ARM_MATH_NEON)
  77. #include "NEMath.h"
  78. float32_t arm_cityblock_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize)
  79. {
  80. float32_t accum=0.0f, tmpA, tmpB;
  81. uint32_t blkCnt;
  82. float32x4_t a,b,accumV, tempV;
  83. float32x2_t accumV2;
  84. accumV = vdupq_n_f32(0.0f);
  85. blkCnt = blockSize >> 2;
  86. while(blkCnt > 0)
  87. {
  88. a = vld1q_f32(pA);
  89. b = vld1q_f32(pB);
  90. tempV = vabdq_f32(a,b);
  91. accumV = vaddq_f32(accumV, tempV);
  92. pA += 4;
  93. pB += 4;
  94. blkCnt --;
  95. }
  96. accumV2 = vpadd_f32(vget_low_f32(accumV),vget_high_f32(accumV));
  97. accumV2 = vpadd_f32(accumV2,accumV2);
  98. accum = vget_lane_f32(accumV2,0);
  99. blkCnt = blockSize & 3;
  100. while(blkCnt > 0)
  101. {
  102. tmpA = *pA++;
  103. tmpB = *pB++;
  104. accum += fabsf(tmpA - tmpB);
  105. blkCnt --;
  106. }
  107. return(accum);
  108. }
  109. #else
  110. float32_t arm_cityblock_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize)
  111. {
  112. float32_t accum,tmpA, tmpB;
  113. accum = 0.0f;
  114. while(blockSize > 0)
  115. {
  116. tmpA = *pA++;
  117. tmpB = *pB++;
  118. accum += fabsf(tmpA - tmpB);
  119. blockSize --;
  120. }
  121. return(accum);
  122. }
  123. #endif
  124. #endif
  125. /**
  126. * @} end of Manhattan group
  127. */