You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

129 line
2.9 KiB

  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cityblock_distance_f16.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_f16.h"
  29. #if defined(ARM_FLOAT16_SUPPORTED)
  30. #include <limits.h>
  31. #include <math.h>
  32. /**
  33. @ingroup FloatDist
  34. */
  35. /**
  36. @defgroup Manhattan Cityblock (Manhattan) distance
  37. Cityblock (Manhattan) distance
  38. */
  39. /**
  40. @addtogroup Manhattan
  41. @{
  42. */
  43. /**
  44. * @brief Cityblock (Manhattan) distance between two vectors
  45. * @param[in] pA First vector
  46. * @param[in] pB Second vector
  47. * @param[in] blockSize vector length
  48. * @return distance
  49. *
  50. */
  51. #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
  52. #include "arm_helium_utils.h"
  53. #include "arm_vec_math.h"
  54. float16_t arm_cityblock_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize)
  55. {
  56. uint32_t blkCnt;
  57. f16x8_t a, b, accumV, tempV;
  58. accumV = vdupq_n_f16(0.0f);
  59. blkCnt = blockSize >> 3;
  60. while (blkCnt > 0U) {
  61. a = vld1q(pA);
  62. b = vld1q(pB);
  63. tempV = vabdq(a, b);
  64. accumV = vaddq(accumV, tempV);
  65. pA += 8;
  66. pB += 8;
  67. blkCnt--;
  68. }
  69. /*
  70. * tail
  71. * (will be merged thru tail predication)
  72. */
  73. blkCnt = blockSize & 7;
  74. if (blkCnt > 0U) {
  75. mve_pred16_t p0 = vctp16q(blkCnt);
  76. a = vldrhq_z_f16(pA, p0);
  77. b = vldrhq_z_f16(pB, p0);
  78. tempV = vabdq(a, b);
  79. accumV = vaddq_m(accumV, accumV, tempV, p0);
  80. }
  81. return vecAddAcrossF16Mve(accumV);
  82. }
  83. #else
  84. float16_t arm_cityblock_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize)
  85. {
  86. _Float16 accum,tmpA, tmpB;
  87. accum = 0.0f16;
  88. while(blockSize > 0)
  89. {
  90. tmpA = *pA++;
  91. tmpB = *pB++;
  92. accum += (_Float16)fabsf((float32_t)((_Float16)tmpA - (_Float16)tmpB));
  93. blockSize --;
  94. }
  95. return(accum);
  96. }
  97. #endif
  98. /**
  99. * @} end of Manhattan group
  100. */
  101. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */