README.txt revision 225736
1204076SpjdCompiler-RT
2204076Spjd================================
3219351Spjd
4204076SpjdThis directory and its subdirectories contain source code for the compiler
5204076Spjdsupport routines.
6204076Spjd
7204076SpjdCompiler-RT is open source software. You may freely distribute it under the
8204076Spjdterms of the license agreement found in LICENSE.txt.
9204076Spjd
10204076Spjd================================
11204076Spjd
12204076SpjdThis is a replacement library for libgcc.  Each function is contained
13204076Spjdin its own file.  Each function has a corresponding unit test under
14204076Spjdtest/Unit.
15204076Spjd
16204076SpjdA rudimentary script to test each file is in the file called
17204076Spjdtest/Unit/test.
18204076Spjd
19204076SpjdHere is the specification for this library:
20204076Spjd
21204076Spjdhttp://gcc.gnu.org/onlinedocs/gccint/Libgcc.html#Libgcc
22204076Spjd
23204076SpjdHere is a synopsis of the contents of this library:
24204076Spjd
25204076Spjdtypedef      int si_int;
26204076Spjdtypedef unsigned su_int;
27204076Spjd
28204076Spjdtypedef          long long di_int;
29204076Spjdtypedef unsigned long long du_int;
30204076Spjd
31204076Spjd// Integral bit manipulation
32204076Spjd
33204076Spjddi_int __ashldi3(di_int a, si_int b);      // a << b
34204076Spjdti_int __ashlti3(ti_int a, si_int b);      // a << b
35204076Spjd
36204076Spjddi_int __ashrdi3(di_int a, si_int b);      // a >> b  arithmetic (sign fill)
37204076Spjdti_int __ashrti3(ti_int a, si_int b);      // a >> b  arithmetic (sign fill)
38204076Spjddi_int __lshrdi3(di_int a, si_int b);      // a >> b  logical    (zero fill)
39204076Spjdti_int __lshrti3(ti_int a, si_int b);      // a >> b  logical    (zero fill)
40204076Spjd
41204076Spjdsi_int __clzsi2(si_int a);  // count leading zeros
42204076Spjdsi_int __clzdi2(di_int a);  // count leading zeros
43204076Spjdsi_int __clzti2(ti_int a);  // count leading zeros
44204076Spjdsi_int __ctzsi2(si_int a);  // count trailing zeros
45219351Spjdsi_int __ctzdi2(di_int a);  // count trailing zeros
46219351Spjdsi_int __ctzti2(ti_int a);  // count trailing zeros
47219351Spjd
48219354Spjdsi_int __ffsdi2(di_int a);  // find least significant 1 bit
49204076Spjdsi_int __ffsti2(ti_int a);  // find least significant 1 bit
50204076Spjd
51204076Spjdsi_int __paritysi2(si_int a);  // bit parity
52204076Spjdsi_int __paritydi2(di_int a);  // bit parity
53204076Spjdsi_int __parityti2(ti_int a);  // bit parity
54204076Spjd
55204076Spjdsi_int __popcountsi2(si_int a);  // bit population
56204076Spjdsi_int __popcountdi2(di_int a);  // bit population
57204076Spjdsi_int __popcountti2(ti_int a);  // bit population
58212033Spjd
59212033Spjduint32_t __bswapsi2(uint32_t a);   // a byteswapped, arm only
60212033Spjduint64_t __bswapdi2(uint64_t a);   // a byteswapped, arm only
61212033Spjd
62204076Spjd// Integral arithmetic
63204076Spjd
64204076Spjddi_int __negdi2    (di_int a);                         // -a
65204076Spjdti_int __negti2    (ti_int a);                         // -a
66204076Spjddi_int __muldi3    (di_int a, di_int b);               // a * b
67204076Spjdti_int __multi3    (ti_int a, ti_int b);               // a * b
68204076Spjdsi_int __divsi3    (si_int a, si_int b);               // a / b   signed
69204076Spjddi_int __divdi3    (di_int a, di_int b);               // a / b   signed
70219354Spjdti_int __divti3    (ti_int a, ti_int b);               // a / b   signed
71221078Strocinysu_int __udivsi3   (su_int n, su_int d);               // a / b   unsigned
72204076Spjddu_int __udivdi3   (du_int a, du_int b);               // a / b   unsigned
73221078Strocinytu_int __udivti3   (tu_int a, tu_int b);               // a / b   unsigned
74204076Spjdsi_int __modsi3    (si_int a, si_int b);               // a % b   signed
75204076Spjddi_int __moddi3    (di_int a, di_int b);               // a % b   signed
76204076Spjdti_int __modti3    (ti_int a, ti_int b);               // a % b   signed
77204076Spjdsu_int __umodsi3   (su_int a, su_int b);               // a % b   unsigned
78204076Spjddu_int __umoddi3   (du_int a, du_int b);               // a % b   unsigned
79204076Spjdtu_int __umodti3   (tu_int a, tu_int b);               // a % b   unsigned
80204076Spjddu_int __udivmoddi4(du_int a, du_int b, du_int* rem);  // a / b, *rem = a % b  unsigned
81204076Spjdtu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem);  // a / b, *rem = a % b  unsigned
82212033Spjdsu_int __udivmodsi4(su_int a, su_int b, su_int* rem);  // a / b, *rem = a % b  unsigned
83204076Spjdsi_int __divmodsi4(si_int a, si_int b, si_int* rem);   // a / b, *rem = a % b  signed
84204076Spjd
85204076Spjd
86204076Spjd
87204076Spjd//  Integral arithmetic with trapping overflow
88204076Spjd
89204076Spjdsi_int __absvsi2(si_int a);           // abs(a)
90204076Spjddi_int __absvdi2(di_int a);           // abs(a)
91204076Spjdti_int __absvti2(ti_int a);           // abs(a)
92204076Spjd
93204076Spjdsi_int __negvsi2(si_int a);           // -a
94204076Spjddi_int __negvdi2(di_int a);           // -a
95204076Spjdti_int __negvti2(ti_int a);           // -a
96204076Spjd
97204076Spjdsi_int __addvsi3(si_int a, si_int b);  // a + b
98204076Spjddi_int __addvdi3(di_int a, di_int b);  // a + b
99204076Spjdti_int __addvti3(ti_int a, ti_int b);  // a + b
100204076Spjd
101219351Spjdsi_int __subvsi3(si_int a, si_int b);  // a - b
102204076Spjddi_int __subvdi3(di_int a, di_int b);  // a - b
103204076Spjdti_int __subvti3(ti_int a, ti_int b);  // a - b
104204076Spjd
105204076Spjdsi_int __mulvsi3(si_int a, si_int b);  // a * b
106204076Spjddi_int __mulvdi3(di_int a, di_int b);  // a * b
107204076Spjdti_int __mulvti3(ti_int a, ti_int b);  // a * b
108204076Spjd
109204076Spjd//  Integral comparison: a  < b -> 0
110204076Spjd//                       a == b -> 1
111204076Spjd//                       a  > b -> 2
112204076Spjd
113204076Spjdsi_int __cmpdi2 (di_int a, di_int b);
114204076Spjdsi_int __cmpti2 (ti_int a, ti_int b);
115246922Spjdsi_int __ucmpdi2(du_int a, du_int b);
116204076Spjdsi_int __ucmpti2(tu_int a, tu_int b);
117229945Spjd
118204076Spjd//  Integral / floating point conversion
119204076Spjd
120204076Spjddi_int __fixsfdi(      float a);
121229945Spjddi_int __fixdfdi(     double a);
122204076Spjddi_int __fixxfdi(long double a);
123229945Spjd
124204076Spjdti_int __fixsfti(      float a);
125204076Spjdti_int __fixdfti(     double a);
126204076Spjdti_int __fixxfti(long double a);
127204076Spjduint64_t __fixtfdi(long double input);  // ppc only, doesn't match documentation
128204076Spjd
129204076Spjdsu_int __fixunssfsi(      float a);
130204076Spjdsu_int __fixunsdfsi(     double a);
131204076Spjdsu_int __fixunsxfsi(long double a);
132204076Spjd
133204076Spjddu_int __fixunssfdi(      float a);
134212033Spjddu_int __fixunsdfdi(     double a);
135204076Spjddu_int __fixunsxfdi(long double a);
136204076Spjd
137204076Spjdtu_int __fixunssfti(      float a);
138204076Spjdtu_int __fixunsdfti(     double a);
139204076Spjdtu_int __fixunsxfti(long double a);
140204076Spjduint64_t __fixunstfdi(long double input);  // ppc only
141204076Spjd
142204076Spjdfloat       __floatdisf(di_int a);
143204076Spjddouble      __floatdidf(di_int a);
144229945Spjdlong double __floatdixf(di_int a);
145204076Spjdlong double __floatditf(int64_t a);        // ppc only
146204076Spjd
147246922Spjdfloat       __floattisf(ti_int a);
148204076Spjddouble      __floattidf(ti_int a);
149204076Spjdlong double __floattixf(ti_int a);
150204076Spjd
151204076Spjdfloat       __floatundisf(du_int a);
152204076Spjddouble      __floatundidf(du_int a);
153204076Spjdlong double __floatundixf(du_int a);
154204076Spjdlong double __floatunditf(uint64_t a);     // ppc only
155204076Spjd
156204076Spjdfloat       __floatuntisf(tu_int a);
157229945Spjddouble      __floatuntidf(tu_int a);
158204076Spjdlong double __floatuntixf(tu_int a);
159204076Spjd
160225787Spjd//  Floating point raised to integer power
161229945Spjd
162204076Spjdfloat       __powisf2(      float a, si_int b);  // a ^ b
163204076Spjddouble      __powidf2(     double a, si_int b);  // a ^ b
164204076Spjdlong double __powixf2(long double a, si_int b);  // a ^ b
165204076Spjdlong double __powitf2(long double a, si_int b);  // ppc only, a ^ b
166204076Spjd
167204076Spjd//  Complex arithmetic
168204076Spjd
169204076Spjd//  (a + ib) * (c + id)
170209175Spjd
171204076Spjd      float _Complex __mulsc3( float a,  float b,  float c,  float d);
172204076Spjd     double _Complex __muldc3(double a, double b, double c, double d);
173204076Spjdlong double _Complex __mulxc3(long double a, long double b,
174204076Spjd                              long double c, long double d);
175204076Spjdlong double _Complex __multc3(long double a, long double b,
176212033Spjd                              long double c, long double d); // ppc only
177204076Spjd
178204076Spjd//  (a + ib) / (c + id)
179204076Spjd
180204076Spjd      float _Complex __divsc3( float a,  float b,  float c,  float d);
181204076Spjd     double _Complex __divdc3(double a, double b, double c, double d);
182204076Spjdlong double _Complex __divxc3(long double a, long double b,
183204076Spjd                              long double c, long double d);
184204076Spjdlong double _Complex __divtc3(long double a, long double b,
185225787Spjd                              long double c, long double d);  // ppc only
186225787Spjd
187204076Spjd
188204076Spjd//         Runtime support
189204076Spjd
190204076Spjd// __clear_cache() is used to tell process that new instructions have been
191204076Spjd// written to an address range.  Necessary on processors that do not have
192204076Spjd// a unified instuction and data cache.
193220522Strocinyvoid __clear_cache(void* start, void* end);
194220522Strociny
195220522Strociny// __enable_execute_stack() is used with nested functions when a trampoline
196220522Strociny// function is written onto the stack and that page range needs to be made
197204076Spjd// executable.
198220522Strocinyvoid __enable_execute_stack(void* addr);
199229945Spjd
200204076Spjd// __gcc_personality_v0() is normally only called by the system unwinder.
201204076Spjd// C code (as opposed to C++) normally does not need a personality function
202204076Spjd// because there are no catch clauses or destructors to be run.  But there
203204076Spjd// is a C language extension __attribute__((cleanup(func))) which marks local
204204076Spjd// variables as needing the cleanup function "func" to be run when the
205204076Spjd// variable goes out of scope.  That includes when an exception is thrown,
206204076Spjd// so a personality handler is needed.  
207204076Spjd_Unwind_Reason_Code __gcc_personality_v0(int version, _Unwind_Action actions,
208204076Spjd         uint64_t exceptionClass, struct _Unwind_Exception* exceptionObject,
209219351Spjd         _Unwind_Context_t context);
210219351Spjd
211204076Spjd// for use with some implementations of assert() in <assert.h>
212219351Spjdvoid __eprintf(const char* format, const char* assertion_expression,
213204076Spjd				const char* line, const char* file);
214204076Spjd				
215204076Spjd
216204076Spjd
217204076Spjd//   Power PC specific functions
218204076Spjd
219204076Spjd// There is no C interface to the saveFP/restFP functions.  They are helper
220204076Spjd// functions called by the prolog and epilog of functions that need to save
221204076Spjd// a number of non-volatile float point registers.  
222204076SpjdsaveFP
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
270// Undocumented functions
271
272float  __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
277                                        //     iff a == b and neither is NaN.
278int    __eqdf2vfp(double a, double b);  // Appears to return  one
279                                        //     iff a == b and neither is NaN.
280double __extendsfdf2vfp(float a);       // Appears to convert from
281                                        //     float to double.
282int    __fixdfsivfp(double a);          // Appears to convert from
283                                        //     double to int.
284int    __fixsfsivfp(float a);           // Appears to convert from
285                                        //     float to int.
286unsigned int __fixunssfsivfp(float a);  // Appears to convert from
287                                        //     float to unsigned int.
288unsigned int __fixunsdfsivfp(double a); // Appears to convert from
289                                        //     double to unsigned int.
290double __floatsidfvfp(int a);           // Appears to convert from
291                                        //     int to double.
292float __floatsisfvfp(int a);            // Appears to convert from
293                                        //     int to float.
294double __floatunssidfvfp(unsigned int a); // Appears to convert from
295                                        //     unisgned int to double.
296float __floatunssisfvfp(unsigned int a); // Appears to convert from
297                                        //     unisgned int to float.
298int __gedf2vfp(double a, double b);     // Appears to return __gedf2
299                                        //     (a >= b)
300int __gesf2vfp(float a, float b);       // Appears to return __gesf2
301                                        //     (a >= b)
302int __gtdf2vfp(double a, double b);     // Appears to return __gtdf2
303                                        //     (a > b)
304int __gtsf2vfp(float a, float b);       // Appears to return __gtsf2
305                                        //     (a > b)
306int __ledf2vfp(double a, double b);     // Appears to return __ledf2
307                                        //     (a <= b)
308int __lesf2vfp(float a, float b);       // Appears to return __lesf2
309                                        //     (a <= b)
310int __ltdf2vfp(double a, double b);     // Appears to return __ltdf2
311                                        //     (a < b)
312int __ltsf2vfp(float a, float b);       // Appears to return __ltsf2
313                                        //     (a < b)
314double __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
317                                        //     (a != b)
318double __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
324                                        //     double to float.
325int __unorddf2vfp(double a, double b);  // Appears to return __unorddf2
326int __unordsf2vfp(float a, float b);    // Appears to return __unordsf2
327
328
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.
335