arm_mult_f32.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_mult_f32.c
  4. * Description: Floating-point vector multiplication
  5. *
  6. * $Date: 27. January 2017
  7. * $Revision: V.1.5.1
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2017 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. *
  35. * Element-by-element multiplication of two vectors.
  36. *
  37. * <pre>
  38. * pDst[n] = pSrcA[n] * pSrcB[n], 0 <= n < blockSize.
  39. * </pre>
  40. *
  41. * There are separate functions for floating-point, Q7, Q15, and Q31 data types.
  42. */
  43. /**
  44. * @addtogroup BasicMult
  45. * @{
  46. */
  47. /**
  48. * @brief Floating-point vector multiplication.
  49. * @param[in] *pSrcA points to the first input vector
  50. * @param[in] *pSrcB points to the second input vector
  51. * @param[out] *pDst points to the output vector
  52. * @param[in] blockSize number of samples in each vector
  53. * @return none.
  54. */
  55. void arm_mult_f32(
  56. float32_t * pSrcA,
  57. float32_t * pSrcB,
  58. float32_t * pDst,
  59. uint32_t blockSize)
  60. {
  61. uint32_t blkCnt; /* loop counters */
  62. #if defined (ARM_MATH_DSP)
  63. /* Run the below code for Cortex-M4 and Cortex-M3 */
  64. float32_t inA1, inA2, inA3, inA4; /* temporary input variables */
  65. float32_t inB1, inB2, inB3, inB4; /* temporary input variables */
  66. float32_t out1, out2, out3, out4; /* temporary output variables */
  67. /* loop Unrolling */
  68. blkCnt = blockSize >> 2U;
  69. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  70. ** a second loop below computes the remaining 1 to 3 samples. */
  71. while (blkCnt > 0U)
  72. {
  73. /* C = A * B */
  74. /* Multiply the inputs and store the results in output buffer */
  75. /* read sample from sourceA */
  76. inA1 = *pSrcA;
  77. /* read sample from sourceB */
  78. inB1 = *pSrcB;
  79. /* read sample from sourceA */
  80. inA2 = *(pSrcA + 1);
  81. /* read sample from sourceB */
  82. inB2 = *(pSrcB + 1);
  83. /* out = sourceA * sourceB */
  84. out1 = inA1 * inB1;
  85. /* read sample from sourceA */
  86. inA3 = *(pSrcA + 2);
  87. /* read sample from sourceB */
  88. inB3 = *(pSrcB + 2);
  89. /* out = sourceA * sourceB */
  90. out2 = inA2 * inB2;
  91. /* read sample from sourceA */
  92. inA4 = *(pSrcA + 3);
  93. /* store result to destination buffer */
  94. *pDst = out1;
  95. /* read sample from sourceB */
  96. inB4 = *(pSrcB + 3);
  97. /* out = sourceA * sourceB */
  98. out3 = inA3 * inB3;
  99. /* store result to destination buffer */
  100. *(pDst + 1) = out2;
  101. /* out = sourceA * sourceB */
  102. out4 = inA4 * inB4;
  103. /* store result to destination buffer */
  104. *(pDst + 2) = out3;
  105. /* store result to destination buffer */
  106. *(pDst + 3) = out4;
  107. /* update pointers to process next samples */
  108. pSrcA += 4U;
  109. pSrcB += 4U;
  110. pDst += 4U;
  111. /* Decrement the blockSize loop counter */
  112. blkCnt--;
  113. }
  114. /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
  115. ** No loop unrolling is used. */
  116. blkCnt = blockSize % 0x4U;
  117. #else
  118. /* Run the below code for Cortex-M0 */
  119. /* Initialize blkCnt with number of samples */
  120. blkCnt = blockSize;
  121. #endif /* #if defined (ARM_MATH_DSP) */
  122. while (blkCnt > 0U)
  123. {
  124. /* C = A * B */
  125. /* Multiply the inputs and store the results in output buffer */
  126. *pDst++ = (*pSrcA++) * (*pSrcB++);
  127. /* Decrement the blockSize loop counter */
  128. blkCnt--;
  129. }
  130. }
  131. /**
  132. * @} end of BasicMult group
  133. */