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