1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_fill_q7.c
4  * Description:  Fills a constant value into a Q7 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   @addtogroup Fill
37   @{
38  */
39 
40 /**
41   @brief         Fills a constant value into a Q7 vector.
42   @param[in]     value      input value to be filled
43   @param[out]    pDst       points to output vector
44   @param[in]     blockSize  number of samples in each vector
45   @return        none
46  */
47 #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
arm_fill_q7(q7_t value,q7_t * pDst,uint32_t blockSize)48 void arm_fill_q7(
49   q7_t value,
50   q7_t * pDst,
51   uint32_t blockSize)
52 {
53   uint32_t blkCnt;
54 
55   blkCnt = blockSize >> 4;
56   while (blkCnt > 0U)
57   {
58 
59         vstrbq_s8(pDst,vdupq_n_s8(value));
60         /*
61          * Decrement the blockSize loop counter
62          * Advance vector source and destination pointers
63          */
64         pDst += 16;
65         blkCnt --;
66     }
67 
68   blkCnt = blockSize & 0xF;
69   while (blkCnt > 0U)
70   {
71     /* C = value */
72 
73     /* Fill value in destination buffer */
74     *pDst++ = value;
75 
76     /* Decrement loop counter */
77     blkCnt--;
78   }
79 }
80 #else
arm_fill_q7(q7_t value,q7_t * pDst,uint32_t blockSize)81 void arm_fill_q7(
82   q7_t value,
83   q7_t * pDst,
84   uint32_t blockSize)
85 {
86   uint32_t blkCnt;                               /* Loop counter */
87 
88 #if defined (ARM_MATH_LOOPUNROLL)
89   q31_t packedValue;                             /* value packed to 32 bits */
90 
91   /* Packing four 8 bit values to 32 bit value in order to use SIMD */
92   packedValue = __PACKq7(value, value, value, value);
93 
94   /* Loop unrolling: Compute 4 outputs at a time */
95   blkCnt = blockSize >> 2U;
96 
97   while (blkCnt > 0U)
98   {
99     /* C = value */
100 
101     /* fill 4 samples at a time */
102     write_q7x4_ia (&pDst, packedValue);
103 
104     /* Decrement loop counter */
105     blkCnt--;
106   }
107 
108   /* Loop unrolling: Compute remaining outputs */
109   blkCnt = blockSize % 0x4U;
110 
111 #else
112 
113   /* Initialize blkCnt with number of samples */
114   blkCnt = blockSize;
115 
116 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
117 
118   while (blkCnt > 0U)
119   {
120     /* C = value */
121 
122     /* Fill value in destination buffer */
123     *pDst++ = value;
124 
125     /* Decrement loop counter */
126     blkCnt--;
127   }
128 }
129 #endif /* defined(ARM_MATH_MVEI) */
130 
131 /**
132   @} end of Fill group
133  */
134