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