arm_clip_q31.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_clip_q31.c
  4. * Description: Floating-point vector addition
  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.h"
  29. /**
  30. @ingroup groupMath
  31. */
  32. /**
  33. @addtogroup BasicClip
  34. @{
  35. */
  36. /**
  37. @brief Elementwise fixed-point clipping
  38. @param[in] pSrc points to input values
  39. @param[out] pDst points to output clipped values
  40. @param[in] low lower bound
  41. @param[in] high higher bound
  42. @param[in] numSamples number of samples to clip
  43. @return none
  44. */
  45. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  46. #include "arm_helium_utils.h"
  47. void arm_clip_q31(const q31_t * pSrc,
  48. q31_t * pDst,
  49. q31_t low,
  50. q31_t high,
  51. uint32_t numSamples)
  52. {
  53. uint32_t blkCnt;
  54. q31x4_t curVec0, curVec1;
  55. q31x4_t vecLow, vecHigh;
  56. vecLow = vdupq_n_s32(low);
  57. vecHigh = vdupq_n_s32(high);
  58. curVec0 = vld1q(pSrc);
  59. pSrc += 4;
  60. /*
  61. * unrolled x 2 to allow
  62. * vldr/vstr/vmin/vmax
  63. * stall free interleaving
  64. */
  65. blkCnt = numSamples >> 3;
  66. while (blkCnt--)
  67. {
  68. curVec0 = vmaxq(curVec0, vecLow);
  69. curVec1 = vld1q(pSrc);
  70. pSrc += 4;
  71. curVec0 = vminq(curVec0, vecHigh);
  72. vst1q(pDst, curVec0);
  73. pDst += 4;
  74. curVec1 = vmaxq(curVec1, vecLow);
  75. curVec0 = vld1q(pSrc);
  76. pSrc += 4;
  77. curVec1 = vminq(curVec1, vecHigh);
  78. vst1q(pDst, curVec1);
  79. pDst += 4;
  80. }
  81. /*
  82. * Tail handling
  83. */
  84. blkCnt = numSamples - ((numSamples >> 3) << 3);
  85. if (blkCnt >= 4)
  86. {
  87. curVec0 = vmaxq(curVec0, vecLow);
  88. curVec0 = vminq(curVec0, vecHigh);
  89. vst1q(pDst, curVec0);
  90. pDst += 4;
  91. curVec0 = vld1q(pSrc);
  92. pSrc += 4;
  93. }
  94. if (blkCnt > 0)
  95. {
  96. mve_pred16_t p0 = vctp32q(blkCnt & 3);
  97. curVec0 = vmaxq(curVec0, vecLow);
  98. curVec0 = vminq(curVec0, vecHigh);
  99. vstrwq_p(pDst, curVec0, p0);
  100. }
  101. }
  102. #else
  103. void arm_clip_q31(const q31_t * pSrc,
  104. q31_t * pDst,
  105. q31_t low,
  106. q31_t high,
  107. uint32_t numSamples)
  108. {
  109. uint32_t i;
  110. for (i = 0; i < numSamples; i++)
  111. {
  112. if (pSrc[i] > high)
  113. pDst[i] = high;
  114. else if (pSrc[i] < low)
  115. pDst[i] = low;
  116. else
  117. pDst[i] = pSrc[i];
  118. }
  119. }
  120. #endif /* defined(ARM_MATH_MVEI) */
  121. /**
  122. @} end of BasicClip group
  123. */