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   @return        none
58  */
59 #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
60 
arm_copy_f32(const float32_t * pSrc,float32_t * pDst,uint32_t blockSize)61 void arm_copy_f32(
62   const float32_t * pSrc,
63   float32_t * pDst,
64   uint32_t blockSize)
65 {
66   uint32_t blkCnt;
67   blkCnt = blockSize >> 2U;
68 
69   /* Compute 4 outputs at a time */
70   while (blkCnt > 0U)
71   {
72       vstrwq_f32(pDst, vldrwq_f32(pSrc));
73       /*
74        * Decrement the blockSize loop counter
75        * Advance vector source and destination pointers
76        */
77       pSrc += 4;
78       pDst += 4;
79       blkCnt --;
80   }
81 
82   blkCnt = blockSize & 3;
83 
84   while (blkCnt > 0U)
85   {
86     /* C = A */
87 
88     /* Copy and store result in destination buffer */
89     *pDst++ = *pSrc++;
90 
91     /* Decrement loop counter */
92     blkCnt--;
93   }
94 
95 }
96 
97 #else
98 #if defined(ARM_MATH_NEON_EXPERIMENTAL)
arm_copy_f32(const float32_t * pSrc,float32_t * pDst,uint32_t blockSize)99 void arm_copy_f32(
100   const float32_t * pSrc,
101   float32_t * pDst,
102   uint32_t blockSize)
103 {
104   uint32_t blkCnt;                               /* loop counter */
105 
106   float32x4_t inV;
107 
108   blkCnt = blockSize >> 2U;
109 
110   /* Compute 4 outputs at a time.
111    ** a second loop below computes the remaining 1 to 3 samples. */
112   while (blkCnt > 0U)
113   {
114     /* C = A */
115     /* Copy and then store the results in the destination buffer */
116     inV = vld1q_f32(pSrc);
117     vst1q_f32(pDst, inV);
118     pSrc += 4;
119     pDst += 4;
120 
121     /* Decrement the loop counter */
122     blkCnt--;
123   }
124 
125   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
126    ** No loop unrolling is used. */
127   blkCnt = blockSize & 3;
128 
129   while (blkCnt > 0U)
130   {
131     /* C = A */
132     /* Copy and then store the results in the destination buffer */
133     *pDst++ = *pSrc++;
134 
135     /* Decrement the loop counter */
136     blkCnt--;
137   }
138 }
139 #else
arm_copy_f32(const float32_t * pSrc,float32_t * pDst,uint32_t blockSize)140 void arm_copy_f32(
141   const float32_t * pSrc,
142         float32_t * pDst,
143         uint32_t blockSize)
144 {
145   uint32_t blkCnt;                               /* Loop counter */
146 
147 #if defined (ARM_MATH_LOOPUNROLL)
148 
149   /* Loop unrolling: Compute 4 outputs at a time */
150   blkCnt = blockSize >> 2U;
151 
152   while (blkCnt > 0U)
153   {
154     /* C = A */
155 
156     /* Copy and store result in destination buffer */
157     *pDst++ = *pSrc++;
158     *pDst++ = *pSrc++;
159     *pDst++ = *pSrc++;
160     *pDst++ = *pSrc++;
161 
162     /* Decrement loop counter */
163     blkCnt--;
164   }
165 
166   /* Loop unrolling: Compute remaining outputs */
167   blkCnt = blockSize % 0x4U;
168 
169 #else
170 
171   /* Initialize blkCnt with number of samples */
172   blkCnt = blockSize;
173 
174 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
175 
176   while (blkCnt > 0U)
177   {
178     /* C = A */
179 
180     /* Copy and store result in destination buffer */
181     *pDst++ = *pSrc++;
182 
183     /* Decrement loop counter */
184     blkCnt--;
185   }
186 }
187 #endif /* #if defined(ARM_MATH_NEON) */
188 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
189 
190 /**
191   @} end of BasicCopy group
192  */
193