Robert Lopez / CMSIS5
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_abs_f32.c Source File

arm_abs_f32.c

00001 /* ----------------------------------------------------------------------
00002  * Project:      CMSIS DSP Library
00003  * Title:        arm_abs_f32.c
00004  * Description:  Floating-point vector absolute value
00005  *
00006  * $Date:        27. January 2017
00007  * $Revision:    V.1.5.1
00008  *
00009  * Target Processor: Cortex-M cores
00010  * -------------------------------------------------------------------- */
00011 /*
00012  * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
00013  *
00014  * SPDX-License-Identifier: Apache-2.0
00015  *
00016  * Licensed under the Apache License, Version 2.0 (the License); you may
00017  * not use this file except in compliance with the License.
00018  * You may obtain a copy of the License at
00019  *
00020  * www.apache.org/licenses/LICENSE-2.0
00021  *
00022  * Unless required by applicable law or agreed to in writing, software
00023  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
00024  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00025  * See the License for the specific language governing permissions and
00026  * limitations under the License.
00027  */
00028 
00029 #include "arm_math.h"
00030 #include <math.h>
00031 
00032 /**
00033  * @ingroup groupMath
00034  */
00035 
00036 /**
00037  * @defgroup BasicAbs Vector Absolute Value
00038  *
00039  * Computes the absolute value of a vector on an element-by-element basis.
00040  *
00041  * <pre>
00042  *     pDst[n] = abs(pSrc[n]),   0 <= n < blockSize.
00043  * </pre>
00044  *
00045  * The functions support in-place computation allowing the source and
00046  * destination pointers to reference the same memory buffer.
00047  * There are separate functions for floating-point, Q7, Q15, and Q31 data types.
00048  */
00049 
00050 /**
00051  * @addtogroup BasicAbs
00052  * @{
00053  */
00054 
00055 /**
00056  * @brief Floating-point vector absolute value.
00057  * @param[in]       *pSrc points to the input buffer
00058  * @param[out]      *pDst points to the output buffer
00059  * @param[in]       blockSize number of samples in each vector
00060  * @return none.
00061  */
00062 
00063 void arm_abs_f32(
00064   float32_t * pSrc,
00065   float32_t * pDst,
00066   uint32_t blockSize)
00067 {
00068   uint32_t blkCnt;                               /* loop counter */
00069 
00070 #if defined (ARM_MATH_DSP)
00071 
00072   /* Run the below code for Cortex-M4 and Cortex-M3 */
00073   float32_t in1, in2, in3, in4;                  /* temporary variables */
00074 
00075   /*loop Unrolling */
00076   blkCnt = blockSize >> 2U;
00077 
00078   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
00079    ** a second loop below computes the remaining 1 to 3 samples. */
00080   while (blkCnt > 0U)
00081   {
00082     /* C = |A| */
00083     /* Calculate absolute and then store the results in the destination buffer. */
00084     /* read sample from source */
00085     in1 = *pSrc;
00086     in2 = *(pSrc + 1);
00087     in3 = *(pSrc + 2);
00088 
00089     /* find absolute value */
00090     in1 = fabsf(in1);
00091 
00092     /* read sample from source */
00093     in4 = *(pSrc + 3);
00094 
00095     /* find absolute value */
00096     in2 = fabsf(in2);
00097 
00098     /* read sample from source */
00099     *pDst = in1;
00100 
00101     /* find absolute value */
00102     in3 = fabsf(in3);
00103 
00104     /* find absolute value */
00105     in4 = fabsf(in4);
00106 
00107     /* store result to destination */
00108     *(pDst + 1) = in2;
00109 
00110     /* store result to destination */
00111     *(pDst + 2) = in3;
00112 
00113     /* store result to destination */
00114     *(pDst + 3) = in4;
00115 
00116 
00117     /* Update source pointer to process next sampels */
00118     pSrc += 4U;
00119 
00120     /* Update destination pointer to process next sampels */
00121     pDst += 4U;
00122 
00123     /* Decrement the loop counter */
00124     blkCnt--;
00125   }
00126 
00127   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
00128    ** No loop unrolling is used. */
00129   blkCnt = blockSize % 0x4U;
00130 
00131 #else
00132 
00133   /* Run the below code for Cortex-M0 */
00134 
00135   /* Initialize blkCnt with number of samples */
00136   blkCnt = blockSize;
00137 
00138 #endif /*   #if defined (ARM_MATH_DSP)   */
00139 
00140   while (blkCnt > 0U)
00141   {
00142     /* C = |A| */
00143     /* Calculate absolute and then store the results in the destination buffer. */
00144     *pDst++ = fabsf(*pSrc++);
00145 
00146     /* Decrement the loop counter */
00147     blkCnt--;
00148   }
00149 }
00150 
00151 /**
00152  * @} end of BasicAbs group
00153  */
00154