1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_fill_f16.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_f16.h"
30 
31 #if defined(ARM_FLOAT16_SUPPORTED)
32 
33 
34 /**
35   @ingroup groupSupport
36  */
37 
38 
39 /**
40   @addtogroup Fill
41   @{
42  */
43 
44 /**
45   @brief         Fills a constant value into a f16 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_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
52 
arm_fill_f16(float16_t value,float16_t * pDst,uint32_t blockSize)53 void arm_fill_f16(
54   float16_t value,
55   float16_t * pDst,
56   uint32_t blockSize)
57 {
58      do {
59         mve_pred16_t    p = vctp16q(blockSize);
60 
61         vstrhq_p_f16(pDst,
62             vdupq_m_n_f16(vuninitializedq_f16(), value, p), p);
63         /*
64          * Decrement the blockSize loop counter
65          * Advance vector source and destination pointers
66          */
67         pDst += 8;
68         blockSize -= 8;
69     }
70     while ((int32_t) blockSize > 0);
71 }
72 #else
arm_fill_f16(float16_t value,float16_t * pDst,uint32_t blockSize)73 void arm_fill_f16(
74   float16_t value,
75   float16_t * pDst,
76   uint32_t blockSize)
77 {
78   uint32_t blkCnt;                               /* Loop counter */
79 
80 #if defined (ARM_MATH_LOOPUNROLL)
81 
82   /* Loop unrolling: Compute 4 outputs at a time */
83   blkCnt = blockSize >> 2U;
84 
85   while (blkCnt > 0U)
86   {
87     /* C = value */
88 
89     /* Fill value in destination buffer */
90     *pDst++ = value;
91     *pDst++ = value;
92     *pDst++ = value;
93     *pDst++ = value;
94 
95     /* Decrement loop counter */
96     blkCnt--;
97   }
98 
99   /* Loop unrolling: Compute remaining outputs */
100   blkCnt = blockSize % 0x4U;
101 
102 #else
103 
104   /* Initialize blkCnt with number of samples */
105   blkCnt = blockSize;
106 
107 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
108 
109   while (blkCnt > 0U)
110   {
111     /* C = value */
112 
113     /* Fill value in destination buffer */
114     *pDst++ = value;
115 
116     /* Decrement loop counter */
117     blkCnt--;
118   }
119 }
120 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
121 
122 /**
123   @} end of Fill group
124  */
125 
126 #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
127 
128