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_scale_f32.c
  4.  * Description:  Multiplies a floating-point vector by a scalar
  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.  * @defgroup scale Vector Scale
  37.  *
  38.  * Multiply a vector by a scalar value.  For floating-point data, the algorithm used is:
  39.  *
  40.  * <pre>
  41.  *     pDst[n] = pSrc[n] * scale,   0 <= n < blockSize.
  42.  * </pre>
  43.  *
  44.  * In the fixed-point Q7, Q15, and Q31 functions, <code>scale</code> is represented by
  45.  * a fractional multiplication <code>scaleFract</code> and an arithmetic shift <code>shift</code>.
  46.  * The shift allows the gain of the scaling operation to exceed 1.0.
  47.  * The algorithm used with fixed-point data is:
  48.  *
  49.  * <pre>
  50.  *     pDst[n] = (pSrc[n] * scaleFract) << shift,   0 <= n < blockSize.
  51.  * </pre>
  52.  *
  53.  * The overall scale factor applied to the fixed-point data is
  54.  * <pre>
  55.  *     scale = scaleFract * 2^shift.
  56.  * </pre>
  57.  *
  58.  * The functions support in-place computation allowing the source and destination
  59.  * pointers to reference the same memory buffer.
  60.  */
  61.  
  62. /**
  63.  * @addtogroup scale
  64.  * @{
  65.  */
  66.  
  67. /**
  68.  * @brief Multiplies a floating-point vector by a scalar.
  69.  * @param[in]       *pSrc points to the input vector
  70.  * @param[in]       scale scale factor to be applied
  71.  * @param[out]      *pDst points to the output vector
  72.  * @param[in]       blockSize number of samples in the vector
  73.  * @return none.
  74.  */
  75.  
  76.  
  77. void arm_scale_f32(
  78.   float32_t * pSrc,
  79.   float32_t scale,
  80.   float32_t * pDst,
  81.   uint32_t blockSize)
  82. {
  83.   uint32_t blkCnt;                               /* loop counter */
  84. #if defined (ARM_MATH_DSP)
  85.  
  86. /* Run the below code for Cortex-M4 and Cortex-M3 */
  87.   float32_t in1, in2, in3, in4;                  /* temporary variabels */
  88.  
  89.   /*loop Unrolling */
  90.   blkCnt = blockSize >> 2U;
  91.  
  92.   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
  93.    ** a second loop below computes the remaining 1 to 3 samples. */
  94.   while (blkCnt > 0U)
  95.   {
  96.     /* C = A * scale */
  97.     /* Scale the input and then store the results in the destination buffer. */
  98.     /* read input samples from source */
  99.     in1 = *pSrc;
  100.     in2 = *(pSrc + 1);
  101.  
  102.     /* multiply with scaling factor */
  103.     in1 = in1 * scale;
  104.  
  105.     /* read input sample from source */
  106.     in3 = *(pSrc + 2);
  107.  
  108.     /* multiply with scaling factor */
  109.     in2 = in2 * scale;
  110.  
  111.     /* read input sample from source */
  112.     in4 = *(pSrc + 3);
  113.  
  114.     /* multiply with scaling factor */
  115.     in3 = in3 * scale;
  116.     in4 = in4 * scale;
  117.     /* store the result to destination */
  118.     *pDst = in1;
  119.     *(pDst + 1) = in2;
  120.     *(pDst + 2) = in3;
  121.     *(pDst + 3) = in4;
  122.  
  123.     /* update pointers to process next samples */
  124.     pSrc += 4U;
  125.     pDst += 4U;
  126.  
  127.     /* Decrement the loop counter */
  128.     blkCnt--;
  129.   }
  130.  
  131.   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
  132.    ** No loop unrolling is used. */
  133.   blkCnt = blockSize % 0x4U;
  134.  
  135. #else
  136.  
  137.   /* Run the below code for Cortex-M0 */
  138.  
  139.   /* Initialize blkCnt with number of samples */
  140.   blkCnt = blockSize;
  141.  
  142. #endif /* #if defined (ARM_MATH_DSP) */
  143.  
  144.   while (blkCnt > 0U)
  145.   {
  146.     /* C = A * scale */
  147.     /* Scale the input and then store the result in the destination buffer. */
  148.     *pDst++ = (*pSrc++) * scale;
  149.  
  150.     /* Decrement the loop counter */
  151.     blkCnt--;
  152.   }
  153. }
  154.  
  155. /**
  156.  * @} end of scale group
  157.  */
  158.