arm_fill_f32.c 4.1 KB

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