arm_fill_f32.c
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 @return none 58 */ 59 #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) 60 void arm_fill_f32( 61 float32_t value, 62 float32_t * pDst, 63 uint32_t blockSize) 64 { 65 uint32_t blkCnt; 66 blkCnt = blockSize >> 2U; 67 68 /* Compute 4 outputs at a time */ 69 while (blkCnt > 0U) 70 { 71 72 vstrwq_f32(pDst,vdupq_n_f32(value)); 73 /* 74 * Decrement the blockSize loop counter 75 * Advance vector source and destination pointers 76 */ 77 pDst += 4; 78 blkCnt --; 79 } 80 81 blkCnt = blockSize & 3; 82 83 while (blkCnt > 0U) 84 { 85 /* C = value */ 86 87 /* Fill value in destination buffer */ 88 *pDst++ = value; 89 90 /* Decrement loop counter */ 91 blkCnt--; 92 } 93 94 } 95 #else 96 #if defined(ARM_MATH_NEON_EXPERIMENTAL) 97 void arm_fill_f32( 98 float32_t value, 99 float32_t * pDst, 100 uint32_t blockSize) 101 { 102 uint32_t blkCnt; /* loop counter */ 103 104 105 float32x4_t inV = vdupq_n_f32(value); 106 107 blkCnt = blockSize >> 2U; 108 109 /* Compute 4 outputs at a time. 110 ** a second loop below computes the remaining 1 to 3 samples. */ 111 while (blkCnt > 0U) 112 { 113 /* C = value */ 114 /* Fill the value in the destination buffer */ 115 vst1q_f32(pDst, inV); 116 pDst += 4; 117 118 /* Decrement the loop counter */ 119 blkCnt--; 120 } 121 122 /* If the blockSize is not a multiple of 4, compute any remaining output samples here. 123 ** No loop unrolling is used. */ 124 blkCnt = blockSize & 3; 125 126 while (blkCnt > 0U) 127 { 128 /* C = value */ 129 /* Fill the value in the destination buffer */ 130 *pDst++ = value; 131 132 /* Decrement the loop counter */ 133 blkCnt--; 134 } 135 } 136 #else 137 void arm_fill_f32( 138 float32_t value, 139 float32_t * pDst, 140 uint32_t blockSize) 141 { 142 uint32_t blkCnt; /* Loop counter */ 143 144 #if defined (ARM_MATH_LOOPUNROLL) 145 146 /* Loop unrolling: Compute 4 outputs at a time */ 147 blkCnt = blockSize >> 2U; 148 149 while (blkCnt > 0U) 150 { 151 /* C = value */ 152 153 /* Fill value in destination buffer */ 154 *pDst++ = value; 155 *pDst++ = value; 156 *pDst++ = value; 157 *pDst++ = value; 158 159 /* Decrement loop counter */ 160 blkCnt--; 161 } 162 163 /* Loop unrolling: Compute remaining outputs */ 164 blkCnt = blockSize % 0x4U; 165 166 #else 167 168 /* Initialize blkCnt with number of samples */ 169 blkCnt = blockSize; 170 171 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ 172 173 while (blkCnt > 0U) 174 { 175 /* C = value */ 176 177 /* Fill value in destination buffer */ 178 *pDst++ = value; 179 180 /* Decrement loop counter */ 181 blkCnt--; 182 } 183 } 184 #endif /* #if defined(ARM_MATH_NEON) */ 185 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */ 186 187 /** 188 @} end of Fill group 189 */