11.1SjoergCompiler-RT
21.1Sjoerg================================
31.1Sjoerg
41.1SjoergThis directory and its subdirectories contain source code for the compiler
51.1Sjoergsupport routines.
61.1Sjoerg
71.1SjoergCompiler-RT is open source software. You may freely distribute it under the
81.1Sjoergterms of the license agreement found in LICENSE.txt.
91.1Sjoerg
101.1Sjoerg================================
111.1Sjoerg
121.1SjoergThis is a replacement library for libgcc.  Each function is contained
131.1Sjoergin its own file.  Each function has a corresponding unit test under
141.1Sjoergtest/Unit.
151.1Sjoerg
161.1SjoergA rudimentary script to test each file is in the file called
171.1Sjoergtest/Unit/test.
181.1Sjoerg
191.1SjoergHere is the specification for this library:
201.1Sjoerg
211.1Sjoerghttp://gcc.gnu.org/onlinedocs/gccint/Libgcc.html#Libgcc
221.1Sjoerg
231.1SjoergHere is a synopsis of the contents of this library:
241.1Sjoerg
251.1Sjoergtypedef      int si_int;
261.1Sjoergtypedef unsigned su_int;
271.1Sjoerg
281.1Sjoergtypedef          long long di_int;
291.1Sjoergtypedef unsigned long long du_int;
301.1Sjoerg
311.1Sjoerg// Integral bit manipulation
321.1Sjoerg
331.1Sjoergdi_int __ashldi3(di_int a, si_int b);      // a << b
341.1Sjoergti_int __ashlti3(ti_int a, si_int b);      // a << b
351.1Sjoerg
361.1Sjoergdi_int __ashrdi3(di_int a, si_int b);      // a >> b  arithmetic (sign fill)
371.1Sjoergti_int __ashrti3(ti_int a, si_int b);      // a >> b  arithmetic (sign fill)
381.1Sjoergdi_int __lshrdi3(di_int a, si_int b);      // a >> b  logical    (zero fill)
391.1Sjoergti_int __lshrti3(ti_int a, si_int b);      // a >> b  logical    (zero fill)
401.1Sjoerg
411.1Sjoergsi_int __clzsi2(si_int a);  // count leading zeros
421.1Sjoergsi_int __clzdi2(di_int a);  // count leading zeros
431.1Sjoergsi_int __clzti2(ti_int a);  // count leading zeros
441.1Sjoergsi_int __ctzsi2(si_int a);  // count trailing zeros
451.1Sjoergsi_int __ctzdi2(di_int a);  // count trailing zeros
461.1Sjoergsi_int __ctzti2(ti_int a);  // count trailing zeros
471.1Sjoerg
481.1Sjoergsi_int __ffsdi2(di_int a);  // find least significant 1 bit
491.1Sjoergsi_int __ffsti2(ti_int a);  // find least significant 1 bit
501.1Sjoerg
511.1Sjoergsi_int __paritysi2(si_int a);  // bit parity
521.1Sjoergsi_int __paritydi2(di_int a);  // bit parity
531.1Sjoergsi_int __parityti2(ti_int a);  // bit parity
541.1Sjoerg
551.1Sjoergsi_int __popcountsi2(si_int a);  // bit population
561.1Sjoergsi_int __popcountdi2(di_int a);  // bit population
571.1Sjoergsi_int __popcountti2(ti_int a);  // bit population
581.1Sjoerg
591.1Sjoerguint32_t __bswapsi2(uint32_t a);   // a byteswapped, arm only
601.1Sjoerguint64_t __bswapdi2(uint64_t a);   // a byteswapped, arm only
611.1Sjoerg
621.1Sjoerg// Integral arithmetic
631.1Sjoerg
641.1Sjoergdi_int __negdi2    (di_int a);                         // -a
651.1Sjoergti_int __negti2    (ti_int a);                         // -a
661.1Sjoergdi_int __muldi3    (di_int a, di_int b);               // a * b
671.1Sjoergti_int __multi3    (ti_int a, ti_int b);               // a * b
681.1Sjoergsi_int __divsi3    (si_int a, si_int b);               // a / b   signed
691.1Sjoergdi_int __divdi3    (di_int a, di_int b);               // a / b   signed
701.1Sjoergti_int __divti3    (ti_int a, ti_int b);               // a / b   signed
711.1Sjoergsu_int __udivsi3   (su_int n, su_int d);               // a / b   unsigned
721.1Sjoergdu_int __udivdi3   (du_int a, du_int b);               // a / b   unsigned
731.1Sjoergtu_int __udivti3   (tu_int a, tu_int b);               // a / b   unsigned
741.1Sjoergsi_int __modsi3    (si_int a, si_int b);               // a % b   signed
751.1Sjoergdi_int __moddi3    (di_int a, di_int b);               // a % b   signed
761.1Sjoergti_int __modti3    (ti_int a, ti_int b);               // a % b   signed
771.1Sjoergsu_int __umodsi3   (su_int a, su_int b);               // a % b   unsigned
781.1Sjoergdu_int __umoddi3   (du_int a, du_int b);               // a % b   unsigned
791.1Sjoergtu_int __umodti3   (tu_int a, tu_int b);               // a % b   unsigned
801.1Sjoergdu_int __udivmoddi4(du_int a, du_int b, du_int* rem);  // a / b, *rem = a % b  unsigned
811.1Sjoergtu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem);  // a / b, *rem = a % b  unsigned
821.1Sjoergsu_int __udivmodsi4(su_int a, su_int b, su_int* rem);  // a / b, *rem = a % b  unsigned
831.1Sjoergsi_int __divmodsi4(si_int a, si_int b, si_int* rem);   // a / b, *rem = a % b  signed
841.1Sjoerg
851.1Sjoerg
861.1Sjoerg
871.1Sjoerg//  Integral arithmetic with trapping overflow
881.1Sjoerg
891.1Sjoergsi_int __absvsi2(si_int a);           // abs(a)
901.1Sjoergdi_int __absvdi2(di_int a);           // abs(a)
911.1Sjoergti_int __absvti2(ti_int a);           // abs(a)
921.1Sjoerg
931.1Sjoergsi_int __negvsi2(si_int a);           // -a
941.1Sjoergdi_int __negvdi2(di_int a);           // -a
951.1Sjoergti_int __negvti2(ti_int a);           // -a
961.1Sjoerg
971.1Sjoergsi_int __addvsi3(si_int a, si_int b);  // a + b
981.1Sjoergdi_int __addvdi3(di_int a, di_int b);  // a + b
991.1Sjoergti_int __addvti3(ti_int a, ti_int b);  // a + b
1001.1Sjoerg
1011.1Sjoergsi_int __subvsi3(si_int a, si_int b);  // a - b
1021.1Sjoergdi_int __subvdi3(di_int a, di_int b);  // a - b
1031.1Sjoergti_int __subvti3(ti_int a, ti_int b);  // a - b
1041.1Sjoerg
1051.1Sjoergsi_int __mulvsi3(si_int a, si_int b);  // a * b
1061.1Sjoergdi_int __mulvdi3(di_int a, di_int b);  // a * b
1071.1Sjoergti_int __mulvti3(ti_int a, ti_int b);  // a * b
1081.1Sjoerg
1091.1Sjoerg
1101.1Sjoerg// Integral arithmetic which returns if overflow
1111.1Sjoerg
1121.1Sjoergsi_int __mulosi4(si_int a, si_int b, int* overflow);  // a * b, overflow set to one if result not in signed range
1131.1Sjoergdi_int __mulodi4(di_int a, di_int b, int* overflow);  // a * b, overflow set to one if result not in signed range
1141.1Sjoergti_int __muloti4(ti_int a, ti_int b, int* overflow);  // a * b, overflow set to
1151.1Sjoerg one if result not in signed range
1161.1Sjoerg
1171.1Sjoerg
1181.1Sjoerg//  Integral comparison: a  < b -> 0
1191.1Sjoerg//                       a == b -> 1
1201.1Sjoerg//                       a  > b -> 2
1211.1Sjoerg
1221.1Sjoergsi_int __cmpdi2 (di_int a, di_int b);
1231.1Sjoergsi_int __cmpti2 (ti_int a, ti_int b);
1241.1Sjoergsi_int __ucmpdi2(du_int a, du_int b);
1251.1Sjoergsi_int __ucmpti2(tu_int a, tu_int b);
1261.1Sjoerg
1271.1Sjoerg//  Integral / floating point conversion
1281.1Sjoerg
1291.1Sjoergdi_int __fixsfdi(      float a);
1301.1Sjoergdi_int __fixdfdi(     double a);
1311.1Sjoergdi_int __fixxfdi(long double a);
1321.1Sjoerg
1331.1Sjoergti_int __fixsfti(      float a);
1341.1Sjoergti_int __fixdfti(     double a);
1351.1Sjoergti_int __fixxfti(long double a);
1361.1Sjoerguint64_t __fixtfdi(long double input);  // ppc only, doesn't match documentation
1371.1Sjoerg
1381.1Sjoergsu_int __fixunssfsi(      float a);
1391.1Sjoergsu_int __fixunsdfsi(     double a);
1401.1Sjoergsu_int __fixunsxfsi(long double a);
1411.1Sjoerg
1421.1Sjoergdu_int __fixunssfdi(      float a);
1431.1Sjoergdu_int __fixunsdfdi(     double a);
1441.1Sjoergdu_int __fixunsxfdi(long double a);
1451.1Sjoerg
1461.1Sjoergtu_int __fixunssfti(      float a);
1471.1Sjoergtu_int __fixunsdfti(     double a);
1481.1Sjoergtu_int __fixunsxfti(long double a);
1491.1Sjoerguint64_t __fixunstfdi(long double input);  // ppc only
1501.1Sjoerg
1511.1Sjoergfloat       __floatdisf(di_int a);
1521.1Sjoergdouble      __floatdidf(di_int a);
1531.1Sjoerglong double __floatdixf(di_int a);
1541.1Sjoerglong double __floatditf(int64_t a);        // ppc only
1551.1Sjoerg
1561.1Sjoergfloat       __floattisf(ti_int a);
1571.1Sjoergdouble      __floattidf(ti_int a);
1581.1Sjoerglong double __floattixf(ti_int a);
1591.1Sjoerg
1601.1Sjoergfloat       __floatundisf(du_int a);
1611.1Sjoergdouble      __floatundidf(du_int a);
1621.1Sjoerglong double __floatundixf(du_int a);
1631.1Sjoerglong double __floatunditf(uint64_t a);     // ppc only
1641.1Sjoerg
1651.1Sjoergfloat       __floatuntisf(tu_int a);
1661.1Sjoergdouble      __floatuntidf(tu_int a);
1671.1Sjoerglong double __floatuntixf(tu_int a);
1681.1Sjoerg
1691.1Sjoerg//  Floating point raised to integer power
1701.1Sjoerg
1711.1Sjoergfloat       __powisf2(      float a, si_int b);  // a ^ b
1721.1Sjoergdouble      __powidf2(     double a, si_int b);  // a ^ b
1731.1Sjoerglong double __powixf2(long double a, si_int b);  // a ^ b
1741.1Sjoerglong double __powitf2(long double a, si_int b);  // ppc only, a ^ b
1751.1Sjoerg
1761.1Sjoerg//  Complex arithmetic
1771.1Sjoerg
1781.1Sjoerg//  (a + ib) * (c + id)
1791.1Sjoerg
1801.1Sjoerg      float _Complex __mulsc3( float a,  float b,  float c,  float d);
1811.1Sjoerg     double _Complex __muldc3(double a, double b, double c, double d);
1821.1Sjoerglong double _Complex __mulxc3(long double a, long double b,
1831.1Sjoerg                              long double c, long double d);
1841.1Sjoerglong double _Complex __multc3(long double a, long double b,
1851.1Sjoerg                              long double c, long double d); // ppc only
1861.1Sjoerg
1871.1Sjoerg//  (a + ib) / (c + id)
1881.1Sjoerg
1891.1Sjoerg      float _Complex __divsc3( float a,  float b,  float c,  float d);
1901.1Sjoerg     double _Complex __divdc3(double a, double b, double c, double d);
1911.1Sjoerglong double _Complex __divxc3(long double a, long double b,
1921.1Sjoerg                              long double c, long double d);
1931.1Sjoerglong double _Complex __divtc3(long double a, long double b,
1941.1Sjoerg                              long double c, long double d);  // ppc only
1951.1Sjoerg
1961.1Sjoerg
1971.1Sjoerg//         Runtime support
1981.1Sjoerg
1991.1Sjoerg// __clear_cache() is used to tell process that new instructions have been
2001.1Sjoerg// written to an address range.  Necessary on processors that do not have
2011.1Sjoerg// a unified instruction and data cache.
2021.1Sjoergvoid __clear_cache(void* start, void* end);
2031.1Sjoerg
2041.1Sjoerg// __enable_execute_stack() is used with nested functions when a trampoline
2051.1Sjoerg// function is written onto the stack and that page range needs to be made
2061.1Sjoerg// executable.
2071.1Sjoergvoid __enable_execute_stack(void* addr);
2081.1Sjoerg
2091.1Sjoerg// __gcc_personality_v0() is normally only called by the system unwinder.
2101.1Sjoerg// C code (as opposed to C++) normally does not need a personality function
2111.1Sjoerg// because there are no catch clauses or destructors to be run.  But there
2121.1Sjoerg// is a C language extension __attribute__((cleanup(func))) which marks local
2131.1Sjoerg// variables as needing the cleanup function "func" to be run when the
2141.1Sjoerg// variable goes out of scope.  That includes when an exception is thrown,
2151.1Sjoerg// so a personality handler is needed.  
2161.1Sjoerg_Unwind_Reason_Code __gcc_personality_v0(int version, _Unwind_Action actions,
2171.1Sjoerg         uint64_t exceptionClass, struct _Unwind_Exception* exceptionObject,
2181.1Sjoerg         _Unwind_Context_t context);
2191.1Sjoerg
2201.1Sjoerg// for use with some implementations of assert() in <assert.h>
2211.1Sjoergvoid __eprintf(const char* format, const char* assertion_expression,
2221.1Sjoerg				const char* line, const char* file);
2231.1.1.2Sjoerg
2241.1.1.2Sjoerg// for systems with emulated thread local storage
2251.1.1.2Sjoergvoid* __emutls_get_address(struct __emutls_control*);
2261.1Sjoerg
2271.1Sjoerg
2281.1Sjoerg//   Power PC specific functions
2291.1Sjoerg
2301.1Sjoerg// There is no C interface to the saveFP/restFP functions.  They are helper
2311.1Sjoerg// functions called by the prolog and epilog of functions that need to save
2321.1Sjoerg// a number of non-volatile float point registers.  
2331.1SjoergsaveFP
2341.1SjoergrestFP
2351.1Sjoerg
2361.1Sjoerg// PowerPC has a standard template for trampoline functions.  This function
2371.1Sjoerg// generates a custom trampoline function with the specific realFunc
2381.1Sjoerg// and localsPtr values.
2391.1Sjoergvoid __trampoline_setup(uint32_t* trampOnStack, int trampSizeAllocated, 
2401.1Sjoerg                                const void* realFunc, void* localsPtr);
2411.1Sjoerg
2421.1Sjoerg// adds two 128-bit double-double precision values ( x + y )
2431.1Sjoerglong double __gcc_qadd(long double x, long double y);  
2441.1Sjoerg
2451.1Sjoerg// subtracts two 128-bit double-double precision values ( x - y )
2461.1Sjoerglong double __gcc_qsub(long double x, long double y); 
2471.1Sjoerg
2481.1Sjoerg// multiples two 128-bit double-double precision values ( x * y )
2491.1Sjoerglong double __gcc_qmul(long double x, long double y);  
2501.1Sjoerg
2511.1Sjoerg// divides two 128-bit double-double precision values ( x / y )
2521.1Sjoerglong double __gcc_qdiv(long double a, long double b);  
2531.1Sjoerg
2541.1Sjoerg
2551.1Sjoerg//    ARM specific functions
2561.1Sjoerg
2571.1Sjoerg// There is no C interface to the switch* functions.  These helper functions
2581.1Sjoerg// are only needed by Thumb1 code for efficient switch table generation.
2591.1Sjoergswitch16
2601.1Sjoergswitch32
2611.1Sjoergswitch8
2621.1Sjoergswitchu8
2631.1Sjoerg
2641.1Sjoerg// There is no C interface to the *_vfp_d8_d15_regs functions.  There are
2651.1Sjoerg// called in the prolog and epilog of Thumb1 functions.  When the C++ ABI use
2661.1Sjoerg// SJLJ for exceptions, each function with a catch clause or destuctors needs
2671.1Sjoerg// to save and restore all registers in it prolog and epliog.  But there is 
2681.1Sjoerg// no way to access vector and high float registers from thumb1 code, so the 
2691.1Sjoerg// compiler must add call outs to these helper functions in the prolog and 
2701.1Sjoerg// epilog.
2711.1Sjoergrestore_vfp_d8_d15_regs
2721.1Sjoergsave_vfp_d8_d15_regs
2731.1Sjoerg
2741.1Sjoerg
2751.1Sjoerg// Note: long ago ARM processors did not have floating point hardware support.
2761.1Sjoerg// Floating point was done in software and floating point parameters were 
2771.1Sjoerg// passed in integer registers.  When hardware support was added for floating
2781.1Sjoerg// point, new *vfp functions were added to do the same operations but with 
2791.1Sjoerg// floating point parameters in floating point registers.
2801.1Sjoerg
2811.1Sjoerg// Undocumented functions
2821.1Sjoerg
2831.1Sjoergfloat  __addsf3vfp(float a, float b);   // Appears to return a + b
2841.1Sjoergdouble __adddf3vfp(double a, double b); // Appears to return a + b
2851.1Sjoergfloat  __divsf3vfp(float a, float b);   // Appears to return a / b
2861.1Sjoergdouble __divdf3vfp(double a, double b); // Appears to return a / b
2871.1Sjoergint    __eqsf2vfp(float a, float b);    // Appears to return  one
2881.1Sjoerg                                        //     iff a == b and neither is NaN.
2891.1Sjoergint    __eqdf2vfp(double a, double b);  // Appears to return  one
2901.1Sjoerg                                        //     iff a == b and neither is NaN.
2911.1Sjoergdouble __extendsfdf2vfp(float a);       // Appears to convert from
2921.1Sjoerg                                        //     float to double.
2931.1Sjoergint    __fixdfsivfp(double a);          // Appears to convert from
2941.1Sjoerg                                        //     double to int.
2951.1Sjoergint    __fixsfsivfp(float a);           // Appears to convert from
2961.1Sjoerg                                        //     float to int.
2971.1Sjoergunsigned int __fixunssfsivfp(float a);  // Appears to convert from
2981.1Sjoerg                                        //     float to unsigned int.
2991.1Sjoergunsigned int __fixunsdfsivfp(double a); // Appears to convert from
3001.1Sjoerg                                        //     double to unsigned int.
3011.1Sjoergdouble __floatsidfvfp(int a);           // Appears to convert from
3021.1Sjoerg                                        //     int to double.
3031.1Sjoergfloat __floatsisfvfp(int a);            // Appears to convert from
3041.1Sjoerg                                        //     int to float.
3051.1Sjoergdouble __floatunssidfvfp(unsigned int a); // Appears to convert from
3061.1Sjoerg                                        //     unisgned int to double.
3071.1Sjoergfloat __floatunssisfvfp(unsigned int a); // Appears to convert from
3081.1Sjoerg                                        //     unisgned int to float.
3091.1Sjoergint __gedf2vfp(double a, double b);     // Appears to return __gedf2
3101.1Sjoerg                                        //     (a >= b)
3111.1Sjoergint __gesf2vfp(float a, float b);       // Appears to return __gesf2
3121.1Sjoerg                                        //     (a >= b)
3131.1Sjoergint __gtdf2vfp(double a, double b);     // Appears to return __gtdf2
3141.1Sjoerg                                        //     (a > b)
3151.1Sjoergint __gtsf2vfp(float a, float b);       // Appears to return __gtsf2
3161.1Sjoerg                                        //     (a > b)
3171.1Sjoergint __ledf2vfp(double a, double b);     // Appears to return __ledf2
3181.1Sjoerg                                        //     (a <= b)
3191.1Sjoergint __lesf2vfp(float a, float b);       // Appears to return __lesf2
3201.1Sjoerg                                        //     (a <= b)
3211.1Sjoergint __ltdf2vfp(double a, double b);     // Appears to return __ltdf2
3221.1Sjoerg                                        //     (a < b)
3231.1Sjoergint __ltsf2vfp(float a, float b);       // Appears to return __ltsf2
3241.1Sjoerg                                        //     (a < b)
3251.1Sjoergdouble __muldf3vfp(double a, double b); // Appears to return a * b
3261.1Sjoergfloat __mulsf3vfp(float a, float b);    // Appears to return a * b
3271.1Sjoergint __nedf2vfp(double a, double b);     // Appears to return __nedf2
3281.1Sjoerg                                        //     (a != b)
3291.1Sjoergdouble __negdf2vfp(double a);           // Appears to return -a
3301.1Sjoergfloat __negsf2vfp(float a);             // Appears to return -a
3311.1Sjoergfloat __negsf2vfp(float a);             // Appears to return -a
3321.1Sjoergdouble __subdf3vfp(double a, double b); // Appears to return a - b
3331.1Sjoergfloat __subsf3vfp(float a, float b);    // Appears to return a - b
3341.1Sjoergfloat __truncdfsf2vfp(double a);        // Appears to convert from
3351.1Sjoerg                                        //     double to float.
3361.1Sjoergint __unorddf2vfp(double a, double b);  // Appears to return __unorddf2
3371.1Sjoergint __unordsf2vfp(float a, float b);    // Appears to return __unordsf2
3381.1Sjoerg
3391.1Sjoerg
3401.1SjoergPreconditions are listed for each function at the definition when there are any.
3411.1SjoergAny preconditions reflect the specification at
3421.1Sjoerghttp://gcc.gnu.org/onlinedocs/gccint/Libgcc.html#Libgcc.
3431.1Sjoerg
3441.1SjoergAssumptions are listed in "int_lib.h", and in individual files.  Where possible
3451.1Sjoergassumptions are checked at compile time.
346