arm_copy_f32.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. */
  50. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  51. void arm_copy_f32(
  52. const float32_t * pSrc,
  53. float32_t * pDst,
  54. uint32_t blockSize)
  55. {
  56. uint32_t blkCnt;
  57. blkCnt = blockSize >> 2U;
  58. /* Compute 4 outputs at a time */
  59. while (blkCnt > 0U)
  60. {
  61. vstrwq_f32(pDst, vldrwq_f32(pSrc));
  62. /*
  63. * Decrement the blockSize loop counter
  64. * Advance vector source and destination pointers
  65. */
  66. pSrc += 4;
  67. pDst += 4;
  68. blkCnt --;
  69. }
  70. blkCnt = blockSize & 3;
  71. while (blkCnt > 0U)
  72. {
  73. /* C = A */
  74. /* Copy and store result in destination buffer */
  75. *pDst++ = *pSrc++;
  76. /* Decrement loop counter */
  77. blkCnt--;
  78. }
  79. }
  80. #else
  81. #if defined(ARM_MATH_NEON_EXPERIMENTAL)
  82. void arm_copy_f32(
  83. const float32_t * pSrc,
  84. float32_t * pDst,
  85. uint32_t blockSize)
  86. {
  87. uint32_t blkCnt; /* loop counter */
  88. float32x4_t inV;
  89. blkCnt = blockSize >> 2U;
  90. /* Compute 4 outputs at a time.
  91. ** a second loop below computes the remaining 1 to 3 samples. */
  92. while (blkCnt > 0U)
  93. {
  94. /* C = A */
  95. /* Copy and then store the results in the destination buffer */
  96. inV = vld1q_f32(pSrc);
  97. vst1q_f32(pDst, inV);
  98. pSrc += 4;
  99. pDst += 4;
  100. /* Decrement the loop counter */
  101. blkCnt--;
  102. }
  103. /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
  104. ** No loop unrolling is used. */
  105. blkCnt = blockSize & 3;
  106. while (blkCnt > 0U)
  107. {
  108. /* C = A */
  109. /* Copy and then store the results in the destination buffer */
  110. *pDst++ = *pSrc++;
  111. /* Decrement the loop counter */
  112. blkCnt--;
  113. }
  114. }
  115. #else
  116. void arm_copy_f32(
  117. const float32_t * pSrc,
  118. float32_t * pDst,
  119. uint32_t blockSize)
  120. {
  121. uint32_t blkCnt; /* Loop counter */
  122. #if defined (ARM_MATH_LOOPUNROLL)
  123. /* Loop unrolling: Compute 4 outputs at a time */
  124. blkCnt = blockSize >> 2U;
  125. while (blkCnt > 0U)
  126. {
  127. /* C = A */
  128. /* Copy and store result in destination buffer */
  129. *pDst++ = *pSrc++;
  130. *pDst++ = *pSrc++;
  131. *pDst++ = *pSrc++;
  132. *pDst++ = *pSrc++;
  133. /* Decrement loop counter */
  134. blkCnt--;
  135. }
  136. /* Loop unrolling: Compute remaining outputs */
  137. blkCnt = blockSize % 0x4U;
  138. #else
  139. /* Initialize blkCnt with number of samples */
  140. blkCnt = blockSize;
  141. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  142. while (blkCnt > 0U)
  143. {
  144. /* C = A */
  145. /* Copy and store result in destination buffer */
  146. *pDst++ = *pSrc++;
  147. /* Decrement loop counter */
  148. blkCnt--;
  149. }
  150. }
  151. #endif /* #if defined(ARM_MATH_NEON) */
  152. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  153. /**
  154. @} end of BasicCopy group
  155. */