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_abs_q7.c
  4.  * Description:  Q7 vector absolute value
  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 groupMath
  33.  */
  34.  
  35. /**
  36.  * @addtogroup BasicAbs
  37.  * @{
  38.  */
  39.  
  40. /**
  41.  * @brief Q7 vector absolute value.
  42.  * @param[in]       *pSrc points to the input buffer
  43.  * @param[out]      *pDst points to the output buffer
  44.  * @param[in]       blockSize number of samples in each vector
  45.  * @return none.
  46.  *
  47.  * \par Conditions for optimum performance
  48.  *  Input and output buffers should be aligned by 32-bit
  49.  *
  50.  *
  51.  * <b>Scaling and Overflow Behavior:</b>
  52.  * \par
  53.  * The function uses saturating arithmetic.
  54.  * The Q7 value -1 (0x80) will be saturated to the maximum allowable positive value 0x7F.
  55.  */
  56.  
  57. void arm_abs_q7(
  58.   q7_t * pSrc,
  59.   q7_t * pDst,
  60.   uint32_t blockSize)
  61. {
  62.   uint32_t blkCnt;                               /* loop counter */
  63.   q7_t in;                                       /* Input value1 */
  64.  
  65. #if defined (ARM_MATH_DSP)
  66.  
  67.   /* Run the below code for Cortex-M4 and Cortex-M3 */
  68.   q31_t in1, in2, in3, in4;                      /* temporary input variables */
  69.   q31_t out1, out2, out3, out4;                  /* temporary output variables */
  70.  
  71.   /*loop Unrolling */
  72.   blkCnt = blockSize >> 2U;
  73.  
  74.   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
  75.    ** a second loop below computes the remaining 1 to 3 samples. */
  76.   while (blkCnt > 0U)
  77.   {
  78.     /* C = |A| */
  79.     /* Read inputs */
  80.     in1 = (q31_t) * pSrc;
  81.     in2 = (q31_t) * (pSrc + 1);
  82.     in3 = (q31_t) * (pSrc + 2);
  83.  
  84.     /* find absolute value */
  85.     out1 = (in1 > 0) ? in1 : (q31_t)__QSUB8(0, in1);
  86.  
  87.     /* read input */
  88.     in4 = (q31_t) * (pSrc + 3);
  89.  
  90.     /* find absolute value */
  91.     out2 = (in2 > 0) ? in2 : (q31_t)__QSUB8(0, in2);
  92.  
  93.     /* store result to destination */
  94.     *pDst = (q7_t) out1;
  95.  
  96.     /* find absolute value */
  97.     out3 = (in3 > 0) ? in3 : (q31_t)__QSUB8(0, in3);
  98.  
  99.     /* find absolute value */
  100.     out4 = (in4 > 0) ? in4 : (q31_t)__QSUB8(0, in4);
  101.  
  102.     /* store result to destination */
  103.     *(pDst + 1) = (q7_t) out2;
  104.  
  105.     /* store result to destination */
  106.     *(pDst + 2) = (q7_t) out3;
  107.  
  108.     /* store result to destination */
  109.     *(pDst + 3) = (q7_t) out4;
  110.  
  111.     /* update pointers to process next samples */
  112.     pSrc += 4U;
  113.     pDst += 4U;
  114.  
  115.     /* Decrement the loop counter */
  116.     blkCnt--;
  117.   }
  118.  
  119.   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
  120.    ** No loop unrolling is used. */
  121.   blkCnt = blockSize % 0x4U;
  122. #else
  123.  
  124.   /* Run the below code for Cortex-M0 */
  125.   blkCnt = blockSize;
  126.  
  127. #endif /* #define ARM_MATH_CM0_FAMILY */
  128.  
  129.   while (blkCnt > 0U)
  130.   {
  131.     /* C = |A| */
  132.     /* Read the input */
  133.     in = *pSrc++;
  134.  
  135.     /* Store the Absolute result in the destination buffer */
  136.     *pDst++ = (in > 0) ? in : ((in == (q7_t) 0x80) ? 0x7f : -in);
  137.  
  138.     /* Decrement the loop counter */
  139.     blkCnt--;
  140.   }
  141. }
  142.  
  143. /**
  144.  * @} end of BasicAbs group
  145.  */
  146.