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 
29 #include "dsp/support_functions.h"
30 
31 /**
32   @ingroup groupSupport
33  */
34 
35 /**
36   @defgroup Fill Vector Fill
37 
38   Fills the destination vector with a constant value.
39 
40   <pre>
41       pDst[n] = value;   0 <= n < blockSize.
42   </pre>
43 
44   There are separate functions for floating point, Q31, Q15, and Q7 data types.
45  */
46 
47 /**
48   @addtogroup Fill
49   @{
50  */
51 
52 /**
53   @brief         Fills a constant value into a floating-point vector.
54   @param[in]     value      input value to be filled
55   @param[out]    pDst       points to output vector
56   @param[in]     blockSize  number of samples in each vector
57  */
58 #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
arm_fill_f32(float32_t value,float32_t * pDst,uint32_t blockSize)59 ARM_DSP_ATTRIBUTE void arm_fill_f32(
60   float32_t value,
61   float32_t * pDst,
62   uint32_t blockSize)
63 {
64   uint32_t blkCnt;
65   blkCnt = blockSize >> 2U;
66 
67   /* Compute 4 outputs at a time */
68   while (blkCnt > 0U)
69   {
70 
71     vstrwq_f32(pDst,vdupq_n_f32(value));
72     /*
73      * Decrement the blockSize loop counter
74      * Advance vector source and destination pointers
75      */
76     pDst += 4;
77     blkCnt --;
78   }
79 
80   blkCnt = blockSize & 3;
81 
82   while (blkCnt > 0U)
83   {
84     /* C = value */
85 
86     /* Fill value in destination buffer */
87     *pDst++ = value;
88 
89     /* Decrement loop counter */
90     blkCnt--;
91   }
92 
93 }
94 #else
95 #if defined(ARM_MATH_NEON_EXPERIMENTAL)
arm_fill_f32(float32_t value,float32_t * pDst,uint32_t blockSize)96 ARM_DSP_ATTRIBUTE void arm_fill_f32(
97   float32_t value,
98   float32_t * pDst,
99   uint32_t blockSize)
100 {
101   uint32_t blkCnt;                               /* loop counter */
102 
103 
104   float32x4_t inV = vdupq_n_f32(value);
105 
106   blkCnt = blockSize >> 2U;
107 
108   /* Compute 4 outputs at a time.
109    ** a second loop below computes the remaining 1 to 3 samples. */
110   while (blkCnt > 0U)
111   {
112     /* C = value */
113     /* Fill the value in the destination buffer */
114     vst1q_f32(pDst, inV);
115     pDst += 4;
116 
117     /* Decrement the loop counter */
118     blkCnt--;
119   }
120 
121   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
122    ** No loop unrolling is used. */
123   blkCnt = blockSize & 3;
124 
125   while (blkCnt > 0U)
126   {
127     /* C = value */
128     /* Fill the value in the destination buffer */
129     *pDst++ = value;
130 
131     /* Decrement the loop counter */
132     blkCnt--;
133   }
134 }
135 #else
arm_fill_f32(float32_t value,float32_t * pDst,uint32_t blockSize)136 ARM_DSP_ATTRIBUTE void arm_fill_f32(
137   float32_t value,
138   float32_t * pDst,
139   uint32_t blockSize)
140 {
141   uint32_t blkCnt;                               /* Loop counter */
142 
143 #if defined (ARM_MATH_LOOPUNROLL)
144 
145   /* Loop unrolling: Compute 4 outputs at a time */
146   blkCnt = blockSize >> 2U;
147 
148   while (blkCnt > 0U)
149   {
150     /* C = value */
151 
152     /* Fill value in destination buffer */
153     *pDst++ = value;
154     *pDst++ = value;
155     *pDst++ = value;
156     *pDst++ = value;
157 
158     /* Decrement loop counter */
159     blkCnt--;
160   }
161 
162   /* Loop unrolling: Compute remaining outputs */
163   blkCnt = blockSize % 0x4U;
164 
165 #else
166 
167   /* Initialize blkCnt with number of samples */
168   blkCnt = blockSize;
169 
170 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
171 
172   while (blkCnt > 0U)
173   {
174     /* C = value */
175 
176     /* Fill value in destination buffer */
177     *pDst++ = value;
178 
179     /* Decrement loop counter */
180     blkCnt--;
181   }
182 }
183 #endif /* #if defined(ARM_MATH_NEON) */
184 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
185 
186 /**
187   @} end of Fill group
188  */
189