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