arm_offset_f16.c
1 /* ---------------------------------------------------------------------- 2 * Project: CMSIS DSP Library 3 * Title: arm_offset_f16.c 4 * Description: Floating-point vector offset 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_f16.h" 30 31 /** 32 @ingroup groupMath 33 */ 34 35 /** 36 @defgroup BasicOffset Vector Offset 37 38 Adds a constant offset to each element of a vector. 39 40 <pre> 41 pDst[n] = pSrc[n] + offset, 0 <= n < blockSize. 42 </pre> 43 44 The functions support in-place computation allowing the source and 45 destination pointers to reference the same memory buffer. 46 There are separate functions for floating-point, Q7, Q15, and Q31 data types. 47 */ 48 49 /** 50 @addtogroup BasicOffset 51 @{ 52 */ 53 54 /** 55 @brief Adds a constant offset to a floating-point vector. 56 @param[in] pSrc points to the input vector 57 @param[in] offset is the offset to be added 58 @param[out] pDst points to the output vector 59 @param[in] blockSize number of samples in each vector 60 @return none 61 */ 62 63 #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE) 64 65 #include "arm_helium_utils.h" 66 67 void arm_offset_f16( 68 const float16_t * pSrc, 69 float16_t offset, 70 float16_t * pDst, 71 uint32_t blockSize) 72 { 73 uint32_t blkCnt; /* Loop counter */ 74 75 f16x8_t vec1; 76 f16x8_t res; 77 78 /* Compute 4 outputs at a time */ 79 blkCnt = blockSize >> 3U; 80 while (blkCnt > 0U) 81 { 82 /* C = A + offset */ 83 84 /* Add offset and then store the results in the destination buffer. */ 85 vec1 = vld1q(pSrc); 86 res = vaddq(vec1,offset); 87 vst1q(pDst, res); 88 89 /* Increment pointers */ 90 pSrc += 8; 91 pDst += 8; 92 93 /* Decrement the loop counter */ 94 blkCnt--; 95 } 96 97 /* Tail */ 98 blkCnt = blockSize & 0x7; 99 100 if (blkCnt > 0U) 101 { 102 mve_pred16_t p0 = vctp16q(blkCnt); 103 vec1 = vld1q((float16_t const *) pSrc); 104 vstrhq_p(pDst, vaddq(vec1, offset), p0); 105 } 106 107 108 } 109 110 #else 111 #if defined(ARM_FLOAT16_SUPPORTED) 112 void arm_offset_f16( 113 const float16_t * pSrc, 114 float16_t offset, 115 float16_t * pDst, 116 uint32_t blockSize) 117 { 118 uint32_t blkCnt; /* Loop counter */ 119 120 121 #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE) 122 123 /* Loop unrolling: Compute 4 outputs at a time */ 124 blkCnt = blockSize >> 2U; 125 126 while (blkCnt > 0U) 127 { 128 /* C = A + offset */ 129 130 /* Add offset and store result in destination buffer. */ 131 *pDst++ = (_Float16)(*pSrc++) + (_Float16)offset; 132 133 *pDst++ = (_Float16)(*pSrc++) + (_Float16)offset; 134 135 *pDst++ = (_Float16)(*pSrc++) + (_Float16)offset; 136 137 *pDst++ = (_Float16)(*pSrc++) + (_Float16)offset; 138 139 /* Decrement loop counter */ 140 blkCnt--; 141 } 142 143 /* Loop unrolling: Compute remaining outputs */ 144 blkCnt = blockSize % 0x4U; 145 146 #else 147 148 /* Initialize blkCnt with number of samples */ 149 blkCnt = blockSize; 150 151 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ 152 153 while (blkCnt > 0U) 154 { 155 /* C = A + offset */ 156 157 /* Add offset and store result in destination buffer. */ 158 *pDst++ = (_Float16)(*pSrc++) + (_Float16)offset; 159 160 /* Decrement loop counter */ 161 blkCnt--; 162 } 163 164 } 165 #endif 166 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */ 167 168 /** 169 @} end of BasicOffset group 170 */