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