blob: cbeb10cf918edeb183caa27fe187c517fc45a829 [file] [log] [blame]
Daniel Dunbarb3a69012009-06-26 16:47:03 +00001Compiler-RT
2================================
3
4This directory and its subdirectories contain source code for the compiler
5support routines.
6
7Compiler-RT is open source software. You may freely distribute it under the
8terms of the license agreement found in LICENSE.txt.
9
10================================
11
Gabor Greif34ecf0f2009-07-03 14:37:30 +000012This is a replacement library for libgcc. Each function is contained
Daniel Dunbarb3a69012009-06-26 16:47:03 +000013in its own file. Each function has a corresponding unit test under
14test/Unit.
15
16A rudimentary script to test each file is in the file called
17test/Unit/test.
18
19Here is the specification for this library:
20
21http://gcc.gnu.org/onlinedocs/gccint/Libgcc.html#Libgcc
22
23Here is a synopsis of the contents of this library:
24
25typedef int si_int;
26typedef unsigned su_int;
27
28typedef long long di_int;
29typedef unsigned long long du_int;
30
31// Integral bit manipulation
32
33di_int __ashldi3(di_int a, si_int b); // a << b
Howard Hinnant09d99f32010-01-20 18:44:52 +000034ti_int __ashlti3(ti_int a, si_int b); // a << b
35
Daniel Dunbarb3a69012009-06-26 16:47:03 +000036di_int __ashrdi3(di_int a, si_int b); // a >> b arithmetic (sign fill)
Howard Hinnant09d99f32010-01-20 18:44:52 +000037ti_int __ashrti3(ti_int a, si_int b); // a >> b arithmetic (sign fill)
Daniel Dunbarb3a69012009-06-26 16:47:03 +000038di_int __lshrdi3(di_int a, si_int b); // a >> b logical (zero fill)
Howard Hinnant09d99f32010-01-20 18:44:52 +000039ti_int __lshrti3(ti_int a, si_int b); // a >> b logical (zero fill)
Daniel Dunbarb3a69012009-06-26 16:47:03 +000040
Gabor Greif34ecf0f2009-07-03 14:37:30 +000041si_int __clzsi2(si_int a); // count leading zeros
42si_int __clzdi2(di_int a); // count leading zeros
Howard Hinnant09d99f32010-01-20 18:44:52 +000043si_int __clzti2(ti_int a); // count leading zeros
Gabor Greif34ecf0f2009-07-03 14:37:30 +000044si_int __ctzsi2(si_int a); // count trailing zeros
45si_int __ctzdi2(di_int a); // count trailing zeros
Howard Hinnant09d99f32010-01-20 18:44:52 +000046si_int __ctzti2(ti_int a); // count trailing zeros
Daniel Dunbarb3a69012009-06-26 16:47:03 +000047
48si_int __ffsdi2(di_int a); // find least significant 1 bit
Howard Hinnant09d99f32010-01-20 18:44:52 +000049si_int __ffsti2(ti_int a); // find least significant 1 bit
Daniel Dunbarb3a69012009-06-26 16:47:03 +000050
51si_int __paritysi2(si_int a); // bit parity
52si_int __paritydi2(di_int a); // bit parity
Howard Hinnant09d99f32010-01-20 18:44:52 +000053si_int __parityti2(ti_int a); // bit parity
Daniel Dunbarb3a69012009-06-26 16:47:03 +000054
55si_int __popcountsi2(si_int a); // bit population
56si_int __popcountdi2(di_int a); // bit population
Howard Hinnant09d99f32010-01-20 18:44:52 +000057si_int __popcountti2(ti_int a); // bit population
58
59uint32_t __bswapsi2(uint32_t a); // a byteswapped, arm only
60uint64_t __bswapdi2(uint64_t a); // a byteswapped, arm only
Daniel Dunbarb3a69012009-06-26 16:47:03 +000061
62// Integral arithmetic
63
64di_int __negdi2 (di_int a); // -a
Howard Hinnant09d99f32010-01-20 18:44:52 +000065ti_int __negti2 (ti_int a); // -a
Daniel Dunbarb3a69012009-06-26 16:47:03 +000066di_int __muldi3 (di_int a, di_int b); // a * b
Howard Hinnant09d99f32010-01-20 18:44:52 +000067ti_int __multi3 (ti_int a, ti_int b); // a * b
68si_int __divsi3 (si_int a, si_int b); // a / b signed
Daniel Dunbarb3a69012009-06-26 16:47:03 +000069di_int __divdi3 (di_int a, di_int b); // a / b signed
Howard Hinnant09d99f32010-01-20 18:44:52 +000070ti_int __divti3 (ti_int a, ti_int b); // a / b signed
71su_int __udivsi3 (su_int n, su_int d); // a / b unsigned
Daniel Dunbarb3a69012009-06-26 16:47:03 +000072du_int __udivdi3 (du_int a, du_int b); // a / b unsigned
Howard Hinnant09d99f32010-01-20 18:44:52 +000073tu_int __udivti3 (tu_int a, tu_int b); // a / b unsigned
74si_int __modsi3 (si_int a, si_int b); // a % b signed
Daniel Dunbarb3a69012009-06-26 16:47:03 +000075di_int __moddi3 (di_int a, di_int b); // a % b signed
Howard Hinnant09d99f32010-01-20 18:44:52 +000076ti_int __modti3 (ti_int a, ti_int b); // a % b signed
77su_int __umodsi3 (su_int a, su_int b); // a % b unsigned
Daniel Dunbarb3a69012009-06-26 16:47:03 +000078du_int __umoddi3 (du_int a, du_int b); // a % b unsigned
Howard Hinnant09d99f32010-01-20 18:44:52 +000079tu_int __umodti3 (tu_int a, tu_int b); // a % b unsigned
Nick Kledzik5c080992011-03-17 00:09:13 +000080du_int __udivmoddi4(du_int a, du_int b, du_int* rem); // a / b, *rem = a % b unsigned
81tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem); // a / b, *rem = a % b unsigned
82su_int __udivmodsi4(su_int a, su_int b, su_int* rem); // a / b, *rem = a % b unsigned
83si_int __divmodsi4(si_int a, si_int b, si_int* rem); // a / b, *rem = a % b signed
84
85
Daniel Dunbarb3a69012009-06-26 16:47:03 +000086
87// Integral arithmetic with trapping overflow
88
89si_int __absvsi2(si_int a); // abs(a)
90di_int __absvdi2(di_int a); // abs(a)
Howard Hinnant09d99f32010-01-20 18:44:52 +000091ti_int __absvti2(ti_int a); // abs(a)
Daniel Dunbarb3a69012009-06-26 16:47:03 +000092
93si_int __negvsi2(si_int a); // -a
94di_int __negvdi2(di_int a); // -a
Howard Hinnant09d99f32010-01-20 18:44:52 +000095ti_int __negvti2(ti_int a); // -a
Daniel Dunbarb3a69012009-06-26 16:47:03 +000096
97si_int __addvsi3(si_int a, si_int b); // a + b
98di_int __addvdi3(di_int a, di_int b); // a + b
Howard Hinnant09d99f32010-01-20 18:44:52 +000099ti_int __addvti3(ti_int a, ti_int b); // a + b
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000100
101si_int __subvsi3(si_int a, si_int b); // a - b
102di_int __subvdi3(di_int a, di_int b); // a - b
Howard Hinnant09d99f32010-01-20 18:44:52 +0000103ti_int __subvti3(ti_int a, ti_int b); // a - b
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000104
105si_int __mulvsi3(si_int a, si_int b); // a * b
106di_int __mulvdi3(di_int a, di_int b); // a * b
Howard Hinnant09d99f32010-01-20 18:44:52 +0000107ti_int __mulvti3(ti_int a, ti_int b); // a * b
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000108
109// Integral comparison: a < b -> 0
110// a == b -> 1
111// a > b -> 2
112
113si_int __cmpdi2 (di_int a, di_int b);
Howard Hinnant09d99f32010-01-20 18:44:52 +0000114si_int __cmpti2 (ti_int a, ti_int b);
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000115si_int __ucmpdi2(du_int a, du_int b);
Howard Hinnant09d99f32010-01-20 18:44:52 +0000116si_int __ucmpti2(tu_int a, tu_int b);
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000117
118// Integral / floating point conversion
119
120di_int __fixsfdi( float a);
121di_int __fixdfdi( double a);
122di_int __fixxfdi(long double a);
123
Howard Hinnant09d99f32010-01-20 18:44:52 +0000124ti_int __fixsfti( float a);
125ti_int __fixdfti( double a);
126ti_int __fixxfti(long double a);
127uint64_t __fixtfdi(long double input); // ppc only, doesn't match documentation
128
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000129su_int __fixunssfsi( float a);
130su_int __fixunsdfsi( double a);
131su_int __fixunsxfsi(long double a);
132
133du_int __fixunssfdi( float a);
134du_int __fixunsdfdi( double a);
135du_int __fixunsxfdi(long double a);
136
Howard Hinnant09d99f32010-01-20 18:44:52 +0000137tu_int __fixunssfti( float a);
138tu_int __fixunsdfti( double a);
139tu_int __fixunsxfti(long double a);
140uint64_t __fixunstfdi(long double input); // ppc only
141
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000142float __floatdisf(di_int a);
143double __floatdidf(di_int a);
144long double __floatdixf(di_int a);
Howard Hinnant09d99f32010-01-20 18:44:52 +0000145long double __floatditf(int64_t a); // ppc only
146
147float __floattisf(ti_int a);
148double __floattidf(ti_int a);
149long double __floattixf(ti_int a);
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000150
151float __floatundisf(du_int a);
152double __floatundidf(du_int a);
153long double __floatundixf(du_int a);
Howard Hinnant09d99f32010-01-20 18:44:52 +0000154long double __floatunditf(uint64_t a); // ppc only
155
156float __floatuntisf(tu_int a);
157double __floatuntidf(tu_int a);
158long double __floatuntixf(tu_int a);
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000159
160// Floating point raised to integer power
161
162float __powisf2( float a, si_int b); // a ^ b
163double __powidf2( double a, si_int b); // a ^ b
164long double __powixf2(long double a, si_int b); // a ^ b
Howard Hinnant09d99f32010-01-20 18:44:52 +0000165long double __powitf2(long double a, si_int b); // ppc only, a ^ b
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000166
167// Complex arithmetic
168
169// (a + ib) * (c + id)
170
171 float _Complex __mulsc3( float a, float b, float c, float d);
172 double _Complex __muldc3(double a, double b, double c, double d);
173long double _Complex __mulxc3(long double a, long double b,
174 long double c, long double d);
Howard Hinnant09d99f32010-01-20 18:44:52 +0000175long double _Complex __multc3(long double a, long double b,
176 long double c, long double d); // ppc only
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000177
178// (a + ib) / (c + id)
179
180 float _Complex __divsc3( float a, float b, float c, float d);
181 double _Complex __divdc3(double a, double b, double c, double d);
182long double _Complex __divxc3(long double a, long double b,
183 long double c, long double d);
Howard Hinnant09d99f32010-01-20 18:44:52 +0000184long double _Complex __divtc3(long double a, long double b,
185 long double c, long double d); // ppc only
186
Nick Kledzika5556d72010-01-22 21:21:14 +0000187
188// Runtime support
189
190// __clear_cache() is used to tell process that new instructions have been
191// written to an address range. Necessary on processors that do not have
192// a unified instuction and data cache.
193void __clear_cache(void* start, void* end);
194
195// __enable_execute_stack() is used with nested functions when a trampoline
196// function is written onto the stack and that page range needs to be made
197// executable.
198void __enable_execute_stack(void* addr);
199
200// __gcc_personality_v0() is normally only called by the system unwinder.
201// C code (as opposed to C++) normally does not need a personality function
202// because there are no catch clauses or destructors to be run. But there
203// is a C language extension __attribute__((cleanup(func))) which marks local
204// variables as needing the cleanup function "func" to be run when the
205// variable goes out of scope. That includes when an exception is thrown,
206// so a personality handler is needed.
207_Unwind_Reason_Code __gcc_personality_v0(int version, _Unwind_Action actions,
208 uint64_t exceptionClass, struct _Unwind_Exception* exceptionObject,
209 _Unwind_Context_t context);
210
211// for use with some implementations of assert() in <assert.h>
212void __eprintf(const char* format, const char* assertion_expression,
213 const char* line, const char* file);
214
215
216
217// Power PC specific functions
218
219// There is no C interface to the saveFP/restFP functions. They are helper
220// functions called by the prolog and epilog of functions that need to save
221// a number of non-volatile float point registers.
222saveFP
223restFP
224
225// PowerPC has a standard template for trampoline functions. This function
226// generates a custom trampoline function with the specific realFunc
227// and localsPtr values.
228void __trampoline_setup(uint32_t* trampOnStack, int trampSizeAllocated,
229 const void* realFunc, void* localsPtr);
230
231// adds two 128-bit double-double precision values ( x + y )
232long double __gcc_qadd(long double x, long double y);
233
234// subtracts two 128-bit double-double precision values ( x - y )
235long double __gcc_qsub(long double x, long double y);
236
237// multiples two 128-bit double-double precision values ( x * y )
238long double __gcc_qmul(long double x, long double y);
239
240// divides two 128-bit double-double precision values ( x / y )
241long double __gcc_qdiv(long double a, long double b);
242
243
244// ARM specific functions
245
246// There is no C interface to the switch* functions. These helper functions
247// are only needed by Thumb1 code for efficient switch table generation.
248switch16
249switch32
250switch8
251switchu8
252
253// There is no C interface to the *_vfp_d8_d15_regs functions. There are
254// called in the prolog and epilog of Thumb1 functions. When the C++ ABI use
255// SJLJ for exceptions, each function with a catch clause or destuctors needs
256// to save and restore all registers in it prolog and epliog. But there is
257// no way to access vector and high float registers from thumb1 code, so the
258// compiler must add call outs to these helper functions in the prolog and
259// epilog.
260restore_vfp_d8_d15_regs
261save_vfp_d8_d15_regs
262
263
264// Note: long ago ARM processors did not have floating point hardware support.
265// Floating point was done in software and floating point parameters were
266// passed in integer registers. When hardware support was added for floating
267// point, new *vfp functions were added to do the same operations but with
268// floating point parameters in floating point registers.
269
Howard Hinnant09d99f32010-01-20 18:44:52 +0000270// Undocumented functions
271
Nick Kledzika5556d72010-01-22 21:21:14 +0000272float __addsf3vfp(float a, float b); // Appears to return a + b
273double __adddf3vfp(double a, double b); // Appears to return a + b
274float __divsf3vfp(float a, float b); // Appears to return a / b
275double __divdf3vfp(double a, double b); // Appears to return a / b
276int __eqsf2vfp(float a, float b); // Appears to return one
Howard Hinnant09d99f32010-01-20 18:44:52 +0000277 // iff a == b and neither is NaN.
Nick Kledzika5556d72010-01-22 21:21:14 +0000278int __eqdf2vfp(double a, double b); // Appears to return one
Howard Hinnant09d99f32010-01-20 18:44:52 +0000279 // iff a == b and neither is NaN.
Nick Kledzika5556d72010-01-22 21:21:14 +0000280double __extendsfdf2vfp(float a); // Appears to convert from
Howard Hinnant09d99f32010-01-20 18:44:52 +0000281 // float to double.
Nick Kledzika5556d72010-01-22 21:21:14 +0000282int __fixdfsivfp(double a); // Appears to convert from
Howard Hinnant09d99f32010-01-20 18:44:52 +0000283 // double to int.
Nick Kledzika5556d72010-01-22 21:21:14 +0000284int __fixsfsivfp(float a); // Appears to convert from
Howard Hinnant09d99f32010-01-20 18:44:52 +0000285 // float to int.
Nick Kledzika5556d72010-01-22 21:21:14 +0000286unsigned int __fixunssfsivfp(float a); // Appears to convert from
Howard Hinnant09d99f32010-01-20 18:44:52 +0000287 // float to unsigned int.
Nick Kledzika5556d72010-01-22 21:21:14 +0000288unsigned int __fixunsdfsivfp(double a); // Appears to convert from
Howard Hinnant09d99f32010-01-20 18:44:52 +0000289 // double to unsigned int.
Nick Kledzika5556d72010-01-22 21:21:14 +0000290double __floatsidfvfp(int a); // Appears to convert from
Howard Hinnant09d99f32010-01-20 18:44:52 +0000291 // int to double.
Nick Kledzika5556d72010-01-22 21:21:14 +0000292float __floatsisfvfp(int a); // Appears to convert from
Howard Hinnant09d99f32010-01-20 18:44:52 +0000293 // int to float.
Nick Kledzika5556d72010-01-22 21:21:14 +0000294double __floatunssidfvfp(unsigned int a); // Appears to convert from
Howard Hinnant09d99f32010-01-20 18:44:52 +0000295 // unisgned int to double.
Nick Kledzika5556d72010-01-22 21:21:14 +0000296float __floatunssisfvfp(unsigned int a); // Appears to convert from
Howard Hinnant09d99f32010-01-20 18:44:52 +0000297 // unisgned int to float.
Nick Kledzika5556d72010-01-22 21:21:14 +0000298int __gedf2vfp(double a, double b); // Appears to return __gedf2
Howard Hinnant09d99f32010-01-20 18:44:52 +0000299 // (a >= b)
Nick Kledzika5556d72010-01-22 21:21:14 +0000300int __gesf2vfp(float a, float b); // Appears to return __gesf2
Howard Hinnant09d99f32010-01-20 18:44:52 +0000301 // (a >= b)
Nick Kledzika5556d72010-01-22 21:21:14 +0000302int __gtdf2vfp(double a, double b); // Appears to return __gtdf2
Howard Hinnant09d99f32010-01-20 18:44:52 +0000303 // (a > b)
Nick Kledzika5556d72010-01-22 21:21:14 +0000304int __gtsf2vfp(float a, float b); // Appears to return __gtsf2
Howard Hinnant09d99f32010-01-20 18:44:52 +0000305 // (a > b)
Nick Kledzika5556d72010-01-22 21:21:14 +0000306int __ledf2vfp(double a, double b); // Appears to return __ledf2
Howard Hinnant09d99f32010-01-20 18:44:52 +0000307 // (a <= b)
Nick Kledzika5556d72010-01-22 21:21:14 +0000308int __lesf2vfp(float a, float b); // Appears to return __lesf2
Howard Hinnant09d99f32010-01-20 18:44:52 +0000309 // (a <= b)
Nick Kledzika5556d72010-01-22 21:21:14 +0000310int __ltdf2vfp(double a, double b); // Appears to return __ltdf2
Howard Hinnant09d99f32010-01-20 18:44:52 +0000311 // (a < b)
Nick Kledzika5556d72010-01-22 21:21:14 +0000312int __ltsf2vfp(float a, float b); // Appears to return __ltsf2
Howard Hinnant09d99f32010-01-20 18:44:52 +0000313 // (a < b)
Nick Kledzika5556d72010-01-22 21:21:14 +0000314double __muldf3vfp(double a, double b); // Appears to return a * b
315float __mulsf3vfp(float a, float b); // Appears to return a * b
316int __nedf2vfp(double a, double b); // Appears to return __nedf2
Howard Hinnant09d99f32010-01-20 18:44:52 +0000317 // (a != b)
Nick Kledzika5556d72010-01-22 21:21:14 +0000318double __negdf2vfp(double a); // Appears to return -a
319float __negsf2vfp(float a); // Appears to return -a
320float __negsf2vfp(float a); // Appears to return -a
321double __subdf3vfp(double a, double b); // Appears to return a - b
322float __subsf3vfp(float a, float b); // Appears to return a - b
323float __truncdfsf2vfp(double a); // Appears to convert from
Howard Hinnant09d99f32010-01-20 18:44:52 +0000324 // double to float.
Nick Kledzika5556d72010-01-22 21:21:14 +0000325int __unorddf2vfp(double a, double b); // Appears to return __unorddf2
326int __unordsf2vfp(float a, float b); // Appears to return __unordsf2
Howard Hinnant09d99f32010-01-20 18:44:52 +0000327
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000328
329Preconditions are listed for each function at the definition when there are any.
330Any preconditions reflect the specification at
331http://gcc.gnu.org/onlinedocs/gccint/Libgcc.html#Libgcc.
332
333Assumptions are listed in "int_lib.h", and in individual files. Where possible
334assumptions are checked at compile time.