Aded CMSIS5 DSP and NN folder. Needs some work
DSP/source/BasicMathFunctions/arm_abs_f32.c@0:eedb7d567a5d, 2018-04-12 (annotated)
- Committer:
- robert_lp
- Date:
- Thu Apr 12 01:31:58 2018 +0000
- Revision:
- 0:eedb7d567a5d
CMSIS5 Library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
robert_lp | 0:eedb7d567a5d | 1 | /* ---------------------------------------------------------------------- |
robert_lp | 0:eedb7d567a5d | 2 | * Project: CMSIS DSP Library |
robert_lp | 0:eedb7d567a5d | 3 | * Title: arm_abs_f32.c |
robert_lp | 0:eedb7d567a5d | 4 | * Description: Floating-point vector absolute value |
robert_lp | 0:eedb7d567a5d | 5 | * |
robert_lp | 0:eedb7d567a5d | 6 | * $Date: 27. January 2017 |
robert_lp | 0:eedb7d567a5d | 7 | * $Revision: V.1.5.1 |
robert_lp | 0:eedb7d567a5d | 8 | * |
robert_lp | 0:eedb7d567a5d | 9 | * Target Processor: Cortex-M cores |
robert_lp | 0:eedb7d567a5d | 10 | * -------------------------------------------------------------------- */ |
robert_lp | 0:eedb7d567a5d | 11 | /* |
robert_lp | 0:eedb7d567a5d | 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. |
robert_lp | 0:eedb7d567a5d | 13 | * |
robert_lp | 0:eedb7d567a5d | 14 | * SPDX-License-Identifier: Apache-2.0 |
robert_lp | 0:eedb7d567a5d | 15 | * |
robert_lp | 0:eedb7d567a5d | 16 | * Licensed under the Apache License, Version 2.0 (the License); you may |
robert_lp | 0:eedb7d567a5d | 17 | * not use this file except in compliance with the License. |
robert_lp | 0:eedb7d567a5d | 18 | * You may obtain a copy of the License at |
robert_lp | 0:eedb7d567a5d | 19 | * |
robert_lp | 0:eedb7d567a5d | 20 | * www.apache.org/licenses/LICENSE-2.0 |
robert_lp | 0:eedb7d567a5d | 21 | * |
robert_lp | 0:eedb7d567a5d | 22 | * Unless required by applicable law or agreed to in writing, software |
robert_lp | 0:eedb7d567a5d | 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
robert_lp | 0:eedb7d567a5d | 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
robert_lp | 0:eedb7d567a5d | 25 | * See the License for the specific language governing permissions and |
robert_lp | 0:eedb7d567a5d | 26 | * limitations under the License. |
robert_lp | 0:eedb7d567a5d | 27 | */ |
robert_lp | 0:eedb7d567a5d | 28 | |
robert_lp | 0:eedb7d567a5d | 29 | #include "arm_math.h" |
robert_lp | 0:eedb7d567a5d | 30 | #include <math.h> |
robert_lp | 0:eedb7d567a5d | 31 | |
robert_lp | 0:eedb7d567a5d | 32 | /** |
robert_lp | 0:eedb7d567a5d | 33 | * @ingroup groupMath |
robert_lp | 0:eedb7d567a5d | 34 | */ |
robert_lp | 0:eedb7d567a5d | 35 | |
robert_lp | 0:eedb7d567a5d | 36 | /** |
robert_lp | 0:eedb7d567a5d | 37 | * @defgroup BasicAbs Vector Absolute Value |
robert_lp | 0:eedb7d567a5d | 38 | * |
robert_lp | 0:eedb7d567a5d | 39 | * Computes the absolute value of a vector on an element-by-element basis. |
robert_lp | 0:eedb7d567a5d | 40 | * |
robert_lp | 0:eedb7d567a5d | 41 | * <pre> |
robert_lp | 0:eedb7d567a5d | 42 | * pDst[n] = abs(pSrc[n]), 0 <= n < blockSize. |
robert_lp | 0:eedb7d567a5d | 43 | * </pre> |
robert_lp | 0:eedb7d567a5d | 44 | * |
robert_lp | 0:eedb7d567a5d | 45 | * The functions support in-place computation allowing the source and |
robert_lp | 0:eedb7d567a5d | 46 | * destination pointers to reference the same memory buffer. |
robert_lp | 0:eedb7d567a5d | 47 | * There are separate functions for floating-point, Q7, Q15, and Q31 data types. |
robert_lp | 0:eedb7d567a5d | 48 | */ |
robert_lp | 0:eedb7d567a5d | 49 | |
robert_lp | 0:eedb7d567a5d | 50 | /** |
robert_lp | 0:eedb7d567a5d | 51 | * @addtogroup BasicAbs |
robert_lp | 0:eedb7d567a5d | 52 | * @{ |
robert_lp | 0:eedb7d567a5d | 53 | */ |
robert_lp | 0:eedb7d567a5d | 54 | |
robert_lp | 0:eedb7d567a5d | 55 | /** |
robert_lp | 0:eedb7d567a5d | 56 | * @brief Floating-point vector absolute value. |
robert_lp | 0:eedb7d567a5d | 57 | * @param[in] *pSrc points to the input buffer |
robert_lp | 0:eedb7d567a5d | 58 | * @param[out] *pDst points to the output buffer |
robert_lp | 0:eedb7d567a5d | 59 | * @param[in] blockSize number of samples in each vector |
robert_lp | 0:eedb7d567a5d | 60 | * @return none. |
robert_lp | 0:eedb7d567a5d | 61 | */ |
robert_lp | 0:eedb7d567a5d | 62 | |
robert_lp | 0:eedb7d567a5d | 63 | void arm_abs_f32( |
robert_lp | 0:eedb7d567a5d | 64 | float32_t * pSrc, |
robert_lp | 0:eedb7d567a5d | 65 | float32_t * pDst, |
robert_lp | 0:eedb7d567a5d | 66 | uint32_t blockSize) |
robert_lp | 0:eedb7d567a5d | 67 | { |
robert_lp | 0:eedb7d567a5d | 68 | uint32_t blkCnt; /* loop counter */ |
robert_lp | 0:eedb7d567a5d | 69 | |
robert_lp | 0:eedb7d567a5d | 70 | #if defined (ARM_MATH_DSP) |
robert_lp | 0:eedb7d567a5d | 71 | |
robert_lp | 0:eedb7d567a5d | 72 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
robert_lp | 0:eedb7d567a5d | 73 | float32_t in1, in2, in3, in4; /* temporary variables */ |
robert_lp | 0:eedb7d567a5d | 74 | |
robert_lp | 0:eedb7d567a5d | 75 | /*loop Unrolling */ |
robert_lp | 0:eedb7d567a5d | 76 | blkCnt = blockSize >> 2U; |
robert_lp | 0:eedb7d567a5d | 77 | |
robert_lp | 0:eedb7d567a5d | 78 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. |
robert_lp | 0:eedb7d567a5d | 79 | ** a second loop below computes the remaining 1 to 3 samples. */ |
robert_lp | 0:eedb7d567a5d | 80 | while (blkCnt > 0U) |
robert_lp | 0:eedb7d567a5d | 81 | { |
robert_lp | 0:eedb7d567a5d | 82 | /* C = |A| */ |
robert_lp | 0:eedb7d567a5d | 83 | /* Calculate absolute and then store the results in the destination buffer. */ |
robert_lp | 0:eedb7d567a5d | 84 | /* read sample from source */ |
robert_lp | 0:eedb7d567a5d | 85 | in1 = *pSrc; |
robert_lp | 0:eedb7d567a5d | 86 | in2 = *(pSrc + 1); |
robert_lp | 0:eedb7d567a5d | 87 | in3 = *(pSrc + 2); |
robert_lp | 0:eedb7d567a5d | 88 | |
robert_lp | 0:eedb7d567a5d | 89 | /* find absolute value */ |
robert_lp | 0:eedb7d567a5d | 90 | in1 = fabsf(in1); |
robert_lp | 0:eedb7d567a5d | 91 | |
robert_lp | 0:eedb7d567a5d | 92 | /* read sample from source */ |
robert_lp | 0:eedb7d567a5d | 93 | in4 = *(pSrc + 3); |
robert_lp | 0:eedb7d567a5d | 94 | |
robert_lp | 0:eedb7d567a5d | 95 | /* find absolute value */ |
robert_lp | 0:eedb7d567a5d | 96 | in2 = fabsf(in2); |
robert_lp | 0:eedb7d567a5d | 97 | |
robert_lp | 0:eedb7d567a5d | 98 | /* read sample from source */ |
robert_lp | 0:eedb7d567a5d | 99 | *pDst = in1; |
robert_lp | 0:eedb7d567a5d | 100 | |
robert_lp | 0:eedb7d567a5d | 101 | /* find absolute value */ |
robert_lp | 0:eedb7d567a5d | 102 | in3 = fabsf(in3); |
robert_lp | 0:eedb7d567a5d | 103 | |
robert_lp | 0:eedb7d567a5d | 104 | /* find absolute value */ |
robert_lp | 0:eedb7d567a5d | 105 | in4 = fabsf(in4); |
robert_lp | 0:eedb7d567a5d | 106 | |
robert_lp | 0:eedb7d567a5d | 107 | /* store result to destination */ |
robert_lp | 0:eedb7d567a5d | 108 | *(pDst + 1) = in2; |
robert_lp | 0:eedb7d567a5d | 109 | |
robert_lp | 0:eedb7d567a5d | 110 | /* store result to destination */ |
robert_lp | 0:eedb7d567a5d | 111 | *(pDst + 2) = in3; |
robert_lp | 0:eedb7d567a5d | 112 | |
robert_lp | 0:eedb7d567a5d | 113 | /* store result to destination */ |
robert_lp | 0:eedb7d567a5d | 114 | *(pDst + 3) = in4; |
robert_lp | 0:eedb7d567a5d | 115 | |
robert_lp | 0:eedb7d567a5d | 116 | |
robert_lp | 0:eedb7d567a5d | 117 | /* Update source pointer to process next sampels */ |
robert_lp | 0:eedb7d567a5d | 118 | pSrc += 4U; |
robert_lp | 0:eedb7d567a5d | 119 | |
robert_lp | 0:eedb7d567a5d | 120 | /* Update destination pointer to process next sampels */ |
robert_lp | 0:eedb7d567a5d | 121 | pDst += 4U; |
robert_lp | 0:eedb7d567a5d | 122 | |
robert_lp | 0:eedb7d567a5d | 123 | /* Decrement the loop counter */ |
robert_lp | 0:eedb7d567a5d | 124 | blkCnt--; |
robert_lp | 0:eedb7d567a5d | 125 | } |
robert_lp | 0:eedb7d567a5d | 126 | |
robert_lp | 0:eedb7d567a5d | 127 | /* If the blockSize is not a multiple of 4, compute any remaining output samples here. |
robert_lp | 0:eedb7d567a5d | 128 | ** No loop unrolling is used. */ |
robert_lp | 0:eedb7d567a5d | 129 | blkCnt = blockSize % 0x4U; |
robert_lp | 0:eedb7d567a5d | 130 | |
robert_lp | 0:eedb7d567a5d | 131 | #else |
robert_lp | 0:eedb7d567a5d | 132 | |
robert_lp | 0:eedb7d567a5d | 133 | /* Run the below code for Cortex-M0 */ |
robert_lp | 0:eedb7d567a5d | 134 | |
robert_lp | 0:eedb7d567a5d | 135 | /* Initialize blkCnt with number of samples */ |
robert_lp | 0:eedb7d567a5d | 136 | blkCnt = blockSize; |
robert_lp | 0:eedb7d567a5d | 137 | |
robert_lp | 0:eedb7d567a5d | 138 | #endif /* #if defined (ARM_MATH_DSP) */ |
robert_lp | 0:eedb7d567a5d | 139 | |
robert_lp | 0:eedb7d567a5d | 140 | while (blkCnt > 0U) |
robert_lp | 0:eedb7d567a5d | 141 | { |
robert_lp | 0:eedb7d567a5d | 142 | /* C = |A| */ |
robert_lp | 0:eedb7d567a5d | 143 | /* Calculate absolute and then store the results in the destination buffer. */ |
robert_lp | 0:eedb7d567a5d | 144 | *pDst++ = fabsf(*pSrc++); |
robert_lp | 0:eedb7d567a5d | 145 | |
robert_lp | 0:eedb7d567a5d | 146 | /* Decrement the loop counter */ |
robert_lp | 0:eedb7d567a5d | 147 | blkCnt--; |
robert_lp | 0:eedb7d567a5d | 148 | } |
robert_lp | 0:eedb7d567a5d | 149 | } |
robert_lp | 0:eedb7d567a5d | 150 | |
robert_lp | 0:eedb7d567a5d | 151 | /** |
robert_lp | 0:eedb7d567a5d | 152 | * @} end of BasicAbs group |
robert_lp | 0:eedb7d567a5d | 153 | */ |
robert_lp | 0:eedb7d567a5d | 154 |