arm_absmin_no_idx_f32.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_absmin_no_idx_f32.c
  4. * Description: Minimum value of absolute values of a floating-point vector
  5. *
  6. * $Date: 16 November 2021
  7. * $Revision: V1.10.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/statistics_functions.h"
  29. #if (defined(ARM_MATH_NEON) || defined(ARM_MATH_MVEF)) && !defined(ARM_MATH_AUTOVECTORIZE)
  30. #include <limits.h>
  31. #endif
  32. /**
  33. @ingroup groupStats
  34. */
  35. /**
  36. @addtogroup AbsMin
  37. @{
  38. */
  39. /**
  40. @brief Minimum value of absolute values of a floating-point vector.
  41. @param[in] pSrc points to the input vector
  42. @param[in] blockSize number of samples in input vector
  43. @param[out] pResult minimum value returned here
  44. @return none
  45. */
  46. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  47. #include "arm_helium_utils.h"
  48. void arm_absmin_no_idx_f32(
  49. const float32_t * pSrc,
  50. uint32_t blockSize,
  51. float32_t * pResult)
  52. {
  53. int32_t blkCnt; /* loop counters */
  54. f32x4_t vecSrc;
  55. float32_t const *pSrcVec;
  56. f32x4_t curExtremValVec = vdupq_n_f32(F32_ABSMAX);
  57. float32_t minValue = F32_ABSMAX;
  58. mve_pred16_t p0;
  59. pSrcVec = (float32_t const *) pSrc;
  60. blkCnt = blockSize >> 2;
  61. while (blkCnt > 0)
  62. {
  63. vecSrc = vldrwq_f32(pSrcVec);
  64. pSrcVec += 4;
  65. /*
  66. * update per-lane min.
  67. */
  68. curExtremValVec = vminnmaq(vecSrc, curExtremValVec);
  69. /*
  70. * Decrement the blockSize loop counter
  71. */
  72. blkCnt--;
  73. }
  74. /*
  75. * tail
  76. * (will be merged thru tail predication)
  77. */
  78. blkCnt = blockSize & 3;
  79. if (blkCnt > 0)
  80. {
  81. vecSrc = vldrwq_f32(pSrcVec);
  82. pSrcVec += 4;
  83. p0 = vctp32q(blkCnt);
  84. /*
  85. * Get current min per lane and current index per lane
  86. * when a min is selected
  87. */
  88. curExtremValVec = vminnmaq_m(curExtremValVec, vecSrc, p0);
  89. }
  90. /*
  91. * Get min value across the vector
  92. */
  93. minValue = vminnmavq(minValue, curExtremValVec);
  94. *pResult = minValue;
  95. }
  96. #else
  97. #if defined(ARM_MATH_LOOPUNROLL)
  98. void arm_absmin_no_idx_f32(
  99. const float32_t * pSrc,
  100. uint32_t blockSize,
  101. float32_t * pResult)
  102. {
  103. float32_t cur_absmin, out; /* Temporary variables to store the output value. */\
  104. uint32_t blkCnt; /* Loop counter */ \
  105. \
  106. \
  107. /* Load first input value that act as reference value for comparision */ \
  108. out = *pSrc++; \
  109. out = (out > 0.0f) ? out : -out; \
  110. \
  111. \
  112. /* Loop unrolling: Compute 4 outputs at a time */ \
  113. blkCnt = (blockSize - 1U) >> 2U; \
  114. \
  115. while (blkCnt > 0U) \
  116. { \
  117. /* Initialize cur_absmin to next consecutive values one by one */ \
  118. cur_absmin = *pSrc++; \
  119. cur_absmin = (cur_absmin > 0.0f) ? cur_absmin : -cur_absmin; \
  120. /* compare for the extrema value */ \
  121. if (cur_absmin < out) \
  122. { \
  123. /* Update the extrema value and it's index */ \
  124. out = cur_absmin; \
  125. } \
  126. \
  127. cur_absmin = *pSrc++; \
  128. cur_absmin = (cur_absmin > 0.0f) ? cur_absmin : -cur_absmin; \
  129. if (cur_absmin < out) \
  130. { \
  131. out = cur_absmin; \
  132. } \
  133. \
  134. cur_absmin = *pSrc++; \
  135. cur_absmin = (cur_absmin > 0.0f) ? cur_absmin : -cur_absmin; \
  136. if (cur_absmin < out) \
  137. { \
  138. out = cur_absmin; \
  139. } \
  140. \
  141. cur_absmin = *pSrc++; \
  142. cur_absmin = (cur_absmin > 0.0f) ? cur_absmin : -cur_absmin; \
  143. if (cur_absmin < out) \
  144. { \
  145. out = cur_absmin; \
  146. } \
  147. \
  148. \
  149. /* Decrement loop counter */ \
  150. blkCnt--; \
  151. } \
  152. \
  153. /* Loop unrolling: Compute remaining outputs */ \
  154. blkCnt = (blockSize - 1U) % 4U; \
  155. \
  156. \
  157. while (blkCnt > 0U) \
  158. { \
  159. cur_absmin = *pSrc++; \
  160. cur_absmin = (cur_absmin > 0.0f) ? cur_absmin : -cur_absmin; \
  161. if (cur_absmin < out) \
  162. { \
  163. out = cur_absmin; \
  164. } \
  165. \
  166. /* Decrement loop counter */ \
  167. blkCnt--; \
  168. } \
  169. \
  170. /* Store the extrema value and it's index into destination pointers */ \
  171. *pResult = out; \
  172. }
  173. #else
  174. void arm_absmin_no_idx_f32(
  175. const float32_t * pSrc,
  176. uint32_t blockSize,
  177. float32_t * pResult)
  178. {
  179. float32_t minVal, out; /* Temporary variables to store the output value. */
  180. uint32_t blkCnt; /* Loop counter */
  181. /* Load first input value that act as reference value for comparision */
  182. out = fabsf(*pSrc++);
  183. /* Initialize blkCnt with number of samples */
  184. blkCnt = (blockSize - 1U);
  185. while (blkCnt > 0U)
  186. {
  187. /* Initialize minVal to the next consecutive values one by one */
  188. minVal = fabsf(*pSrc++);
  189. /* compare for the minimum value */
  190. if (out > minVal)
  191. {
  192. /* Update the minimum value and it's index */
  193. out = minVal;
  194. }
  195. /* Decrement loop counter */
  196. blkCnt--;
  197. }
  198. /* Store the minimum value and it's index into destination pointers */
  199. *pResult = out;
  200. }
  201. #endif /* defined(ARM_MATH_LOOPUNROLL) */
  202. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  203. /**
  204. @} end of AbsMin group
  205. */