arm_add_f32.c
1 /* ---------------------------------------------------------------------- 2 * Project: CMSIS DSP Library 3 * Title: arm_add_f32.c 4 * Description: Floating-point vector addition 5 * 6 * $Date: 23 April 2021 7 * $Revision: V1.9.0 8 * 9 * Target Processor: Cortex-M and Cortex-A cores 10 * -------------------------------------------------------------------- */ 11 /* 12 * Copyright (C) 2010-2021 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 "dsp/basic_math_functions.h" 30 31 /** 32 @ingroup groupMath 33 */ 34 35 /** 36 @defgroup BasicAdd Vector Addition 37 38 Element-by-element addition of two vectors. 39 40 <pre> 41 pDst[n] = pSrcA[n] + pSrcB[n], 0 <= n < blockSize. 42 </pre> 43 44 There are separate functions for floating-point, Q7, Q15, and Q31 data types. 45 */ 46 47 /** 48 @addtogroup BasicAdd 49 @{ 50 */ 51 52 /** 53 @brief Floating-point vector addition. 54 @param[in] pSrcA points to first input vector 55 @param[in] pSrcB points to second input vector 56 @param[out] pDst points to output vector 57 @param[in] blockSize number of samples in each vector 58 @return none 59 */ 60 61 #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) 62 63 #include "arm_helium_utils.h" 64 65 void arm_add_f32( 66 const float32_t * pSrcA, 67 const float32_t * pSrcB, 68 float32_t * pDst, 69 uint32_t blockSize) 70 { 71 uint32_t blkCnt; /* Loop counter */ 72 73 f32x4_t vec1; 74 f32x4_t vec2; 75 f32x4_t res; 76 77 /* Compute 4 outputs at a time */ 78 blkCnt = blockSize >> 2U; 79 80 while (blkCnt > 0U) 81 { 82 /* C = A + B */ 83 84 /* Add and then store the results in the destination buffer. */ 85 vec1 = vld1q(pSrcA); 86 vec2 = vld1q(pSrcB); 87 res = vaddq(vec1, vec2); 88 vst1q(pDst, res); 89 90 /* Increment pointers */ 91 pSrcA += 4; 92 pSrcB += 4; 93 pDst += 4; 94 95 /* Decrement the loop counter */ 96 blkCnt--; 97 } 98 99 /* Tail */ 100 blkCnt = blockSize & 0x3; 101 102 if (blkCnt > 0U) 103 { 104 /* C = A + B */ 105 mve_pred16_t p0 = vctp32q(blkCnt); 106 vec1 = vld1q(pSrcA); 107 vec2 = vld1q(pSrcB); 108 vstrwq_p(pDst, vaddq(vec1,vec2), p0); 109 } 110 111 } 112 113 #else 114 void arm_add_f32( 115 const float32_t * pSrcA, 116 const float32_t * pSrcB, 117 float32_t * pDst, 118 uint32_t blockSize) 119 { 120 uint32_t blkCnt; /* Loop counter */ 121 122 #if defined(ARM_MATH_NEON) && !defined(ARM_MATH_AUTOVECTORIZE) 123 f32x4_t vec1; 124 f32x4_t vec2; 125 f32x4_t res; 126 127 /* Compute 4 outputs at a time */ 128 blkCnt = blockSize >> 2U; 129 130 while (blkCnt > 0U) 131 { 132 /* C = A + B */ 133 134 /* Add and then store the results in the destination buffer. */ 135 vec1 = vld1q_f32(pSrcA); 136 vec2 = vld1q_f32(pSrcB); 137 res = vaddq_f32(vec1, vec2); 138 vst1q_f32(pDst, res); 139 140 /* Increment pointers */ 141 pSrcA += 4; 142 pSrcB += 4; 143 pDst += 4; 144 145 /* Decrement the loop counter */ 146 blkCnt--; 147 } 148 149 /* Tail */ 150 blkCnt = blockSize & 0x3; 151 152 #else 153 #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE) 154 155 /* Loop unrolling: Compute 4 outputs at a time */ 156 blkCnt = blockSize >> 2U; 157 158 while (blkCnt > 0U) 159 { 160 /* C = A + B */ 161 162 /* Add and store result in destination buffer. */ 163 *pDst++ = (*pSrcA++) + (*pSrcB++); 164 *pDst++ = (*pSrcA++) + (*pSrcB++); 165 *pDst++ = (*pSrcA++) + (*pSrcB++); 166 *pDst++ = (*pSrcA++) + (*pSrcB++); 167 168 /* Decrement loop counter */ 169 blkCnt--; 170 } 171 172 /* Loop unrolling: Compute remaining outputs */ 173 blkCnt = blockSize % 0x4U; 174 175 #else 176 177 /* Initialize blkCnt with number of samples */ 178 blkCnt = blockSize; 179 180 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ 181 #endif /* #if defined(ARM_MATH_NEON) */ 182 183 while (blkCnt > 0U) 184 { 185 /* C = A + B */ 186 187 /* Add and store result in destination buffer. */ 188 *pDst++ = (*pSrcA++) + (*pSrcB++); 189 190 /* Decrement loop counter */ 191 blkCnt--; 192 } 193 194 } 195 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */ 196 197 /** 198 @} end of BasicAdd group 199 */