arm_add_f32.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_add_f32.c
  4. * Description: Floating-point vector addition
  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 BasicAdd Vector Addition
  34. *
  35. * Element-by-element addition 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 BasicAdd
  45. * @{
  46. */
  47. /**
  48. * @brief Floating-point vector addition.
  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_add_f32(
  56. float32_t * pSrcA,
  57. float32_t * pSrcB,
  58. float32_t * pDst,
  59. uint32_t blockSize)
  60. {
  61. uint32_t blkCnt; /* loop counter */
  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 variabels */
  65. float32_t inB1, inB2, inB3, inB4; /* temporary input variables */
  66. /*loop Unrolling */
  67. blkCnt = blockSize >> 2U;
  68. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  69. ** a second loop below computes the remaining 1 to 3 samples. */
  70. while (blkCnt > 0U)
  71. {
  72. /* C = A + B */
  73. /* Add and then store the results in the destination buffer. */
  74. /* read four inputs from sourceA and four inputs from sourceB */
  75. inA1 = *pSrcA;
  76. inB1 = *pSrcB;
  77. inA2 = *(pSrcA + 1);
  78. inB2 = *(pSrcB + 1);
  79. inA3 = *(pSrcA + 2);
  80. inB3 = *(pSrcB + 2);
  81. inA4 = *(pSrcA + 3);
  82. inB4 = *(pSrcB + 3);
  83. /* C = A + B */
  84. /* add and store result to destination */
  85. *pDst = inA1 + inB1;
  86. *(pDst + 1) = inA2 + inB2;
  87. *(pDst + 2) = inA3 + inB3;
  88. *(pDst + 3) = inA4 + inB4;
  89. /* update pointers to process next samples */
  90. pSrcA += 4U;
  91. pSrcB += 4U;
  92. pDst += 4U;
  93. /* Decrement the loop counter */
  94. blkCnt--;
  95. }
  96. /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
  97. ** No loop unrolling is used. */
  98. blkCnt = blockSize % 0x4U;
  99. #else
  100. /* Run the below code for Cortex-M0 */
  101. /* Initialize blkCnt with number of samples */
  102. blkCnt = blockSize;
  103. #endif /* #if defined (ARM_MATH_DSP) */
  104. while (blkCnt > 0U)
  105. {
  106. /* C = A + B */
  107. /* Add and then store the results in the destination buffer. */
  108. *pDst++ = (*pSrcA++) + (*pSrcB++);
  109. /* Decrement the loop counter */
  110. blkCnt--;
  111. }
  112. }
  113. /**
  114. * @} end of BasicAdd group
  115. */