Subversion Repositories dashGPS

Rev

Rev 2 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /* ----------------------------------------------------------------------
  2.  * Project:      CMSIS DSP Library
  3.  * Title:        arm_q15_to_q7.c
  4.  * Description:  Converts the elements of the Q15 vector to Q7 vector
  5.  *
  6.  * $Date:        27. January 2017
  7.  * $Revision:    V.1.5.1
  8.  *
  9.  * Target Processor: Cortex-M cores
  10.  * -------------------------------------------------------------------- */
  11. /*
  12.  * Copyright (C) 2010-2017 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 "arm_math.h"
  30.  
  31. /**
  32.  * @ingroup groupSupport
  33.  */
  34.  
  35. /**
  36.  * @addtogroup q15_to_x
  37.  * @{
  38.  */
  39.  
  40.  
  41. /**
  42.  * @brief Converts the elements of the Q15 vector to Q7 vector.
  43.  * @param[in]       *pSrc points to the Q15 input vector
  44.  * @param[out]      *pDst points to the Q7 output vector
  45.  * @param[in]       blockSize length of the input vector
  46.  * @return none.
  47.  *
  48.  * \par Description:
  49.  *
  50.  * The equation used for the conversion process is:
  51.  *
  52.  * <pre>
  53.  *      pDst[n] = (q7_t) pSrc[n] >> 8;   0 <= n < blockSize.
  54.  * </pre>
  55.  *
  56.  */
  57.  
  58.  
  59. void arm_q15_to_q7(
  60.   q15_t * pSrc,
  61.   q7_t * pDst,
  62.   uint32_t blockSize)
  63. {
  64.   q15_t *pIn = pSrc;                             /* Src pointer */
  65.   uint32_t blkCnt;                               /* loop counter */
  66.  
  67. #if defined (ARM_MATH_DSP)
  68.  
  69.   /* Run the below code for Cortex-M4 and Cortex-M3 */
  70.   q31_t in1, in2;
  71.   q31_t out1, out2;
  72.  
  73.   /*loop Unrolling */
  74.   blkCnt = blockSize >> 2U;
  75.  
  76.   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
  77.    ** a second loop below computes the remaining 1 to 3 samples. */
  78.   while (blkCnt > 0U)
  79.   {
  80.     /* C = (q7_t) A >> 8 */
  81.     /* convert from q15 to q7 and then store the results in the destination buffer */
  82.     in1 = *__SIMD32(pIn)++;
  83.     in2 = *__SIMD32(pIn)++;
  84.  
  85. #ifndef ARM_MATH_BIG_ENDIAN
  86.  
  87.     out1 = __PKHTB(in2, in1, 16);
  88.     out2 = __PKHBT(in2, in1, 16);
  89.  
  90. #else
  91.  
  92.     out1 = __PKHTB(in1, in2, 16);
  93.     out2 = __PKHBT(in1, in2, 16);
  94.  
  95. #endif //      #ifndef ARM_MATH_BIG_ENDIAN
  96.  
  97.     /* rotate packed value by 24 */
  98.     out2 = ((uint32_t) out2 << 8) | ((uint32_t) out2 >> 24);
  99.  
  100.     /* anding with 0xff00ff00 to get two 8 bit values */
  101.     out1 = out1 & 0xFF00FF00;
  102.     /* anding with 0x00ff00ff to get two 8 bit values */
  103.     out2 = out2 & 0x00FF00FF;
  104.  
  105.     /* oring two values(contains two 8 bit values) to get four packed 8 bit values */
  106.     out1 = out1 | out2;
  107.  
  108.     /* store 4 samples at a time to destiantion buffer */
  109.     *__SIMD32(pDst)++ = out1;
  110.  
  111.     /* Decrement the loop counter */
  112.     blkCnt--;
  113.   }
  114.  
  115.   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
  116.    ** No loop unrolling is used. */
  117.   blkCnt = blockSize % 0x4U;
  118.  
  119. #else
  120.  
  121.   /* Run the below code for Cortex-M0 */
  122.  
  123.   /* Loop over blockSize number of values */
  124.   blkCnt = blockSize;
  125.  
  126. #endif /* #if defined (ARM_MATH_DSP) */
  127.  
  128.   while (blkCnt > 0U)
  129.   {
  130.     /* C = (q7_t) A >> 8 */
  131.     /* convert from q15 to q7 and then store the results in the destination buffer */
  132.     *pDst++ = (q7_t) (*pIn++ >> 8);
  133.  
  134.     /* Decrement the loop counter */
  135.     blkCnt--;
  136.   }
  137.  
  138. }
  139.  
  140. /**
  141.  * @} end of q15_to_x group
  142.  */
  143.