1 @c Copyright (C) 2003, 2004 Free Software Foundation, Inc.
2 @c This is part of the GCC manual.
3 @c For copying conditions, see the file gcc.texi.
4 @c Contributed by Aldy Hernandez <aldy@quesejoda.com>
7 @chapter The GCC low-level runtime library
9 GCC provides a low-level runtime library, @file{libgcc.a} or
10 @file{libgcc_s.so.1} on some platforms. GCC generates calls to
11 routines in this library automatically, whenever it needs to perform
12 some operation that is too complicated to emit inline code for.
14 Most of the routines in @code{libgcc} handle arithmetic operations
15 that the target processor cannot perform directly. This includes
16 integer multiply and divide on some machines, and all floating-point
17 operations on other machines. @code{libgcc} also includes routines
18 for exception handling, and a handful of miscellaneous operations.
20 Some of these routines can be defined in mostly machine-independent C@.
21 Others must be hand-written in assembly language for each processor
24 GCC will also generate calls to C library routines, such as
25 @code{memcpy} and @code{memset}, in some cases. The set of routines
26 that GCC may possibly use is documented in @ref{Other
27 Builtins,,,gcc, Using the GNU Compiler Collection (GCC)}.
29 These routines take arguments and return values of a specific machine
30 mode, not a specific C type. @xref{Machine Modes}, for an explanation
31 of this concept. For illustrative purposes, in this chapter the
32 floating point type @code{float} is assumed to correspond to @code{SFmode};
33 @code{double} to @code{DFmode}; and @code{@w{long double}} to both
34 @code{TFmode} and @code{XFmode}. Similarly, the integer types @code{int}
35 and @code{@w{unsigned int}} correspond to @code{SImode}; @code{long} and
36 @code{@w{unsigned long}} to @code{DImode}; and @code{@w{long long}} and
37 @code{@w{unsigned long long}} to @code{TImode}.
40 * Integer library routines::
41 * Soft float library routines::
42 * Exception handling routines::
43 * Miscellaneous routines::
46 @node Integer library routines
47 @section Routines for integer arithmetic
49 The integer arithmetic routines are used on platforms that don't provide
50 hardware support for arithmetic operations on some modes.
52 @subsection Arithmetic functions
54 @deftypefn {Runtime Function} int __ashlsi3 (int @var{a}, int @var{b})
55 @deftypefnx {Runtime Function} long __ashldi3 (long @var{a}, int @var{b})
56 @deftypefnx {Runtime Function} {long long} __ashlti3 (long long @var{a}, int @var{b})
57 These functions return the result of shifting @var{a} left by @var{b} bits.
60 @deftypefn {Runtime Function} int __ashrsi3 (int @var{a}, int @var{b})
61 @deftypefnx {Runtime Function} long __ashrdi3 (long @var{a}, int @var{b})
62 @deftypefnx {Runtime Function} {long long} __ashrti3 (long long @var{a}, int @var{b})
63 These functions return the result of arithmetically shifting @var{a} right
67 @deftypefn {Runtime Function} int __divsi3 (int @var{a}, int @var{b})
68 @deftypefnx {Runtime Function} long __divdi3 (long @var{a}, long @var{b})
69 @deftypefnx {Runtime Function} {long long} __divti3 (long long @var{a}, long long @var{b})
70 These functions return the quotient of the signed division of @var{a} and
74 @deftypefn {Runtime Function} int __lshrsi3 (int @var{a}, int @var{b})
75 @deftypefnx {Runtime Function} long __lshrdi3 (long @var{a}, int @var{b})
76 @deftypefnx {Runtime Function} {long long} __lshrti3 (long long @var{a}, int @var{b})
77 These functions return the result of logically shifting @var{a} right by
81 @deftypefn {Runtime Function} int __modsi3 (int @var{a}, int @var{b})
82 @deftypefnx {Runtime Function} long __moddi3 (long @var{a}, long @var{b})
83 @deftypefnx {Runtime Function} {long long} __modti3 (long long @var{a}, long long @var{b})
84 These functions return the remainder of the signed division of @var{a}
88 @deftypefn {Runtime Function} int __mulsi3 (int @var{a}, int @var{b})
89 @deftypefnx {Runtime Function} long __muldi3 (long @var{a}, long @var{b})
90 @deftypefnx {Runtime Function} {long long} __multi3 (long long @var{a}, long long @var{b})
91 These functions return the product of @var{a} and @var{b}.
94 @deftypefn {Runtime Function} long __negdi2 (long @var{a})
95 @deftypefnx {Runtime Function} {long long} __negti2 (long long @var{a})
96 These functions return the negation of @var{a}.
99 @deftypefn {Runtime Function} {unsigned int} __udivsi3 (unsigned int @var{a}, unsigned int @var{b})
100 @deftypefnx {Runtime Function} {unsigned long} __udivdi3 (unsigned long @var{a}, unsigned long @var{b})
101 @deftypefnx {Runtime Function} {unsigned long long} __udivti3 (unsigned long long @var{a}, unsigned long long @var{b})
102 These functions return the quotient of the unsigned division of @var{a}
106 @deftypefn {Runtime Function} {unsigned long} __udivmoddi3 (unsigned long @var{a}, unsigned long @var{b}, unsigned long *@var{c})
107 @deftypefnx {Runtime Function} {unsigned long long} __udivti3 (unsigned long long @var{a}, unsigned long long @var{b}, unsigned long long *@var{c})
108 These functions calculate both the quotient and remainder of the unsigned
109 division of @var{a} and @var{b}. The return value is the quotient, and
110 the remainder is placed in variable pointed to by @var{c}.
113 @deftypefn {Runtime Function} {unsigned int} __umodsi3 (unsigned int @var{a}, unsigned int @var{b})
114 @deftypefnx {Runtime Function} {unsigned long} __umoddi3 (unsigned long @var{a}, unsigned long @var{b})
115 @deftypefnx {Runtime Function} {unsigned long long} __umodti3 (unsigned long long @var{a}, unsigned long long @var{b})
116 These functions return the remainder of the unsigned division of @var{a}
120 @subsection Comparison functions
122 The following functions implement integral comparisons. These functions
123 implement a low-level compare, upon which the higher level comparison
124 operators (such as less than and greater than or equal to) can be
125 constructed. The returned values lie in the range zero to two, to allow
126 the high-level operators to be implemented by testing the returned
127 result using either signed or unsigned comparison.
129 @deftypefn {Runtime Function} int __cmpdi2 (long @var{a}, long @var{b})
130 @deftypefnx {Runtime Function} int __cmpti2 (long long @var{a}, long long @var{b})
131 These functions perform a signed comparison of @var{a} and @var{b}. If
132 @var{a} is less than @var{b}, they return 0; if @var{a} is greater than
133 @var{b}, they return 2; and if @var{a} and @var{b} are equal they return 1.
136 @deftypefn {Runtime Function} int __ucmpdi2 (unsigned long @var{a}, unsigned long @var{b})
137 @deftypefnx {Runtime Function} int __ucmpti2 (unsigned long long @var{a}, unsigned long long @var{b})
138 These functions perform an unsigned comparison of @var{a} and @var{b}.
139 If @var{a} is less than @var{b}, they return 0; if @var{a} is greater than
140 @var{b}, they return 2; and if @var{a} and @var{b} are equal they return 1.
143 @subsection Trapping arithmetic functions
145 The following functions implement trapping arithmetic. These functions
146 call the libc function @code{abort} upon signed arithmetic overflow.
148 @deftypefn {Runtime Function} int __absvsi2 (int @var{a})
149 @deftypefnx {Runtime Function} long __absvdi2 (long @var{a})
150 These functions return the absolute value of @var{a}.
153 @deftypefn {Runtime Function} int __addvsi3 (int @var{a}, int @var{b})
154 @deftypefnx {Runtime Function} long __addvdi3 (long @var{a}, long @var{b})
155 These functions return the sum of @var{a} and @var{b}; that is
156 @code{@var{a} + @var{b}}.
159 @deftypefn {Runtime Function} int __mulvsi3 (int @var{a}, int @var{b})
160 @deftypefnx {Runtime Function} long __mulvdi3 (long @var{a}, long @var{b})
161 The functions return the product of @var{a} and @var{b}; that is
162 @code{@var{a} * @var{b}}.
165 @deftypefn {Runtime Function} int __negvsi2 (int @var{a})
166 @deftypefnx {Runtime Function} long __negvdi2 (long @var{a})
167 These functions return the negation of @var{a}; that is @code{-@var{a}}.
170 @deftypefn {Runtime Function} int __subvsi3 (int @var{a}, int @var{b})
171 @deftypefnx {Runtime Function} long __subvdi3 (long @var{a}, long @var{b})
172 These functions return the difference between @var{b} and @var{a};
173 that is @code{@var{a} - @var{b}}.
176 @subsection Bit operations
178 @deftypefn {Runtime Function} int __clzsi2 (int @var{a})
179 @deftypefnx {Runtime Function} int __clzdi2 (long @var{a})
180 @deftypefnx {Runtime Function} int __clzti2 (long long @var{a})
181 These functions return the number of leading 0-bits in @var{a}, starting
182 at the most significant bit position. If @var{a} is zero, the result is
186 @deftypefn {Runtime Function} int __ctzsi2 (int @var{a})
187 @deftypefnx {Runtime Function} int __ctzdi2 (long @var{a})
188 @deftypefnx {Runtime Function} int __ctzti2 (long long @var{a})
189 These functions return the number of trailing 0-bits in @var{a}, starting
190 at the least significant bit position. If @var{a} is zero, the result is
194 @deftypefn {Runtime Function} int __ffsdi2 (long @var{a})
195 @deftypefnx {Runtime Function} int __ffsti2 (long long @var{a})
196 These functions return the index of the least significant 1-bit in @var{a},
197 or the value zero if @var{a} is zero. The least significant bit is index
201 @deftypefn {Runtime Function} int __paritysi2 (int @var{a})
202 @deftypefnx {Runtime Function} int __paritydi2 (long @var{a})
203 @deftypefnx {Runtime Function} int __parityti2 (long long @var{a})
204 These functions return the value zero if the number of bits set in
205 @var{a} is even, and the value one otherwise.
208 @deftypefn {Runtime Function} int __popcountsi2 (int @var{a})
209 @deftypefnx {Runtime Function} int __popcountdi2 (long @var{a})
210 @deftypefnx {Runtime Function} int __popcountti2 (long long @var{a})
211 These functions return the number of bits set in @var{a}.
214 @node Soft float library routines
215 @section Routines for floating point emulation
216 @cindex soft float library
217 @cindex arithmetic library
221 The software floating point library is used on machines which do not
222 have hardware support for floating point. It is also used whenever
223 @option{-msoft-float} is used to disable generation of floating point
224 instructions. (Not all targets support this switch.)
226 For compatibility with other compilers, the floating point emulation
227 routines can be renamed with the @code{DECLARE_LIBRARY_RENAMES} macro
228 (@pxref{Library Calls}). In this section, the default names are used.
230 Presently the library does not support @code{XFmode}, which is used
231 for @code{long double} on some architectures.
233 @subsection Arithmetic functions
235 @deftypefn {Runtime Function} float __addsf3 (float @var{a}, float @var{b})
236 @deftypefnx {Runtime Function} double __adddf3 (double @var{a}, double @var{b})
237 @deftypefnx {Runtime Function} {long double} __addtf3 (long double @var{a}, long double @var{b})
238 @deftypefnx {Runtime Function} {long double} __addxf3 (long double @var{a}, long double @var{b})
239 These functions return the sum of @var{a} and @var{b}.
242 @deftypefn {Runtime Function} float __subsf3 (float @var{a}, float @var{b})
243 @deftypefnx {Runtime Function} double __subdf3 (double @var{a}, double @var{b})
244 @deftypefnx {Runtime Function} {long double} __subtf3 (long double @var{a}, long double @var{b})
245 @deftypefnx {Runtime Function} {long double} __subxf3 (long double @var{a}, long double @var{b})
246 These functions return the difference between @var{b} and @var{a};
247 that is, @w{@math{@var{a} - @var{b}}}.
250 @deftypefn {Runtime Function} float __mulsf3 (float @var{a}, float @var{b})
251 @deftypefnx {Runtime Function} double __muldf3 (double @var{a}, double @var{b})
252 @deftypefnx {Runtime Function} {long double} __multf3 (long double @var{a}, long double @var{b})
253 @deftypefnx {Runtime Function} {long double} __mulxf3 (long double @var{a}, long double @var{b})
254 These functions return the product of @var{a} and @var{b}.
257 @deftypefn {Runtime Function} float __divsf3 (float @var{a}, float @var{b})
258 @deftypefnx {Runtime Function} double __divdf3 (double @var{a}, double @var{b})
259 @deftypefnx {Runtime Function} {long double} __divtf3 (long double @var{a}, long double @var{b})
260 @deftypefnx {Runtime Function} {long double} __divxf3 (long double @var{a}, long double @var{b})
261 These functions return the quotient of @var{a} and @var{b}; that is,
262 @w{@math{@var{a} / @var{b}}}.
265 @deftypefn {Runtime Function} float __negsf2 (float @var{a})
266 @deftypefnx {Runtime Function} double __negdf2 (double @var{a})
267 @deftypefnx {Runtime Function} {long double} __negtf2 (long double @var{a})
268 @deftypefnx {Runtime Function} {long double} __negxf2 (long double @var{a})
269 These functions return the negation of @var{a}. They simply flip the
270 sign bit, so they can produce negative zero and negative NaN@.
273 @subsection Conversion functions
275 @deftypefn {Runtime Function} double __extendsfdf2 (float @var{a})
276 @deftypefnx {Runtime Function} {long double} __extendsftf2 (float @var{a})
277 @deftypefnx {Runtime Function} {long double} __extendsfxf2 (float @var{a})
278 @deftypefnx {Runtime Function} {long double} __extenddftf2 (double @var{a})
279 @deftypefnx {Runtime Function} {long double} __extenddfxf2 (double @var{a})
280 These functions extend @var{a} to the wider mode of their return
284 @deftypefn {Runtime Function} double __truncxfdf2 (long double @var{a})
285 @deftypefnx {Runtime Function} double __trunctfdf2 (long double @var{a})
286 @deftypefnx {Runtime Function} float __truncxfsf2 (long double @var{a})
287 @deftypefnx {Runtime Function} float __trunctfsf2 (long double @var{a})
288 @deftypefnx {Runtime Function} float __truncdfsf2 (double @var{a})
289 These functions truncate @var{a} to the narrower mode of their return
290 type, rounding toward zero.
293 @deftypefn {Runtime Function} int __fixsfsi (float @var{a})
294 @deftypefnx {Runtime Function} int __fixdfsi (double @var{a})
295 @deftypefnx {Runtime Function} int __fixtfsi (long double @var{a})
296 @deftypefnx {Runtime Function} int __fixxfsi (long double @var{a})
297 These functions convert @var{a} to a signed integer, rounding toward zero.
300 @deftypefn {Runtime Function} long __fixsfdi (float @var{a})
301 @deftypefnx {Runtime Function} long __fixdfdi (double @var{a})
302 @deftypefnx {Runtime Function} long __fixtfdi (long double @var{a})
303 @deftypefnx {Runtime Function} long __fixxfdi (long double @var{a})
304 These functions convert @var{a} to a signed long, rounding toward zero.
307 @deftypefn {Runtime Function} {long long} __fixsfti (float @var{a})
308 @deftypefnx {Runtime Function} {long long} __fixdfti (double @var{a})
309 @deftypefnx {Runtime Function} {long long} __fixtfti (long double @var{a})
310 @deftypefnx {Runtime Function} {long long} __fixxfti (long double @var{a})
311 These functions convert @var{a} to a signed long long, rounding toward zero.
314 @deftypefn {Runtime Function} {unsigned int} __fixunssfsi (float @var{a})
315 @deftypefnx {Runtime Function} {unsigned int} __fixunsdfsi (double @var{a})
316 @deftypefnx {Runtime Function} {unsigned int} __fixunstfsi (long double @var{a})
317 @deftypefnx {Runtime Function} {unsigned int} __fixunsxfsi (long double @var{a})
318 These functions convert @var{a} to an unsigned integer, rounding
319 toward zero. Negative values all become zero.
322 @deftypefn {Runtime Function} {unsigned long} __fixunssfdi (float @var{a})
323 @deftypefnx {Runtime Function} {unsigned long} __fixunsdfdi (double @var{a})
324 @deftypefnx {Runtime Function} {unsigned long} __fixunstfdi (long double @var{a})
325 @deftypefnx {Runtime Function} {unsigned long} __fixunsxfdi (long double @var{a})
326 These functions convert @var{a} to an unsigned long, rounding
327 toward zero. Negative values all become zero.
330 @deftypefn {Runtime Function} {unsigned long long} __fixunssfti (float @var{a})
331 @deftypefnx {Runtime Function} {unsigned long long} __fixunsdfti (double @var{a})
332 @deftypefnx {Runtime Function} {unsigned long long} __fixunstfti (long double @var{a})
333 @deftypefnx {Runtime Function} {unsigned long long} __fixunsxfti (long double @var{a})
334 These functions convert @var{a} to an unsigned long long, rounding
335 toward zero. Negative values all become zero.
338 @deftypefn {Runtime Function} float __floatsisf (int @var{i})
339 @deftypefnx {Runtime Function} double __floatsidf (int @var{i})
340 @deftypefnx {Runtime Function} {long double} __floatsitf (int @var{i})
341 @deftypefnx {Runtime Function} {long double} __floatsixf (int @var{i})
342 These functions convert @var{i}, a signed integer, to floating point.
345 @deftypefn {Runtime Function} float __floatdisf (long @var{i})
346 @deftypefnx {Runtime Function} double __floatdidf (long @var{i})
347 @deftypefnx {Runtime Function} {long double} __floatditf (long @var{i})
348 @deftypefnx {Runtime Function} {long double} __floatdixf (long @var{i})
349 These functions convert @var{i}, a signed long, to floating point.
352 @deftypefn {Runtime Function} float __floattisf (long long @var{i})
353 @deftypefnx {Runtime Function} double __floattidf (long long @var{i})
354 @deftypefnx {Runtime Function} {long double} __floattitf (long long @var{i})
355 @deftypefnx {Runtime Function} {long double} __floattixf (long long @var{i})
356 These functions convert @var{i}, a signed long long, to floating point.
359 @subsection Comparison functions
361 There are two sets of basic comparison functions.
363 @deftypefn {Runtime Function} int __cmpsf2 (float @var{a}, float @var{b})
364 @deftypefnx {Runtime Function} int __cmpdf2 (double @var{a}, double @var{b})
365 @deftypefnx {Runtime Function} int __cmptf2 (long double @var{a}, long double @var{b})
366 These functions calculate @math{a <=> b}. That is, if @var{a} is less
367 than @var{b}, they return @minus{}1; if @var{a} is greater than @var{b}, they
368 return 1; and if @var{a} and @var{b} are equal they return 0. If
369 either argument is NaN they return 1, but you should not rely on this;
370 if NaN is a possibility, use one of the higher-level comparison
374 @deftypefn {Runtime Function} int __unordsf2 (float @var{a}, float @var{b})
375 @deftypefnx {Runtime Function} int __unorddf2 (double @var{a}, double @var{b})
376 @deftypefnx {Runtime Function} int __unordtf2 (long double @var{a}, long double @var{b})
377 These functions return a nonzero value if either argument is NaN, otherwise 0.
380 There is also a complete group of higher level functions which
381 correspond directly to comparison operators. They implement the ISO C
382 semantics for floating-point comparisons, taking NaN into account.
383 Pay careful attention to the return values defined for each set.
384 Under the hood, all of these routines are implemented as
387 if (__unord@var{X}f2 (a, b))
389 return __cmp@var{X}f2 (a, b);
393 where @var{E} is a constant chosen to give the proper behavior for
394 NaN@. Thus, the meaning of the return value is different for each set.
395 Do not rely on this implementation; only the semantics documented
396 below are guaranteed.
398 @deftypefn {Runtime Function} int __eqsf2 (float @var{a}, float @var{b})
399 @deftypefnx {Runtime Function} int __eqdf2 (double @var{a}, double @var{b})
400 @deftypefnx {Runtime Function} int __eqtf2 (long double @var{a}, long double @var{b})
401 These functions return zero if neither argument is NaN, and @var{a} and
405 @deftypefn {Runtime Function} int __nesf2 (float @var{a}, float @var{b})
406 @deftypefnx {Runtime Function} int __nedf2 (double @var{a}, double @var{b})
407 @deftypefnx {Runtime Function} int __netf2 (long double @var{a}, long double @var{b})
408 These functions return a nonzero value if either argument is NaN, or
409 if @var{a} and @var{b} are unequal.
412 @deftypefn {Runtime Function} int __gesf2 (float @var{a}, float @var{b})
413 @deftypefnx {Runtime Function} int __gedf2 (double @var{a}, double @var{b})
414 @deftypefnx {Runtime Function} int __getf2 (long double @var{a}, long double @var{b})
415 These functions return a value greater than or equal to zero if
416 neither argument is NaN, and @var{a} is greater than or equal to
420 @deftypefn {Runtime Function} int __ltsf2 (float @var{a}, float @var{b})
421 @deftypefnx {Runtime Function} int __ltdf2 (double @var{a}, double @var{b})
422 @deftypefnx {Runtime Function} int __lttf2 (long double @var{a}, long double @var{b})
423 These functions return a value less than zero if neither argument is
424 NaN, and @var{a} is strictly less than @var{b}.
427 @deftypefn {Runtime Function} int __lesf2 (float @var{a}, float @var{b})
428 @deftypefnx {Runtime Function} int __ledf2 (double @var{a}, double @var{b})
429 @deftypefnx {Runtime Function} int __letf2 (long double @var{a}, long double @var{b})
430 These functions return a value less than or equal to zero if neither
431 argument is NaN, and @var{a} is less than or equal to @var{b}.
434 @deftypefn {Runtime Function} int __gtsf2 (float @var{a}, float @var{b})
435 @deftypefnx {Runtime Function} int __gtdf2 (double @var{a}, double @var{b})
436 @deftypefnx {Runtime Function} int __gttf2 (long double @var{a}, long double @var{b})
437 These functions return a value greater than zero if neither argument
438 is NaN, and @var{a} is strictly greater than @var{b}.
441 @node Exception handling routines
442 @section Language-independent routines for exception handling
447 _Unwind_DeleteException
452 _Unwind_GetLanguageSpecificData
453 _Unwind_GetRegionStart
454 _Unwind_GetTextRelBase
455 _Unwind_GetDataRelBase
456 _Unwind_RaiseException
460 _Unwind_FindEnclosingFunction
461 _Unwind_SjLj_Register
462 _Unwind_SjLj_Unregister
463 _Unwind_SjLj_RaiseException
464 _Unwind_SjLj_ForcedUnwind
467 __deregister_frame_info
468 __deregister_frame_info_bases
470 __register_frame_info
471 __register_frame_info_bases
472 __register_frame_info_table
473 __register_frame_info_table_bases
474 __register_frame_table
477 @node Miscellaneous routines
478 @section Miscellaneous runtime library routines
480 @subsection Cache control functions
481 @deftypefn {Runtime Function} void __clear_cache (char *@var{beg}, char *@var{end})
482 This function clears the instruction cache between @var{beg} and @var{end}.