README.txt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. Compiler-RT
  2. ================================
  3. This directory and its subdirectories contain source code for the compiler
  4. support routines.
  5. Compiler-RT is open source software. You may freely distribute it under the
  6. terms of the license agreement found in LICENSE.txt.
  7. ================================
  8. This is a replacement library for libgcc. Each function is contained
  9. in its own file. Each function has a corresponding unit test under
  10. test/Unit.
  11. A rudimentary script to test each file is in the file called
  12. test/Unit/test.
  13. Here is the specification for this library:
  14. http://gcc.gnu.org/onlinedocs/gccint/Libgcc.html#Libgcc
  15. Please note that the libgcc specification explicitly mentions actual types of
  16. arguments and returned values being expressed with machine modes.
  17. In some cases particular types such as "int", "unsigned", "long long", etc.
  18. may be specified just as examples there.
  19. Here is a synopsis of the contents of this library:
  20. typedef int32_t si_int;
  21. typedef uint32_t su_int;
  22. typedef int64_t di_int;
  23. typedef uint64_t du_int;
  24. // Integral bit manipulation
  25. di_int __ashldi3(di_int a, si_int b); // a << b
  26. ti_int __ashlti3(ti_int a, si_int b); // a << b
  27. di_int __ashrdi3(di_int a, si_int b); // a >> b arithmetic (sign fill)
  28. ti_int __ashrti3(ti_int a, si_int b); // a >> b arithmetic (sign fill)
  29. di_int __lshrdi3(di_int a, si_int b); // a >> b logical (zero fill)
  30. ti_int __lshrti3(ti_int a, si_int b); // a >> b logical (zero fill)
  31. int __clzsi2(si_int a); // count leading zeros
  32. int __clzdi2(di_int a); // count leading zeros
  33. int __clzti2(ti_int a); // count leading zeros
  34. int __ctzsi2(si_int a); // count trailing zeros
  35. int __ctzdi2(di_int a); // count trailing zeros
  36. int __ctzti2(ti_int a); // count trailing zeros
  37. int __ffssi2(si_int a); // find least significant 1 bit
  38. int __ffsdi2(di_int a); // find least significant 1 bit
  39. int __ffsti2(ti_int a); // find least significant 1 bit
  40. int __paritysi2(si_int a); // bit parity
  41. int __paritydi2(di_int a); // bit parity
  42. int __parityti2(ti_int a); // bit parity
  43. int __popcountsi2(si_int a); // bit population
  44. int __popcountdi2(di_int a); // bit population
  45. int __popcountti2(ti_int a); // bit population
  46. uint32_t __bswapsi2(uint32_t a); // a byteswapped
  47. uint64_t __bswapdi2(uint64_t a); // a byteswapped
  48. // Integral arithmetic
  49. di_int __negdi2 (di_int a); // -a
  50. ti_int __negti2 (ti_int a); // -a
  51. di_int __muldi3 (di_int a, di_int b); // a * b
  52. ti_int __multi3 (ti_int a, ti_int b); // a * b
  53. si_int __divsi3 (si_int a, si_int b); // a / b signed
  54. di_int __divdi3 (di_int a, di_int b); // a / b signed
  55. ti_int __divti3 (ti_int a, ti_int b); // a / b signed
  56. su_int __udivsi3 (su_int n, su_int d); // a / b unsigned
  57. du_int __udivdi3 (du_int a, du_int b); // a / b unsigned
  58. tu_int __udivti3 (tu_int a, tu_int b); // a / b unsigned
  59. si_int __modsi3 (si_int a, si_int b); // a % b signed
  60. di_int __moddi3 (di_int a, di_int b); // a % b signed
  61. ti_int __modti3 (ti_int a, ti_int b); // a % b signed
  62. su_int __umodsi3 (su_int a, su_int b); // a % b unsigned
  63. du_int __umoddi3 (du_int a, du_int b); // a % b unsigned
  64. tu_int __umodti3 (tu_int a, tu_int b); // a % b unsigned
  65. du_int __udivmoddi4(du_int a, du_int b, du_int* rem); // a / b, *rem = a % b unsigned
  66. tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem); // a / b, *rem = a % b unsigned
  67. su_int __udivmodsi4(su_int a, su_int b, su_int* rem); // a / b, *rem = a % b unsigned
  68. si_int __divmodsi4(si_int a, si_int b, si_int* rem); // a / b, *rem = a % b signed
  69. di_int __divmoddi4(di_int a, di_int b, di_int* rem); // a / b, *rem = a % b signed
  70. ti_int __divmodti4(ti_int a, ti_int b, ti_int* rem); // a / b, *rem = a % b signed
  71. // Integral arithmetic with trapping overflow
  72. si_int __absvsi2(si_int a); // abs(a)
  73. di_int __absvdi2(di_int a); // abs(a)
  74. ti_int __absvti2(ti_int a); // abs(a)
  75. si_int __negvsi2(si_int a); // -a
  76. di_int __negvdi2(di_int a); // -a
  77. ti_int __negvti2(ti_int a); // -a
  78. si_int __addvsi3(si_int a, si_int b); // a + b
  79. di_int __addvdi3(di_int a, di_int b); // a + b
  80. ti_int __addvti3(ti_int a, ti_int b); // a + b
  81. si_int __subvsi3(si_int a, si_int b); // a - b
  82. di_int __subvdi3(di_int a, di_int b); // a - b
  83. ti_int __subvti3(ti_int a, ti_int b); // a - b
  84. si_int __mulvsi3(si_int a, si_int b); // a * b
  85. di_int __mulvdi3(di_int a, di_int b); // a * b
  86. ti_int __mulvti3(ti_int a, ti_int b); // a * b
  87. // Integral arithmetic which returns if overflow
  88. si_int __mulosi4(si_int a, si_int b, int* overflow); // a * b, overflow set to one if result not in signed range
  89. di_int __mulodi4(di_int a, di_int b, int* overflow); // a * b, overflow set to one if result not in signed range
  90. ti_int __muloti4(ti_int a, ti_int b, int* overflow); // a * b, overflow set to
  91. one if result not in signed range
  92. // Integral comparison: a < b -> 0
  93. // a == b -> 1
  94. // a > b -> 2
  95. si_int __cmpdi2 (di_int a, di_int b);
  96. si_int __cmpti2 (ti_int a, ti_int b);
  97. si_int __ucmpdi2(du_int a, du_int b);
  98. si_int __ucmpti2(tu_int a, tu_int b);
  99. // Integral / floating point conversion
  100. di_int __fixsfdi( float a);
  101. di_int __fixdfdi( double a);
  102. di_int __fixxfdi(long double a);
  103. ti_int __fixsfti( float a);
  104. ti_int __fixdfti( double a);
  105. ti_int __fixxfti(long double a);
  106. uint64_t __fixtfdi(long double input); // ppc only, doesn't match documentation
  107. su_int __fixunssfsi( float a);
  108. su_int __fixunsdfsi( double a);
  109. su_int __fixunsxfsi(long double a);
  110. du_int __fixunssfdi( float a);
  111. du_int __fixunsdfdi( double a);
  112. du_int __fixunsxfdi(long double a);
  113. tu_int __fixunssfti( float a);
  114. tu_int __fixunsdfti( double a);
  115. tu_int __fixunsxfti(long double a);
  116. uint64_t __fixunstfdi(long double input); // ppc only
  117. float __floatdisf(di_int a);
  118. double __floatdidf(di_int a);
  119. long double __floatdixf(di_int a);
  120. long double __floatditf(int64_t a); // ppc only
  121. float __floattisf(ti_int a);
  122. double __floattidf(ti_int a);
  123. long double __floattixf(ti_int a);
  124. float __floatundisf(du_int a);
  125. double __floatundidf(du_int a);
  126. long double __floatundixf(du_int a);
  127. long double __floatunditf(uint64_t a); // ppc only
  128. float __floatuntisf(tu_int a);
  129. double __floatuntidf(tu_int a);
  130. long double __floatuntixf(tu_int a);
  131. // Floating point raised to integer power
  132. float __powisf2( float a, int b); // a ^ b
  133. double __powidf2( double a, int b); // a ^ b
  134. long double __powixf2(long double a, int b); // a ^ b
  135. long double __powitf2(long double a, int b); // ppc only, a ^ b
  136. // Complex arithmetic
  137. // (a + ib) * (c + id)
  138. float _Complex __mulsc3( float a, float b, float c, float d);
  139. double _Complex __muldc3(double a, double b, double c, double d);
  140. long double _Complex __mulxc3(long double a, long double b,
  141. long double c, long double d);
  142. long double _Complex __multc3(long double a, long double b,
  143. long double c, long double d); // ppc only
  144. // (a + ib) / (c + id)
  145. float _Complex __divsc3( float a, float b, float c, float d);
  146. double _Complex __divdc3(double a, double b, double c, double d);
  147. long double _Complex __divxc3(long double a, long double b,
  148. long double c, long double d);
  149. long double _Complex __divtc3(long double a, long double b,
  150. long double c, long double d); // ppc only
  151. // Runtime support
  152. // __clear_cache() is used to tell process that new instructions have been
  153. // written to an address range. Necessary on processors that do not have
  154. // a unified instruction and data cache.
  155. void __clear_cache(void* start, void* end);
  156. // __enable_execute_stack() is used with nested functions when a trampoline
  157. // function is written onto the stack and that page range needs to be made
  158. // executable.
  159. void __enable_execute_stack(void* addr);
  160. // __gcc_personality_v0() is normally only called by the system unwinder.
  161. // C code (as opposed to C++) normally does not need a personality function
  162. // because there are no catch clauses or destructors to be run. But there
  163. // is a C language extension __attribute__((cleanup(func))) which marks local
  164. // variables as needing the cleanup function "func" to be run when the
  165. // variable goes out of scope. That includes when an exception is thrown,
  166. // so a personality handler is needed.
  167. _Unwind_Reason_Code __gcc_personality_v0(int version, _Unwind_Action actions,
  168. uint64_t exceptionClass, struct _Unwind_Exception* exceptionObject,
  169. _Unwind_Context_t context);
  170. // for use with some implementations of assert() in <assert.h>
  171. void __eprintf(const char* format, const char* assertion_expression,
  172. const char* line, const char* file);
  173. // for systems with emulated thread local storage
  174. void* __emutls_get_address(struct __emutls_control*);
  175. // Power PC specific functions
  176. // There is no C interface to the saveFP/restFP functions. They are helper
  177. // functions called by the prolog and epilog of functions that need to save
  178. // a number of non-volatile float point registers.
  179. saveFP
  180. restFP
  181. // PowerPC has a standard template for trampoline functions. This function
  182. // generates a custom trampoline function with the specific realFunc
  183. // and localsPtr values.
  184. void __trampoline_setup(uint32_t* trampOnStack, int trampSizeAllocated,
  185. const void* realFunc, void* localsPtr);
  186. // adds two 128-bit double-double precision values ( x + y )
  187. long double __gcc_qadd(long double x, long double y);
  188. // subtracts two 128-bit double-double precision values ( x - y )
  189. long double __gcc_qsub(long double x, long double y);
  190. // multiples two 128-bit double-double precision values ( x * y )
  191. long double __gcc_qmul(long double x, long double y);
  192. // divides two 128-bit double-double precision values ( x / y )
  193. long double __gcc_qdiv(long double a, long double b);
  194. // ARM specific functions
  195. // There is no C interface to the switch* functions. These helper functions
  196. // are only needed by Thumb1 code for efficient switch table generation.
  197. switch16
  198. switch32
  199. switch8
  200. switchu8
  201. // There is no C interface to the *_vfp_d8_d15_regs functions. There are
  202. // called in the prolog and epilog of Thumb1 functions. When the C++ ABI use
  203. // SJLJ for exceptions, each function with a catch clause or destructors needs
  204. // to save and restore all registers in it prolog and epilog. But there is
  205. // no way to access vector and high float registers from thumb1 code, so the
  206. // compiler must add call outs to these helper functions in the prolog and
  207. // epilog.
  208. restore_vfp_d8_d15_regs
  209. save_vfp_d8_d15_regs
  210. // Note: long ago ARM processors did not have floating point hardware support.
  211. // Floating point was done in software and floating point parameters were
  212. // passed in integer registers. When hardware support was added for floating
  213. // point, new *vfp functions were added to do the same operations but with
  214. // floating point parameters in floating point registers.
  215. // Undocumented functions
  216. float __addsf3vfp(float a, float b); // Appears to return a + b
  217. double __adddf3vfp(double a, double b); // Appears to return a + b
  218. float __divsf3vfp(float a, float b); // Appears to return a / b
  219. double __divdf3vfp(double a, double b); // Appears to return a / b
  220. int __eqsf2vfp(float a, float b); // Appears to return one
  221. // iff a == b and neither is NaN.
  222. int __eqdf2vfp(double a, double b); // Appears to return one
  223. // iff a == b and neither is NaN.
  224. double __extendsfdf2vfp(float a); // Appears to convert from
  225. // float to double.
  226. int __fixdfsivfp(double a); // Appears to convert from
  227. // double to int.
  228. int __fixsfsivfp(float a); // Appears to convert from
  229. // float to int.
  230. unsigned int __fixunssfsivfp(float a); // Appears to convert from
  231. // float to unsigned int.
  232. unsigned int __fixunsdfsivfp(double a); // Appears to convert from
  233. // double to unsigned int.
  234. double __floatsidfvfp(int a); // Appears to convert from
  235. // int to double.
  236. float __floatsisfvfp(int a); // Appears to convert from
  237. // int to float.
  238. double __floatunssidfvfp(unsigned int a); // Appears to convert from
  239. // unsigned int to double.
  240. float __floatunssisfvfp(unsigned int a); // Appears to convert from
  241. // unsigned int to float.
  242. int __gedf2vfp(double a, double b); // Appears to return __gedf2
  243. // (a >= b)
  244. int __gesf2vfp(float a, float b); // Appears to return __gesf2
  245. // (a >= b)
  246. int __gtdf2vfp(double a, double b); // Appears to return __gtdf2
  247. // (a > b)
  248. int __gtsf2vfp(float a, float b); // Appears to return __gtsf2
  249. // (a > b)
  250. int __ledf2vfp(double a, double b); // Appears to return __ledf2
  251. // (a <= b)
  252. int __lesf2vfp(float a, float b); // Appears to return __lesf2
  253. // (a <= b)
  254. int __ltdf2vfp(double a, double b); // Appears to return __ltdf2
  255. // (a < b)
  256. int __ltsf2vfp(float a, float b); // Appears to return __ltsf2
  257. // (a < b)
  258. double __muldf3vfp(double a, double b); // Appears to return a * b
  259. float __mulsf3vfp(float a, float b); // Appears to return a * b
  260. int __nedf2vfp(double a, double b); // Appears to return __nedf2
  261. // (a != b)
  262. double __negdf2vfp(double a); // Appears to return -a
  263. float __negsf2vfp(float a); // Appears to return -a
  264. float __negsf2vfp(float a); // Appears to return -a
  265. double __subdf3vfp(double a, double b); // Appears to return a - b
  266. float __subsf3vfp(float a, float b); // Appears to return a - b
  267. float __truncdfsf2vfp(double a); // Appears to convert from
  268. // double to float.
  269. int __unorddf2vfp(double a, double b); // Appears to return __unorddf2
  270. int __unordsf2vfp(float a, float b); // Appears to return __unordsf2
  271. Preconditions are listed for each function at the definition when there are any.
  272. Any preconditions reflect the specification at
  273. http://gcc.gnu.org/onlinedocs/gccint/Libgcc.html#Libgcc.
  274. Assumptions are listed in "int_lib.h", and in individual files. Where possible
  275. assumptions are checked at compile time.