libgcc.texi revision 132718
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>
5
6@node Libgcc
7@chapter The GCC low-level runtime library
8
9GCC provides a low-level runtime library, @file{libgcc.a} or
10@file{libgcc_s.so.1} on some platforms.  GCC generates calls to
11routines in this library automatically, whenever it needs to perform
12some operation that is too complicated to emit inline code for.
13
14Most of the routines in @code{libgcc} handle arithmetic operations
15that the target processor cannot perform directly.  This includes
16integer multiply and divide on some machines, and all floating-point
17operations on other machines.  @code{libgcc} also includes routines
18for exception handling, and a handful of miscellaneous operations.
19
20Some of these routines can be defined in mostly machine-independent C.
21Others must be hand-written in assembly language for each processor
22that needs them.
23
24GCC will also generate calls to C library routines, such as
25@code{memcpy} and @code{memset}, in some cases.  The set of routines
26that GCC may possibly use is documented in @ref{Other
27Builtins,,,gcc, Using the GNU Compiler Collection (GCC)}.
28
29These routines take arguments and return values of a specific machine
30mode, not a specific C type.  @xref{Machine Modes}, for an explanation
31of this concept.  For illustrative purposes, in this chapter the
32floating 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}
35and @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}.
38
39@menu
40* Integer library routines::
41* Soft float library routines::
42* Exception handling routines::
43* Miscellaneous routines::
44@end menu
45
46@node Integer library routines
47@section Routines for integer arithmetic
48
49The integer arithmetic routines are used on platforms that don't provide
50hardware support for arithmetic operations on some modes.
51
52@subsection Arithmetic functions
53
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})
57These functions return the result of shifting @var{a} left by @var{b} bits.
58@end deftypefn
59
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})
63These functions return the result of arithmetically shifting @var{a} right
64by @var{b} bits.
65@end deftypefn
66
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})
70These functions return the quotient of the signed division of @var{a} and
71@var{b}.
72@end deftypefn
73
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})
77These functions return the result of logically shifting @var{a} right by
78@var{b} bits.
79@end deftypefn
80
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})
84These functions return the remainder of the signed division of @var{a}
85and @var{b}.
86@end deftypefn
87
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})
91These functions return the product of @var{a} and @var{b}.
92@end deftypefn
93
94@deftypefn {Runtime Function} long __negdi2 (long @var{a})
95@deftypefnx {Runtime Function} {long long} __negti2 (long long @var{a})
96These functions return the negation of @var{a}.
97@end deftypefn
98
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})
102These functions return the quotient of the unsigned division of @var{a}
103and @var{b}.
104@end deftypefn
105
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})
108These functions calculate both the quotient and remainder of the unsigned
109division of @var{a} and @var{b}.  The return value is the quotient, and
110the remainder is placed in variable pointed to by @var{c}.
111@end deftypefn
112
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})
116These functions return the remainder of the unsigned division of @var{a}
117and @var{b}.
118@end deftypefn
119
120@subsection Comparison functions
121
122The following functions implement integral comparisons.  These functions
123implement a low-level compare, upon which the higher level comparison
124operators (such as less than and greater than or equal to) can be
125constructed.  The returned values lie in the range zero to two, to allow
126the high-level operators to be implemented by testing the returned
127result using either signed or unsigned comparison.
128
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})
131These 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.
134@end deftypefn
135
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})
138These functions perform an unsigned comparison of @var{a} and @var{b}.
139If @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.
141@end deftypefn
142
143@subsection Trapping arithmetic functions
144
145The following functions implement trapping arithmetic.  These functions
146call the libc function @code{abort} upon signed arithmetic overflow.
147
148@deftypefn {Runtime Function} int __absvsi2 (int @var{a})
149@deftypefnx {Runtime Function} long __absvdi2 (long @var{a})
150These functions return the absolute value of @var{a}.
151@end deftypefn
152
153@deftypefn {Runtime Function} int __addvsi3 (int @var{a}, int @var{b})
154@deftypefnx {Runtime Function} long __addvdi3 (long @var{a}, long @var{b})
155These functions return the sum of @var{a} and @var{b}; that is
156@code{@var{a} + @var{b}}.
157@end deftypefn
158
159@deftypefn {Runtime Function} int __mulvsi3 (int @var{a}, int @var{b})
160@deftypefnx {Runtime Function} long __mulvdi3 (long @var{a}, long @var{b})
161The functions return the product of @var{a} and @var{b}; that is
162@code{@var{a} * @var{b}}.
163@end deftypefn
164
165@deftypefn {Runtime Function} int __negvsi2 (int @var{a})
166@deftypefnx {Runtime Function} long __negvdi2 (long @var{a})
167These functions return the negation of @var{a}; that is @code{-@var{a}}.
168@end deftypefn
169
170@deftypefn {Runtime Function} int __subvsi3 (int @var{a}, int @var{b})
171@deftypefnx {Runtime Function} long __subvdi3 (long @var{a}, long @var{b})
172These functions return the difference between @var{b} and @var{a};
173that is @code{@var{a} - @var{b}}.
174@end deftypefn
175
176@subsection Bit operations
177
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})
181These functions return the number of leading 0-bits in @var{a}, starting
182at the most significant bit position.  If @var{a} is zero, the result is
183undefined.
184@end deftypefn
185
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})
189These functions return the number of trailing 0-bits in @var{a}, starting
190at the least significant bit position.  If @var{a} is zero, the result is
191undefined.
192@end deftypefn
193
194@deftypefn {Runtime Function} int __ffsdi2 (long @var{a})
195@deftypefnx {Runtime Function} int __ffsti2 (long long @var{a})
196These functions return the index of the least significant 1-bit in @var{a},
197or the value zero if @var{a} is zero.  The least significant bit is index
198one.
199@end deftypefn
200
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})
204These functions return the value zero if the number of bits set in
205@var{a} is even, and the value one otherwise.
206@end deftypefn
207
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})
211These functions return the number of bits set in @var{a}.
212@end deftypefn
213
214@node Soft float library routines
215@section Routines for floating point emulation
216@cindex soft float library
217@cindex arithmetic library
218@cindex math library
219@opindex msoft-float
220
221The software floating point library is used on machines which do not
222have hardware support for floating point.  It is also used whenever
223@option{-msoft-float} is used to disable generation of floating point
224instructions.  (Not all targets support this switch.)
225
226For compatibility with other compilers, the floating point emulation
227routines can be renamed with the @code{DECLARE_LIBRARY_RENAMES} macro
228(@pxref{Library Calls}).  In this section, the default names are used.
229
230Presently the library does not support @code{XFmode}, which is used
231for @code{long double} on some architectures.
232
233@subsection Arithmetic functions
234
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})
239These functions return the sum of @var{a} and @var{b}.
240@end deftypefn
241
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})
246These functions return the difference between @var{b} and @var{a};
247that is, @w{@math{@var{a} - @var{b}}}.
248@end deftypefn
249
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})
254These functions return the product of @var{a} and @var{b}.
255@end deftypefn
256
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})
261These functions return the quotient of @var{a} and @var{b}; that is,
262@w{@math{@var{a} / @var{b}}}.
263@end deftypefn
264
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})
269These functions return the negation of @var{a}.  They simply flip the
270sign bit, so they can produce negative zero and negative NaN.
271@end deftypefn
272
273@subsection Conversion functions
274
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})
280These functions extend @var{a} to the wider mode of their return
281type.
282@end deftypefn
283
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})
289These functions truncate @var{a} to the narrower mode of their return
290type, rounding toward zero.
291@end deftypefn
292
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})
297These functions convert @var{a} to a signed integer, rounding toward zero.
298@end deftypefn
299
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})
304These functions convert @var{a} to a signed long, rounding toward zero.
305@end deftypefn
306
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})
311These functions convert @var{a} to a signed long long, rounding toward zero.
312@end deftypefn
313
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})
318These functions convert @var{a} to an unsigned integer, rounding
319toward zero.  Negative values all become zero.
320@end deftypefn
321
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})
326These functions convert @var{a} to an unsigned long, rounding
327toward zero.  Negative values all become zero.
328@end deftypefn
329
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})
334These functions convert @var{a} to an unsigned long long, rounding
335toward zero.  Negative values all become zero.
336@end deftypefn
337
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})
342These functions convert @var{i}, a signed integer, to floating point.
343@end deftypefn
344
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})
349These functions convert @var{i}, a signed long, to floating point.
350@end deftypefn
351
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})
356These functions convert @var{i}, a signed long long, to floating point.
357@end deftypefn
358
359@subsection Comparison functions
360
361There are two sets of basic comparison functions.
362
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})
366These functions calculate @math{a <=> b}.  That is, if @var{a} is less
367than @var{b}, they return -1; if @var{a} is greater than @var{b}, they
368return 1; and if @var{a} and @var{b} are equal they return 0.  If
369either argument is NaN they return 1, but you should not rely on this;
370if NaN is a possibility, use one of the higher-level comparison
371functions.
372@end deftypefn
373
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})
377These functions return a nonzero value if either argument is NaN, otherwise 0.
378@end deftypefn
379
380There is also a complete group of higher level functions which
381correspond directly to comparison operators.  They implement the ISO C
382semantics for floating-point comparisons, taking NaN into account.
383Pay careful attention to the return values defined for each set.
384Under the hood, all of these routines are implemented as
385
386@smallexample
387  if (__unord@var{X}f2 (a, b))
388    return @var{E};
389  return __cmp@var{X}f2 (a, b);
390@end smallexample
391
392@noindent
393where @var{E} is a constant chosen to give the proper behavior for
394NaN.  Thus, the meaning of the return value is different for each set.
395Do not rely on this implementation; only the semantics documented
396below are guaranteed.
397
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})
401These functions return zero if neither argument is NaN, and @var{a} and
402@var{b} are equal.
403@end deftypefn
404
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})
408These functions return a nonzero value if either argument is NaN, or
409if @var{a} and @var{b} are unequal.
410@end deftypefn
411
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})
415These functions return a value greater than or equal to zero if
416neither argument is NaN, and @var{a} is greater than or equal to
417@var{b}.
418@end deftypefn
419
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})
423These functions return a value less than zero if neither argument is
424NaN, and @var{a} is strictly less than @var{b}.
425@end deftypefn
426
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})
430These functions return a value less than or equal to zero if neither
431argument is NaN, and @var{a} is less than or equal to @var{b}.
432@end deftypefn
433
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})
437These functions return a value greater than zero if neither argument
438is NaN, and @var{a} is strictly greater than @var{b}.
439@end deftypefn
440
441@node Exception handling routines
442@section Language-independent routines for exception handling
443
444document me!
445
446@smallexample
447  _Unwind_DeleteException
448  _Unwind_Find_FDE
449  _Unwind_ForcedUnwind
450  _Unwind_GetGR
451  _Unwind_GetIP
452  _Unwind_GetLanguageSpecificData
453  _Unwind_GetRegionStart
454  _Unwind_GetTextRelBase
455  _Unwind_GetDataRelBase
456  _Unwind_RaiseException
457  _Unwind_Resume
458  _Unwind_SetGR
459  _Unwind_SetIP
460  _Unwind_FindEnclosingFunction
461  _Unwind_SjLj_Register
462  _Unwind_SjLj_Unregister
463  _Unwind_SjLj_RaiseException
464  _Unwind_SjLj_ForcedUnwind
465  _Unwind_SjLj_Resume
466  __deregister_frame
467  __deregister_frame_info
468  __deregister_frame_info_bases
469  __register_frame
470  __register_frame_info
471  __register_frame_info_bases
472  __register_frame_info_table
473  __register_frame_info_table_bases
474  __register_frame_table
475@end smallexample
476
477@node Miscellaneous routines
478@section Miscellaneous runtime library routines
479
480@subsection Cache control functions
481@deftypefn {Runtime Function} void __clear_cache (char *@var{beg}, char *@var{end})
482This function clears the instruction cache between @var{beg} and @var{end}.
483@end deftypefn
484
485