arm_fill_f32.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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: 18. March 2019
  7. * $Revision: V1.6.0
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2019 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 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_NEON_EXPERIMENTAL)
  52. void arm_fill_f32(
  53. float32_t value,
  54. float32_t * pDst,
  55. uint32_t blockSize)
  56. {
  57. uint32_t blkCnt; /* loop counter */
  58. float32x4_t inV = vdupq_n_f32(value);
  59. blkCnt = blockSize >> 2U;
  60. /* Compute 4 outputs at a time.
  61. ** a second loop below computes the remaining 1 to 3 samples. */
  62. while (blkCnt > 0U)
  63. {
  64. /* C = value */
  65. /* Fill the value in the destination buffer */
  66. vst1q_f32(pDst, inV);
  67. pDst += 4;
  68. /* Decrement the loop counter */
  69. blkCnt--;
  70. }
  71. /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
  72. ** No loop unrolling is used. */
  73. blkCnt = blockSize & 3;
  74. while (blkCnt > 0U)
  75. {
  76. /* C = value */
  77. /* Fill the value in the destination buffer */
  78. *pDst++ = value;
  79. /* Decrement the loop counter */
  80. blkCnt--;
  81. }
  82. }
  83. #else
  84. void arm_fill_f32(
  85. float32_t value,
  86. float32_t * pDst,
  87. uint32_t blockSize)
  88. {
  89. uint32_t blkCnt; /* Loop counter */
  90. #if defined (ARM_MATH_LOOPUNROLL)
  91. /* Loop unrolling: Compute 4 outputs at a time */
  92. blkCnt = blockSize >> 2U;
  93. while (blkCnt > 0U)
  94. {
  95. /* C = value */
  96. /* Fill value in destination buffer */
  97. *pDst++ = value;
  98. *pDst++ = value;
  99. *pDst++ = value;
  100. *pDst++ = value;
  101. /* Decrement loop counter */
  102. blkCnt--;
  103. }
  104. /* Loop unrolling: Compute remaining outputs */
  105. blkCnt = blockSize % 0x4U;
  106. #else
  107. /* Initialize blkCnt with number of samples */
  108. blkCnt = blockSize;
  109. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  110. while (blkCnt > 0U)
  111. {
  112. /* C = value */
  113. /* Fill value in destination buffer */
  114. *pDst++ = value;
  115. /* Decrement loop counter */
  116. blkCnt--;
  117. }
  118. }
  119. #endif /* #if defined(ARM_MATH_NEON) */
  120. /**
  121. @} end of Fill group
  122. */