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