Mercurial > hg > CbC > CbC_gcc
annotate gcc/libgcc2.c @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | 855418dad1a3 |
children | f6334be47118 |
rev | line source |
---|---|
0 | 1 /* More subroutines needed by GCC output code on some machines. */ |
2 /* Compile this one with gcc. */ | |
3 /* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, | |
4 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009 | |
5 Free Software Foundation, Inc. | |
6 | |
7 This file is part of GCC. | |
8 | |
9 GCC is free software; you can redistribute it and/or modify it under | |
10 the terms of the GNU General Public License as published by the Free | |
11 Software Foundation; either version 3, or (at your option) any later | |
12 version. | |
13 | |
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 Under Section 7 of GPL version 3, you are granted additional | |
20 permissions described in the GCC Runtime Library Exception, version | |
21 3.1, as published by the Free Software Foundation. | |
22 | |
23 You should have received a copy of the GNU General Public License and | |
24 a copy of the GCC Runtime Library Exception along with this program; | |
25 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
26 <http://www.gnu.org/licenses/>. */ | |
27 | |
28 #include "tconfig.h" | |
29 #include "tsystem.h" | |
30 #include "coretypes.h" | |
31 #include "tm.h" | |
32 | |
33 #ifdef HAVE_GAS_HIDDEN | |
34 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden"))) | |
35 #else | |
36 #define ATTRIBUTE_HIDDEN | |
37 #endif | |
38 | |
39 #ifndef MIN_UNITS_PER_WORD | |
40 #define MIN_UNITS_PER_WORD UNITS_PER_WORD | |
41 #endif | |
42 | |
43 /* Work out the largest "word" size that we can deal with on this target. */ | |
44 #if MIN_UNITS_PER_WORD > 4 | |
45 # define LIBGCC2_MAX_UNITS_PER_WORD 8 | |
46 #elif (MIN_UNITS_PER_WORD > 2 \ | |
47 || (MIN_UNITS_PER_WORD > 1 && LONG_LONG_TYPE_SIZE > 32)) | |
48 # define LIBGCC2_MAX_UNITS_PER_WORD 4 | |
49 #else | |
50 # define LIBGCC2_MAX_UNITS_PER_WORD MIN_UNITS_PER_WORD | |
51 #endif | |
52 | |
53 /* Work out what word size we are using for this compilation. | |
54 The value can be set on the command line. */ | |
55 #ifndef LIBGCC2_UNITS_PER_WORD | |
56 #define LIBGCC2_UNITS_PER_WORD LIBGCC2_MAX_UNITS_PER_WORD | |
57 #endif | |
58 | |
59 #if LIBGCC2_UNITS_PER_WORD <= LIBGCC2_MAX_UNITS_PER_WORD | |
60 | |
61 #include "libgcc2.h" | |
62 | |
63 #ifdef DECLARE_LIBRARY_RENAMES | |
64 DECLARE_LIBRARY_RENAMES | |
65 #endif | |
66 | |
67 #if defined (L_negdi2) | |
68 DWtype | |
69 __negdi2 (DWtype u) | |
70 { | |
71 const DWunion uu = {.ll = u}; | |
72 const DWunion w = { {.low = -uu.s.low, | |
73 .high = -uu.s.high - ((UWtype) -uu.s.low > 0) } }; | |
74 | |
75 return w.ll; | |
76 } | |
77 #endif | |
78 | |
79 #ifdef L_addvsi3 | |
80 Wtype | |
81 __addvSI3 (Wtype a, Wtype b) | |
82 { | |
83 const Wtype w = (UWtype) a + (UWtype) b; | |
84 | |
85 if (b >= 0 ? w < a : w > a) | |
86 abort (); | |
87 | |
88 return w; | |
89 } | |
90 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC | |
91 SItype | |
92 __addvsi3 (SItype a, SItype b) | |
93 { | |
94 const SItype w = (USItype) a + (USItype) b; | |
95 | |
96 if (b >= 0 ? w < a : w > a) | |
97 abort (); | |
98 | |
99 return w; | |
100 } | |
101 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */ | |
102 #endif | |
103 | |
104 #ifdef L_addvdi3 | |
105 DWtype | |
106 __addvDI3 (DWtype a, DWtype b) | |
107 { | |
108 const DWtype w = (UDWtype) a + (UDWtype) b; | |
109 | |
110 if (b >= 0 ? w < a : w > a) | |
111 abort (); | |
112 | |
113 return w; | |
114 } | |
115 #endif | |
116 | |
117 #ifdef L_subvsi3 | |
118 Wtype | |
119 __subvSI3 (Wtype a, Wtype b) | |
120 { | |
121 const Wtype w = (UWtype) a - (UWtype) b; | |
122 | |
123 if (b >= 0 ? w > a : w < a) | |
124 abort (); | |
125 | |
126 return w; | |
127 } | |
128 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC | |
129 SItype | |
130 __subvsi3 (SItype a, SItype b) | |
131 { | |
132 const SItype w = (USItype) a - (USItype) b; | |
133 | |
134 if (b >= 0 ? w > a : w < a) | |
135 abort (); | |
136 | |
137 return w; | |
138 } | |
139 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */ | |
140 #endif | |
141 | |
142 #ifdef L_subvdi3 | |
143 DWtype | |
144 __subvDI3 (DWtype a, DWtype b) | |
145 { | |
146 const DWtype w = (UDWtype) a - (UDWtype) b; | |
147 | |
148 if (b >= 0 ? w > a : w < a) | |
149 abort (); | |
150 | |
151 return w; | |
152 } | |
153 #endif | |
154 | |
155 #ifdef L_mulvsi3 | |
156 Wtype | |
157 __mulvSI3 (Wtype a, Wtype b) | |
158 { | |
159 const DWtype w = (DWtype) a * (DWtype) b; | |
160 | |
161 if ((Wtype) (w >> W_TYPE_SIZE) != (Wtype) w >> (W_TYPE_SIZE - 1)) | |
162 abort (); | |
163 | |
164 return w; | |
165 } | |
166 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC | |
167 #undef WORD_SIZE | |
168 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT) | |
169 SItype | |
170 __mulvsi3 (SItype a, SItype b) | |
171 { | |
172 const DItype w = (DItype) a * (DItype) b; | |
173 | |
174 if ((SItype) (w >> WORD_SIZE) != (SItype) w >> (WORD_SIZE-1)) | |
175 abort (); | |
176 | |
177 return w; | |
178 } | |
179 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */ | |
180 #endif | |
181 | |
182 #ifdef L_negvsi2 | |
183 Wtype | |
184 __negvSI2 (Wtype a) | |
185 { | |
186 const Wtype w = -(UWtype) a; | |
187 | |
188 if (a >= 0 ? w > 0 : w < 0) | |
189 abort (); | |
190 | |
191 return w; | |
192 } | |
193 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC | |
194 SItype | |
195 __negvsi2 (SItype a) | |
196 { | |
197 const SItype w = -(USItype) a; | |
198 | |
199 if (a >= 0 ? w > 0 : w < 0) | |
200 abort (); | |
201 | |
202 return w; | |
203 } | |
204 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */ | |
205 #endif | |
206 | |
207 #ifdef L_negvdi2 | |
208 DWtype | |
209 __negvDI2 (DWtype a) | |
210 { | |
211 const DWtype w = -(UDWtype) a; | |
212 | |
213 if (a >= 0 ? w > 0 : w < 0) | |
214 abort (); | |
215 | |
216 return w; | |
217 } | |
218 #endif | |
219 | |
220 #ifdef L_absvsi2 | |
221 Wtype | |
222 __absvSI2 (Wtype a) | |
223 { | |
224 Wtype w = a; | |
225 | |
226 if (a < 0) | |
227 #ifdef L_negvsi2 | |
228 w = __negvSI2 (a); | |
229 #else | |
230 w = -(UWtype) a; | |
231 | |
232 if (w < 0) | |
233 abort (); | |
234 #endif | |
235 | |
236 return w; | |
237 } | |
238 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC | |
239 SItype | |
240 __absvsi2 (SItype a) | |
241 { | |
242 SItype w = a; | |
243 | |
244 if (a < 0) | |
245 #ifdef L_negvsi2 | |
246 w = __negvsi2 (a); | |
247 #else | |
248 w = -(USItype) a; | |
249 | |
250 if (w < 0) | |
251 abort (); | |
252 #endif | |
253 | |
254 return w; | |
255 } | |
256 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */ | |
257 #endif | |
258 | |
259 #ifdef L_absvdi2 | |
260 DWtype | |
261 __absvDI2 (DWtype a) | |
262 { | |
263 DWtype w = a; | |
264 | |
265 if (a < 0) | |
266 #ifdef L_negvdi2 | |
267 w = __negvDI2 (a); | |
268 #else | |
269 w = -(UDWtype) a; | |
270 | |
271 if (w < 0) | |
272 abort (); | |
273 #endif | |
274 | |
275 return w; | |
276 } | |
277 #endif | |
278 | |
279 #ifdef L_mulvdi3 | |
280 DWtype | |
281 __mulvDI3 (DWtype u, DWtype v) | |
282 { | |
283 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications, | |
284 but the checked multiplication needs only two. */ | |
285 const DWunion uu = {.ll = u}; | |
286 const DWunion vv = {.ll = v}; | |
287 | |
288 if (__builtin_expect (uu.s.high == uu.s.low >> (W_TYPE_SIZE - 1), 1)) | |
289 { | |
290 /* u fits in a single Wtype. */ | |
291 if (__builtin_expect (vv.s.high == vv.s.low >> (W_TYPE_SIZE - 1), 1)) | |
292 { | |
293 /* v fits in a single Wtype as well. */ | |
294 /* A single multiplication. No overflow risk. */ | |
295 return (DWtype) uu.s.low * (DWtype) vv.s.low; | |
296 } | |
297 else | |
298 { | |
299 /* Two multiplications. */ | |
300 DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low | |
301 * (UDWtype) (UWtype) vv.s.low}; | |
302 DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.low | |
303 * (UDWtype) (UWtype) vv.s.high}; | |
304 | |
305 if (vv.s.high < 0) | |
306 w1.s.high -= uu.s.low; | |
307 if (uu.s.low < 0) | |
308 w1.ll -= vv.ll; | |
309 w1.ll += (UWtype) w0.s.high; | |
310 if (__builtin_expect (w1.s.high == w1.s.low >> (W_TYPE_SIZE - 1), 1)) | |
311 { | |
312 w0.s.high = w1.s.low; | |
313 return w0.ll; | |
314 } | |
315 } | |
316 } | |
317 else | |
318 { | |
319 if (__builtin_expect (vv.s.high == vv.s.low >> (W_TYPE_SIZE - 1), 1)) | |
320 { | |
321 /* v fits into a single Wtype. */ | |
322 /* Two multiplications. */ | |
323 DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low | |
324 * (UDWtype) (UWtype) vv.s.low}; | |
325 DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.high | |
326 * (UDWtype) (UWtype) vv.s.low}; | |
327 | |
328 if (uu.s.high < 0) | |
329 w1.s.high -= vv.s.low; | |
330 if (vv.s.low < 0) | |
331 w1.ll -= uu.ll; | |
332 w1.ll += (UWtype) w0.s.high; | |
333 if (__builtin_expect (w1.s.high == w1.s.low >> (W_TYPE_SIZE - 1), 1)) | |
334 { | |
335 w0.s.high = w1.s.low; | |
336 return w0.ll; | |
337 } | |
338 } | |
339 else | |
340 { | |
341 /* A few sign checks and a single multiplication. */ | |
342 if (uu.s.high >= 0) | |
343 { | |
344 if (vv.s.high >= 0) | |
345 { | |
346 if (uu.s.high == 0 && vv.s.high == 0) | |
347 { | |
348 const DWtype w = (UDWtype) (UWtype) uu.s.low | |
349 * (UDWtype) (UWtype) vv.s.low; | |
350 if (__builtin_expect (w >= 0, 1)) | |
351 return w; | |
352 } | |
353 } | |
354 else | |
355 { | |
356 if (uu.s.high == 0 && vv.s.high == (Wtype) -1) | |
357 { | |
358 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low | |
359 * (UDWtype) (UWtype) vv.s.low}; | |
360 | |
361 ww.s.high -= uu.s.low; | |
362 if (__builtin_expect (ww.s.high < 0, 1)) | |
363 return ww.ll; | |
364 } | |
365 } | |
366 } | |
367 else | |
368 { | |
369 if (vv.s.high >= 0) | |
370 { | |
371 if (uu.s.high == (Wtype) -1 && vv.s.high == 0) | |
372 { | |
373 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low | |
374 * (UDWtype) (UWtype) vv.s.low}; | |
375 | |
376 ww.s.high -= vv.s.low; | |
377 if (__builtin_expect (ww.s.high < 0, 1)) | |
378 return ww.ll; | |
379 } | |
380 } | |
381 else | |
382 { | |
383 if (uu.s.high == (Wtype) -1 && vv.s.high == (Wtype) - 1) | |
384 { | |
385 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low | |
386 * (UDWtype) (UWtype) vv.s.low}; | |
387 | |
388 ww.s.high -= uu.s.low; | |
389 ww.s.high -= vv.s.low; | |
390 if (__builtin_expect (ww.s.high >= 0, 1)) | |
391 return ww.ll; | |
392 } | |
393 } | |
394 } | |
395 } | |
396 } | |
397 | |
398 /* Overflow. */ | |
399 abort (); | |
400 } | |
401 #endif | |
402 | |
403 | |
404 /* Unless shift functions are defined with full ANSI prototypes, | |
405 parameter b will be promoted to int if shift_count_type is smaller than an int. */ | |
406 #ifdef L_lshrdi3 | |
407 DWtype | |
408 __lshrdi3 (DWtype u, shift_count_type b) | |
409 { | |
410 if (b == 0) | |
411 return u; | |
412 | |
413 const DWunion uu = {.ll = u}; | |
414 const shift_count_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b; | |
415 DWunion w; | |
416 | |
417 if (bm <= 0) | |
418 { | |
419 w.s.high = 0; | |
420 w.s.low = (UWtype) uu.s.high >> -bm; | |
421 } | |
422 else | |
423 { | |
424 const UWtype carries = (UWtype) uu.s.high << bm; | |
425 | |
426 w.s.high = (UWtype) uu.s.high >> b; | |
427 w.s.low = ((UWtype) uu.s.low >> b) | carries; | |
428 } | |
429 | |
430 return w.ll; | |
431 } | |
432 #endif | |
433 | |
434 #ifdef L_ashldi3 | |
435 DWtype | |
436 __ashldi3 (DWtype u, shift_count_type b) | |
437 { | |
438 if (b == 0) | |
439 return u; | |
440 | |
441 const DWunion uu = {.ll = u}; | |
442 const shift_count_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b; | |
443 DWunion w; | |
444 | |
445 if (bm <= 0) | |
446 { | |
447 w.s.low = 0; | |
448 w.s.high = (UWtype) uu.s.low << -bm; | |
449 } | |
450 else | |
451 { | |
452 const UWtype carries = (UWtype) uu.s.low >> bm; | |
453 | |
454 w.s.low = (UWtype) uu.s.low << b; | |
455 w.s.high = ((UWtype) uu.s.high << b) | carries; | |
456 } | |
457 | |
458 return w.ll; | |
459 } | |
460 #endif | |
461 | |
462 #ifdef L_ashrdi3 | |
463 DWtype | |
464 __ashrdi3 (DWtype u, shift_count_type b) | |
465 { | |
466 if (b == 0) | |
467 return u; | |
468 | |
469 const DWunion uu = {.ll = u}; | |
470 const shift_count_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b; | |
471 DWunion w; | |
472 | |
473 if (bm <= 0) | |
474 { | |
475 /* w.s.high = 1..1 or 0..0 */ | |
476 w.s.high = uu.s.high >> (sizeof (Wtype) * BITS_PER_UNIT - 1); | |
477 w.s.low = uu.s.high >> -bm; | |
478 } | |
479 else | |
480 { | |
481 const UWtype carries = (UWtype) uu.s.high << bm; | |
482 | |
483 w.s.high = uu.s.high >> b; | |
484 w.s.low = ((UWtype) uu.s.low >> b) | carries; | |
485 } | |
486 | |
487 return w.ll; | |
488 } | |
489 #endif | |
490 | |
491 #ifdef L_bswapsi2 | |
492 SItype | |
493 __bswapsi2 (SItype u) | |
494 { | |
495 return ((((u) & 0xff000000) >> 24) | |
496 | (((u) & 0x00ff0000) >> 8) | |
497 | (((u) & 0x0000ff00) << 8) | |
498 | (((u) & 0x000000ff) << 24)); | |
499 } | |
500 #endif | |
501 #ifdef L_bswapdi2 | |
502 DItype | |
503 __bswapdi2 (DItype u) | |
504 { | |
505 return ((((u) & 0xff00000000000000ull) >> 56) | |
506 | (((u) & 0x00ff000000000000ull) >> 40) | |
507 | (((u) & 0x0000ff0000000000ull) >> 24) | |
508 | (((u) & 0x000000ff00000000ull) >> 8) | |
509 | (((u) & 0x00000000ff000000ull) << 8) | |
510 | (((u) & 0x0000000000ff0000ull) << 24) | |
511 | (((u) & 0x000000000000ff00ull) << 40) | |
512 | (((u) & 0x00000000000000ffull) << 56)); | |
513 } | |
514 #endif | |
515 #ifdef L_ffssi2 | |
516 #undef int | |
517 int | |
518 __ffsSI2 (UWtype u) | |
519 { | |
520 UWtype count; | |
521 | |
522 if (u == 0) | |
523 return 0; | |
524 | |
525 count_trailing_zeros (count, u); | |
526 return count + 1; | |
527 } | |
528 #endif | |
529 | |
530 #ifdef L_ffsdi2 | |
531 #undef int | |
532 int | |
533 __ffsDI2 (DWtype u) | |
534 { | |
535 const DWunion uu = {.ll = u}; | |
536 UWtype word, count, add; | |
537 | |
538 if (uu.s.low != 0) | |
539 word = uu.s.low, add = 0; | |
540 else if (uu.s.high != 0) | |
541 word = uu.s.high, add = BITS_PER_UNIT * sizeof (Wtype); | |
542 else | |
543 return 0; | |
544 | |
545 count_trailing_zeros (count, word); | |
546 return count + add + 1; | |
547 } | |
548 #endif | |
549 | |
550 #ifdef L_muldi3 | |
551 DWtype | |
552 __muldi3 (DWtype u, DWtype v) | |
553 { | |
554 const DWunion uu = {.ll = u}; | |
555 const DWunion vv = {.ll = v}; | |
556 DWunion w = {.ll = __umulsidi3 (uu.s.low, vv.s.low)}; | |
557 | |
558 w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high | |
559 + (UWtype) uu.s.high * (UWtype) vv.s.low); | |
560 | |
561 return w.ll; | |
562 } | |
563 #endif | |
564 | |
565 #if (defined (L_udivdi3) || defined (L_divdi3) || \ | |
566 defined (L_umoddi3) || defined (L_moddi3)) | |
567 #if defined (sdiv_qrnnd) | |
568 #define L_udiv_w_sdiv | |
569 #endif | |
570 #endif | |
571 | |
572 #ifdef L_udiv_w_sdiv | |
573 #if defined (sdiv_qrnnd) | |
574 #if (defined (L_udivdi3) || defined (L_divdi3) || \ | |
575 defined (L_umoddi3) || defined (L_moddi3)) | |
576 static inline __attribute__ ((__always_inline__)) | |
577 #endif | |
578 UWtype | |
579 __udiv_w_sdiv (UWtype *rp, UWtype a1, UWtype a0, UWtype d) | |
580 { | |
581 UWtype q, r; | |
582 UWtype c0, c1, b1; | |
583 | |
584 if ((Wtype) d >= 0) | |
585 { | |
586 if (a1 < d - a1 - (a0 >> (W_TYPE_SIZE - 1))) | |
587 { | |
588 /* Dividend, divisor, and quotient are nonnegative. */ | |
589 sdiv_qrnnd (q, r, a1, a0, d); | |
590 } | |
591 else | |
592 { | |
593 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d. */ | |
594 sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (W_TYPE_SIZE - 1)); | |
595 /* Divide (c1*2^32 + c0) by d. */ | |
596 sdiv_qrnnd (q, r, c1, c0, d); | |
597 /* Add 2^31 to quotient. */ | |
598 q += (UWtype) 1 << (W_TYPE_SIZE - 1); | |
599 } | |
600 } | |
601 else | |
602 { | |
603 b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */ | |
604 c1 = a1 >> 1; /* A/2 */ | |
605 c0 = (a1 << (W_TYPE_SIZE - 1)) + (a0 >> 1); | |
606 | |
607 if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */ | |
608 { | |
609 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */ | |
610 | |
611 r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */ | |
612 if ((d & 1) != 0) | |
613 { | |
614 if (r >= q) | |
615 r = r - q; | |
616 else if (q - r <= d) | |
617 { | |
618 r = r - q + d; | |
619 q--; | |
620 } | |
621 else | |
622 { | |
623 r = r - q + 2*d; | |
624 q -= 2; | |
625 } | |
626 } | |
627 } | |
628 else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */ | |
629 { | |
630 c1 = (b1 - 1) - c1; | |
631 c0 = ~c0; /* logical NOT */ | |
632 | |
633 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */ | |
634 | |
635 q = ~q; /* (A/2)/b1 */ | |
636 r = (b1 - 1) - r; | |
637 | |
638 r = 2*r + (a0 & 1); /* A/(2*b1) */ | |
639 | |
640 if ((d & 1) != 0) | |
641 { | |
642 if (r >= q) | |
643 r = r - q; | |
644 else if (q - r <= d) | |
645 { | |
646 r = r - q + d; | |
647 q--; | |
648 } | |
649 else | |
650 { | |
651 r = r - q + 2*d; | |
652 q -= 2; | |
653 } | |
654 } | |
655 } | |
656 else /* Implies c1 = b1 */ | |
657 { /* Hence a1 = d - 1 = 2*b1 - 1 */ | |
658 if (a0 >= -d) | |
659 { | |
660 q = -1; | |
661 r = a0 + d; | |
662 } | |
663 else | |
664 { | |
665 q = -2; | |
666 r = a0 + 2*d; | |
667 } | |
668 } | |
669 } | |
670 | |
671 *rp = r; | |
672 return q; | |
673 } | |
674 #else | |
675 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */ | |
676 UWtype | |
677 __udiv_w_sdiv (UWtype *rp __attribute__ ((__unused__)), | |
678 UWtype a1 __attribute__ ((__unused__)), | |
679 UWtype a0 __attribute__ ((__unused__)), | |
680 UWtype d __attribute__ ((__unused__))) | |
681 { | |
682 return 0; | |
683 } | |
684 #endif | |
685 #endif | |
686 | |
687 #if (defined (L_udivdi3) || defined (L_divdi3) || \ | |
688 defined (L_umoddi3) || defined (L_moddi3)) | |
689 #define L_udivmoddi4 | |
690 #endif | |
691 | |
692 #ifdef L_clz | |
693 const UQItype __clz_tab[256] = | |
694 { | |
695 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, | |
696 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | |
697 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | |
698 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | |
699 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | |
700 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | |
701 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | |
702 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 | |
703 }; | |
704 #endif | |
705 | |
706 #ifdef L_clzsi2 | |
707 #undef int | |
708 int | |
709 __clzSI2 (UWtype x) | |
710 { | |
711 Wtype ret; | |
712 | |
713 count_leading_zeros (ret, x); | |
714 | |
715 return ret; | |
716 } | |
717 #endif | |
718 | |
719 #ifdef L_clzdi2 | |
720 #undef int | |
721 int | |
722 __clzDI2 (UDWtype x) | |
723 { | |
724 const DWunion uu = {.ll = x}; | |
725 UWtype word; | |
726 Wtype ret, add; | |
727 | |
728 if (uu.s.high) | |
729 word = uu.s.high, add = 0; | |
730 else | |
731 word = uu.s.low, add = W_TYPE_SIZE; | |
732 | |
733 count_leading_zeros (ret, word); | |
734 return ret + add; | |
735 } | |
736 #endif | |
737 | |
738 #ifdef L_ctzsi2 | |
739 #undef int | |
740 int | |
741 __ctzSI2 (UWtype x) | |
742 { | |
743 Wtype ret; | |
744 | |
745 count_trailing_zeros (ret, x); | |
746 | |
747 return ret; | |
748 } | |
749 #endif | |
750 | |
751 #ifdef L_ctzdi2 | |
752 #undef int | |
753 int | |
754 __ctzDI2 (UDWtype x) | |
755 { | |
756 const DWunion uu = {.ll = x}; | |
757 UWtype word; | |
758 Wtype ret, add; | |
759 | |
760 if (uu.s.low) | |
761 word = uu.s.low, add = 0; | |
762 else | |
763 word = uu.s.high, add = W_TYPE_SIZE; | |
764 | |
765 count_trailing_zeros (ret, word); | |
766 return ret + add; | |
767 } | |
768 #endif | |
769 | |
770 #ifdef L_popcount_tab | |
771 const UQItype __popcount_tab[256] = | |
772 { | |
773 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, | |
774 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, | |
775 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, | |
776 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, | |
777 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, | |
778 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, | |
779 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, | |
780 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8 | |
781 }; | |
782 #endif | |
783 | |
784 #ifdef L_popcountsi2 | |
785 #undef int | |
786 int | |
787 __popcountSI2 (UWtype x) | |
788 { | |
789 int i, ret = 0; | |
790 | |
791 for (i = 0; i < W_TYPE_SIZE; i += 8) | |
792 ret += __popcount_tab[(x >> i) & 0xff]; | |
793 | |
794 return ret; | |
795 } | |
796 #endif | |
797 | |
798 #ifdef L_popcountdi2 | |
799 #undef int | |
800 int | |
801 __popcountDI2 (UDWtype x) | |
802 { | |
803 int i, ret = 0; | |
804 | |
805 for (i = 0; i < 2*W_TYPE_SIZE; i += 8) | |
806 ret += __popcount_tab[(x >> i) & 0xff]; | |
807 | |
808 return ret; | |
809 } | |
810 #endif | |
811 | |
812 #ifdef L_paritysi2 | |
813 #undef int | |
814 int | |
815 __paritySI2 (UWtype x) | |
816 { | |
817 #if W_TYPE_SIZE > 64 | |
818 # error "fill out the table" | |
819 #endif | |
820 #if W_TYPE_SIZE > 32 | |
821 x ^= x >> 32; | |
822 #endif | |
823 #if W_TYPE_SIZE > 16 | |
824 x ^= x >> 16; | |
825 #endif | |
826 x ^= x >> 8; | |
827 x ^= x >> 4; | |
828 x &= 0xf; | |
829 return (0x6996 >> x) & 1; | |
830 } | |
831 #endif | |
832 | |
833 #ifdef L_paritydi2 | |
834 #undef int | |
835 int | |
836 __parityDI2 (UDWtype x) | |
837 { | |
838 const DWunion uu = {.ll = x}; | |
839 UWtype nx = uu.s.low ^ uu.s.high; | |
840 | |
841 #if W_TYPE_SIZE > 64 | |
842 # error "fill out the table" | |
843 #endif | |
844 #if W_TYPE_SIZE > 32 | |
845 nx ^= nx >> 32; | |
846 #endif | |
847 #if W_TYPE_SIZE > 16 | |
848 nx ^= nx >> 16; | |
849 #endif | |
850 nx ^= nx >> 8; | |
851 nx ^= nx >> 4; | |
852 nx &= 0xf; | |
853 return (0x6996 >> nx) & 1; | |
854 } | |
855 #endif | |
856 | |
857 #ifdef L_udivmoddi4 | |
858 | |
859 #if (defined (L_udivdi3) || defined (L_divdi3) || \ | |
860 defined (L_umoddi3) || defined (L_moddi3)) | |
861 static inline __attribute__ ((__always_inline__)) | |
862 #endif | |
863 UDWtype | |
864 __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp) | |
865 { | |
866 const DWunion nn = {.ll = n}; | |
867 const DWunion dd = {.ll = d}; | |
868 DWunion rr; | |
869 UWtype d0, d1, n0, n1, n2; | |
870 UWtype q0, q1; | |
871 UWtype b, bm; | |
872 | |
873 d0 = dd.s.low; | |
874 d1 = dd.s.high; | |
875 n0 = nn.s.low; | |
876 n1 = nn.s.high; | |
877 | |
878 #if !UDIV_NEEDS_NORMALIZATION | |
879 if (d1 == 0) | |
880 { | |
881 if (d0 > n1) | |
882 { | |
883 /* 0q = nn / 0D */ | |
884 | |
885 udiv_qrnnd (q0, n0, n1, n0, d0); | |
886 q1 = 0; | |
887 | |
888 /* Remainder in n0. */ | |
889 } | |
890 else | |
891 { | |
892 /* qq = NN / 0d */ | |
893 | |
894 if (d0 == 0) | |
895 d0 = 1 / d0; /* Divide intentionally by zero. */ | |
896 | |
897 udiv_qrnnd (q1, n1, 0, n1, d0); | |
898 udiv_qrnnd (q0, n0, n1, n0, d0); | |
899 | |
900 /* Remainder in n0. */ | |
901 } | |
902 | |
903 if (rp != 0) | |
904 { | |
905 rr.s.low = n0; | |
906 rr.s.high = 0; | |
907 *rp = rr.ll; | |
908 } | |
909 } | |
910 | |
911 #else /* UDIV_NEEDS_NORMALIZATION */ | |
912 | |
913 if (d1 == 0) | |
914 { | |
915 if (d0 > n1) | |
916 { | |
917 /* 0q = nn / 0D */ | |
918 | |
919 count_leading_zeros (bm, d0); | |
920 | |
921 if (bm != 0) | |
922 { | |
923 /* Normalize, i.e. make the most significant bit of the | |
924 denominator set. */ | |
925 | |
926 d0 = d0 << bm; | |
927 n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm)); | |
928 n0 = n0 << bm; | |
929 } | |
930 | |
931 udiv_qrnnd (q0, n0, n1, n0, d0); | |
932 q1 = 0; | |
933 | |
934 /* Remainder in n0 >> bm. */ | |
935 } | |
936 else | |
937 { | |
938 /* qq = NN / 0d */ | |
939 | |
940 if (d0 == 0) | |
941 d0 = 1 / d0; /* Divide intentionally by zero. */ | |
942 | |
943 count_leading_zeros (bm, d0); | |
944 | |
945 if (bm == 0) | |
946 { | |
947 /* From (n1 >= d0) /\ (the most significant bit of d0 is set), | |
948 conclude (the most significant bit of n1 is set) /\ (the | |
949 leading quotient digit q1 = 1). | |
950 | |
951 This special case is necessary, not an optimization. | |
952 (Shifts counts of W_TYPE_SIZE are undefined.) */ | |
953 | |
954 n1 -= d0; | |
955 q1 = 1; | |
956 } | |
957 else | |
958 { | |
959 /* Normalize. */ | |
960 | |
961 b = W_TYPE_SIZE - bm; | |
962 | |
963 d0 = d0 << bm; | |
964 n2 = n1 >> b; | |
965 n1 = (n1 << bm) | (n0 >> b); | |
966 n0 = n0 << bm; | |
967 | |
968 udiv_qrnnd (q1, n1, n2, n1, d0); | |
969 } | |
970 | |
971 /* n1 != d0... */ | |
972 | |
973 udiv_qrnnd (q0, n0, n1, n0, d0); | |
974 | |
975 /* Remainder in n0 >> bm. */ | |
976 } | |
977 | |
978 if (rp != 0) | |
979 { | |
980 rr.s.low = n0 >> bm; | |
981 rr.s.high = 0; | |
982 *rp = rr.ll; | |
983 } | |
984 } | |
985 #endif /* UDIV_NEEDS_NORMALIZATION */ | |
986 | |
987 else | |
988 { | |
989 if (d1 > n1) | |
990 { | |
991 /* 00 = nn / DD */ | |
992 | |
993 q0 = 0; | |
994 q1 = 0; | |
995 | |
996 /* Remainder in n1n0. */ | |
997 if (rp != 0) | |
998 { | |
999 rr.s.low = n0; | |
1000 rr.s.high = n1; | |
1001 *rp = rr.ll; | |
1002 } | |
1003 } | |
1004 else | |
1005 { | |
1006 /* 0q = NN / dd */ | |
1007 | |
1008 count_leading_zeros (bm, d1); | |
1009 if (bm == 0) | |
1010 { | |
1011 /* From (n1 >= d1) /\ (the most significant bit of d1 is set), | |
1012 conclude (the most significant bit of n1 is set) /\ (the | |
1013 quotient digit q0 = 0 or 1). | |
1014 | |
1015 This special case is necessary, not an optimization. */ | |
1016 | |
1017 /* The condition on the next line takes advantage of that | |
1018 n1 >= d1 (true due to program flow). */ | |
1019 if (n1 > d1 || n0 >= d0) | |
1020 { | |
1021 q0 = 1; | |
1022 sub_ddmmss (n1, n0, n1, n0, d1, d0); | |
1023 } | |
1024 else | |
1025 q0 = 0; | |
1026 | |
1027 q1 = 0; | |
1028 | |
1029 if (rp != 0) | |
1030 { | |
1031 rr.s.low = n0; | |
1032 rr.s.high = n1; | |
1033 *rp = rr.ll; | |
1034 } | |
1035 } | |
1036 else | |
1037 { | |
1038 UWtype m1, m0; | |
1039 /* Normalize. */ | |
1040 | |
1041 b = W_TYPE_SIZE - bm; | |
1042 | |
1043 d1 = (d1 << bm) | (d0 >> b); | |
1044 d0 = d0 << bm; | |
1045 n2 = n1 >> b; | |
1046 n1 = (n1 << bm) | (n0 >> b); | |
1047 n0 = n0 << bm; | |
1048 | |
1049 udiv_qrnnd (q0, n1, n2, n1, d1); | |
1050 umul_ppmm (m1, m0, q0, d0); | |
1051 | |
1052 if (m1 > n1 || (m1 == n1 && m0 > n0)) | |
1053 { | |
1054 q0--; | |
1055 sub_ddmmss (m1, m0, m1, m0, d1, d0); | |
1056 } | |
1057 | |
1058 q1 = 0; | |
1059 | |
1060 /* Remainder in (n1n0 - m1m0) >> bm. */ | |
1061 if (rp != 0) | |
1062 { | |
1063 sub_ddmmss (n1, n0, n1, n0, m1, m0); | |
1064 rr.s.low = (n1 << b) | (n0 >> bm); | |
1065 rr.s.high = n1 >> bm; | |
1066 *rp = rr.ll; | |
1067 } | |
1068 } | |
1069 } | |
1070 } | |
1071 | |
1072 const DWunion ww = {{.low = q0, .high = q1}}; | |
1073 return ww.ll; | |
1074 } | |
1075 #endif | |
1076 | |
1077 #ifdef L_divdi3 | |
1078 DWtype | |
1079 __divdi3 (DWtype u, DWtype v) | |
1080 { | |
1081 Wtype c = 0; | |
1082 DWunion uu = {.ll = u}; | |
1083 DWunion vv = {.ll = v}; | |
1084 DWtype w; | |
1085 | |
1086 if (uu.s.high < 0) | |
1087 c = ~c, | |
1088 uu.ll = -uu.ll; | |
1089 if (vv.s.high < 0) | |
1090 c = ~c, | |
1091 vv.ll = -vv.ll; | |
1092 | |
1093 w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0); | |
1094 if (c) | |
1095 w = -w; | |
1096 | |
1097 return w; | |
1098 } | |
1099 #endif | |
1100 | |
1101 #ifdef L_moddi3 | |
1102 DWtype | |
1103 __moddi3 (DWtype u, DWtype v) | |
1104 { | |
1105 Wtype c = 0; | |
1106 DWunion uu = {.ll = u}; | |
1107 DWunion vv = {.ll = v}; | |
1108 DWtype w; | |
1109 | |
1110 if (uu.s.high < 0) | |
1111 c = ~c, | |
1112 uu.ll = -uu.ll; | |
1113 if (vv.s.high < 0) | |
1114 vv.ll = -vv.ll; | |
1115 | |
1116 (void) __udivmoddi4 (uu.ll, vv.ll, (UDWtype*)&w); | |
1117 if (c) | |
1118 w = -w; | |
1119 | |
1120 return w; | |
1121 } | |
1122 #endif | |
1123 | |
1124 #ifdef L_umoddi3 | |
1125 UDWtype | |
1126 __umoddi3 (UDWtype u, UDWtype v) | |
1127 { | |
1128 UDWtype w; | |
1129 | |
1130 (void) __udivmoddi4 (u, v, &w); | |
1131 | |
1132 return w; | |
1133 } | |
1134 #endif | |
1135 | |
1136 #ifdef L_udivdi3 | |
1137 UDWtype | |
1138 __udivdi3 (UDWtype n, UDWtype d) | |
1139 { | |
1140 return __udivmoddi4 (n, d, (UDWtype *) 0); | |
1141 } | |
1142 #endif | |
1143 | |
1144 #ifdef L_cmpdi2 | |
1145 cmp_return_type | |
1146 __cmpdi2 (DWtype a, DWtype b) | |
1147 { | |
1148 const DWunion au = {.ll = a}; | |
1149 const DWunion bu = {.ll = b}; | |
1150 | |
1151 if (au.s.high < bu.s.high) | |
1152 return 0; | |
1153 else if (au.s.high > bu.s.high) | |
1154 return 2; | |
1155 if ((UWtype) au.s.low < (UWtype) bu.s.low) | |
1156 return 0; | |
1157 else if ((UWtype) au.s.low > (UWtype) bu.s.low) | |
1158 return 2; | |
1159 return 1; | |
1160 } | |
1161 #endif | |
1162 | |
1163 #ifdef L_ucmpdi2 | |
1164 cmp_return_type | |
1165 __ucmpdi2 (DWtype a, DWtype b) | |
1166 { | |
1167 const DWunion au = {.ll = a}; | |
1168 const DWunion bu = {.ll = b}; | |
1169 | |
1170 if ((UWtype) au.s.high < (UWtype) bu.s.high) | |
1171 return 0; | |
1172 else if ((UWtype) au.s.high > (UWtype) bu.s.high) | |
1173 return 2; | |
1174 if ((UWtype) au.s.low < (UWtype) bu.s.low) | |
1175 return 0; | |
1176 else if ((UWtype) au.s.low > (UWtype) bu.s.low) | |
1177 return 2; | |
1178 return 1; | |
1179 } | |
1180 #endif | |
1181 | |
1182 #if defined(L_fixunstfdi) && LIBGCC2_HAS_TF_MODE | |
1183 UDWtype | |
1184 __fixunstfDI (TFtype a) | |
1185 { | |
1186 if (a < 0) | |
1187 return 0; | |
1188 | |
1189 /* Compute high word of result, as a flonum. */ | |
1190 const TFtype b = (a / Wtype_MAXp1_F); | |
1191 /* Convert that to fixed (but not to DWtype!), | |
1192 and shift it into the high word. */ | |
1193 UDWtype v = (UWtype) b; | |
1194 v <<= W_TYPE_SIZE; | |
1195 /* Remove high part from the TFtype, leaving the low part as flonum. */ | |
1196 a -= (TFtype)v; | |
1197 /* Convert that to fixed (but not to DWtype!) and add it in. | |
1198 Sometimes A comes out negative. This is significant, since | |
1199 A has more bits than a long int does. */ | |
1200 if (a < 0) | |
1201 v -= (UWtype) (- a); | |
1202 else | |
1203 v += (UWtype) a; | |
1204 return v; | |
1205 } | |
1206 #endif | |
1207 | |
1208 #if defined(L_fixtfdi) && LIBGCC2_HAS_TF_MODE | |
1209 DWtype | |
1210 __fixtfdi (TFtype a) | |
1211 { | |
1212 if (a < 0) | |
1213 return - __fixunstfDI (-a); | |
1214 return __fixunstfDI (a); | |
1215 } | |
1216 #endif | |
1217 | |
1218 #if defined(L_fixunsxfdi) && LIBGCC2_HAS_XF_MODE | |
1219 UDWtype | |
1220 __fixunsxfDI (XFtype a) | |
1221 { | |
1222 if (a < 0) | |
1223 return 0; | |
1224 | |
1225 /* Compute high word of result, as a flonum. */ | |
1226 const XFtype b = (a / Wtype_MAXp1_F); | |
1227 /* Convert that to fixed (but not to DWtype!), | |
1228 and shift it into the high word. */ | |
1229 UDWtype v = (UWtype) b; | |
1230 v <<= W_TYPE_SIZE; | |
1231 /* Remove high part from the XFtype, leaving the low part as flonum. */ | |
1232 a -= (XFtype)v; | |
1233 /* Convert that to fixed (but not to DWtype!) and add it in. | |
1234 Sometimes A comes out negative. This is significant, since | |
1235 A has more bits than a long int does. */ | |
1236 if (a < 0) | |
1237 v -= (UWtype) (- a); | |
1238 else | |
1239 v += (UWtype) a; | |
1240 return v; | |
1241 } | |
1242 #endif | |
1243 | |
1244 #if defined(L_fixxfdi) && LIBGCC2_HAS_XF_MODE | |
1245 DWtype | |
1246 __fixxfdi (XFtype a) | |
1247 { | |
1248 if (a < 0) | |
1249 return - __fixunsxfDI (-a); | |
1250 return __fixunsxfDI (a); | |
1251 } | |
1252 #endif | |
1253 | |
1254 #if defined(L_fixunsdfdi) && LIBGCC2_HAS_DF_MODE | |
1255 UDWtype | |
1256 __fixunsdfDI (DFtype a) | |
1257 { | |
1258 /* Get high part of result. The division here will just moves the radix | |
1259 point and will not cause any rounding. Then the conversion to integral | |
1260 type chops result as desired. */ | |
1261 const UWtype hi = a / Wtype_MAXp1_F; | |
1262 | |
1263 /* Get low part of result. Convert `hi' to floating type and scale it back, | |
1264 then subtract this from the number being converted. This leaves the low | |
1265 part. Convert that to integral type. */ | |
1266 const UWtype lo = a - (DFtype) hi * Wtype_MAXp1_F; | |
1267 | |
1268 /* Assemble result from the two parts. */ | |
1269 return ((UDWtype) hi << W_TYPE_SIZE) | lo; | |
1270 } | |
1271 #endif | |
1272 | |
1273 #if defined(L_fixdfdi) && LIBGCC2_HAS_DF_MODE | |
1274 DWtype | |
1275 __fixdfdi (DFtype a) | |
1276 { | |
1277 if (a < 0) | |
1278 return - __fixunsdfDI (-a); | |
1279 return __fixunsdfDI (a); | |
1280 } | |
1281 #endif | |
1282 | |
1283 #if defined(L_fixunssfdi) && LIBGCC2_HAS_SF_MODE | |
1284 UDWtype | |
1285 __fixunssfDI (SFtype a) | |
1286 { | |
1287 #if LIBGCC2_HAS_DF_MODE | |
1288 /* Convert the SFtype to a DFtype, because that is surely not going | |
1289 to lose any bits. Some day someone else can write a faster version | |
1290 that avoids converting to DFtype, and verify it really works right. */ | |
1291 const DFtype dfa = a; | |
1292 | |
1293 /* Get high part of result. The division here will just moves the radix | |
1294 point and will not cause any rounding. Then the conversion to integral | |
1295 type chops result as desired. */ | |
1296 const UWtype hi = dfa / Wtype_MAXp1_F; | |
1297 | |
1298 /* Get low part of result. Convert `hi' to floating type and scale it back, | |
1299 then subtract this from the number being converted. This leaves the low | |
1300 part. Convert that to integral type. */ | |
1301 const UWtype lo = dfa - (DFtype) hi * Wtype_MAXp1_F; | |
1302 | |
1303 /* Assemble result from the two parts. */ | |
1304 return ((UDWtype) hi << W_TYPE_SIZE) | lo; | |
1305 #elif FLT_MANT_DIG < W_TYPE_SIZE | |
1306 if (a < 1) | |
1307 return 0; | |
1308 if (a < Wtype_MAXp1_F) | |
1309 return (UWtype)a; | |
1310 if (a < Wtype_MAXp1_F * Wtype_MAXp1_F) | |
1311 { | |
1312 /* Since we know that there are fewer significant bits in the SFmode | |
1313 quantity than in a word, we know that we can convert out all the | |
1314 significant bits in one step, and thus avoid losing bits. */ | |
1315 | |
1316 /* ??? This following loop essentially performs frexpf. If we could | |
1317 use the real libm function, or poke at the actual bits of the fp | |
1318 format, it would be significantly faster. */ | |
1319 | |
1320 UWtype shift = 0, counter; | |
1321 SFtype msb; | |
1322 | |
1323 a /= Wtype_MAXp1_F; | |
1324 for (counter = W_TYPE_SIZE / 2; counter != 0; counter >>= 1) | |
1325 { | |
1326 SFtype counterf = (UWtype)1 << counter; | |
1327 if (a >= counterf) | |
1328 { | |
1329 shift |= counter; | |
1330 a /= counterf; | |
1331 } | |
1332 } | |
1333 | |
1334 /* Rescale into the range of one word, extract the bits of that | |
1335 one word, and shift the result into position. */ | |
1336 a *= Wtype_MAXp1_F; | |
1337 counter = a; | |
1338 return (DWtype)counter << shift; | |
1339 } | |
1340 return -1; | |
1341 #else | |
1342 # error | |
1343 #endif | |
1344 } | |
1345 #endif | |
1346 | |
1347 #if defined(L_fixsfdi) && LIBGCC2_HAS_SF_MODE | |
1348 DWtype | |
1349 __fixsfdi (SFtype a) | |
1350 { | |
1351 if (a < 0) | |
1352 return - __fixunssfDI (-a); | |
1353 return __fixunssfDI (a); | |
1354 } | |
1355 #endif | |
1356 | |
1357 #if defined(L_floatdixf) && LIBGCC2_HAS_XF_MODE | |
1358 XFtype | |
1359 __floatdixf (DWtype u) | |
1360 { | |
1361 #if W_TYPE_SIZE > XF_SIZE | |
1362 # error | |
1363 #endif | |
1364 XFtype d = (Wtype) (u >> W_TYPE_SIZE); | |
1365 d *= Wtype_MAXp1_F; | |
1366 d += (UWtype)u; | |
1367 return d; | |
1368 } | |
1369 #endif | |
1370 | |
1371 #if defined(L_floatundixf) && LIBGCC2_HAS_XF_MODE | |
1372 XFtype | |
1373 __floatundixf (UDWtype u) | |
1374 { | |
1375 #if W_TYPE_SIZE > XF_SIZE | |
1376 # error | |
1377 #endif | |
1378 XFtype d = (UWtype) (u >> W_TYPE_SIZE); | |
1379 d *= Wtype_MAXp1_F; | |
1380 d += (UWtype)u; | |
1381 return d; | |
1382 } | |
1383 #endif | |
1384 | |
1385 #if defined(L_floatditf) && LIBGCC2_HAS_TF_MODE | |
1386 TFtype | |
1387 __floatditf (DWtype u) | |
1388 { | |
1389 #if W_TYPE_SIZE > TF_SIZE | |
1390 # error | |
1391 #endif | |
1392 TFtype d = (Wtype) (u >> W_TYPE_SIZE); | |
1393 d *= Wtype_MAXp1_F; | |
1394 d += (UWtype)u; | |
1395 return d; | |
1396 } | |
1397 #endif | |
1398 | |
1399 #if defined(L_floatunditf) && LIBGCC2_HAS_TF_MODE | |
1400 TFtype | |
1401 __floatunditf (UDWtype u) | |
1402 { | |
1403 #if W_TYPE_SIZE > TF_SIZE | |
1404 # error | |
1405 #endif | |
1406 TFtype d = (UWtype) (u >> W_TYPE_SIZE); | |
1407 d *= Wtype_MAXp1_F; | |
1408 d += (UWtype)u; | |
1409 return d; | |
1410 } | |
1411 #endif | |
1412 | |
1413 #if (defined(L_floatdisf) && LIBGCC2_HAS_SF_MODE) \ | |
1414 || (defined(L_floatdidf) && LIBGCC2_HAS_DF_MODE) | |
1415 #define DI_SIZE (W_TYPE_SIZE * 2) | |
1416 #define F_MODE_OK(SIZE) \ | |
1417 (SIZE < DI_SIZE \ | |
1418 && SIZE > (DI_SIZE - SIZE + FSSIZE) \ | |
1419 && !AVOID_FP_TYPE_CONVERSION(SIZE)) | |
1420 #if defined(L_floatdisf) | |
1421 #define FUNC __floatdisf | |
1422 #define FSTYPE SFtype | |
1423 #define FSSIZE SF_SIZE | |
1424 #else | |
1425 #define FUNC __floatdidf | |
1426 #define FSTYPE DFtype | |
1427 #define FSSIZE DF_SIZE | |
1428 #endif | |
1429 | |
1430 FSTYPE | |
1431 FUNC (DWtype u) | |
1432 { | |
1433 #if FSSIZE >= W_TYPE_SIZE | |
1434 /* When the word size is small, we never get any rounding error. */ | |
1435 FSTYPE f = (Wtype) (u >> W_TYPE_SIZE); | |
1436 f *= Wtype_MAXp1_F; | |
1437 f += (UWtype)u; | |
1438 return f; | |
1439 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE)) \ | |
1440 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE)) \ | |
1441 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE)) | |
1442 | |
1443 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE)) | |
1444 # define FSIZE DF_SIZE | |
1445 # define FTYPE DFtype | |
1446 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE)) | |
1447 # define FSIZE XF_SIZE | |
1448 # define FTYPE XFtype | |
1449 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE)) | |
1450 # define FSIZE TF_SIZE | |
1451 # define FTYPE TFtype | |
1452 #else | |
1453 # error | |
1454 #endif | |
1455 | |
1456 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE)) | |
1457 | |
1458 /* Protect against double-rounding error. | |
1459 Represent any low-order bits, that might be truncated by a bit that | |
1460 won't be lost. The bit can go in anywhere below the rounding position | |
1461 of the FSTYPE. A fixed mask and bit position handles all usual | |
1462 configurations. */ | |
1463 if (! (- ((DWtype) 1 << FSIZE) < u | |
1464 && u < ((DWtype) 1 << FSIZE))) | |
1465 { | |
1466 if ((UDWtype) u & (REP_BIT - 1)) | |
1467 { | |
1468 u &= ~ (REP_BIT - 1); | |
1469 u |= REP_BIT; | |
1470 } | |
1471 } | |
1472 | |
1473 /* Do the calculation in a wider type so that we don't lose any of | |
1474 the precision of the high word while multiplying it. */ | |
1475 FTYPE f = (Wtype) (u >> W_TYPE_SIZE); | |
1476 f *= Wtype_MAXp1_F; | |
1477 f += (UWtype)u; | |
1478 return (FSTYPE) f; | |
1479 #else | |
1480 #if FSSIZE >= W_TYPE_SIZE - 2 | |
1481 # error | |
1482 #endif | |
1483 /* Finally, the word size is larger than the number of bits in the | |
1484 required FSTYPE, and we've got no suitable wider type. The only | |
1485 way to avoid double rounding is to special case the | |
1486 extraction. */ | |
1487 | |
1488 /* If there are no high bits set, fall back to one conversion. */ | |
1489 if ((Wtype)u == u) | |
1490 return (FSTYPE)(Wtype)u; | |
1491 | |
1492 /* Otherwise, find the power of two. */ | |
1493 Wtype hi = u >> W_TYPE_SIZE; | |
1494 if (hi < 0) | |
1495 hi = -hi; | |
1496 | |
1497 UWtype count, shift; | |
1498 count_leading_zeros (count, hi); | |
1499 | |
1500 /* No leading bits means u == minimum. */ | |
1501 if (count == 0) | |
1502 return -(Wtype_MAXp1_F * (Wtype_MAXp1_F / 2)); | |
1503 | |
1504 shift = 1 + W_TYPE_SIZE - count; | |
1505 | |
1506 /* Shift down the most significant bits. */ | |
1507 hi = u >> shift; | |
1508 | |
1509 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */ | |
1510 if ((UWtype)u << (W_TYPE_SIZE - shift)) | |
1511 hi |= 1; | |
1512 | |
1513 /* Convert the one word of data, and rescale. */ | |
1514 FSTYPE f = hi, e; | |
1515 if (shift == W_TYPE_SIZE) | |
1516 e = Wtype_MAXp1_F; | |
1517 /* The following two cases could be merged if we knew that the target | |
1518 supported a native unsigned->float conversion. More often, we only | |
1519 have a signed conversion, and have to add extra fixup code. */ | |
1520 else if (shift == W_TYPE_SIZE - 1) | |
1521 e = Wtype_MAXp1_F / 2; | |
1522 else | |
1523 e = (Wtype)1 << shift; | |
1524 return f * e; | |
1525 #endif | |
1526 } | |
1527 #endif | |
1528 | |
1529 #if (defined(L_floatundisf) && LIBGCC2_HAS_SF_MODE) \ | |
1530 || (defined(L_floatundidf) && LIBGCC2_HAS_DF_MODE) | |
1531 #define DI_SIZE (W_TYPE_SIZE * 2) | |
1532 #define F_MODE_OK(SIZE) \ | |
1533 (SIZE < DI_SIZE \ | |
1534 && SIZE > (DI_SIZE - SIZE + FSSIZE) \ | |
1535 && !AVOID_FP_TYPE_CONVERSION(SIZE)) | |
1536 #if defined(L_floatundisf) | |
1537 #define FUNC __floatundisf | |
1538 #define FSTYPE SFtype | |
1539 #define FSSIZE SF_SIZE | |
1540 #else | |
1541 #define FUNC __floatundidf | |
1542 #define FSTYPE DFtype | |
1543 #define FSSIZE DF_SIZE | |
1544 #endif | |
1545 | |
1546 FSTYPE | |
1547 FUNC (UDWtype u) | |
1548 { | |
1549 #if FSSIZE >= W_TYPE_SIZE | |
1550 /* When the word size is small, we never get any rounding error. */ | |
1551 FSTYPE f = (UWtype) (u >> W_TYPE_SIZE); | |
1552 f *= Wtype_MAXp1_F; | |
1553 f += (UWtype)u; | |
1554 return f; | |
1555 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE)) \ | |
1556 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE)) \ | |
1557 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE)) | |
1558 | |
1559 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE)) | |
1560 # define FSIZE DF_SIZE | |
1561 # define FTYPE DFtype | |
1562 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE)) | |
1563 # define FSIZE XF_SIZE | |
1564 # define FTYPE XFtype | |
1565 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE)) | |
1566 # define FSIZE TF_SIZE | |
1567 # define FTYPE TFtype | |
1568 #else | |
1569 # error | |
1570 #endif | |
1571 | |
1572 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE)) | |
1573 | |
1574 /* Protect against double-rounding error. | |
1575 Represent any low-order bits, that might be truncated by a bit that | |
1576 won't be lost. The bit can go in anywhere below the rounding position | |
1577 of the FSTYPE. A fixed mask and bit position handles all usual | |
1578 configurations. */ | |
1579 if (u >= ((UDWtype) 1 << FSIZE)) | |
1580 { | |
1581 if ((UDWtype) u & (REP_BIT - 1)) | |
1582 { | |
1583 u &= ~ (REP_BIT - 1); | |
1584 u |= REP_BIT; | |
1585 } | |
1586 } | |
1587 | |
1588 /* Do the calculation in a wider type so that we don't lose any of | |
1589 the precision of the high word while multiplying it. */ | |
1590 FTYPE f = (UWtype) (u >> W_TYPE_SIZE); | |
1591 f *= Wtype_MAXp1_F; | |
1592 f += (UWtype)u; | |
1593 return (FSTYPE) f; | |
1594 #else | |
1595 #if FSSIZE == W_TYPE_SIZE - 1 | |
1596 # error | |
1597 #endif | |
1598 /* Finally, the word size is larger than the number of bits in the | |
1599 required FSTYPE, and we've got no suitable wider type. The only | |
1600 way to avoid double rounding is to special case the | |
1601 extraction. */ | |
1602 | |
1603 /* If there are no high bits set, fall back to one conversion. */ | |
1604 if ((UWtype)u == u) | |
1605 return (FSTYPE)(UWtype)u; | |
1606 | |
1607 /* Otherwise, find the power of two. */ | |
1608 UWtype hi = u >> W_TYPE_SIZE; | |
1609 | |
1610 UWtype count, shift; | |
1611 count_leading_zeros (count, hi); | |
1612 | |
1613 shift = W_TYPE_SIZE - count; | |
1614 | |
1615 /* Shift down the most significant bits. */ | |
1616 hi = u >> shift; | |
1617 | |
1618 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */ | |
1619 if ((UWtype)u << (W_TYPE_SIZE - shift)) | |
1620 hi |= 1; | |
1621 | |
1622 /* Convert the one word of data, and rescale. */ | |
1623 FSTYPE f = hi, e; | |
1624 if (shift == W_TYPE_SIZE) | |
1625 e = Wtype_MAXp1_F; | |
1626 /* The following two cases could be merged if we knew that the target | |
1627 supported a native unsigned->float conversion. More often, we only | |
1628 have a signed conversion, and have to add extra fixup code. */ | |
1629 else if (shift == W_TYPE_SIZE - 1) | |
1630 e = Wtype_MAXp1_F / 2; | |
1631 else | |
1632 e = (Wtype)1 << shift; | |
1633 return f * e; | |
1634 #endif | |
1635 } | |
1636 #endif | |
1637 | |
1638 #if defined(L_fixunsxfsi) && LIBGCC2_HAS_XF_MODE | |
1639 /* Reenable the normal types, in case limits.h needs them. */ | |
1640 #undef char | |
1641 #undef short | |
1642 #undef int | |
1643 #undef long | |
1644 #undef unsigned | |
1645 #undef float | |
1646 #undef double | |
1647 #undef MIN | |
1648 #undef MAX | |
1649 #include <limits.h> | |
1650 | |
1651 UWtype | |
1652 __fixunsxfSI (XFtype a) | |
1653 { | |
1654 if (a >= - (DFtype) Wtype_MIN) | |
1655 return (Wtype) (a + Wtype_MIN) - Wtype_MIN; | |
1656 return (Wtype) a; | |
1657 } | |
1658 #endif | |
1659 | |
1660 #if defined(L_fixunsdfsi) && LIBGCC2_HAS_DF_MODE | |
1661 /* Reenable the normal types, in case limits.h needs them. */ | |
1662 #undef char | |
1663 #undef short | |
1664 #undef int | |
1665 #undef long | |
1666 #undef unsigned | |
1667 #undef float | |
1668 #undef double | |
1669 #undef MIN | |
1670 #undef MAX | |
1671 #include <limits.h> | |
1672 | |
1673 UWtype | |
1674 __fixunsdfSI (DFtype a) | |
1675 { | |
1676 if (a >= - (DFtype) Wtype_MIN) | |
1677 return (Wtype) (a + Wtype_MIN) - Wtype_MIN; | |
1678 return (Wtype) a; | |
1679 } | |
1680 #endif | |
1681 | |
1682 #if defined(L_fixunssfsi) && LIBGCC2_HAS_SF_MODE | |
1683 /* Reenable the normal types, in case limits.h needs them. */ | |
1684 #undef char | |
1685 #undef short | |
1686 #undef int | |
1687 #undef long | |
1688 #undef unsigned | |
1689 #undef float | |
1690 #undef double | |
1691 #undef MIN | |
1692 #undef MAX | |
1693 #include <limits.h> | |
1694 | |
1695 UWtype | |
1696 __fixunssfSI (SFtype a) | |
1697 { | |
1698 if (a >= - (SFtype) Wtype_MIN) | |
1699 return (Wtype) (a + Wtype_MIN) - Wtype_MIN; | |
1700 return (Wtype) a; | |
1701 } | |
1702 #endif | |
1703 | |
1704 /* Integer power helper used from __builtin_powi for non-constant | |
1705 exponents. */ | |
1706 | |
1707 #if (defined(L_powisf2) && LIBGCC2_HAS_SF_MODE) \ | |
1708 || (defined(L_powidf2) && LIBGCC2_HAS_DF_MODE) \ | |
1709 || (defined(L_powixf2) && LIBGCC2_HAS_XF_MODE) \ | |
1710 || (defined(L_powitf2) && LIBGCC2_HAS_TF_MODE) | |
1711 # if defined(L_powisf2) | |
1712 # define TYPE SFtype | |
1713 # define NAME __powisf2 | |
1714 # elif defined(L_powidf2) | |
1715 # define TYPE DFtype | |
1716 # define NAME __powidf2 | |
1717 # elif defined(L_powixf2) | |
1718 # define TYPE XFtype | |
1719 # define NAME __powixf2 | |
1720 # elif defined(L_powitf2) | |
1721 # define TYPE TFtype | |
1722 # define NAME __powitf2 | |
1723 # endif | |
1724 | |
1725 #undef int | |
1726 #undef unsigned | |
1727 TYPE | |
1728 NAME (TYPE x, int m) | |
1729 { | |
1730 unsigned int n = m < 0 ? -m : m; | |
1731 TYPE y = n % 2 ? x : 1; | |
1732 while (n >>= 1) | |
1733 { | |
1734 x = x * x; | |
1735 if (n % 2) | |
1736 y = y * x; | |
1737 } | |
1738 return m < 0 ? 1/y : y; | |
1739 } | |
1740 | |
1741 #endif | |
1742 | |
1743 #if ((defined(L_mulsc3) || defined(L_divsc3)) && LIBGCC2_HAS_SF_MODE) \ | |
1744 || ((defined(L_muldc3) || defined(L_divdc3)) && LIBGCC2_HAS_DF_MODE) \ | |
1745 || ((defined(L_mulxc3) || defined(L_divxc3)) && LIBGCC2_HAS_XF_MODE) \ | |
1746 || ((defined(L_multc3) || defined(L_divtc3)) && LIBGCC2_HAS_TF_MODE) | |
1747 | |
1748 #undef float | |
1749 #undef double | |
1750 #undef long | |
1751 | |
1752 #if defined(L_mulsc3) || defined(L_divsc3) | |
1753 # define MTYPE SFtype | |
1754 # define CTYPE SCtype | |
1755 # define MODE sc | |
1756 # define CEXT f | |
1757 # define NOTRUNC __FLT_EVAL_METHOD__ == 0 | |
1758 #elif defined(L_muldc3) || defined(L_divdc3) | |
1759 # define MTYPE DFtype | |
1760 # define CTYPE DCtype | |
1761 # define MODE dc | |
1762 # if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 64 | |
1763 # define CEXT l | |
1764 # define NOTRUNC 1 | |
1765 # else | |
1766 # define CEXT | |
1767 # define NOTRUNC __FLT_EVAL_METHOD__ == 0 || __FLT_EVAL_METHOD__ == 1 | |
1768 # endif | |
1769 #elif defined(L_mulxc3) || defined(L_divxc3) | |
1770 # define MTYPE XFtype | |
1771 # define CTYPE XCtype | |
1772 # define MODE xc | |
1773 # define CEXT l | |
1774 # define NOTRUNC 1 | |
1775 #elif defined(L_multc3) || defined(L_divtc3) | |
1776 # define MTYPE TFtype | |
1777 # define CTYPE TCtype | |
1778 # define MODE tc | |
1779 # if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128 | |
1780 # define CEXT l | |
1781 # else | |
1782 # define CEXT LIBGCC2_TF_CEXT | |
1783 # endif | |
1784 # define NOTRUNC 1 | |
1785 #else | |
1786 # error | |
1787 #endif | |
1788 | |
1789 #define CONCAT3(A,B,C) _CONCAT3(A,B,C) | |
1790 #define _CONCAT3(A,B,C) A##B##C | |
1791 | |
1792 #define CONCAT2(A,B) _CONCAT2(A,B) | |
1793 #define _CONCAT2(A,B) A##B | |
1794 | |
1795 /* All of these would be present in a full C99 implementation of <math.h> | |
1796 and <complex.h>. Our problem is that only a few systems have such full | |
1797 implementations. Further, libgcc_s.so isn't currently linked against | |
1798 libm.so, and even for systems that do provide full C99, the extra overhead | |
1799 of all programs using libgcc having to link against libm. So avoid it. */ | |
1800 | |
1801 #define isnan(x) __builtin_expect ((x) != (x), 0) | |
1802 #define isfinite(x) __builtin_expect (!isnan((x) - (x)), 1) | |
1803 #define isinf(x) __builtin_expect (!isnan(x) & !isfinite(x), 0) | |
1804 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
1805 #define INFINITY CONCAT2(__builtin_huge_val, CEXT) () |
0 | 1806 #define I 1i |
1807 | |
1808 /* Helpers to make the following code slightly less gross. */ | |
1809 #define COPYSIGN CONCAT2(__builtin_copysign, CEXT) | |
1810 #define FABS CONCAT2(__builtin_fabs, CEXT) | |
1811 | |
1812 /* Verify that MTYPE matches up with CEXT. */ | |
1813 extern void *compile_type_assert[sizeof(INFINITY) == sizeof(MTYPE) ? 1 : -1]; | |
1814 | |
1815 /* Ensure that we've lost any extra precision. */ | |
1816 #if NOTRUNC | |
1817 # define TRUNC(x) | |
1818 #else | |
1819 # define TRUNC(x) __asm__ ("" : "=m"(x) : "m"(x)) | |
1820 #endif | |
1821 | |
1822 #if defined(L_mulsc3) || defined(L_muldc3) \ | |
1823 || defined(L_mulxc3) || defined(L_multc3) | |
1824 | |
1825 CTYPE | |
1826 CONCAT3(__mul,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d) | |
1827 { | |
1828 MTYPE ac, bd, ad, bc, x, y; | |
1829 CTYPE res; | |
1830 | |
1831 ac = a * c; | |
1832 bd = b * d; | |
1833 ad = a * d; | |
1834 bc = b * c; | |
1835 | |
1836 TRUNC (ac); | |
1837 TRUNC (bd); | |
1838 TRUNC (ad); | |
1839 TRUNC (bc); | |
1840 | |
1841 x = ac - bd; | |
1842 y = ad + bc; | |
1843 | |
1844 if (isnan (x) && isnan (y)) | |
1845 { | |
1846 /* Recover infinities that computed as NaN + iNaN. */ | |
1847 _Bool recalc = 0; | |
1848 if (isinf (a) || isinf (b)) | |
1849 { | |
1850 /* z is infinite. "Box" the infinity and change NaNs in | |
1851 the other factor to 0. */ | |
1852 a = COPYSIGN (isinf (a) ? 1 : 0, a); | |
1853 b = COPYSIGN (isinf (b) ? 1 : 0, b); | |
1854 if (isnan (c)) c = COPYSIGN (0, c); | |
1855 if (isnan (d)) d = COPYSIGN (0, d); | |
1856 recalc = 1; | |
1857 } | |
1858 if (isinf (c) || isinf (d)) | |
1859 { | |
1860 /* w is infinite. "Box" the infinity and change NaNs in | |
1861 the other factor to 0. */ | |
1862 c = COPYSIGN (isinf (c) ? 1 : 0, c); | |
1863 d = COPYSIGN (isinf (d) ? 1 : 0, d); | |
1864 if (isnan (a)) a = COPYSIGN (0, a); | |
1865 if (isnan (b)) b = COPYSIGN (0, b); | |
1866 recalc = 1; | |
1867 } | |
1868 if (!recalc | |
1869 && (isinf (ac) || isinf (bd) | |
1870 || isinf (ad) || isinf (bc))) | |
1871 { | |
1872 /* Recover infinities from overflow by changing NaNs to 0. */ | |
1873 if (isnan (a)) a = COPYSIGN (0, a); | |
1874 if (isnan (b)) b = COPYSIGN (0, b); | |
1875 if (isnan (c)) c = COPYSIGN (0, c); | |
1876 if (isnan (d)) d = COPYSIGN (0, d); | |
1877 recalc = 1; | |
1878 } | |
1879 if (recalc) | |
1880 { | |
1881 x = INFINITY * (a * c - b * d); | |
1882 y = INFINITY * (a * d + b * c); | |
1883 } | |
1884 } | |
1885 | |
1886 __real__ res = x; | |
1887 __imag__ res = y; | |
1888 return res; | |
1889 } | |
1890 #endif /* complex multiply */ | |
1891 | |
1892 #if defined(L_divsc3) || defined(L_divdc3) \ | |
1893 || defined(L_divxc3) || defined(L_divtc3) | |
1894 | |
1895 CTYPE | |
1896 CONCAT3(__div,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d) | |
1897 { | |
1898 MTYPE denom, ratio, x, y; | |
1899 CTYPE res; | |
1900 | |
1901 /* ??? We can get better behavior from logarithmic scaling instead of | |
1902 the division. But that would mean starting to link libgcc against | |
1903 libm. We could implement something akin to ldexp/frexp as gcc builtins | |
1904 fairly easily... */ | |
1905 if (FABS (c) < FABS (d)) | |
1906 { | |
1907 ratio = c / d; | |
1908 denom = (c * ratio) + d; | |
1909 x = ((a * ratio) + b) / denom; | |
1910 y = ((b * ratio) - a) / denom; | |
1911 } | |
1912 else | |
1913 { | |
1914 ratio = d / c; | |
1915 denom = (d * ratio) + c; | |
1916 x = ((b * ratio) + a) / denom; | |
1917 y = (b - (a * ratio)) / denom; | |
1918 } | |
1919 | |
1920 /* Recover infinities and zeros that computed as NaN+iNaN; the only cases | |
1921 are nonzero/zero, infinite/finite, and finite/infinite. */ | |
1922 if (isnan (x) && isnan (y)) | |
1923 { | |
1924 if (c == 0.0 && d == 0.0 && (!isnan (a) || !isnan (b))) | |
1925 { | |
1926 x = COPYSIGN (INFINITY, c) * a; | |
1927 y = COPYSIGN (INFINITY, c) * b; | |
1928 } | |
1929 else if ((isinf (a) || isinf (b)) && isfinite (c) && isfinite (d)) | |
1930 { | |
1931 a = COPYSIGN (isinf (a) ? 1 : 0, a); | |
1932 b = COPYSIGN (isinf (b) ? 1 : 0, b); | |
1933 x = INFINITY * (a * c + b * d); | |
1934 y = INFINITY * (b * c - a * d); | |
1935 } | |
1936 else if ((isinf (c) || isinf (d)) && isfinite (a) && isfinite (b)) | |
1937 { | |
1938 c = COPYSIGN (isinf (c) ? 1 : 0, c); | |
1939 d = COPYSIGN (isinf (d) ? 1 : 0, d); | |
1940 x = 0.0 * (a * c + b * d); | |
1941 y = 0.0 * (b * c - a * d); | |
1942 } | |
1943 } | |
1944 | |
1945 __real__ res = x; | |
1946 __imag__ res = y; | |
1947 return res; | |
1948 } | |
1949 #endif /* complex divide */ | |
1950 | |
1951 #endif /* all complex float routines */ | |
1952 | |
1953 /* From here on down, the routines use normal data types. */ | |
1954 | |
1955 #define SItype bogus_type | |
1956 #define USItype bogus_type | |
1957 #define DItype bogus_type | |
1958 #define UDItype bogus_type | |
1959 #define SFtype bogus_type | |
1960 #define DFtype bogus_type | |
1961 #undef Wtype | |
1962 #undef UWtype | |
1963 #undef HWtype | |
1964 #undef UHWtype | |
1965 #undef DWtype | |
1966 #undef UDWtype | |
1967 | |
1968 #undef char | |
1969 #undef short | |
1970 #undef int | |
1971 #undef long | |
1972 #undef unsigned | |
1973 #undef float | |
1974 #undef double | |
1975 | |
1976 #ifdef L__gcc_bcmp | |
1977 | |
1978 /* Like bcmp except the sign is meaningful. | |
1979 Result is negative if S1 is less than S2, | |
1980 positive if S1 is greater, 0 if S1 and S2 are equal. */ | |
1981 | |
1982 int | |
1983 __gcc_bcmp (const unsigned char *s1, const unsigned char *s2, size_t size) | |
1984 { | |
1985 while (size > 0) | |
1986 { | |
1987 const unsigned char c1 = *s1++, c2 = *s2++; | |
1988 if (c1 != c2) | |
1989 return c1 - c2; | |
1990 size--; | |
1991 } | |
1992 return 0; | |
1993 } | |
1994 | |
1995 #endif | |
1996 | |
1997 /* __eprintf used to be used by GCC's private version of <assert.h>. | |
1998 We no longer provide that header, but this routine remains in libgcc.a | |
1999 for binary backward compatibility. Note that it is not included in | |
2000 the shared version of libgcc. */ | |
2001 #ifdef L_eprintf | |
2002 #ifndef inhibit_libc | |
2003 | |
2004 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */ | |
2005 #include <stdio.h> | |
2006 | |
2007 void | |
2008 __eprintf (const char *string, const char *expression, | |
2009 unsigned int line, const char *filename) | |
2010 { | |
2011 fprintf (stderr, string, expression, line, filename); | |
2012 fflush (stderr); | |
2013 abort (); | |
2014 } | |
2015 | |
2016 #endif | |
2017 #endif | |
2018 | |
2019 | |
2020 #ifdef L_clear_cache | |
2021 /* Clear part of an instruction cache. */ | |
2022 | |
2023 void | |
2024 __clear_cache (char *beg __attribute__((__unused__)), | |
2025 char *end __attribute__((__unused__))) | |
2026 { | |
2027 #ifdef CLEAR_INSN_CACHE | |
2028 CLEAR_INSN_CACHE (beg, end); | |
2029 #endif /* CLEAR_INSN_CACHE */ | |
2030 } | |
2031 | |
2032 #endif /* L_clear_cache */ | |
2033 | |
2034 #ifdef L_enable_execute_stack | |
2035 /* Attempt to turn on execute permission for the stack. */ | |
2036 | |
2037 #ifdef ENABLE_EXECUTE_STACK | |
2038 ENABLE_EXECUTE_STACK | |
2039 #else | |
2040 void | |
2041 __enable_execute_stack (void *addr __attribute__((__unused__))) | |
2042 {} | |
2043 #endif /* ENABLE_EXECUTE_STACK */ | |
2044 | |
2045 #endif /* L_enable_execute_stack */ | |
2046 | |
2047 #ifdef L_trampoline | |
2048 | |
2049 /* Jump to a trampoline, loading the static chain address. */ | |
2050 | |
2051 #if defined(WINNT) && ! defined(__CYGWIN__) | |
36 | 2052 int getpagesize (void); |
2053 int mprotect (char *,int, int); | |
0 | 2054 |
2055 int | |
2056 getpagesize (void) | |
2057 { | |
2058 #ifdef _ALPHA_ | |
2059 return 8192; | |
2060 #else | |
2061 return 4096; | |
2062 #endif | |
2063 } | |
2064 | |
2065 int | |
2066 mprotect (char *addr, int len, int prot) | |
2067 { | |
2068 DWORD np, op; | |
2069 | |
2070 if (prot == 7) | |
2071 np = 0x40; | |
2072 else if (prot == 5) | |
2073 np = 0x20; | |
2074 else if (prot == 4) | |
2075 np = 0x10; | |
2076 else if (prot == 3) | |
2077 np = 0x04; | |
2078 else if (prot == 1) | |
2079 np = 0x02; | |
2080 else if (prot == 0) | |
2081 np = 0x01; | |
2082 else | |
2083 return -1; | |
2084 | |
2085 if (VirtualProtect (addr, len, np, &op)) | |
2086 return 0; | |
2087 else | |
2088 return -1; | |
2089 } | |
2090 | |
2091 #endif /* WINNT && ! __CYGWIN__ */ | |
2092 | |
2093 #ifdef TRANSFER_FROM_TRAMPOLINE | |
2094 TRANSFER_FROM_TRAMPOLINE | |
2095 #endif | |
2096 #endif /* L_trampoline */ | |
2097 | |
2098 #ifndef __CYGWIN__ | |
2099 #ifdef L__main | |
2100 | |
2101 #include "gbl-ctors.h" | |
2102 | |
2103 /* Some systems use __main in a way incompatible with its use in gcc, in these | |
2104 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to | |
2105 give the same symbol without quotes for an alternative entry point. You | |
2106 must define both, or neither. */ | |
2107 #ifndef NAME__MAIN | |
2108 #define NAME__MAIN "__main" | |
2109 #define SYMBOL__MAIN __main | |
2110 #endif | |
2111 | |
2112 #if defined (INIT_SECTION_ASM_OP) || defined (INIT_ARRAY_SECTION_ASM_OP) | |
2113 #undef HAS_INIT_SECTION | |
2114 #define HAS_INIT_SECTION | |
2115 #endif | |
2116 | |
2117 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF) | |
2118 | |
2119 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this | |
2120 code to run constructors. In that case, we need to handle EH here, too. */ | |
2121 | |
2122 #ifdef EH_FRAME_SECTION_NAME | |
2123 #include "unwind-dw2-fde.h" | |
2124 extern unsigned char __EH_FRAME_BEGIN__[]; | |
2125 #endif | |
2126 | |
2127 /* Run all the global destructors on exit from the program. */ | |
2128 | |
2129 void | |
2130 __do_global_dtors (void) | |
2131 { | |
2132 #ifdef DO_GLOBAL_DTORS_BODY | |
2133 DO_GLOBAL_DTORS_BODY; | |
2134 #else | |
2135 static func_ptr *p = __DTOR_LIST__ + 1; | |
2136 while (*p) | |
2137 { | |
2138 p++; | |
2139 (*(p-1)) (); | |
2140 } | |
2141 #endif | |
2142 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION) | |
2143 { | |
2144 static int completed = 0; | |
2145 if (! completed) | |
2146 { | |
2147 completed = 1; | |
2148 __deregister_frame_info (__EH_FRAME_BEGIN__); | |
2149 } | |
2150 } | |
2151 #endif | |
2152 } | |
2153 #endif | |
2154 | |
2155 #ifndef HAS_INIT_SECTION | |
2156 /* Run all the global constructors on entry to the program. */ | |
2157 | |
2158 void | |
2159 __do_global_ctors (void) | |
2160 { | |
2161 #ifdef EH_FRAME_SECTION_NAME | |
2162 { | |
2163 static struct object object; | |
2164 __register_frame_info (__EH_FRAME_BEGIN__, &object); | |
2165 } | |
2166 #endif | |
2167 DO_GLOBAL_CTORS_BODY; | |
2168 atexit (__do_global_dtors); | |
2169 } | |
2170 #endif /* no HAS_INIT_SECTION */ | |
2171 | |
2172 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main) | |
2173 /* Subroutine called automatically by `main'. | |
2174 Compiling a global function named `main' | |
2175 produces an automatic call to this function at the beginning. | |
2176 | |
2177 For many systems, this routine calls __do_global_ctors. | |
2178 For systems which support a .init section we use the .init section | |
2179 to run __do_global_ctors, so we need not do anything here. */ | |
2180 | |
2181 extern void SYMBOL__MAIN (void); | |
2182 void | |
2183 SYMBOL__MAIN (void) | |
2184 { | |
2185 /* Support recursive calls to `main': run initializers just once. */ | |
2186 static int initialized; | |
2187 if (! initialized) | |
2188 { | |
2189 initialized = 1; | |
2190 __do_global_ctors (); | |
2191 } | |
2192 } | |
2193 #endif /* no HAS_INIT_SECTION or INVOKE__main */ | |
2194 | |
2195 #endif /* L__main */ | |
2196 #endif /* __CYGWIN__ */ | |
2197 | |
2198 #ifdef L_ctors | |
2199 | |
2200 #include "gbl-ctors.h" | |
2201 | |
2202 /* Provide default definitions for the lists of constructors and | |
2203 destructors, so that we don't get linker errors. These symbols are | |
2204 intentionally bss symbols, so that gld and/or collect will provide | |
2205 the right values. */ | |
2206 | |
2207 /* We declare the lists here with two elements each, | |
2208 so that they are valid empty lists if no other definition is loaded. | |
2209 | |
2210 If we are using the old "set" extensions to have the gnu linker | |
2211 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__ | |
2212 must be in the bss/common section. | |
2213 | |
2214 Long term no port should use those extensions. But many still do. */ | |
2215 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY) | |
2216 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2) | |
2217 func_ptr __CTOR_LIST__[2] = {0, 0}; | |
2218 func_ptr __DTOR_LIST__[2] = {0, 0}; | |
2219 #else | |
2220 func_ptr __CTOR_LIST__[2]; | |
2221 func_ptr __DTOR_LIST__[2]; | |
2222 #endif | |
2223 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */ | |
2224 #endif /* L_ctors */ | |
2225 #endif /* LIBGCC2_UNITS_PER_WORD <= MIN_UNITS_PER_WORD */ |