arm_sub_f16.c
1 /* ---------------------------------------------------------------------- 2 * Project: CMSIS DSP Library 3 * Title: arm_sub_f16.c 4 * Description: Floating-point vector subtraction 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 BasicSub Vector Subtraction 37 38 Element-by-element subtraction 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 BasicSub 49 @{ 50 */ 51 52 /** 53 @brief Floating-point vector subtraction. 54 @param[in] pSrcA points to the first input vector 55 @param[in] pSrcB points to the second input vector 56 @param[out] pDst points to the output vector 57 @param[in] blockSize number of samples in each vector 58 @return none 59 */ 60 61 #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE) 62 #include "arm_helium_utils.h" 63 64 void arm_sub_f16( 65 const float16_t * pSrcA, 66 const float16_t * pSrcB, 67 float16_t * pDst, 68 uint32_t blockSize) 69 { 70 uint32_t blkCnt; /* Loop counter */ 71 72 f16x8_t vec1; 73 f16x8_t vec2; 74 f16x8_t res; 75 76 /* Compute 4 outputs at a time */ 77 blkCnt = blockSize >> 3U; 78 79 while (blkCnt > 0U) 80 { 81 /* C = A + B */ 82 83 /* Add and then store the results in the destination buffer. */ 84 vec1 = vld1q(pSrcA); 85 vec2 = vld1q(pSrcB); 86 res = vsubq(vec1, vec2); 87 vst1q(pDst, res); 88 89 /* Increment pointers */ 90 pSrcA += 8; 91 pSrcB += 8; 92 pDst += 8; 93 94 /* Decrement the loop counter */ 95 blkCnt--; 96 } 97 98 /* Tail */ 99 blkCnt = blockSize & 0x7; 100 101 if (blkCnt > 0U) 102 { 103 /* C = A + B */ 104 mve_pred16_t p0 = vctp16q(blkCnt); 105 vec1 = vld1q(pSrcA); 106 vec2 = vld1q(pSrcB); 107 vstrhq_p(pDst, vsubq(vec1,vec2), p0); 108 } 109 110 } 111 112 #else 113 #if defined(ARM_FLOAT16_SUPPORTED) 114 void arm_sub_f16( 115 const float16_t * pSrcA, 116 const float16_t * pSrcB, 117 float16_t * pDst, 118 uint32_t blockSize) 119 { 120 uint32_t blkCnt; /* Loop counter */ 121 122 #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE) 123 124 /* Loop unrolling: Compute 4 outputs at a time */ 125 blkCnt = blockSize >> 2U; 126 127 while (blkCnt > 0U) 128 { 129 /* C = A - B */ 130 131 /* Subtract and store result in destination buffer. */ 132 *pDst++ = (_Float16)(*pSrcA++) - (_Float16)(*pSrcB++); 133 134 *pDst++ = (_Float16)(*pSrcA++) - (_Float16)(*pSrcB++); 135 136 *pDst++ = (_Float16)(*pSrcA++) - (_Float16)(*pSrcB++); 137 138 *pDst++ = (_Float16)(*pSrcA++) - (_Float16)(*pSrcB++); 139 140 /* Decrement loop counter */ 141 blkCnt--; 142 } 143 144 /* Loop unrolling: Compute remaining outputs */ 145 blkCnt = blockSize % 0x4U; 146 147 #else 148 149 /* Initialize blkCnt with number of samples */ 150 blkCnt = blockSize; 151 152 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ 153 154 while (blkCnt > 0U) 155 { 156 /* C = A - B */ 157 158 /* Subtract and store result in destination buffer. */ 159 *pDst++ = (_Float16)(*pSrcA++) - (_Float16)(*pSrcB++); 160 161 /* Decrement loop counter */ 162 blkCnt--; 163 } 164 165 } 166 #endif 167 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */ 168 169 /** 170 @} end of BasicSub group 171 */