arm_mult_f32.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_mult_f32.c
  4. * Description: Floating-point vector multiplication
  5. *
  6. * $Date: 18. March 2019
  7. * $Revision: V1.6.0
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2019 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 "arm_math.h"
  29. /**
  30. @ingroup groupMath
  31. */
  32. /**
  33. @defgroup BasicMult Vector Multiplication
  34. Element-by-element multiplication 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 BasicMult
  42. @{
  43. */
  44. /**
  45. @brief Floating-point vector multiplication.
  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_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  53. #include "arm_helium_utils.h"
  54. void arm_mult_f32(
  55. const float32_t * pSrcA,
  56. const float32_t * pSrcB,
  57. float32_t * pDst,
  58. uint32_t blockSize)
  59. {
  60. uint32_t blkCnt; /* Loop counter */
  61. f32x4_t vec1;
  62. f32x4_t vec2;
  63. f32x4_t res;
  64. /* Compute 4 outputs at a time */
  65. blkCnt = blockSize >> 2U;
  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 = vmulq(vec1, vec2);
  73. vst1q(pDst, res);
  74. /* Increment pointers */
  75. pSrcA += 4;
  76. pSrcB += 4;
  77. pDst += 4;
  78. /* Decrement the loop counter */
  79. blkCnt--;
  80. }
  81. /* Tail */
  82. blkCnt = blockSize & 0x3;
  83. if (blkCnt > 0U)
  84. {
  85. /* C = A + B */
  86. mve_pred16_t p0 = vctp32q(blkCnt);
  87. vec1 = vld1q(pSrcA);
  88. vec2 = vld1q(pSrcB);
  89. vstrwq_p(pDst, vmulq(vec1,vec2), p0);
  90. }
  91. }
  92. #else
  93. void arm_mult_f32(
  94. const float32_t * pSrcA,
  95. const float32_t * pSrcB,
  96. float32_t * pDst,
  97. uint32_t blockSize)
  98. {
  99. uint32_t blkCnt; /* Loop counter */
  100. #if defined(ARM_MATH_NEON) && !defined(ARM_MATH_AUTOVECTORIZE)
  101. f32x4_t vec1;
  102. f32x4_t vec2;
  103. f32x4_t res;
  104. /* Compute 4 outputs at a time */
  105. blkCnt = blockSize >> 2U;
  106. while (blkCnt > 0U)
  107. {
  108. /* C = A * B */
  109. /* Multiply the inputs and then store the results in the destination buffer. */
  110. vec1 = vld1q_f32(pSrcA);
  111. vec2 = vld1q_f32(pSrcB);
  112. res = vmulq_f32(vec1, vec2);
  113. vst1q_f32(pDst, res);
  114. /* Increment pointers */
  115. pSrcA += 4;
  116. pSrcB += 4;
  117. pDst += 4;
  118. /* Decrement the loop counter */
  119. blkCnt--;
  120. }
  121. /* Tail */
  122. blkCnt = blockSize & 0x3;
  123. #else
  124. #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
  125. /* Loop unrolling: Compute 4 outputs at a time */
  126. blkCnt = blockSize >> 2U;
  127. while (blkCnt > 0U)
  128. {
  129. /* C = A * B */
  130. /* Multiply inputs and store result in destination buffer. */
  131. *pDst++ = (*pSrcA++) * (*pSrcB++);
  132. *pDst++ = (*pSrcA++) * (*pSrcB++);
  133. *pDst++ = (*pSrcA++) * (*pSrcB++);
  134. *pDst++ = (*pSrcA++) * (*pSrcB++);
  135. /* Decrement loop counter */
  136. blkCnt--;
  137. }
  138. /* Loop unrolling: Compute remaining outputs */
  139. blkCnt = blockSize % 0x4U;
  140. #else
  141. /* Initialize blkCnt with number of samples */
  142. blkCnt = blockSize;
  143. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  144. #endif /* #if defined(ARM_MATH_NEON) */
  145. while (blkCnt > 0U)
  146. {
  147. /* C = A * B */
  148. /* Multiply input and store result in destination buffer. */
  149. *pDst++ = (*pSrcA++) * (*pSrcB++);
  150. /* Decrement loop counter */
  151. blkCnt--;
  152. }
  153. }
  154. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  155. /**
  156. @} end of BasicMult group
  157. */