arm_mult_f16.c 3.9 KB

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