152419Sjulian/* Header file for libgcc2.c.  */
252419Sjulian/* Copyright (C) 2000, 2001, 2004, 2005
352419Sjulian   Free Software Foundation, Inc.
452419Sjulian
552419SjulianThis file is part of GCC.
652419Sjulian
752419SjulianGCC is free software; you can redistribute it and/or modify it under
852419Sjulianthe terms of the GNU General Public License as published by the Free
952419SjulianSoftware Foundation; either version 2, or (at your option) any later
1052419Sjulianversion.
1152419Sjulian
1252419SjulianGCC is distributed in the hope that it will be useful, but WITHOUT ANY
1352419SjulianWARRANTY; without even the implied warranty of MERCHANTABILITY or
1452419SjulianFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1552419Sjulianfor more details.
1652419Sjulian
1752419SjulianYou should have received a copy of the GNU General Public License
1852419Sjulianalong with GCC; see the file COPYING.  If not, write to the Free
1952419SjulianSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
2052419Sjulian02110-1301, USA.  */
2152419Sjulian
2252419Sjulian/* As a special exception, if you link this library with other files,
2352419Sjulian   some of which are compiled with GCC, to produce an executable,
2452419Sjulian   this library does not by itself cause the resulting executable
2552419Sjulian   to be covered by the GNU General Public License.
2652419Sjulian   This exception does not however invalidate any other reasons why
2752419Sjulian   the executable file might be covered by the GNU General Public License.  */
2852419Sjulian
2952419Sjulian
3052419Sjulian#ifndef GCC_LIBGCC2_H
3152419Sjulian#define GCC_LIBGCC2_H
3252419Sjulian
3352419Sjulian#ifndef HIDE_EXPORTS
3452419Sjulian#pragma GCC visibility push(default)
3552419Sjulian#endif
3652419Sjulian
3752419Sjulianextern int __gcc_bcmp (const unsigned char *, const unsigned char *, size_t);
3852419Sjulianextern void __clear_cache (char *, char *);
3952419Sjulianextern void __eprintf (const char *, const char *, unsigned int, const char *)
4052419Sjulian  __attribute__ ((__noreturn__));
4184215Sdillon
4284215Sdillonstruct exception_descriptor;
4384215Sdillonextern short int __get_eh_table_language (struct exception_descriptor *);
4452419Sjulianextern short int __get_eh_table_version (struct exception_descriptor *);
45163469Sglebius
4652419Sjulian/* Permit the tm.h file to select the endianness to use just for this
4752419Sjulian   file.  This is used when the endianness is determined when the
4852419Sjulian   compiler is run.  */
4952419Sjulian
5052419Sjulian#ifndef LIBGCC2_WORDS_BIG_ENDIAN
5152419Sjulian#define LIBGCC2_WORDS_BIG_ENDIAN WORDS_BIG_ENDIAN
5252419Sjulian#endif
5356708Sarchie
5456708Sarchie#ifndef LIBGCC2_DOUBLE_TYPE_SIZE
5556708Sarchie#define LIBGCC2_DOUBLE_TYPE_SIZE DOUBLE_TYPE_SIZE
5652419Sjulian#endif
5752419Sjulian#ifndef LIBGCC2_LONG_DOUBLE_TYPE_SIZE
5852419Sjulian#define LIBGCC2_LONG_DOUBLE_TYPE_SIZE LONG_DOUBLE_TYPE_SIZE
5952419Sjulian#endif
6052419Sjulian
6152419Sjulian#ifndef LIBGCC2_HAS_SF_MODE
6252419Sjulian#define LIBGCC2_HAS_SF_MODE (BITS_PER_UNIT == 8)
6352419Sjulian#endif
64122649Sharti
6552419Sjulian#ifndef LIBGCC2_HAS_DF_MODE
6652419Sjulian#define LIBGCC2_HAS_DF_MODE \
6752419Sjulian  (BITS_PER_UNIT == 8 \
6852419Sjulian   && (LIBGCC2_DOUBLE_TYPE_SIZE == 64 \
6952419Sjulian       || LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 64))
7052419Sjulian#endif
7152419Sjulian
7252419Sjulian#ifndef LIBGCC2_HAS_XF_MODE
7356708Sarchie#define LIBGCC2_HAS_XF_MODE \
74244538Skevlo  (BITS_PER_UNIT == 8 && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80)
7556708Sarchie#endif
7652419Sjulian
77244538Skevlo#ifndef LIBGCC2_HAS_TF_MODE
7856708Sarchie#define LIBGCC2_HAS_TF_MODE \
7956708Sarchie  (BITS_PER_UNIT == 8 && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
8056708Sarchie#endif
8156708Sarchie
8256708Sarchie/* In the first part of this file, we are interfacing to calls generated
8356708Sarchie   by the compiler itself.  These calls pass values into these routines
8456708Sarchie   which have very specific modes (rather than very specific types), and
8556708Sarchie   these compiler-generated calls also expect any return values to have
8656708Sarchie   very specific modes (rather than very specific types).  Thus, we need
8756708Sarchie   to avoid using regular C language type names in this part of the file
8852419Sjulian   because the sizes for those types can be configured to be anything.
8952419Sjulian   Instead we use the following special type names.  */
9052419Sjulian
9152419Sjuliantypedef		 int QItype	__attribute__ ((mode (QI)));
9252419Sjuliantypedef unsigned int UQItype	__attribute__ ((mode (QI)));
9352419Sjuliantypedef		 int HItype	__attribute__ ((mode (HI)));
9456708Sarchietypedef unsigned int UHItype	__attribute__ ((mode (HI)));
9552419Sjulian#if MIN_UNITS_PER_WORD > 1
9652419Sjulian/* These typedefs are usually forbidden on dsp's with UNITS_PER_WORD 1.  */
97122649Shartitypedef 	 int SItype	__attribute__ ((mode (SI)));
9852419Sjuliantypedef unsigned int USItype	__attribute__ ((mode (SI)));
9952419Sjulian#if LONG_LONG_TYPE_SIZE > 32
10052419Sjulian/* These typedefs are usually forbidden on archs with UNITS_PER_WORD 2.  */
101122649Shartitypedef		 int DItype	__attribute__ ((mode (DI)));
10252419Sjuliantypedef unsigned int UDItype	__attribute__ ((mode (DI)));
103122649Sharti#if MIN_UNITS_PER_WORD > 4
10452419Sjulian/* These typedefs are usually forbidden on archs with UNITS_PER_WORD 4.  */
10552419Sjuliantypedef		 int TItype	__attribute__ ((mode (TI)));
10652419Sjuliantypedef unsigned int UTItype	__attribute__ ((mode (TI)));
10752419Sjulian#endif
10852419Sjulian#endif
10952419Sjulian#endif
11052419Sjulian
11152419Sjulian#if LIBGCC2_HAS_SF_MODE
112122649Shartitypedef 	float SFtype	__attribute__ ((mode (SF)));
11352419Sjuliantypedef _Complex float SCtype	__attribute__ ((mode (SC)));
11452419Sjulian#endif
11552419Sjulian#if LIBGCC2_HAS_DF_MODE
11652419Sjuliantypedef		float DFtype	__attribute__ ((mode (DF)));
11752419Sjuliantypedef _Complex float DCtype	__attribute__ ((mode (DC)));
11852419Sjulian#endif
11952419Sjulian#if LIBGCC2_HAS_XF_MODE
12052419Sjuliantypedef		float XFtype	__attribute__ ((mode (XF)));
12152419Sjuliantypedef _Complex float XCtype	__attribute__ ((mode (XC)));
12252419Sjulian#endif
12352419Sjulian#if LIBGCC2_HAS_TF_MODE
12452419Sjuliantypedef		float TFtype	__attribute__ ((mode (TF)));
12552419Sjuliantypedef _Complex float TCtype	__attribute__ ((mode (TC)));
12652419Sjulian#endif
12752419Sjulian
12852419Sjuliantypedef int word_type __attribute__ ((mode (__word__)));
12952419Sjulian
13052419Sjulian/* Make sure that we don't accidentally use any normal C language built-in
13152419Sjulian   type names in the first part of this file.  Instead we want to use *only*
13252419Sjulian   the type names defined above.  The following macro definitions insure
13352419Sjulian   that if we *do* accidentally use some normal C language built-in type name,
13452419Sjulian   we will get a syntax error.  */
13552419Sjulian
13652419Sjulian#define char bogus_type
13752419Sjulian#define short bogus_type
13852419Sjulian#define int bogus_type
139122649Sharti#define long bogus_type
14052419Sjulian#define unsigned bogus_type
14152419Sjulian#define float bogus_type
14252419Sjulian#define double bogus_type
14352419Sjulian
14452419Sjulian/* Versions prior to 3.4.4 were not taking into account the word size for
14552419Sjulian   the 5 trapping arithmetic functions absv, addv, subv, mulv and negv.  As
14652419Sjulian   a consequence, the si and di variants were always and the only ones emitted.
14752419Sjulian   To maintain backward compatibility, COMPAT_SIMODE_TRAPPING_ARITHMETIC is
14852419Sjulian   defined on platforms where it makes sense to still have the si variants
14952419Sjulian   emitted.  As a bonus, their implementation is now correct.  Note that the
15052419Sjulian   same mechanism should have been implemented for the di variants, but it
151122649Sharti   turns out that no platform would define COMPAT_DIMODE_TRAPPING_ARITHMETIC
15252419Sjulian   if it existed.  */
153122649Sharti
15452419Sjulian#if LIBGCC2_UNITS_PER_WORD == 8
15552419Sjulian#define W_TYPE_SIZE (8 * BITS_PER_UNIT)
15652419Sjulian#define Wtype	DItype
15752419Sjulian#define UWtype	UDItype
15852419Sjulian#define HWtype	DItype
15952419Sjulian#define UHWtype	UDItype
16052419Sjulian#define DWtype	TItype
16152419Sjulian#define UDWtype	UTItype
16252419Sjulian#define __NW(a,b)	__ ## a ## di ## b
16352419Sjulian#define __NDW(a,b)	__ ## a ## ti ## b
16452419Sjulian#define COMPAT_SIMODE_TRAPPING_ARITHMETIC
16552419Sjulian#elif LIBGCC2_UNITS_PER_WORD == 4
16652419Sjulian#define W_TYPE_SIZE (4 * BITS_PER_UNIT)
16752419Sjulian#define Wtype	SItype
16852419Sjulian#define UWtype	USItype
16952419Sjulian#define HWtype	SItype
17052419Sjulian#define UHWtype	USItype
17152419Sjulian#define DWtype	DItype
17252419Sjulian#define UDWtype	UDItype
17352419Sjulian#define __NW(a,b)	__ ## a ## si ## b
17452419Sjulian#define __NDW(a,b)	__ ## a ## di ## b
17552419Sjulian#elif LIBGCC2_UNITS_PER_WORD == 2
17652419Sjulian#define W_TYPE_SIZE (2 * BITS_PER_UNIT)
17752419Sjulian#define Wtype	HItype
17852419Sjulian#define UWtype	UHItype
17952419Sjulian#define HWtype	HItype
18052419Sjulian#define UHWtype	UHItype
18152419Sjulian#define DWtype	SItype
18252419Sjulian#define UDWtype	USItype
18352419Sjulian#define __NW(a,b)	__ ## a ## hi ## b
18452419Sjulian#define __NDW(a,b)	__ ## a ## si ## b
18552419Sjulian#else
18652419Sjulian#define W_TYPE_SIZE BITS_PER_UNIT
18752419Sjulian#define Wtype	QItype
18852419Sjulian#define UWtype  UQItype
18952419Sjulian#define HWtype	QItype
19052419Sjulian#define UHWtype	UQItype
19152419Sjulian#define DWtype	HItype
19252419Sjulian#define UDWtype	UHItype
19352419Sjulian#define __NW(a,b)	__ ## a ## qi ## b
19452419Sjulian#define __NDW(a,b)	__ ## a ## hi ## b
19552419Sjulian#endif
19652419Sjulian
19752419Sjulian#define Wtype_MAX ((Wtype)(((UWtype)1 << (W_TYPE_SIZE - 1)) - 1))
19852419Sjulian#define Wtype_MIN (- Wtype_MAX - 1)
19952419Sjulian
200135576Sstefanf#if W_TYPE_SIZE == 8
20152419Sjulian# define Wtype_MAXp1_F	0x1p8f
20252419Sjulian#elif W_TYPE_SIZE == 16
20352419Sjulian# define Wtype_MAXp1_F	0x1p16f
20452419Sjulian#elif W_TYPE_SIZE == 32
20552419Sjulian# define Wtype_MAXp1_F	0x1p32f
20652419Sjulian#elif W_TYPE_SIZE == 64
20752419Sjulian# define Wtype_MAXp1_F	0x1p64f
20852419Sjulian#else
20952419Sjulian# error "expand the table"
21052419Sjulian#endif
21152419Sjulian
21252419Sjulian#define __muldi3	__NDW(mul,3)
21352419Sjulian#define __divdi3	__NDW(div,3)
21452419Sjulian#define __udivdi3	__NDW(udiv,3)
215122649Sharti#define __moddi3	__NDW(mod,3)
21652419Sjulian#define __umoddi3	__NDW(umod,3)
217145546Smux#define __negdi2	__NDW(neg,2)
21852419Sjulian#define __lshrdi3	__NDW(lshr,3)
21952419Sjulian#define __ashldi3	__NDW(ashl,3)
22052419Sjulian#define __ashrdi3	__NDW(ashr,3)
22152419Sjulian#define __cmpdi2	__NDW(cmp,2)
22252419Sjulian#define __ucmpdi2	__NDW(ucmp,2)
22352419Sjulian#define __udivmoddi4	__NDW(udivmod,4)
22452419Sjulian#define __fixunstfDI	__NDW(fixunstf,)
22552419Sjulian#define __fixtfdi	__NDW(fixtf,)
22652419Sjulian#define __fixunsxfDI	__NDW(fixunsxf,)
22752419Sjulian#define __fixxfdi	__NDW(fixxf,)
22852419Sjulian#define __fixunsdfDI	__NDW(fixunsdf,)
22952419Sjulian#define __fixdfdi	__NDW(fixdf,)
23052419Sjulian#define __fixunssfDI	__NDW(fixunssf,)
23152419Sjulian#define __fixsfdi	__NDW(fixsf,)
232122649Sharti#define __floatdixf	__NDW(float,xf)
23352419Sjulian#define __floatditf	__NDW(float,tf)
23452419Sjulian#define __floatdidf	__NDW(float,df)
23552419Sjulian#define __floatdisf	__NDW(float,sf)
23652419Sjulian#define __fixunsxfSI	__NW(fixunsxf,)
23752419Sjulian#define __fixunstfSI	__NW(fixunstf,)
23852419Sjulian#define __fixunsdfSI	__NW(fixunsdf,)
23952419Sjulian#define __fixunssfSI	__NW(fixunssf,)
24052419Sjulian
24152419Sjulian#define __absvSI2	__NW(absv,2)
24252419Sjulian#define __addvSI3	__NW(addv,3)
24352419Sjulian#define __subvSI3	__NW(subv,3)
24452419Sjulian#define __mulvSI3	__NW(mulv,3)
24552419Sjulian#define __negvSI2	__NW(negv,2)
24652419Sjulian#define __absvDI2	__NDW(absv,2)
247125113Sru#define __addvDI3	__NDW(addv,3)
248125113Sru#define __subvDI3	__NDW(subv,3)
249125113Sru#define __mulvDI3	__NDW(mulv,3)
250125113Sru#define __negvDI2	__NDW(negv,2)
251125113Sru
252125113Sru#define __ffsSI2	__NW(ffs,2)
253125113Sru#define __clzSI2	__NW(clz,2)
254125113Sru#define __ctzSI2	__NW(ctz,2)
255125113Sru#define __popcountSI2	__NW(popcount,2)
256125113Sru#define __paritySI2	__NW(parity,2)
257125113Sru#define __ffsDI2	__NDW(ffs,2)
258125113Sru#define __clzDI2	__NDW(clz,2)
259125113Sru#define __ctzDI2	__NDW(ctz,2)
260125113Sru#define __popcountDI2	__NDW(popcount,2)
261125113Sru#define __parityDI2	__NDW(parity,2)
262125113Sru
263125113Sruextern DWtype __muldi3 (DWtype, DWtype);
264125113Sruextern DWtype __divdi3 (DWtype, DWtype);
26552419Sjulianextern UDWtype __udivdi3 (UDWtype, UDWtype);
26652419Sjulianextern UDWtype __umoddi3 (UDWtype, UDWtype);
26752419Sjulianextern DWtype __moddi3 (DWtype, DWtype);
26852419Sjulian
26952419Sjulian/* __udivmoddi4 is static inline when building other libgcc2 portions.  */
27052419Sjulian#if (!defined (L_udivdi3) && !defined (L_divdi3) && \
27152419Sjulian     !defined (L_umoddi3) && !defined (L_moddi3))
272122649Shartiextern UDWtype __udivmoddi4 (UDWtype, UDWtype, UDWtype *);
27352419Sjulian#endif
27452419Sjulian
27552419Sjulian/* __negdi2 is static inline when building other libgcc2 portions.  */
27652419Sjulian#if !defined(L_divdi3) && !defined(L_moddi3)
27752419Sjulianextern DWtype __negdi2 (DWtype);
278122649Sharti#endif
279122649Sharti
28052419Sjulianextern DWtype __lshrdi3 (DWtype, word_type);
28152419Sjulianextern DWtype __ashldi3 (DWtype, word_type);
28252419Sjulianextern DWtype __ashrdi3 (DWtype, word_type);
28352419Sjulian
28452419Sjulian/* __udiv_w_sdiv is static inline when building other libgcc2 portions.  */
28552419Sjulian#if (!defined(L_udivdi3) && !defined(L_divdi3) && \
28652419Sjulian     !defined(L_umoddi3) && !defined(L_moddi3))
28752419Sjulianextern UWtype __udiv_w_sdiv (UWtype *, UWtype, UWtype, UWtype);
28852419Sjulian#endif
28952419Sjulian
29052419Sjulianextern word_type __cmpdi2 (DWtype, DWtype);
29152419Sjulianextern word_type __ucmpdi2 (DWtype, DWtype);
29252419Sjulian
29352419Sjulianextern Wtype __absvSI2 (Wtype);
29452419Sjulianextern Wtype __addvSI3 (Wtype, Wtype);
29552419Sjulianextern Wtype __subvSI3 (Wtype, Wtype);
29652419Sjulianextern Wtype __mulvSI3 (Wtype, Wtype);
29752419Sjulianextern Wtype __negvSI2 (Wtype);
29852419Sjulianextern DWtype __absvDI2 (DWtype);
29952419Sjulianextern DWtype __addvDI3 (DWtype, DWtype);
30052419Sjulianextern DWtype __subvDI3 (DWtype, DWtype);
30152419Sjulianextern DWtype __mulvDI3 (DWtype, DWtype);
302extern DWtype __negvDI2 (DWtype);
303
304#ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
305extern SItype __absvsi2 (SItype);
306extern SItype __addvsi3 (SItype, SItype);
307extern SItype __subvsi3 (SItype, SItype);
308extern SItype __mulvsi3 (SItype, SItype);
309extern SItype __negvsi2 (SItype);
310#endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
311
312#undef int
313#if LIBGCC2_HAS_SF_MODE
314extern DWtype __fixsfdi (SFtype);
315extern SFtype __floatdisf (DWtype);
316extern UWtype __fixunssfSI (SFtype);
317extern DWtype __fixunssfDI (SFtype);
318extern SFtype __powisf2 (SFtype, int);
319extern SCtype __divsc3 (SFtype, SFtype, SFtype, SFtype);
320extern SCtype __mulsc3 (SFtype, SFtype, SFtype, SFtype);
321#endif
322#if LIBGCC2_HAS_DF_MODE
323extern DWtype __fixdfdi (DFtype);
324extern DFtype __floatdidf (DWtype);
325extern UWtype __fixunsdfSI (DFtype);
326extern DWtype __fixunsdfDI (DFtype);
327extern DFtype __powidf2 (DFtype, int);
328extern DCtype __divdc3 (DFtype, DFtype, DFtype, DFtype);
329extern DCtype __muldc3 (DFtype, DFtype, DFtype, DFtype);
330#endif
331
332#if LIBGCC2_HAS_XF_MODE
333extern DWtype __fixxfdi (XFtype);
334extern DWtype __fixunsxfDI (XFtype);
335extern XFtype __floatdixf (DWtype);
336extern UWtype __fixunsxfSI (XFtype);
337extern XFtype __powixf2 (XFtype, int);
338extern XCtype __divxc3 (XFtype, XFtype, XFtype, XFtype);
339extern XCtype __mulxc3 (XFtype, XFtype, XFtype, XFtype);
340#endif
341
342#if LIBGCC2_HAS_TF_MODE
343extern DWtype __fixunstfDI (TFtype);
344extern DWtype __fixtfdi (TFtype);
345extern TFtype __floatditf (DWtype);
346extern TFtype __powitf2 (TFtype, int);
347extern TCtype __divtc3 (TFtype, TFtype, TFtype, TFtype);
348extern TCtype __multc3 (TFtype, TFtype, TFtype, TFtype);
349#endif
350#define int bogus_type
351
352/* DWstructs are pairs of Wtype values in the order determined by
353   LIBGCC2_WORDS_BIG_ENDIAN.  */
354
355#if LIBGCC2_WORDS_BIG_ENDIAN
356  struct DWstruct {Wtype high, low;};
357#else
358  struct DWstruct {Wtype low, high;};
359#endif
360
361/* We need this union to unpack/pack DImode values, since we don't have
362   any arithmetic yet.  Incoming DImode parameters are stored into the
363   `ll' field, and the unpacked result is read from the struct `s'.  */
364
365typedef union
366{
367  struct DWstruct s;
368  DWtype ll;
369} DWunion;
370
371/* Defined for L_popcount_tab.  Exported here because some targets may
372   want to use it for their own versions of the __popcount builtins.  */
373extern const UQItype __popcount_tab[256];
374
375/* Defined for L_clz.  Exported here because some targets may want to use
376   it for their own versions of the __clz builtins.  It contains the bit
377   position of the first set bit for the numbers 0 - 255.  This avoids the
378   need for a seperate table for the __ctz builtins.  */
379extern const UQItype __clz_tab[256];
380
381#include "longlong.h"
382
383#undef int
384extern int __clzDI2 (UDWtype);
385extern int __clzSI2 (UWtype);
386extern int __ctzSI2 (UWtype);
387extern int __ffsSI2 (UWtype);
388extern int __ffsDI2 (DWtype);
389extern int __ctzDI2 (UDWtype);
390extern int __popcountSI2 (UWtype);
391extern int __popcountDI2 (UDWtype);
392extern int __paritySI2 (UWtype);
393extern int __parityDI2 (UDWtype);
394#define int bogus_type
395
396extern void __enable_execute_stack (void *);
397
398#ifndef HIDE_EXPORTS
399#pragma GCC visibility pop
400#endif
401
402#endif /* ! GCC_LIBGCC2_H */
403