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