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  */
50 #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
51 
arm_fill_f16(float16_t value,float16_t * pDst,uint32_t blockSize)52 ARM_DSP_ATTRIBUTE void arm_fill_f16(
53   float16_t value,
54   float16_t * pDst,
55   uint32_t blockSize)
56 {
57      do {
58         mve_pred16_t    p = vctp16q(blockSize);
59 
60         vstrhq_p_f16(pDst,
61             vdupq_m_n_f16(vuninitializedq_f16(), value, p), p);
62         /*
63          * Decrement the blockSize loop counter
64          * Advance vector source and destination pointers
65          */
66         pDst += 8;
67         blockSize -= 8;
68     }
69     while ((int32_t) blockSize > 0);
70 }
71 #else
arm_fill_f16(float16_t value,float16_t * pDst,uint32_t blockSize)72 ARM_DSP_ATTRIBUTE void arm_fill_f16(
73   float16_t value,
74   float16_t * pDst,
75   uint32_t blockSize)
76 {
77   uint32_t blkCnt;                               /* Loop counter */
78 
79 #if defined (ARM_MATH_LOOPUNROLL)
80 
81   /* Loop unrolling: Compute 4 outputs at a time */
82   blkCnt = blockSize >> 2U;
83 
84   while (blkCnt > 0U)
85   {
86     /* C = value */
87 
88     /* Fill value in destination buffer */
89     *pDst++ = value;
90     *pDst++ = value;
91     *pDst++ = value;
92     *pDst++ = value;
93 
94     /* Decrement loop counter */
95     blkCnt--;
96   }
97 
98   /* Loop unrolling: Compute remaining outputs */
99   blkCnt = blockSize % 0x4U;
100 
101 #else
102 
103   /* Initialize blkCnt with number of samples */
104   blkCnt = blockSize;
105 
106 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
107 
108   while (blkCnt > 0U)
109   {
110     /* C = value */
111 
112     /* Fill value in destination buffer */
113     *pDst++ = value;
114 
115     /* Decrement loop counter */
116     blkCnt--;
117   }
118 }
119 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
120 
121 /**
122   @} end of Fill group
123  */
124 
125 #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
126 
127