arm_sub_f16.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_sub_f16.c
  4. * Description: Floating-point vector subtraction
  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. /**
  30. @ingroup groupMath
  31. */
  32. /**
  33. @defgroup BasicSub Vector Subtraction
  34. Element-by-element subtraction of two vectors.
  35. <pre>
  36. pDst[n] = pSrcA[n] - pSrcB[n], 0 <= n < blockSize.
  37. </pre>
  38. There are separate functions for floating-point, Q7, Q15, and Q31 data types.
  39. */
  40. /**
  41. @addtogroup BasicSub
  42. @{
  43. */
  44. /**
  45. @brief Floating-point vector subtraction.
  46. @param[in] pSrcA points to the first input vector
  47. @param[in] pSrcB points to the second input vector
  48. @param[out] pDst points to the output vector
  49. @param[in] blockSize number of samples in each vector
  50. @return none
  51. */
  52. #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
  53. #include "arm_helium_utils.h"
  54. void arm_sub_f16(
  55. const float16_t * pSrcA,
  56. const float16_t * pSrcB,
  57. float16_t * pDst,
  58. uint32_t blockSize)
  59. {
  60. uint32_t blkCnt; /* Loop counter */
  61. f16x8_t vec1;
  62. f16x8_t vec2;
  63. f16x8_t res;
  64. /* Compute 4 outputs at a time */
  65. blkCnt = blockSize >> 3U;
  66. while (blkCnt > 0U)
  67. {
  68. /* C = A + B */
  69. /* Add and then store the results in the destination buffer. */
  70. vec1 = vld1q(pSrcA);
  71. vec2 = vld1q(pSrcB);
  72. res = vsubq(vec1, vec2);
  73. vst1q(pDst, res);
  74. /* Increment pointers */
  75. pSrcA += 8;
  76. pSrcB += 8;
  77. pDst += 8;
  78. /* Decrement the loop counter */
  79. blkCnt--;
  80. }
  81. /* Tail */
  82. blkCnt = blockSize & 0x7;
  83. if (blkCnt > 0U)
  84. {
  85. /* C = A + B */
  86. mve_pred16_t p0 = vctp16q(blkCnt);
  87. vec1 = vld1q(pSrcA);
  88. vec2 = vld1q(pSrcB);
  89. vstrhq_p(pDst, vsubq(vec1,vec2), p0);
  90. }
  91. }
  92. #else
  93. #if defined(ARM_FLOAT16_SUPPORTED)
  94. void arm_sub_f16(
  95. const float16_t * pSrcA,
  96. const float16_t * pSrcB,
  97. float16_t * pDst,
  98. uint32_t blockSize)
  99. {
  100. uint32_t blkCnt; /* Loop counter */
  101. #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
  102. /* Loop unrolling: Compute 4 outputs at a time */
  103. blkCnt = blockSize >> 2U;
  104. while (blkCnt > 0U)
  105. {
  106. /* C = A - B */
  107. /* Subtract and store result in destination buffer. */
  108. *pDst++ = (_Float16)(*pSrcA++) - (_Float16)(*pSrcB++);
  109. *pDst++ = (_Float16)(*pSrcA++) - (_Float16)(*pSrcB++);
  110. *pDst++ = (_Float16)(*pSrcA++) - (_Float16)(*pSrcB++);
  111. *pDst++ = (_Float16)(*pSrcA++) - (_Float16)(*pSrcB++);
  112. /* Decrement loop counter */
  113. blkCnt--;
  114. }
  115. /* Loop unrolling: Compute remaining outputs */
  116. blkCnt = blockSize % 0x4U;
  117. #else
  118. /* Initialize blkCnt with number of samples */
  119. blkCnt = blockSize;
  120. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  121. while (blkCnt > 0U)
  122. {
  123. /* C = A - B */
  124. /* Subtract and store result in destination buffer. */
  125. *pDst++ = (_Float16)(*pSrcA++) - (_Float16)(*pSrcB++);
  126. /* Decrement loop counter */
  127. blkCnt--;
  128. }
  129. }
  130. #endif
  131. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  132. /**
  133. @} end of BasicSub group
  134. */