README.txt revision 222656
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 109214152Sed// Integral comparison: a < b -> 0 110214152Sed// a == b -> 1 111214152Sed// a > b -> 2 112214152Sed 113214152Sedsi_int __cmpdi2 (di_int a, di_int b); 114214152Sedsi_int __cmpti2 (ti_int a, ti_int b); 115214152Sedsi_int __ucmpdi2(du_int a, du_int b); 116214152Sedsi_int __ucmpti2(tu_int a, tu_int b); 117214152Sed 118214152Sed// Integral / floating point conversion 119214152Sed 120214152Seddi_int __fixsfdi( float a); 121214152Seddi_int __fixdfdi( double a); 122214152Seddi_int __fixxfdi(long double a); 123214152Sed 124214152Sedti_int __fixsfti( float a); 125214152Sedti_int __fixdfti( double a); 126214152Sedti_int __fixxfti(long double a); 127214152Seduint64_t __fixtfdi(long double input); // ppc only, doesn't match documentation 128214152Sed 129214152Sedsu_int __fixunssfsi( float a); 130214152Sedsu_int __fixunsdfsi( double a); 131214152Sedsu_int __fixunsxfsi(long double a); 132214152Sed 133214152Seddu_int __fixunssfdi( float a); 134214152Seddu_int __fixunsdfdi( double a); 135214152Seddu_int __fixunsxfdi(long double a); 136214152Sed 137214152Sedtu_int __fixunssfti( float a); 138214152Sedtu_int __fixunsdfti( double a); 139214152Sedtu_int __fixunsxfti(long double a); 140214152Seduint64_t __fixunstfdi(long double input); // ppc only 141214152Sed 142214152Sedfloat __floatdisf(di_int a); 143214152Seddouble __floatdidf(di_int a); 144214152Sedlong double __floatdixf(di_int a); 145214152Sedlong double __floatditf(int64_t a); // ppc only 146214152Sed 147214152Sedfloat __floattisf(ti_int a); 148214152Seddouble __floattidf(ti_int a); 149214152Sedlong double __floattixf(ti_int a); 150214152Sed 151214152Sedfloat __floatundisf(du_int a); 152214152Seddouble __floatundidf(du_int a); 153214152Sedlong double __floatundixf(du_int a); 154214152Sedlong double __floatunditf(uint64_t a); // ppc only 155214152Sed 156214152Sedfloat __floatuntisf(tu_int a); 157214152Seddouble __floatuntidf(tu_int a); 158214152Sedlong double __floatuntixf(tu_int a); 159214152Sed 160214152Sed// Floating point raised to integer power 161214152Sed 162214152Sedfloat __powisf2( float a, si_int b); // a ^ b 163214152Seddouble __powidf2( double a, si_int b); // a ^ b 164214152Sedlong double __powixf2(long double a, si_int b); // a ^ b 165214152Sedlong double __powitf2(long double a, si_int b); // ppc only, a ^ b 166214152Sed 167214152Sed// Complex arithmetic 168214152Sed 169214152Sed// (a + ib) * (c + id) 170214152Sed 171214152Sed float _Complex __mulsc3( float a, float b, float c, float d); 172214152Sed double _Complex __muldc3(double a, double b, double c, double d); 173214152Sedlong double _Complex __mulxc3(long double a, long double b, 174214152Sed long double c, long double d); 175214152Sedlong double _Complex __multc3(long double a, long double b, 176214152Sed long double c, long double d); // ppc only 177214152Sed 178214152Sed// (a + ib) / (c + id) 179214152Sed 180214152Sed float _Complex __divsc3( float a, float b, float c, float d); 181214152Sed double _Complex __divdc3(double a, double b, double c, double d); 182214152Sedlong double _Complex __divxc3(long double a, long double b, 183214152Sed long double c, long double d); 184214152Sedlong double _Complex __divtc3(long double a, long double b, 185214152Sed long double c, long double d); // ppc only 186214152Sed 187214152Sed 188214152Sed// Runtime support 189214152Sed 190214152Sed// __clear_cache() is used to tell process that new instructions have been 191214152Sed// written to an address range. Necessary on processors that do not have 192214152Sed// a unified instuction and data cache. 193214152Sedvoid __clear_cache(void* start, void* end); 194214152Sed 195214152Sed// __enable_execute_stack() is used with nested functions when a trampoline 196214152Sed// function is written onto the stack and that page range needs to be made 197214152Sed// executable. 198214152Sedvoid __enable_execute_stack(void* addr); 199214152Sed 200214152Sed// __gcc_personality_v0() is normally only called by the system unwinder. 201214152Sed// C code (as opposed to C++) normally does not need a personality function 202214152Sed// because there are no catch clauses or destructors to be run. But there 203214152Sed// is a C language extension __attribute__((cleanup(func))) which marks local 204214152Sed// variables as needing the cleanup function "func" to be run when the 205214152Sed// variable goes out of scope. That includes when an exception is thrown, 206214152Sed// so a personality handler is needed. 207214152Sed_Unwind_Reason_Code __gcc_personality_v0(int version, _Unwind_Action actions, 208214152Sed uint64_t exceptionClass, struct _Unwind_Exception* exceptionObject, 209214152Sed _Unwind_Context_t context); 210214152Sed 211214152Sed// for use with some implementations of assert() in <assert.h> 212214152Sedvoid __eprintf(const char* format, const char* assertion_expression, 213214152Sed const char* line, const char* file); 214214152Sed 215214152Sed 216214152Sed 217214152Sed// Power PC specific functions 218214152Sed 219214152Sed// There is no C interface to the saveFP/restFP functions. They are helper 220214152Sed// functions called by the prolog and epilog of functions that need to save 221214152Sed// a number of non-volatile float point registers. 222214152SedsaveFP 223214152SedrestFP 224214152Sed 225214152Sed// PowerPC has a standard template for trampoline functions. This function 226214152Sed// generates a custom trampoline function with the specific realFunc 227214152Sed// and localsPtr values. 228214152Sedvoid __trampoline_setup(uint32_t* trampOnStack, int trampSizeAllocated, 229214152Sed const void* realFunc, void* localsPtr); 230214152Sed 231214152Sed// adds two 128-bit double-double precision values ( x + y ) 232214152Sedlong double __gcc_qadd(long double x, long double y); 233214152Sed 234214152Sed// subtracts two 128-bit double-double precision values ( x - y ) 235214152Sedlong double __gcc_qsub(long double x, long double y); 236214152Sed 237214152Sed// multiples two 128-bit double-double precision values ( x * y ) 238214152Sedlong double __gcc_qmul(long double x, long double y); 239214152Sed 240214152Sed// divides two 128-bit double-double precision values ( x / y ) 241214152Sedlong double __gcc_qdiv(long double a, long double b); 242214152Sed 243214152Sed 244214152Sed// ARM specific functions 245214152Sed 246214152Sed// There is no C interface to the switch* functions. These helper functions 247214152Sed// are only needed by Thumb1 code for efficient switch table generation. 248214152Sedswitch16 249214152Sedswitch32 250214152Sedswitch8 251214152Sedswitchu8 252214152Sed 253214152Sed// There is no C interface to the *_vfp_d8_d15_regs functions. There are 254214152Sed// called in the prolog and epilog of Thumb1 functions. When the C++ ABI use 255214152Sed// SJLJ for exceptions, each function with a catch clause or destuctors needs 256214152Sed// to save and restore all registers in it prolog and epliog. But there is 257214152Sed// no way to access vector and high float registers from thumb1 code, so the 258214152Sed// compiler must add call outs to these helper functions in the prolog and 259214152Sed// epilog. 260214152Sedrestore_vfp_d8_d15_regs 261214152Sedsave_vfp_d8_d15_regs 262214152Sed 263214152Sed 264214152Sed// Note: long ago ARM processors did not have floating point hardware support. 265214152Sed// Floating point was done in software and floating point parameters were 266214152Sed// passed in integer registers. When hardware support was added for floating 267214152Sed// point, new *vfp functions were added to do the same operations but with 268214152Sed// floating point parameters in floating point registers. 269214152Sed 270214152Sed// Undocumented functions 271214152Sed 272214152Sedfloat __addsf3vfp(float a, float b); // Appears to return a + b 273214152Seddouble __adddf3vfp(double a, double b); // Appears to return a + b 274214152Sedfloat __divsf3vfp(float a, float b); // Appears to return a / b 275214152Seddouble __divdf3vfp(double a, double b); // Appears to return a / b 276214152Sedint __eqsf2vfp(float a, float b); // Appears to return one 277214152Sed // iff a == b and neither is NaN. 278214152Sedint __eqdf2vfp(double a, double b); // Appears to return one 279214152Sed // iff a == b and neither is NaN. 280214152Seddouble __extendsfdf2vfp(float a); // Appears to convert from 281214152Sed // float to double. 282214152Sedint __fixdfsivfp(double a); // Appears to convert from 283214152Sed // double to int. 284214152Sedint __fixsfsivfp(float a); // Appears to convert from 285214152Sed // float to int. 286214152Sedunsigned int __fixunssfsivfp(float a); // Appears to convert from 287214152Sed // float to unsigned int. 288214152Sedunsigned int __fixunsdfsivfp(double a); // Appears to convert from 289214152Sed // double to unsigned int. 290214152Seddouble __floatsidfvfp(int a); // Appears to convert from 291214152Sed // int to double. 292214152Sedfloat __floatsisfvfp(int a); // Appears to convert from 293214152Sed // int to float. 294214152Seddouble __floatunssidfvfp(unsigned int a); // Appears to convert from 295214152Sed // unisgned int to double. 296214152Sedfloat __floatunssisfvfp(unsigned int a); // Appears to convert from 297214152Sed // unisgned int to float. 298214152Sedint __gedf2vfp(double a, double b); // Appears to return __gedf2 299214152Sed // (a >= b) 300214152Sedint __gesf2vfp(float a, float b); // Appears to return __gesf2 301214152Sed // (a >= b) 302214152Sedint __gtdf2vfp(double a, double b); // Appears to return __gtdf2 303214152Sed // (a > b) 304214152Sedint __gtsf2vfp(float a, float b); // Appears to return __gtsf2 305214152Sed // (a > b) 306214152Sedint __ledf2vfp(double a, double b); // Appears to return __ledf2 307214152Sed // (a <= b) 308214152Sedint __lesf2vfp(float a, float b); // Appears to return __lesf2 309214152Sed // (a <= b) 310214152Sedint __ltdf2vfp(double a, double b); // Appears to return __ltdf2 311214152Sed // (a < b) 312214152Sedint __ltsf2vfp(float a, float b); // Appears to return __ltsf2 313214152Sed // (a < b) 314214152Seddouble __muldf3vfp(double a, double b); // Appears to return a * b 315214152Sedfloat __mulsf3vfp(float a, float b); // Appears to return a * b 316214152Sedint __nedf2vfp(double a, double b); // Appears to return __nedf2 317214152Sed // (a != b) 318214152Seddouble __negdf2vfp(double a); // Appears to return -a 319214152Sedfloat __negsf2vfp(float a); // Appears to return -a 320214152Sedfloat __negsf2vfp(float a); // Appears to return -a 321214152Seddouble __subdf3vfp(double a, double b); // Appears to return a - b 322214152Sedfloat __subsf3vfp(float a, float b); // Appears to return a - b 323214152Sedfloat __truncdfsf2vfp(double a); // Appears to convert from 324214152Sed // double to float. 325214152Sedint __unorddf2vfp(double a, double b); // Appears to return __unorddf2 326214152Sedint __unordsf2vfp(float a, float b); // Appears to return __unordsf2 327214152Sed 328214152Sed 329214152SedPreconditions are listed for each function at the definition when there are any. 330214152SedAny preconditions reflect the specification at 331214152Sedhttp://gcc.gnu.org/onlinedocs/gccint/Libgcc.html#Libgcc. 332214152Sed 333214152SedAssumptions are listed in "int_lib.h", and in individual files. Where possible 334214152Sedassumptions are checked at compile time. 335