1/* Header file for libgcc2.c.  */
2/* Copyright (C) 2000-2020 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14for more details.
15
16Under Section 7 of GPL version 3, you are granted additional
17permissions described in the GCC Runtime Library Exception, version
183.1, as published by the Free Software Foundation.
19
20You should have received a copy of the GNU General Public License and
21a copy of the GCC Runtime Library Exception along with this program;
22see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23<http://www.gnu.org/licenses/>.  */
24
25#ifndef GCC_LIBGCC2_H
26#define GCC_LIBGCC2_H
27
28#ifndef HIDE_EXPORTS
29#pragma GCC visibility push(default)
30#endif
31
32extern int __gcc_bcmp (const unsigned char *, const unsigned char *, size_t);
33extern void __clear_cache (void *, void *);
34extern void __eprintf (const char *, const char *, unsigned int, const char *)
35  __attribute__ ((__noreturn__));
36
37#ifdef __LIBGCC_HAS_HF_MODE__
38#define LIBGCC2_HAS_HF_MODE 1
39#else
40#define LIBGCC2_HAS_HF_MODE 0
41#endif
42
43#ifdef __LIBGCC_HAS_SF_MODE__
44#define LIBGCC2_HAS_SF_MODE 1
45#else
46#define LIBGCC2_HAS_SF_MODE 0
47#endif
48
49#ifdef __LIBGCC_HAS_DF_MODE__
50#define LIBGCC2_HAS_DF_MODE 1
51#else
52#define LIBGCC2_HAS_DF_MODE 0
53#endif
54
55#ifdef __LIBGCC_HAS_XF_MODE__
56#define LIBGCC2_HAS_XF_MODE 1
57#else
58#define LIBGCC2_HAS_XF_MODE 0
59#endif
60
61#ifdef __LIBGCC_HAS_TF_MODE__
62#define LIBGCC2_HAS_TF_MODE 1
63#else
64#define LIBGCC2_HAS_TF_MODE 0
65#endif
66
67#ifndef __LIBGCC_SF_MANT_DIG__
68#if LIBGCC2_HAS_SF_MODE
69#error __LIBGCC_SF_MANT_DIG__ not defined
70#else
71#define __LIBGCC_SF_MANT_DIG__ 0
72#endif
73#endif
74
75#ifndef __LIBGCC_DF_MANT_DIG__
76#if LIBGCC2_HAS_DF_MODE
77#error __LIBGCC_DF_MANT_DIG__ not defined
78#else
79#define __LIBGCC_DF_MANT_DIG__ 0
80#endif
81#endif
82
83#ifndef __LIBGCC_XF_MANT_DIG__
84#if LIBGCC2_HAS_XF_MODE
85#error __LIBGCC_XF_MANT_DIG__ not defined
86#else
87#define __LIBGCC_XF_MANT_DIG__ 0
88#endif
89#endif
90
91#ifndef __LIBGCC_TF_MANT_DIG__
92#if LIBGCC2_HAS_TF_MODE
93#error __LIBGCC_TF_MANT_DIG__ not defined
94#else
95#define __LIBGCC_TF_MANT_DIG__ 0
96#endif
97#endif
98
99/* FIXME: This #ifdef probably should be removed, ie. enable the test
100   for mips too.  */
101/* Don't use IBM Extended Double TFmode for TI->SF calculations.
102   The conversion from long double to float suffers from double
103   rounding, because we convert via double.  In other cases, going
104   through the software fp routines is much slower than the fallback.  */
105#ifdef __powerpc__
106#define AVOID_FP_TYPE_CONVERSION(SIZE) (SIZE == 106)
107#elif defined(WIDEST_HARDWARE_FP_SIZE)
108#define AVOID_FP_TYPE_CONVERSION(SIZE) (SIZE > WIDEST_HARDWARE_FP_SIZE)
109#else
110#define AVOID_FP_TYPE_CONVERSION(SIZE) 0
111#endif
112
113/* In the first part of this file, we are interfacing to calls generated
114   by the compiler itself.  These calls pass values into these routines
115   which have very specific modes (rather than very specific types), and
116   these compiler-generated calls also expect any return values to have
117   very specific modes (rather than very specific types).  Thus, we need
118   to avoid using regular C language type names in this part of the file
119   because the sizes for those types can be configured to be anything.
120   Instead we use the following special type names.  */
121
122typedef		 int QItype	__attribute__ ((mode (QI)));
123typedef unsigned int UQItype	__attribute__ ((mode (QI)));
124typedef		 int HItype	__attribute__ ((mode (HI)));
125typedef unsigned int UHItype	__attribute__ ((mode (HI)));
126#if MIN_UNITS_PER_WORD > 1
127/* These typedefs are usually forbidden on dsp's with UNITS_PER_WORD 1.  */
128typedef 	 int SItype	__attribute__ ((mode (SI)));
129typedef unsigned int USItype	__attribute__ ((mode (SI)));
130#if __SIZEOF_LONG_LONG__ > 4
131/* These typedefs are usually forbidden on archs with UNITS_PER_WORD 2.  */
132typedef		 int DItype	__attribute__ ((mode (DI)));
133typedef unsigned int UDItype	__attribute__ ((mode (DI)));
134#if MIN_UNITS_PER_WORD > 4
135/* These typedefs are usually forbidden on archs with UNITS_PER_WORD 4.  */
136typedef		 int TItype	__attribute__ ((mode (TI)));
137typedef unsigned int UTItype	__attribute__ ((mode (TI)));
138#endif
139#endif
140#endif
141
142#if LIBGCC2_HAS_HF_MODE
143typedef		float HFtype	__attribute__ ((mode (HF)));
144typedef _Complex float HCtype	__attribute__ ((mode (HC)));
145#endif
146#if LIBGCC2_HAS_SF_MODE
147typedef 	float SFtype	__attribute__ ((mode (SF)));
148typedef _Complex float SCtype	__attribute__ ((mode (SC)));
149#endif
150#if LIBGCC2_HAS_DF_MODE
151typedef		float DFtype	__attribute__ ((mode (DF)));
152typedef _Complex float DCtype	__attribute__ ((mode (DC)));
153#endif
154#if LIBGCC2_HAS_XF_MODE
155typedef		float XFtype	__attribute__ ((mode (XF)));
156typedef _Complex float XCtype	__attribute__ ((mode (XC)));
157#endif
158#if LIBGCC2_HAS_TF_MODE
159typedef		float TFtype	__attribute__ ((mode (TF)));
160typedef _Complex float TCtype	__attribute__ ((mode (TC)));
161#endif
162
163typedef int cmp_return_type __attribute__((mode (__libgcc_cmp_return__)));
164typedef int shift_count_type __attribute__((mode (__libgcc_shift_count__)));
165
166/* Make sure that we don't accidentally use any normal C language built-in
167   type names in the first part of this file.  Instead we want to use *only*
168   the type names defined above.  The following macro definitions insure
169   that if we *do* accidentally use some normal C language built-in type name,
170   we will get a syntax error.  */
171
172#define char bogus_type
173#define short bogus_type
174#define int bogus_type
175#define long bogus_type
176#define unsigned bogus_type
177#define float bogus_type
178#define double bogus_type
179
180/* Versions prior to 3.4.4 were not taking into account the word size for
181   the 5 trapping arithmetic functions absv, addv, subv, mulv and negv.  As
182   a consequence, the si and di variants were always and the only ones emitted.
183   To maintain backward compatibility, COMPAT_SIMODE_TRAPPING_ARITHMETIC is
184   defined on platforms where it makes sense to still have the si variants
185   emitted.  As a bonus, their implementation is now correct.  Note that the
186   same mechanism should have been implemented for the di variants, but it
187   turns out that no platform would define COMPAT_DIMODE_TRAPPING_ARITHMETIC
188   if it existed.  */
189
190#if LIBGCC2_UNITS_PER_WORD == 8
191#define W_TYPE_SIZE (8 * __CHAR_BIT__)
192#define Wtype	DItype
193#define UWtype	UDItype
194#define HWtype	DItype
195#define UHWtype	UDItype
196#define DWtype	TItype
197#define UDWtype	UTItype
198#ifdef LIBGCC2_GNU_PREFIX
199#define __NW(a,b)	__gnu_ ## a ## di ## b
200#define __NDW(a,b)	__gnu_ ## a ## ti ## b
201#else
202#define __NW(a,b)	__ ## a ## di ## b
203#define __NDW(a,b)	__ ## a ## ti ## b
204#endif
205#define COMPAT_SIMODE_TRAPPING_ARITHMETIC
206#elif LIBGCC2_UNITS_PER_WORD == 4
207#define W_TYPE_SIZE (4 * __CHAR_BIT__)
208#define Wtype	SItype
209#define UWtype	USItype
210#define HWtype	SItype
211#define UHWtype	USItype
212#define DWtype	DItype
213#define UDWtype	UDItype
214#ifdef LIBGCC2_GNU_PREFIX
215#define __NW(a,b)	__gnu_ ## a ## si ## b
216#define __NDW(a,b)	__gnu_ ## a ## di ## b
217#else
218#define __NW(a,b)	__ ## a ## si ## b
219#define __NDW(a,b)	__ ## a ## di ## b
220#endif
221#elif LIBGCC2_UNITS_PER_WORD == 2
222#define W_TYPE_SIZE (2 * __CHAR_BIT__)
223#define Wtype	HItype
224#define UWtype	UHItype
225#define HWtype	HItype
226#define UHWtype	UHItype
227#define DWtype	SItype
228#define UDWtype	USItype
229#ifdef LIBGCC2_GNU_PREFIX
230#define __NW(a,b)	__gnu_ ## a ## hi ## b
231#define __NDW(a,b)	__gnu_ ## a ## si ## b
232#else
233#define __NW(a,b)	__ ## a ## hi ## b
234#define __NDW(a,b)	__ ## a ## si ## b
235#endif
236#else
237#define W_TYPE_SIZE __CHAR_BIT__
238#define Wtype	QItype
239#define UWtype  UQItype
240#define HWtype	QItype
241#define UHWtype	UQItype
242#define DWtype	HItype
243#define UDWtype	UHItype
244#ifdef LIBGCC2_GNU_PREFIX
245#define __NW(a,b)	__gnu_ ## a ## qi ## b
246#define __NDW(a,b)	__gnu_ ## a ## hi ## b
247#else
248#define __NW(a,b)	__ ## a ## qi ## b
249#define __NDW(a,b)	__ ## a ## hi ## b
250#endif
251#endif
252
253#ifdef LIBGCC2_GNU_PREFIX
254#define __N(a)	__gnu_ ## a
255#else
256#define __N(a)	__ ## a
257#endif
258#define Wtype_MAX ((Wtype)(((UWtype)1 << (W_TYPE_SIZE - 1)) - 1))
259#define Wtype_MIN (- Wtype_MAX - 1)
260
261#if W_TYPE_SIZE == 8
262# define Wtype_MAXp1_F	0x1p8f
263#elif W_TYPE_SIZE == 16
264# define Wtype_MAXp1_F	0x1p16f
265#elif W_TYPE_SIZE == 32
266# define Wtype_MAXp1_F	0x1p32f
267#elif W_TYPE_SIZE == 64
268# define Wtype_MAXp1_F	0x1p64f
269#else
270# error "expand the table"
271#endif
272
273#define __muldi3	__NDW(mul,3)
274#define __divdi3	__NDW(div,3)
275#define __udivdi3	__NDW(udiv,3)
276#define __moddi3	__NDW(mod,3)
277#define __umoddi3	__NDW(umod,3)
278#define __negdi2	__NDW(neg,2)
279#define __lshrdi3	__NDW(lshr,3)
280#define __ashldi3	__NDW(ashl,3)
281#define __ashrdi3	__NDW(ashr,3)
282#define __cmpdi2	__NDW(cmp,2)
283#define __ucmpdi2	__NDW(ucmp,2)
284#define __divmoddi4	__NDW(divmod,4)
285#define __udivmoddi4	__NDW(udivmod,4)
286#define __fixunstfDI	__NDW(fixunstf,)
287#define __fixtfdi	__NDW(fixtf,)
288#define __fixunsxfDI	__NDW(fixunsxf,)
289#define __fixxfdi	__NDW(fixxf,)
290#define __fixunsdfDI	__NDW(fixunsdf,)
291#define __fixdfdi	__NDW(fixdf,)
292#define __fixunssfDI	__NDW(fixunssf,)
293#define __fixsfdi	__NDW(fixsf,)
294#define __floatdixf	__NDW(float,xf)
295#define __floatditf	__NDW(float,tf)
296#define __floatdidf	__NDW(float,df)
297#define __floatdisf	__NDW(float,sf)
298#define __floatundixf	__NDW(floatun,xf)
299#define __floatunditf	__NDW(floatun,tf)
300#define __floatundidf	__NDW(floatun,df)
301#define __floatundisf	__NDW(floatun,sf)
302#define __fixunsxfSI	__NW(fixunsxf,)
303#define __fixunstfSI	__NW(fixunstf,)
304#define __fixunsdfSI	__NW(fixunsdf,)
305#define __fixunssfSI	__NW(fixunssf,)
306
307#define __absvSI2	__NW(absv,2)
308#define __addvSI3	__NW(addv,3)
309#define __subvSI3	__NW(subv,3)
310#define __mulvSI3	__NW(mulv,3)
311#define __negvSI2	__NW(negv,2)
312#define __absvDI2	__NDW(absv,2)
313#define __addvDI3	__NDW(addv,3)
314#define __subvDI3	__NDW(subv,3)
315#define __mulvDI3	__NDW(mulv,3)
316#define __negvDI2	__NDW(negv,2)
317
318#define __ffsSI2	__NW(ffs,2)
319#define __clzSI2	__NW(clz,2)
320#define __ctzSI2	__NW(ctz,2)
321#define __clrsbSI2	__NW(clrsb,2)
322#define __popcountSI2	__NW(popcount,2)
323#define __paritySI2	__NW(parity,2)
324#define __ffsDI2	__NDW(ffs,2)
325#define __clzDI2	__NDW(clz,2)
326#define __ctzDI2	__NDW(ctz,2)
327#define __clrsbDI2	__NDW(clrsb,2)
328#define __popcountDI2	__NDW(popcount,2)
329#define __parityDI2	__NDW(parity,2)
330
331#define __clz_tab		__N(clz_tab)
332#define __bswapsi2		__N(bswapsi2)
333#define __bswapdi2		__N(bswapdi2)
334#define __udiv_w_sdiv		__N(udiv_w_sdiv)
335#define __clear_cache		__N(clear_cache)
336#define __enable_execute_stack	__N(enable_execute_stack)
337
338#ifndef __powisf2
339#define __powisf2		__N(powisf2)
340#endif
341#ifndef __powidf2
342#define __powidf2		__N(powidf2)
343#endif
344#ifndef __powitf2
345#define __powitf2		__N(powitf2)
346#endif
347#ifndef __powixf2
348#define __powixf2		__N(powixf2)
349#endif
350#ifndef __mulsc3
351#define __mulsc3		__N(mulsc3)
352#endif
353#ifndef __muldc3
354#define __muldc3		__N(muldc3)
355#endif
356#ifndef __mulxc3
357#define __mulxc3		__N(mulxc3)
358#endif
359#ifndef __multc3
360#define __multc3		__N(multc3)
361#endif
362#ifndef __divsc3
363#define __divsc3		__N(divsc3)
364#endif
365#ifndef __divdc3
366#define __divdc3		__N(divdc3)
367#endif
368#ifndef __divxc3
369#define __divxc3		__N(divxc3)
370#endif
371#ifndef __divtc3
372#define __divtc3		__N(divtc3)
373#endif
374
375extern DWtype __muldi3 (DWtype, DWtype);
376extern DWtype __divdi3 (DWtype, DWtype);
377extern UDWtype __udivdi3 (UDWtype, UDWtype);
378extern UDWtype __umoddi3 (UDWtype, UDWtype);
379extern DWtype __moddi3 (DWtype, DWtype);
380extern DWtype __divmoddi4 (DWtype, DWtype, DWtype *);
381
382/* __udivmoddi4 is static inline when building other libgcc2 portions.  */
383#if (!defined (L_udivdi3) && !defined (L_divdi3) && \
384     !defined (L_umoddi3) && !defined (L_moddi3) && \
385     !defined (L_divmoddi4))
386extern UDWtype __udivmoddi4 (UDWtype, UDWtype, UDWtype *);
387#endif
388
389/* __negdi2 is static inline when building other libgcc2 portions.  */
390#if !defined(L_divdi3) && !defined(L_moddi3)
391extern DWtype __negdi2 (DWtype);
392#endif
393
394extern DWtype __lshrdi3 (DWtype, shift_count_type);
395extern DWtype __ashldi3 (DWtype, shift_count_type);
396extern DWtype __ashrdi3 (DWtype, shift_count_type);
397
398/* __udiv_w_sdiv is static inline when building other libgcc2 portions.  */
399#if (!defined(L_udivdi3) && !defined(L_divdi3) && \
400     !defined(L_umoddi3) && !defined(L_moddi3))
401extern UWtype __udiv_w_sdiv (UWtype *, UWtype, UWtype, UWtype);
402#endif
403
404extern cmp_return_type __cmpdi2 (DWtype, DWtype);
405extern cmp_return_type __ucmpdi2 (DWtype, DWtype);
406
407#if MIN_UNITS_PER_WORD > 1
408extern SItype __bswapsi2 (SItype);
409#endif
410#if __SIZEOF_LONG_LONG__ > 4
411extern DItype __bswapdi2 (DItype);
412#endif
413
414extern Wtype __absvSI2 (Wtype);
415extern Wtype __addvSI3 (Wtype, Wtype);
416extern Wtype __subvSI3 (Wtype, Wtype);
417extern Wtype __mulvSI3 (Wtype, Wtype);
418extern Wtype __negvSI2 (Wtype);
419extern DWtype __absvDI2 (DWtype);
420extern DWtype __addvDI3 (DWtype, DWtype);
421extern DWtype __subvDI3 (DWtype, DWtype);
422extern DWtype __mulvDI3 (DWtype, DWtype);
423extern DWtype __negvDI2 (DWtype);
424
425#ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
426#define __absvsi2	__N(absvsi2)
427#define __negvsi2	__N(negvsi2)
428#define __addvsi3	__N(addvsi3)
429#define __subvsi3	__N(subvsi3)
430#define __mulvsi3	__N(mulvsi3)
431
432extern SItype __absvsi2 (SItype);
433extern SItype __addvsi3 (SItype, SItype);
434extern SItype __subvsi3 (SItype, SItype);
435extern SItype __mulvsi3 (SItype, SItype);
436extern SItype __negvsi2 (SItype);
437#endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
438
439#undef int
440#if LIBGCC2_HAS_HF_MODE
441extern HCtype __divhc3 (HFtype, HFtype, HFtype, HFtype);
442extern HCtype __mulhc3 (HFtype, HFtype, HFtype, HFtype);
443#endif
444#if LIBGCC2_HAS_SF_MODE
445extern DWtype __fixsfdi (SFtype);
446extern SFtype __floatdisf (DWtype);
447extern SFtype __floatundisf (UDWtype);
448extern UWtype __fixunssfSI (SFtype);
449extern UDWtype __fixunssfDI (SFtype);
450extern SFtype __powisf2 (SFtype, int);
451extern SCtype __divsc3 (SFtype, SFtype, SFtype, SFtype);
452extern SCtype __mulsc3 (SFtype, SFtype, SFtype, SFtype);
453#endif
454#if LIBGCC2_HAS_DF_MODE
455extern DWtype __fixdfdi (DFtype);
456extern DFtype __floatdidf (DWtype);
457extern DFtype __floatundidf (UDWtype);
458extern UWtype __fixunsdfSI (DFtype);
459extern UDWtype __fixunsdfDI (DFtype);
460extern DFtype __powidf2 (DFtype, int);
461extern DCtype __divdc3 (DFtype, DFtype, DFtype, DFtype);
462extern DCtype __muldc3 (DFtype, DFtype, DFtype, DFtype);
463#endif
464
465#if LIBGCC2_HAS_XF_MODE
466extern DWtype __fixxfdi (XFtype);
467extern UDWtype __fixunsxfDI (XFtype);
468extern XFtype __floatdixf (DWtype);
469extern XFtype __floatundixf (UDWtype);
470extern UWtype __fixunsxfSI (XFtype);
471extern XFtype __powixf2 (XFtype, int);
472extern XCtype __divxc3 (XFtype, XFtype, XFtype, XFtype);
473extern XCtype __mulxc3 (XFtype, XFtype, XFtype, XFtype);
474#endif
475
476#if LIBGCC2_HAS_TF_MODE
477extern UDWtype __fixunstfDI (TFtype);
478extern DWtype __fixtfdi (TFtype);
479extern TFtype __floatditf (DWtype);
480extern TFtype __floatunditf (UDWtype);
481extern TFtype __powitf2 (TFtype, int);
482extern TCtype __divtc3 (TFtype, TFtype, TFtype, TFtype);
483extern TCtype __multc3 (TFtype, TFtype, TFtype, TFtype);
484#endif
485#define int bogus_type
486
487/* DWstructs are pairs of Wtype values in the order determined by
488   __BYTE_ORDER__.  */
489
490#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
491  struct DWstruct {Wtype high, low;};
492#else
493  struct DWstruct {Wtype low, high;};
494#endif
495
496/* We need this union to unpack/pack DImode values, since we don't have
497   any arithmetic yet.  Incoming DImode parameters are stored into the
498   `ll' field, and the unpacked result is read from the struct `s'.  */
499
500typedef union
501{
502  struct DWstruct s;
503  DWtype ll;
504} DWunion;
505
506/* Defined for L_popcount_tab.  Exported here because some targets may
507   want to use it for their own versions of the __popcount builtins.  */
508extern const UQItype __popcount_tab[256];
509
510/* Defined for L_clz.  Exported here because some targets may want to use
511   it for their own versions of the __clz builtins.  It contains the bit
512   position of the first set bit for the numbers 0 - 255.  This avoids the
513   need for a separate table for the __ctz builtins.  */
514extern const UQItype __clz_tab[256];
515
516#include "longlong.h"
517
518#undef int
519extern int __clzDI2 (UDWtype);
520extern int __clzSI2 (UWtype);
521extern int __ctzSI2 (UWtype);
522extern int __ctzDI2 (UDWtype);
523extern int __clrsbSI2 (Wtype);
524extern int __clrsbDI2 (DWtype);
525extern int __ffsSI2 (UWtype);
526extern int __ffsDI2 (DWtype);
527extern int __popcountSI2 (UWtype);
528extern int __popcountDI2 (UDWtype);
529extern int __paritySI2 (UWtype);
530extern int __parityDI2 (UDWtype);
531#define int bogus_type
532
533extern void __enable_execute_stack (void *);
534
535#ifndef HIDE_EXPORTS
536#pragma GCC visibility pop
537#endif
538
539#endif /* ! GCC_LIBGCC2_H */
540