arm_abs_f16.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_abs_f16.c
  4. * Description: Floating-point vector absolute value
  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/basic_math_functions_f16.h"
  29. #include <math.h>
  30. /**
  31. @ingroup groupMath
  32. */
  33. /**
  34. @addtogroup BasicAbs
  35. @{
  36. */
  37. /**
  38. @brief Floating-point vector absolute value.
  39. @param[in] pSrc points to the input vector
  40. @param[out] pDst points to the output vector
  41. @param[in] blockSize number of samples in each vector
  42. */
  43. #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
  44. #include "arm_helium_utils.h"
  45. void arm_abs_f16(
  46. const float16_t * pSrc,
  47. float16_t * pDst,
  48. uint32_t blockSize)
  49. {
  50. uint32_t blkCnt; /* Loop counter */
  51. f16x8_t vec1;
  52. f16x8_t res;
  53. /* Compute 4 outputs at a time */
  54. blkCnt = blockSize >> 3U;
  55. while (blkCnt > 0U)
  56. {
  57. /* C = |A| */
  58. /* Calculate absolute values and then store the results in the destination buffer. */
  59. vec1 = vld1q(pSrc);
  60. res = vabsq(vec1);
  61. vst1q(pDst, res);
  62. /* Increment pointers */
  63. pSrc += 8;
  64. pDst += 8;
  65. /* Decrement the loop counter */
  66. blkCnt--;
  67. }
  68. /* Tail */
  69. blkCnt = blockSize & 0x7;
  70. if (blkCnt > 0U)
  71. {
  72. /* C = |A| */
  73. mve_pred16_t p0 = vctp16q(blkCnt);
  74. vec1 = vld1q(pSrc);
  75. vstrhq_p(pDst, vabsq(vec1), p0);
  76. }
  77. }
  78. #else
  79. #if defined(ARM_FLOAT16_SUPPORTED)
  80. void arm_abs_f16(
  81. const float16_t * pSrc,
  82. float16_t * pDst,
  83. uint32_t blockSize)
  84. {
  85. uint32_t blkCnt; /* Loop counter */
  86. #if defined(ARM_MATH_NEON_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
  87. f16x8_t vec1;
  88. f16x8_t res;
  89. /* Compute 4 outputs at a time */
  90. blkCnt = blockSize >> 2U;
  91. while (blkCnt > 0U)
  92. {
  93. /* C = |A| */
  94. /* Calculate absolute values and then store the results in the destination buffer. */
  95. vec1 = vld1q_f16(pSrc);
  96. res = vabsq_f16(vec1);
  97. vst1q_f16(pDst, res);
  98. /* Increment pointers */
  99. pSrc += 4;
  100. pDst += 4;
  101. /* Decrement the loop counter */
  102. blkCnt--;
  103. }
  104. /* Tail */
  105. blkCnt = blockSize & 0x3;
  106. #else
  107. #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
  108. /* Loop unrolling: Compute 4 outputs at a time */
  109. blkCnt = blockSize >> 2U;
  110. while (blkCnt > 0U)
  111. {
  112. /* C = |A| */
  113. /* Calculate absolute and store result in destination buffer. */
  114. *pDst++ = (_Float16)fabsf((float32_t)*pSrc++);
  115. *pDst++ = (_Float16)fabsf((float32_t)*pSrc++);
  116. *pDst++ = (_Float16)fabsf((float32_t)*pSrc++);
  117. *pDst++ = (_Float16)fabsf((float32_t)*pSrc++);
  118. /* Decrement loop counter */
  119. blkCnt--;
  120. }
  121. /* Loop unrolling: Compute remaining outputs */
  122. blkCnt = blockSize % 0x4U;
  123. #else
  124. /* Initialize blkCnt with number of samples */
  125. blkCnt = blockSize;
  126. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  127. #endif /* #if defined(ARM_MATH_NEON) */
  128. while (blkCnt > 0U)
  129. {
  130. /* C = |A| */
  131. /* Calculate absolute and store result in destination buffer. */
  132. *pDst++ = (_Float16)fabsf((float32_t)*pSrc++);
  133. /* Decrement loop counter */
  134. blkCnt--;
  135. }
  136. }
  137. #endif /* defined(ARM_FLOAT16_SUPPORTED */
  138. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  139. /**
  140. @} end of BasicAbs group
  141. */