arm_copy_f32.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_copy_f32.c
  4. * Description: Copies the elements of a floating-point vector
  5. *
  6. * $Date: 23 April 2021
  7. * $Revision: V1.9.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 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 "dsp/support_functions.h"
  29. /**
  30. @ingroup groupSupport
  31. */
  32. /**
  33. @defgroup copy Vector Copy
  34. Copies sample by sample from source vector to destination vector.
  35. <pre>
  36. pDst[n] = pSrc[n]; 0 <= n < blockSize.
  37. </pre>
  38. There are separate functions for floating point, Q31, Q15, and Q7 data types.
  39. */
  40. /**
  41. @addtogroup copy
  42. @{
  43. */
  44. /**
  45. @brief Copies 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. void arm_copy_f32(
  53. const float32_t * pSrc,
  54. float32_t * pDst,
  55. uint32_t blockSize)
  56. {
  57. uint32_t blkCnt;
  58. blkCnt = blockSize >> 2U;
  59. /* Compute 4 outputs at a time */
  60. while (blkCnt > 0U)
  61. {
  62. vstrwq_f32(pDst, vldrwq_f32(pSrc));
  63. /*
  64. * Decrement the blockSize loop counter
  65. * Advance vector source and destination pointers
  66. */
  67. pSrc += 4;
  68. pDst += 4;
  69. blkCnt --;
  70. }
  71. blkCnt = blockSize & 3;
  72. while (blkCnt > 0U)
  73. {
  74. /* C = A */
  75. /* Copy and store result in destination buffer */
  76. *pDst++ = *pSrc++;
  77. /* Decrement loop counter */
  78. blkCnt--;
  79. }
  80. }
  81. #else
  82. #if defined(ARM_MATH_NEON_EXPERIMENTAL)
  83. void arm_copy_f32(
  84. const float32_t * pSrc,
  85. float32_t * pDst,
  86. uint32_t blockSize)
  87. {
  88. uint32_t blkCnt; /* loop counter */
  89. float32x4_t inV;
  90. blkCnt = blockSize >> 2U;
  91. /* Compute 4 outputs at a time.
  92. ** a second loop below computes the remaining 1 to 3 samples. */
  93. while (blkCnt > 0U)
  94. {
  95. /* C = A */
  96. /* Copy and then store the results in the destination buffer */
  97. inV = vld1q_f32(pSrc);
  98. vst1q_f32(pDst, inV);
  99. pSrc += 4;
  100. pDst += 4;
  101. /* Decrement the loop counter */
  102. blkCnt--;
  103. }
  104. /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
  105. ** No loop unrolling is used. */
  106. blkCnt = blockSize & 3;
  107. while (blkCnt > 0U)
  108. {
  109. /* C = A */
  110. /* Copy and then store the results in the destination buffer */
  111. *pDst++ = *pSrc++;
  112. /* Decrement the loop counter */
  113. blkCnt--;
  114. }
  115. }
  116. #else
  117. void arm_copy_f32(
  118. const float32_t * pSrc,
  119. float32_t * pDst,
  120. uint32_t blockSize)
  121. {
  122. uint32_t blkCnt; /* Loop counter */
  123. #if defined (ARM_MATH_LOOPUNROLL)
  124. /* Loop unrolling: Compute 4 outputs at a time */
  125. blkCnt = blockSize >> 2U;
  126. while (blkCnt > 0U)
  127. {
  128. /* C = A */
  129. /* Copy and store result in destination buffer */
  130. *pDst++ = *pSrc++;
  131. *pDst++ = *pSrc++;
  132. *pDst++ = *pSrc++;
  133. *pDst++ = *pSrc++;
  134. /* Decrement loop counter */
  135. blkCnt--;
  136. }
  137. /* Loop unrolling: Compute remaining outputs */
  138. blkCnt = blockSize % 0x4U;
  139. #else
  140. /* Initialize blkCnt with number of samples */
  141. blkCnt = blockSize;
  142. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  143. while (blkCnt > 0U)
  144. {
  145. /* C = A */
  146. /* Copy and store result in destination buffer */
  147. *pDst++ = *pSrc++;
  148. /* Decrement loop counter */
  149. blkCnt--;
  150. }
  151. }
  152. #endif /* #if defined(ARM_MATH_NEON) */
  153. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  154. /**
  155. @} end of BasicCopy group
  156. */