1 /* ARM FP16 intrinsics include file.
2 
3    Copyright (C) 2016-2021 Free Software Foundation, Inc.
4    Contributed by ARM Ltd.
5 
6    This file is part of GCC.
7 
8    GCC is free software; you can redistribute it and/or modify it
9    under the terms of the GNU General Public License as published
10    by the Free Software Foundation; either version 3, or (at your
11    option) any later version.
12 
13    GCC is distributed in the hope that it will be useful, but WITHOUT
14    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16    License for more details.
17 
18    Under Section 7 of GPL version 3, you are granted additional
19    permissions described in the GCC Runtime Library Exception, version
20    3.1, as published by the Free Software Foundation.
21 
22    You should have received a copy of the GNU General Public License and
23    a copy of the GCC Runtime Library Exception along with this program;
24    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
25    <http://www.gnu.org/licenses/>.  */
26 
27 #ifndef _GCC_ARM_FP16_H
28 #define _GCC_ARM_FP16_H 1
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include <stdint.h>
35 
36 /* Intrinsics for FP16 instructions.  */
37 #pragma GCC push_options
38 #pragma GCC target ("fpu=fp-armv8")
39 
40 #if defined (__ARM_FEATURE_FP16_SCALAR_ARITHMETIC)
41 
42 typedef __fp16 float16_t;
43 
44 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vabsh_f16(float16_t __a)45 vabsh_f16 (float16_t __a)
46 {
47   return __builtin_neon_vabshf (__a);
48 }
49 
50 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vaddh_f16(float16_t __a,float16_t __b)51 vaddh_f16 (float16_t __a, float16_t __b)
52 {
53   return __a + __b;
54 }
55 
56 __extension__ static __inline int32_t __attribute__ ((__always_inline__))
vcvtah_s32_f16(float16_t __a)57 vcvtah_s32_f16 (float16_t __a)
58 {
59   return __builtin_neon_vcvtahssi (__a);
60 }
61 
62 __extension__ static __inline uint32_t __attribute__ ((__always_inline__))
vcvtah_u32_f16(float16_t __a)63 vcvtah_u32_f16 (float16_t __a)
64 {
65   return __builtin_neon_vcvtahusi (__a);
66 }
67 
68 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vcvth_f16_s32(int32_t __a)69 vcvth_f16_s32 (int32_t __a)
70 {
71   return __builtin_neon_vcvthshf (__a);
72 }
73 
74 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vcvth_f16_u32(uint32_t __a)75 vcvth_f16_u32 (uint32_t __a)
76 {
77   return __builtin_neon_vcvthuhf (__a);
78 }
79 
80 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vcvth_n_f16_s32(int32_t __a,const int __b)81 vcvth_n_f16_s32 (int32_t __a, const int __b)
82 {
83   return __builtin_neon_vcvths_nhf (__a, __b);
84 }
85 
86 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vcvth_n_f16_u32(uint32_t __a,const int __b)87 vcvth_n_f16_u32 (uint32_t __a, const int __b)
88 {
89   return __builtin_neon_vcvthu_nhf ((int32_t)__a, __b);
90 }
91 
92 __extension__ static __inline int32_t __attribute__ ((__always_inline__))
vcvth_n_s32_f16(float16_t __a,const int __b)93 vcvth_n_s32_f16 (float16_t __a, const int __b)
94 {
95   return __builtin_neon_vcvths_nsi (__a, __b);
96 }
97 
98 __extension__ static __inline uint32_t __attribute__ ((__always_inline__))
vcvth_n_u32_f16(float16_t __a,const int __b)99 vcvth_n_u32_f16 (float16_t __a, const int __b)
100 {
101   return (uint32_t)__builtin_neon_vcvthu_nsi (__a, __b);
102 }
103 
104 __extension__ static __inline int32_t __attribute__ ((__always_inline__))
vcvth_s32_f16(float16_t __a)105 vcvth_s32_f16 (float16_t __a)
106 {
107   return __builtin_neon_vcvthssi (__a);
108 }
109 
110 __extension__ static __inline uint32_t __attribute__ ((__always_inline__))
vcvth_u32_f16(float16_t __a)111 vcvth_u32_f16 (float16_t __a)
112 {
113   return __builtin_neon_vcvthusi (__a);
114 }
115 
116 __extension__ static __inline int32_t __attribute__ ((__always_inline__))
vcvtmh_s32_f16(float16_t __a)117 vcvtmh_s32_f16 (float16_t __a)
118 {
119   return __builtin_neon_vcvtmhssi (__a);
120 }
121 
122 __extension__ static __inline uint32_t __attribute__ ((__always_inline__))
vcvtmh_u32_f16(float16_t __a)123 vcvtmh_u32_f16 (float16_t __a)
124 {
125   return __builtin_neon_vcvtmhusi (__a);
126 }
127 
128 __extension__ static __inline int32_t __attribute__ ((__always_inline__))
vcvtnh_s32_f16(float16_t __a)129 vcvtnh_s32_f16 (float16_t __a)
130 {
131   return __builtin_neon_vcvtnhssi (__a);
132 }
133 
134 __extension__ static __inline uint32_t __attribute__ ((__always_inline__))
vcvtnh_u32_f16(float16_t __a)135 vcvtnh_u32_f16 (float16_t __a)
136 {
137   return __builtin_neon_vcvtnhusi (__a);
138 }
139 
140 __extension__ static __inline int32_t __attribute__ ((__always_inline__))
vcvtph_s32_f16(float16_t __a)141 vcvtph_s32_f16 (float16_t __a)
142 {
143   return __builtin_neon_vcvtphssi (__a);
144 }
145 
146 __extension__ static __inline uint32_t __attribute__ ((__always_inline__))
vcvtph_u32_f16(float16_t __a)147 vcvtph_u32_f16 (float16_t __a)
148 {
149   return __builtin_neon_vcvtphusi (__a);
150 }
151 
152 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vdivh_f16(float16_t __a,float16_t __b)153 vdivh_f16 (float16_t __a, float16_t __b)
154 {
155   return __a / __b;
156 }
157 
158 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vfmah_f16(float16_t __a,float16_t __b,float16_t __c)159 vfmah_f16 (float16_t __a, float16_t __b, float16_t __c)
160 {
161   return __builtin_neon_vfmahf (__a, __b, __c);
162 }
163 
164 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vfmsh_f16(float16_t __a,float16_t __b,float16_t __c)165 vfmsh_f16 (float16_t __a, float16_t __b, float16_t __c)
166 {
167   return __builtin_neon_vfmshf (__a, __b, __c);
168 }
169 
170 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vmaxnmh_f16(float16_t __a,float16_t __b)171 vmaxnmh_f16 (float16_t __a, float16_t __b)
172 {
173   return __builtin_neon_vmaxnmhf (__a, __b);
174 }
175 
176 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vminnmh_f16(float16_t __a,float16_t __b)177 vminnmh_f16 (float16_t __a, float16_t __b)
178 {
179   return __builtin_neon_vminnmhf (__a, __b);
180 }
181 
182 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vmulh_f16(float16_t __a,float16_t __b)183 vmulh_f16 (float16_t __a, float16_t __b)
184 {
185   return __a * __b;
186 }
187 
188 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vnegh_f16(float16_t __a)189 vnegh_f16 (float16_t __a)
190 {
191   return  - __a;
192 }
193 
194 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vrndah_f16(float16_t __a)195 vrndah_f16 (float16_t __a)
196 {
197   return __builtin_neon_vrndahf (__a);
198 }
199 
200 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vrndh_f16(float16_t __a)201 vrndh_f16 (float16_t __a)
202 {
203   return __builtin_neon_vrndhf (__a);
204 }
205 
206 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vrndih_f16(float16_t __a)207 vrndih_f16 (float16_t __a)
208 {
209   return __builtin_neon_vrndihf (__a);
210 }
211 
212 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vrndmh_f16(float16_t __a)213 vrndmh_f16 (float16_t __a)
214 {
215   return __builtin_neon_vrndmhf (__a);
216 }
217 
218 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vrndnh_f16(float16_t __a)219 vrndnh_f16 (float16_t __a)
220 {
221   return __builtin_neon_vrndnhf (__a);
222 }
223 
224 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vrndph_f16(float16_t __a)225 vrndph_f16 (float16_t __a)
226 {
227   return __builtin_neon_vrndphf (__a);
228 }
229 
230 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vrndxh_f16(float16_t __a)231 vrndxh_f16 (float16_t __a)
232 {
233   return __builtin_neon_vrndxhf (__a);
234 }
235 
236 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vsqrth_f16(float16_t __a)237 vsqrth_f16 (float16_t __a)
238 {
239   return __builtin_neon_vsqrthf (__a);
240 }
241 
242 __extension__ static __inline float16_t __attribute__ ((__always_inline__))
vsubh_f16(float16_t __a,float16_t __b)243 vsubh_f16 (float16_t __a, float16_t __b)
244 {
245   return __a - __b;
246 }
247 
248 #endif /* __ARM_FEATURE_FP16_SCALAR_ARITHMETIC  */
249 #pragma GCC pop_options
250 
251 #ifdef __cplusplus
252 }
253 #endif
254 
255 #endif
256