arm_negate_f16.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 "arm_math.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_MVEF) && !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. void arm_negate_f16(
  88. const float16_t * pSrc,
  89. float16_t * pDst,
  90. uint32_t blockSize)
  91. {
  92. uint32_t blkCnt; /* Loop counter */
  93. #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
  94. /* Loop unrolling: Compute 4 outputs at a time */
  95. blkCnt = blockSize >> 2U;
  96. while (blkCnt > 0U)
  97. {
  98. /* C = -A */
  99. /* Negate and store result in destination buffer. */
  100. *pDst++ = -*pSrc++;
  101. *pDst++ = -*pSrc++;
  102. *pDst++ = -*pSrc++;
  103. *pDst++ = -*pSrc++;
  104. /* Decrement loop counter */
  105. blkCnt--;
  106. }
  107. /* Loop unrolling: Compute remaining outputs */
  108. blkCnt = blockSize % 0x4U;
  109. #else
  110. /* Initialize blkCnt with number of samples */
  111. blkCnt = blockSize;
  112. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  113. while (blkCnt > 0U)
  114. {
  115. /* C = -A */
  116. /* Negate and store result in destination buffer. */
  117. *pDst++ = -*pSrc++;
  118. /* Decrement loop counter */
  119. blkCnt--;
  120. }
  121. }
  122. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  123. /**
  124. @} end of BasicNegate group
  125. */