1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_copy_q15.c
4  * Description:  Copies the elements of a Q15 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 copy
37   @{
38  */
39 
40 /**
41   @brief         Copies the elements of a Q15 vector.
42   @param[in]     pSrc       points to input vector
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_copy_q15(const q15_t * pSrc,q15_t * pDst,uint32_t blockSize)47 ARM_DSP_ATTRIBUTE void arm_copy_q15(
48   const q15_t * pSrc,
49         q15_t * pDst,
50         uint32_t blockSize)
51 {
52   uint32_t blkCnt;
53 
54   blkCnt = blockSize >> 3;
55   while (blkCnt > 0U)
56   {
57       vstrhq_s16(pDst,vldrhq_s16(pSrc));
58       /*
59        * Decrement the blockSize loop counter
60        * Advance vector source and destination pointers
61        */
62       pSrc += 8;
63       pDst += 8;
64       blkCnt --;
65   }
66 
67   blkCnt = blockSize & 7;
68   while (blkCnt > 0U)
69   {
70     /* C = A */
71 
72     /* Copy and store result in destination buffer */
73     *pDst++ = *pSrc++;
74 
75     /* Decrement loop counter */
76     blkCnt--;
77   }
78 }
79 #else
arm_copy_q15(const q15_t * pSrc,q15_t * pDst,uint32_t blockSize)80 ARM_DSP_ATTRIBUTE void arm_copy_q15(
81   const q15_t * pSrc,
82         q15_t * pDst,
83         uint32_t blockSize)
84 {
85   uint32_t blkCnt;                               /* Loop counter */
86 
87 #if defined (ARM_MATH_LOOPUNROLL)
88 
89   /* Loop unrolling: Compute 4 outputs at a time */
90   blkCnt = blockSize >> 2U;
91 
92   while (blkCnt > 0U)
93   {
94     /* C = A */
95 
96     /* read 2 times 2 samples at a time */
97     write_q15x2_ia (&pDst, read_q15x2_ia (&pSrc));
98     write_q15x2_ia (&pDst, read_q15x2_ia (&pSrc));
99 
100     /* Decrement loop counter */
101     blkCnt--;
102   }
103 
104   /* Loop unrolling: Compute remaining outputs */
105   blkCnt = blockSize % 0x4U;
106 
107 #else
108 
109   /* Initialize blkCnt with number of samples */
110   blkCnt = blockSize;
111 
112 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
113 
114   while (blkCnt > 0U)
115   {
116     /* C = A */
117 
118     /* Copy and store result in destination buffer */
119     *pDst++ = *pSrc++;
120 
121     /* Decrement loop counter */
122     blkCnt--;
123   }
124 }
125 #endif /* defined(ARM_MATH_MVEI) */
126 
127 /**
128   @} end of BasicCopy group
129  */
130