1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_copy_f32.c
4  * Description:  Copies the elements of 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 copy Vector Copy
37 
38   Copies sample by sample from source vector to destination vector.
39 
40   <pre>
41       pDst[n] = pSrc[n];   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 copy
49   @{
50  */
51 
52 /**
53   @brief         Copies the elements of a floating-point vector.
54   @param[in]     pSrc       points to input vector
55   @param[out]    pDst       points to output vector
56   @param[in]     blockSize  number of samples in each vector
57  */
58 #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
59 
arm_copy_f32(const float32_t * pSrc,float32_t * pDst,uint32_t blockSize)60 ARM_DSP_ATTRIBUTE void arm_copy_f32(
61   const float32_t * pSrc,
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       vstrwq_f32(pDst, vldrwq_f32(pSrc));
72       /*
73        * Decrement the blockSize loop counter
74        * Advance vector source and destination pointers
75        */
76       pSrc += 4;
77       pDst += 4;
78       blkCnt --;
79   }
80 
81   blkCnt = blockSize & 3;
82 
83   while (blkCnt > 0U)
84   {
85     /* C = A */
86 
87     /* Copy and store result in destination buffer */
88     *pDst++ = *pSrc++;
89 
90     /* Decrement loop counter */
91     blkCnt--;
92   }
93 
94 }
95 
96 #else
97 #if defined(ARM_MATH_NEON_EXPERIMENTAL)
arm_copy_f32(const float32_t * pSrc,float32_t * pDst,uint32_t blockSize)98 ARM_DSP_ATTRIBUTE void arm_copy_f32(
99   const float32_t * pSrc,
100   float32_t * pDst,
101   uint32_t blockSize)
102 {
103   uint32_t blkCnt;                               /* loop counter */
104 
105   float32x4_t inV;
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 = A */
114     /* Copy and then store the results in the destination buffer */
115     inV = vld1q_f32(pSrc);
116     vst1q_f32(pDst, inV);
117     pSrc += 4;
118     pDst += 4;
119 
120     /* Decrement the loop counter */
121     blkCnt--;
122   }
123 
124   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
125    ** No loop unrolling is used. */
126   blkCnt = blockSize & 3;
127 
128   while (blkCnt > 0U)
129   {
130     /* C = A */
131     /* Copy and then store the results in the destination buffer */
132     *pDst++ = *pSrc++;
133 
134     /* Decrement the loop counter */
135     blkCnt--;
136   }
137 }
138 #else
arm_copy_f32(const float32_t * pSrc,float32_t * pDst,uint32_t blockSize)139 ARM_DSP_ATTRIBUTE void arm_copy_f32(
140   const float32_t * pSrc,
141         float32_t * pDst,
142         uint32_t blockSize)
143 {
144   uint32_t blkCnt;                               /* Loop counter */
145 
146 #if defined (ARM_MATH_LOOPUNROLL)
147 
148   /* Loop unrolling: Compute 4 outputs at a time */
149   blkCnt = blockSize >> 2U;
150 
151   while (blkCnt > 0U)
152   {
153     /* C = A */
154 
155     /* Copy and store result in destination buffer */
156     *pDst++ = *pSrc++;
157     *pDst++ = *pSrc++;
158     *pDst++ = *pSrc++;
159     *pDst++ = *pSrc++;
160 
161     /* Decrement loop counter */
162     blkCnt--;
163   }
164 
165   /* Loop unrolling: Compute remaining outputs */
166   blkCnt = blockSize % 0x4U;
167 
168 #else
169 
170   /* Initialize blkCnt with number of samples */
171   blkCnt = blockSize;
172 
173 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
174 
175   while (blkCnt > 0U)
176   {
177     /* C = A */
178 
179     /* Copy and store result in destination buffer */
180     *pDst++ = *pSrc++;
181 
182     /* Decrement loop counter */
183     blkCnt--;
184   }
185 }
186 #endif /* #if defined(ARM_MATH_NEON) */
187 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
188 
189 /**
190   @} end of BasicCopy group
191  */
192