arm_fill_f32.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_fill_f32.c
  4. * Description: Fills a constant value into 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 Fill Vector Fill
  34. Fills the destination vector with a constant value.
  35. <pre>
  36. pDst[n] = value; 0 <= n < blockSize.
  37. </pre>
  38. There are separate functions for floating point, Q31, Q15, and Q7 data types.
  39. */
  40. /**
  41. @addtogroup Fill
  42. @{
  43. */
  44. /**
  45. @brief Fills a constant value into a floating-point vector.
  46. @param[in] value input value to be filled
  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_fill_f32(
  52. float32_t value,
  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,vdupq_n_f32(value));
  62. /*
  63. * Decrement the blockSize loop counter
  64. * Advance vector source and destination pointers
  65. */
  66. pDst += 4;
  67. blkCnt --;
  68. }
  69. blkCnt = blockSize & 3;
  70. while (blkCnt > 0U)
  71. {
  72. /* C = value */
  73. /* Fill value in destination buffer */
  74. *pDst++ = value;
  75. /* Decrement loop counter */
  76. blkCnt--;
  77. }
  78. }
  79. #else
  80. #if defined(ARM_MATH_NEON_EXPERIMENTAL)
  81. void arm_fill_f32(
  82. float32_t value,
  83. float32_t * pDst,
  84. uint32_t blockSize)
  85. {
  86. uint32_t blkCnt; /* loop counter */
  87. float32x4_t inV = vdupq_n_f32(value);
  88. blkCnt = blockSize >> 2U;
  89. /* Compute 4 outputs at a time.
  90. ** a second loop below computes the remaining 1 to 3 samples. */
  91. while (blkCnt > 0U)
  92. {
  93. /* C = value */
  94. /* Fill the value in the destination buffer */
  95. vst1q_f32(pDst, inV);
  96. pDst += 4;
  97. /* Decrement the loop counter */
  98. blkCnt--;
  99. }
  100. /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
  101. ** No loop unrolling is used. */
  102. blkCnt = blockSize & 3;
  103. while (blkCnt > 0U)
  104. {
  105. /* C = value */
  106. /* Fill the value in the destination buffer */
  107. *pDst++ = value;
  108. /* Decrement the loop counter */
  109. blkCnt--;
  110. }
  111. }
  112. #else
  113. void arm_fill_f32(
  114. float32_t value,
  115. float32_t * pDst,
  116. uint32_t blockSize)
  117. {
  118. uint32_t blkCnt; /* Loop counter */
  119. #if defined (ARM_MATH_LOOPUNROLL)
  120. /* Loop unrolling: Compute 4 outputs at a time */
  121. blkCnt = blockSize >> 2U;
  122. while (blkCnt > 0U)
  123. {
  124. /* C = value */
  125. /* Fill value in destination buffer */
  126. *pDst++ = value;
  127. *pDst++ = value;
  128. *pDst++ = value;
  129. *pDst++ = value;
  130. /* Decrement loop counter */
  131. blkCnt--;
  132. }
  133. /* Loop unrolling: Compute remaining outputs */
  134. blkCnt = blockSize % 0x4U;
  135. #else
  136. /* Initialize blkCnt with number of samples */
  137. blkCnt = blockSize;
  138. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  139. while (blkCnt > 0U)
  140. {
  141. /* C = value */
  142. /* Fill value in destination buffer */
  143. *pDst++ = value;
  144. /* Decrement loop counter */
  145. blkCnt--;
  146. }
  147. }
  148. #endif /* #if defined(ARM_MATH_NEON) */
  149. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  150. /**
  151. @} end of Fill group
  152. */