arm_negate_f16.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_negate_f16.c
  4. * Description: Negates floating-point vectors
  5. *
  6. *
  7. * Target Processor: Cortex-M cores
  8. * -------------------------------------------------------------------- */
  9. /*
  10. * Copyright (C) 2010-2020 ARM Limited or its affiliates. All rights reserved.
  11. *
  12. * SPDX-License-Identifier: Apache-2.0
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the License); you may
  15. * not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at
  17. *
  18. * www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  22. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. */
  26. #include "dsp/basic_math_functions_f16.h"
  27. /**
  28. @ingroup groupMath
  29. */
  30. /**
  31. @defgroup BasicNegate Vector Negate
  32. Negates the elements of a vector.
  33. <pre>
  34. pDst[n] = -pSrc[n], 0 <= n < blockSize.
  35. </pre>
  36. The functions support in-place computation allowing the source and
  37. destination pointers to reference the same memory buffer.
  38. There are separate functions for floating-point, Q7, Q15, and Q31 data types.
  39. */
  40. /**
  41. @addtogroup BasicNegate
  42. @{
  43. */
  44. /**
  45. @brief Negates the elements of a floating-point vector.
  46. @param[in] pSrc points to input vector.
  47. @param[out] pDst points to output vector.
  48. @param[in] blockSize number of samples in each vector.
  49. @return none
  50. */
  51. #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
  52. #include "arm_helium_utils.h"
  53. void arm_negate_f16(
  54. const float16_t * pSrc,
  55. float16_t * pDst,
  56. uint32_t blockSize)
  57. {
  58. uint32_t blkCnt; /* Loop counter */
  59. f16x8_t vec1;
  60. f16x8_t res;
  61. /* Compute 4 outputs at a time */
  62. blkCnt = blockSize >> 3U;
  63. while (blkCnt > 0U)
  64. {
  65. /* C = |A| */
  66. /* Calculate absolute values and then store the results in the destination buffer. */
  67. vec1 = vld1q(pSrc);
  68. res = vnegq(vec1);
  69. vst1q(pDst, res);
  70. /* Increment pointers */
  71. pSrc += 8;
  72. pDst += 8;
  73. /* Decrement the loop counter */
  74. blkCnt--;
  75. }
  76. /* Tail */
  77. blkCnt = blockSize & 0x7;
  78. if (blkCnt > 0U)
  79. {
  80. /* C = |A| */
  81. mve_pred16_t p0 = vctp16q(blkCnt);
  82. vec1 = vld1q((float16_t const *) pSrc);
  83. vstrhq_p(pDst, vnegq(vec1), p0);
  84. }
  85. }
  86. #else
  87. #if defined(ARM_FLOAT16_SUPPORTED)
  88. void arm_negate_f16(
  89. const float16_t * pSrc,
  90. float16_t * pDst,
  91. uint32_t blockSize)
  92. {
  93. uint32_t blkCnt; /* Loop counter */
  94. #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
  95. /* Loop unrolling: Compute 4 outputs at a time */
  96. blkCnt = blockSize >> 2U;
  97. while (blkCnt > 0U)
  98. {
  99. /* C = -A */
  100. /* Negate and store result in destination buffer. */
  101. *pDst++ = -*pSrc++;
  102. *pDst++ = -*pSrc++;
  103. *pDst++ = -*pSrc++;
  104. *pDst++ = -*pSrc++;
  105. /* Decrement loop counter */
  106. blkCnt--;
  107. }
  108. /* Loop unrolling: Compute remaining outputs */
  109. blkCnt = blockSize % 0x4U;
  110. #else
  111. /* Initialize blkCnt with number of samples */
  112. blkCnt = blockSize;
  113. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  114. while (blkCnt > 0U)
  115. {
  116. /* C = -A */
  117. /* Negate and store result in destination buffer. */
  118. *pDst++ = -*pSrc++;
  119. /* Decrement loop counter */
  120. blkCnt--;
  121. }
  122. }
  123. #endif
  124. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  125. /**
  126. @} end of BasicNegate group
  127. */