1214152SedCompiler-RT
2214152Sed================================
3214152Sed
4214152SedThis directory and its subdirectories contain source code for the compiler
5214152Sedsupport routines.
6214152Sed
7214152SedCompiler-RT is open source software. You may freely distribute it under the
8214152Sedterms of the license agreement found in LICENSE.txt.
9214152Sed
10214152Sed================================
11214152Sed
12214152SedThis is a replacement library for libgcc.  Each function is contained
13214152Sedin its own file.  Each function has a corresponding unit test under
14214152Sedtest/Unit.
15214152Sed
16214152SedA rudimentary script to test each file is in the file called
17214152Sedtest/Unit/test.
18214152Sed
19214152SedHere is the specification for this library:
20214152Sed
21214152Sedhttp://gcc.gnu.org/onlinedocs/gccint/Libgcc.html#Libgcc
22214152Sed
23214152SedHere is a synopsis of the contents of this library:
24214152Sed
25214152Sedtypedef      int si_int;
26214152Sedtypedef unsigned su_int;
27214152Sed
28214152Sedtypedef          long long di_int;
29214152Sedtypedef unsigned long long du_int;
30214152Sed
31214152Sed// Integral bit manipulation
32214152Sed
33214152Seddi_int __ashldi3(di_int a, si_int b);      // a << b
34214152Sedti_int __ashlti3(ti_int a, si_int b);      // a << b
35214152Sed
36214152Seddi_int __ashrdi3(di_int a, si_int b);      // a >> b  arithmetic (sign fill)
37214152Sedti_int __ashrti3(ti_int a, si_int b);      // a >> b  arithmetic (sign fill)
38214152Seddi_int __lshrdi3(di_int a, si_int b);      // a >> b  logical    (zero fill)
39214152Sedti_int __lshrti3(ti_int a, si_int b);      // a >> b  logical    (zero fill)
40214152Sed
41214152Sedsi_int __clzsi2(si_int a);  // count leading zeros
42214152Sedsi_int __clzdi2(di_int a);  // count leading zeros
43214152Sedsi_int __clzti2(ti_int a);  // count leading zeros
44214152Sedsi_int __ctzsi2(si_int a);  // count trailing zeros
45214152Sedsi_int __ctzdi2(di_int a);  // count trailing zeros
46214152Sedsi_int __ctzti2(ti_int a);  // count trailing zeros
47214152Sed
48214152Sedsi_int __ffsdi2(di_int a);  // find least significant 1 bit
49214152Sedsi_int __ffsti2(ti_int a);  // find least significant 1 bit
50214152Sed
51214152Sedsi_int __paritysi2(si_int a);  // bit parity
52214152Sedsi_int __paritydi2(di_int a);  // bit parity
53214152Sedsi_int __parityti2(ti_int a);  // bit parity
54214152Sed
55214152Sedsi_int __popcountsi2(si_int a);  // bit population
56214152Sedsi_int __popcountdi2(di_int a);  // bit population
57214152Sedsi_int __popcountti2(ti_int a);  // bit population
58214152Sed
59214152Seduint32_t __bswapsi2(uint32_t a);   // a byteswapped, arm only
60214152Seduint64_t __bswapdi2(uint64_t a);   // a byteswapped, arm only
61214152Sed
62214152Sed// Integral arithmetic
63214152Sed
64214152Seddi_int __negdi2    (di_int a);                         // -a
65214152Sedti_int __negti2    (ti_int a);                         // -a
66214152Seddi_int __muldi3    (di_int a, di_int b);               // a * b
67214152Sedti_int __multi3    (ti_int a, ti_int b);               // a * b
68214152Sedsi_int __divsi3    (si_int a, si_int b);               // a / b   signed
69214152Seddi_int __divdi3    (di_int a, di_int b);               // a / b   signed
70214152Sedti_int __divti3    (ti_int a, ti_int b);               // a / b   signed
71214152Sedsu_int __udivsi3   (su_int n, su_int d);               // a / b   unsigned
72214152Seddu_int __udivdi3   (du_int a, du_int b);               // a / b   unsigned
73214152Sedtu_int __udivti3   (tu_int a, tu_int b);               // a / b   unsigned
74214152Sedsi_int __modsi3    (si_int a, si_int b);               // a % b   signed
75214152Seddi_int __moddi3    (di_int a, di_int b);               // a % b   signed
76214152Sedti_int __modti3    (ti_int a, ti_int b);               // a % b   signed
77214152Sedsu_int __umodsi3   (su_int a, su_int b);               // a % b   unsigned
78214152Seddu_int __umoddi3   (du_int a, du_int b);               // a % b   unsigned
79214152Sedtu_int __umodti3   (tu_int a, tu_int b);               // a % b   unsigned
80222656Seddu_int __udivmoddi4(du_int a, du_int b, du_int* rem);  // a / b, *rem = a % b  unsigned
81222656Sedtu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem);  // a / b, *rem = a % b  unsigned
82222656Sedsu_int __udivmodsi4(su_int a, su_int b, su_int* rem);  // a / b, *rem = a % b  unsigned
83222656Sedsi_int __divmodsi4(si_int a, si_int b, si_int* rem);   // a / b, *rem = a % b  signed
84214152Sed
85222656Sed
86222656Sed
87214152Sed//  Integral arithmetic with trapping overflow
88214152Sed
89214152Sedsi_int __absvsi2(si_int a);           // abs(a)
90214152Seddi_int __absvdi2(di_int a);           // abs(a)
91214152Sedti_int __absvti2(ti_int a);           // abs(a)
92214152Sed
93214152Sedsi_int __negvsi2(si_int a);           // -a
94214152Seddi_int __negvdi2(di_int a);           // -a
95214152Sedti_int __negvti2(ti_int a);           // -a
96214152Sed
97214152Sedsi_int __addvsi3(si_int a, si_int b);  // a + b
98214152Seddi_int __addvdi3(di_int a, di_int b);  // a + b
99214152Sedti_int __addvti3(ti_int a, ti_int b);  // a + b
100214152Sed
101214152Sedsi_int __subvsi3(si_int a, si_int b);  // a - b
102214152Seddi_int __subvdi3(di_int a, di_int b);  // a - b
103214152Sedti_int __subvti3(ti_int a, ti_int b);  // a - b
104214152Sed
105214152Sedsi_int __mulvsi3(si_int a, si_int b);  // a * b
106214152Seddi_int __mulvdi3(di_int a, di_int b);  // a * b
107214152Sedti_int __mulvti3(ti_int a, ti_int b);  // a * b
108214152Sed
109236011Smarius
110236011Smarius// Integral arithmetic which returns if overflow
111236011Smarius
112236011Smariussi_int __mulosi4(si_int a, si_int b, int* overflow);  // a * b, overflow set to one if result not in signed range
113236011Smariusdi_int __mulodi4(di_int a, di_int b, int* overflow);  // a * b, overflow set to one if result not in signed range
114236011Smariusti_int __muloti4(ti_int a, ti_int b, int* overflow);  // a * b, overflow set to
115236011Smarius one if result not in signed range
116236011Smarius
117236011Smarius
118214152Sed//  Integral comparison: a  < b -> 0
119214152Sed//                       a == b -> 1
120214152Sed//                       a  > b -> 2
121214152Sed
122214152Sedsi_int __cmpdi2 (di_int a, di_int b);
123214152Sedsi_int __cmpti2 (ti_int a, ti_int b);
124214152Sedsi_int __ucmpdi2(du_int a, du_int b);
125214152Sedsi_int __ucmpti2(tu_int a, tu_int b);
126214152Sed
127214152Sed//  Integral / floating point conversion
128214152Sed
129214152Seddi_int __fixsfdi(      float a);
130214152Seddi_int __fixdfdi(     double a);
131214152Seddi_int __fixxfdi(long double a);
132214152Sed
133214152Sedti_int __fixsfti(      float a);
134214152Sedti_int __fixdfti(     double a);
135214152Sedti_int __fixxfti(long double a);
136214152Seduint64_t __fixtfdi(long double input);  // ppc only, doesn't match documentation
137214152Sed
138214152Sedsu_int __fixunssfsi(      float a);
139214152Sedsu_int __fixunsdfsi(     double a);
140214152Sedsu_int __fixunsxfsi(long double a);
141214152Sed
142214152Seddu_int __fixunssfdi(      float a);
143214152Seddu_int __fixunsdfdi(     double a);
144214152Seddu_int __fixunsxfdi(long double a);
145214152Sed
146214152Sedtu_int __fixunssfti(      float a);
147214152Sedtu_int __fixunsdfti(     double a);
148214152Sedtu_int __fixunsxfti(long double a);
149214152Seduint64_t __fixunstfdi(long double input);  // ppc only
150214152Sed
151214152Sedfloat       __floatdisf(di_int a);
152214152Seddouble      __floatdidf(di_int a);
153214152Sedlong double __floatdixf(di_int a);
154214152Sedlong double __floatditf(int64_t a);        // ppc only
155214152Sed
156214152Sedfloat       __floattisf(ti_int a);
157214152Seddouble      __floattidf(ti_int a);
158214152Sedlong double __floattixf(ti_int a);
159214152Sed
160214152Sedfloat       __floatundisf(du_int a);
161214152Seddouble      __floatundidf(du_int a);
162214152Sedlong double __floatundixf(du_int a);
163214152Sedlong double __floatunditf(uint64_t a);     // ppc only
164214152Sed
165214152Sedfloat       __floatuntisf(tu_int a);
166214152Seddouble      __floatuntidf(tu_int a);
167214152Sedlong double __floatuntixf(tu_int a);
168214152Sed
169214152Sed//  Floating point raised to integer power
170214152Sed
171214152Sedfloat       __powisf2(      float a, si_int b);  // a ^ b
172214152Seddouble      __powidf2(     double a, si_int b);  // a ^ b
173214152Sedlong double __powixf2(long double a, si_int b);  // a ^ b
174214152Sedlong double __powitf2(long double a, si_int b);  // ppc only, a ^ b
175214152Sed
176214152Sed//  Complex arithmetic
177214152Sed
178214152Sed//  (a + ib) * (c + id)
179214152Sed
180214152Sed      float _Complex __mulsc3( float a,  float b,  float c,  float d);
181214152Sed     double _Complex __muldc3(double a, double b, double c, double d);
182214152Sedlong double _Complex __mulxc3(long double a, long double b,
183214152Sed                              long double c, long double d);
184214152Sedlong double _Complex __multc3(long double a, long double b,
185214152Sed                              long double c, long double d); // ppc only
186214152Sed
187214152Sed//  (a + ib) / (c + id)
188214152Sed
189214152Sed      float _Complex __divsc3( float a,  float b,  float c,  float d);
190214152Sed     double _Complex __divdc3(double a, double b, double c, double d);
191214152Sedlong double _Complex __divxc3(long double a, long double b,
192214152Sed                              long double c, long double d);
193214152Sedlong double _Complex __divtc3(long double a, long double b,
194214152Sed                              long double c, long double d);  // ppc only
195214152Sed
196214152Sed
197214152Sed//         Runtime support
198214152Sed
199214152Sed// __clear_cache() is used to tell process that new instructions have been
200214152Sed// written to an address range.  Necessary on processors that do not have
201214152Sed// a unified instuction and data cache.
202214152Sedvoid __clear_cache(void* start, void* end);
203214152Sed
204214152Sed// __enable_execute_stack() is used with nested functions when a trampoline
205214152Sed// function is written onto the stack and that page range needs to be made
206214152Sed// executable.
207214152Sedvoid __enable_execute_stack(void* addr);
208214152Sed
209214152Sed// __gcc_personality_v0() is normally only called by the system unwinder.
210214152Sed// C code (as opposed to C++) normally does not need a personality function
211214152Sed// because there are no catch clauses or destructors to be run.  But there
212214152Sed// is a C language extension __attribute__((cleanup(func))) which marks local
213214152Sed// variables as needing the cleanup function "func" to be run when the
214214152Sed// variable goes out of scope.  That includes when an exception is thrown,
215214152Sed// so a personality handler is needed.  
216214152Sed_Unwind_Reason_Code __gcc_personality_v0(int version, _Unwind_Action actions,
217214152Sed         uint64_t exceptionClass, struct _Unwind_Exception* exceptionObject,
218214152Sed         _Unwind_Context_t context);
219214152Sed
220214152Sed// for use with some implementations of assert() in <assert.h>
221214152Sedvoid __eprintf(const char* format, const char* assertion_expression,
222214152Sed				const char* line, const char* file);
223214152Sed				
224214152Sed
225214152Sed
226214152Sed//   Power PC specific functions
227214152Sed
228214152Sed// There is no C interface to the saveFP/restFP functions.  They are helper
229214152Sed// functions called by the prolog and epilog of functions that need to save
230214152Sed// a number of non-volatile float point registers.  
231214152SedsaveFP
232214152SedrestFP
233214152Sed
234214152Sed// PowerPC has a standard template for trampoline functions.  This function
235214152Sed// generates a custom trampoline function with the specific realFunc
236214152Sed// and localsPtr values.
237214152Sedvoid __trampoline_setup(uint32_t* trampOnStack, int trampSizeAllocated, 
238214152Sed                                const void* realFunc, void* localsPtr);
239214152Sed
240214152Sed// adds two 128-bit double-double precision values ( x + y )
241214152Sedlong double __gcc_qadd(long double x, long double y);  
242214152Sed
243214152Sed// subtracts two 128-bit double-double precision values ( x - y )
244214152Sedlong double __gcc_qsub(long double x, long double y); 
245214152Sed
246214152Sed// multiples two 128-bit double-double precision values ( x * y )
247214152Sedlong double __gcc_qmul(long double x, long double y);  
248214152Sed
249214152Sed// divides two 128-bit double-double precision values ( x / y )
250214152Sedlong double __gcc_qdiv(long double a, long double b);  
251214152Sed
252214152Sed
253214152Sed//    ARM specific functions
254214152Sed
255214152Sed// There is no C interface to the switch* functions.  These helper functions
256214152Sed// are only needed by Thumb1 code for efficient switch table generation.
257214152Sedswitch16
258214152Sedswitch32
259214152Sedswitch8
260214152Sedswitchu8
261214152Sed
262214152Sed// There is no C interface to the *_vfp_d8_d15_regs functions.  There are
263214152Sed// called in the prolog and epilog of Thumb1 functions.  When the C++ ABI use
264214152Sed// SJLJ for exceptions, each function with a catch clause or destuctors needs
265214152Sed// to save and restore all registers in it prolog and epliog.  But there is 
266214152Sed// no way to access vector and high float registers from thumb1 code, so the 
267214152Sed// compiler must add call outs to these helper functions in the prolog and 
268214152Sed// epilog.
269214152Sedrestore_vfp_d8_d15_regs
270214152Sedsave_vfp_d8_d15_regs
271214152Sed
272214152Sed
273214152Sed// Note: long ago ARM processors did not have floating point hardware support.
274214152Sed// Floating point was done in software and floating point parameters were 
275214152Sed// passed in integer registers.  When hardware support was added for floating
276214152Sed// point, new *vfp functions were added to do the same operations but with 
277214152Sed// floating point parameters in floating point registers.
278214152Sed
279214152Sed// Undocumented functions
280214152Sed
281214152Sedfloat  __addsf3vfp(float a, float b);   // Appears to return a + b
282214152Seddouble __adddf3vfp(double a, double b); // Appears to return a + b
283214152Sedfloat  __divsf3vfp(float a, float b);   // Appears to return a / b
284214152Seddouble __divdf3vfp(double a, double b); // Appears to return a / b
285214152Sedint    __eqsf2vfp(float a, float b);    // Appears to return  one
286214152Sed                                        //     iff a == b and neither is NaN.
287214152Sedint    __eqdf2vfp(double a, double b);  // Appears to return  one
288214152Sed                                        //     iff a == b and neither is NaN.
289214152Seddouble __extendsfdf2vfp(float a);       // Appears to convert from
290214152Sed                                        //     float to double.
291214152Sedint    __fixdfsivfp(double a);          // Appears to convert from
292214152Sed                                        //     double to int.
293214152Sedint    __fixsfsivfp(float a);           // Appears to convert from
294214152Sed                                        //     float to int.
295214152Sedunsigned int __fixunssfsivfp(float a);  // Appears to convert from
296214152Sed                                        //     float to unsigned int.
297214152Sedunsigned int __fixunsdfsivfp(double a); // Appears to convert from
298214152Sed                                        //     double to unsigned int.
299214152Seddouble __floatsidfvfp(int a);           // Appears to convert from
300214152Sed                                        //     int to double.
301214152Sedfloat __floatsisfvfp(int a);            // Appears to convert from
302214152Sed                                        //     int to float.
303214152Seddouble __floatunssidfvfp(unsigned int a); // Appears to convert from
304214152Sed                                        //     unisgned int to double.
305214152Sedfloat __floatunssisfvfp(unsigned int a); // Appears to convert from
306214152Sed                                        //     unisgned int to float.
307214152Sedint __gedf2vfp(double a, double b);     // Appears to return __gedf2
308214152Sed                                        //     (a >= b)
309214152Sedint __gesf2vfp(float a, float b);       // Appears to return __gesf2
310214152Sed                                        //     (a >= b)
311214152Sedint __gtdf2vfp(double a, double b);     // Appears to return __gtdf2
312214152Sed                                        //     (a > b)
313214152Sedint __gtsf2vfp(float a, float b);       // Appears to return __gtsf2
314214152Sed                                        //     (a > b)
315214152Sedint __ledf2vfp(double a, double b);     // Appears to return __ledf2
316214152Sed                                        //     (a <= b)
317214152Sedint __lesf2vfp(float a, float b);       // Appears to return __lesf2
318214152Sed                                        //     (a <= b)
319214152Sedint __ltdf2vfp(double a, double b);     // Appears to return __ltdf2
320214152Sed                                        //     (a < b)
321214152Sedint __ltsf2vfp(float a, float b);       // Appears to return __ltsf2
322214152Sed                                        //     (a < b)
323214152Seddouble __muldf3vfp(double a, double b); // Appears to return a * b
324214152Sedfloat __mulsf3vfp(float a, float b);    // Appears to return a * b
325214152Sedint __nedf2vfp(double a, double b);     // Appears to return __nedf2
326214152Sed                                        //     (a != b)
327214152Seddouble __negdf2vfp(double a);           // Appears to return -a
328214152Sedfloat __negsf2vfp(float a);             // Appears to return -a
329214152Sedfloat __negsf2vfp(float a);             // Appears to return -a
330214152Seddouble __subdf3vfp(double a, double b); // Appears to return a - b
331214152Sedfloat __subsf3vfp(float a, float b);    // Appears to return a - b
332214152Sedfloat __truncdfsf2vfp(double a);        // Appears to convert from
333214152Sed                                        //     double to float.
334214152Sedint __unorddf2vfp(double a, double b);  // Appears to return __unorddf2
335214152Sedint __unordsf2vfp(float a, float b);    // Appears to return __unordsf2
336214152Sed
337214152Sed
338214152SedPreconditions are listed for each function at the definition when there are any.
339214152SedAny preconditions reflect the specification at
340214152Sedhttp://gcc.gnu.org/onlinedocs/gccint/Libgcc.html#Libgcc.
341214152Sed
342214152SedAssumptions are listed in "int_lib.h", and in individual files.  Where possible
343214152Sedassumptions are checked at compile time.
344