Deleted Added
sdiff udiff text old ( 146906 ) new ( 169699 )
full compact
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 Free Software Foundation, Inc.
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 2, or (at your option) any later
11version.
12
13In addition to the permissions in the GNU General Public License, the
14Free Software Foundation gives you unlimited permission to link the
15compiled version of this file into combinations with other programs,
16and to distribute those combinations without any restriction coming
17from the use of this file. (The General Public License restrictions
18do apply in other respects; for example, they cover modification of
19the file, and distribution when not linked into a combine
20executable.)
21
22GCC is distributed in the hope that it will be useful, but WITHOUT ANY
23WARRANTY; without even the implied warranty of MERCHANTABILITY or
24FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25for more details.
26
27You should have received a copy of the GNU General Public License
28along with GCC; see the file COPYING. If not, write to the Free
29Software Foundation, 59 Temple Place - Suite 330, Boston, MA
3002111-1307, USA. */
31
32
33/* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
34 supposedly valid even though this is a "target" file. */
35#include "auto-host.h"
36
37/* It is incorrect to include config.h here, because this file is being
38 compiled for the target, and hence definitions concerning only the host
39 do not apply. */
40#include "tconfig.h"
41#include "tsystem.h"
42#include "coretypes.h"
43#include "tm.h"
44
45/* Don't use `fancy_abort' here even if config.h says to use it. */
46#ifdef abort
47#undef abort
48#endif
49
50#ifdef HAVE_GAS_HIDDEN
51#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
52#else
53#define ATTRIBUTE_HIDDEN
54#endif
55
56#include "libgcc2.h"
57
58#ifdef DECLARE_LIBRARY_RENAMES
59 DECLARE_LIBRARY_RENAMES
60#endif
61
62#if defined (L_negdi2)
63DWtype
64__negdi2 (DWtype u)
65{
66 const DWunion uu = {.ll = u};
67 const DWunion w = { {.low = -uu.s.low,
68 .high = -uu.s.high - ((UWtype) -uu.s.low > 0) } };
69
70 return w.ll;
71}
72#endif
73
74#ifdef L_addvsi3
75Wtype
76__addvSI3 (Wtype a, Wtype b)
77{
78 const Wtype w = a + b;
79
80 if (b >= 0 ? w < a : w > a)
81 abort ();
82
83 return w;
84}
85#ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
86SItype
87__addvsi3 (SItype a, SItype b)
88{
89 const SItype w = a + b;
90
91 if (b >= 0 ? w < a : w > a)
92 abort ();
93
94 return w;
95}
96#endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
97#endif
98
99#ifdef L_addvdi3
100DWtype
101__addvDI3 (DWtype a, DWtype b)
102{
103 const DWtype w = a + b;
104
105 if (b >= 0 ? w < a : w > a)
106 abort ();
107
108 return w;
109}
110#endif
111
112#ifdef L_subvsi3
113Wtype
114__subvSI3 (Wtype a, Wtype b)
115{
116 const Wtype w = a - b;
117
118 if (b >= 0 ? w > a : w < a)
119 abort ();
120
121 return w;
122}
123#ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
124SItype
125__subvsi3 (SItype a, SItype b)
126{
127 const SItype w = a - b;
128
129 if (b >= 0 ? w > a : w < a)
130 abort ();
131
132 return w;
133}
134#endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
135#endif
136
137#ifdef L_subvdi3
138DWtype
139__subvDI3 (DWtype a, DWtype b)
140{
141 const DWtype w = a - b;
142
143 if (b >= 0 ? w > a : w < a)
144 abort ();
145
146 return w;
147}
148#endif
149
150#ifdef L_mulvsi3
151#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
152Wtype
153__mulvSI3 (Wtype a, Wtype b)
154{
155 const DWtype w = (DWtype) a * (DWtype) b;
156
157 if ((Wtype) (w >> WORD_SIZE) != (Wtype) w >> (WORD_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)
165SItype
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
178#ifdef L_negvsi2
179Wtype
180__negvSI2 (Wtype a)
181{
182 const Wtype w = -a;
183
184 if (a >= 0 ? w > 0 : w < 0)
185 abort ();
186
187 return w;
188}
189#ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
190SItype
191__negvsi2 (SItype a)
192{
193 const SItype w = -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
203#ifdef L_negvdi2
204DWtype
205__negvDI2 (DWtype a)
206{
207 const DWtype w = -a;
208
209 if (a >= 0 ? w > 0 : w < 0)
210 abort ();
211
212 return w;
213}
214#endif
215
216#ifdef L_absvsi2
217Wtype
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 = -a;
227
228 if (w < 0)
229 abort ();
230#endif
231
232 return w;
233}
234#ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
235SItype
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 = -a;
245
246 if (w < 0)
247 abort ();
248#endif
249
250 return w;
251}
252#endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
253#endif
254
255#ifdef L_absvdi2
256DWtype
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 = -a;
266
267 if (w < 0)
268 abort ();
269#endif
270
271 return w;
272}
273#endif
274
275#ifdef L_mulvdi3
276#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
277DWtype
278__mulvDI3 (DWtype u, DWtype v)
279{
280 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
281 but the checked multiplication needs only two. */
282 const DWunion uu = {.ll = u};
283 const DWunion vv = {.ll = v};
284
285 if (__builtin_expect (uu.s.high == uu.s.low >> (WORD_SIZE - 1), 1))
286 {
287 /* u fits in a single Wtype. */
288 if (__builtin_expect (vv.s.high == vv.s.low >> (WORD_SIZE - 1), 1))
289 {
290 /* v fits in a single Wtype as well. */
291 /* A single multiplication. No overflow risk. */
292 return (DWtype) uu.s.low * (DWtype) vv.s.low;
293 }
294 else
295 {
296 /* Two multiplications. */
297 DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
298 * (UDWtype) (UWtype) vv.s.low};
299 DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.low
300 * (UDWtype) (UWtype) vv.s.high};
301
302 if (vv.s.high < 0)
303 w1.s.high -= uu.s.low;
304 if (uu.s.low < 0)
305 w1.ll -= vv.ll;
306 w1.ll += (UWtype) w0.s.high;
307 if (__builtin_expect (w1.s.high == w1.s.low >> (WORD_SIZE - 1), 1))
308 {
309 w0.s.high = w1.s.low;
310 return w0.ll;
311 }
312 }
313 }
314 else
315 {
316 if (__builtin_expect (vv.s.high == vv.s.low >> (WORD_SIZE - 1), 1))
317 {
318 /* v fits into a single Wtype. */
319 /* Two multiplications. */
320 DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
321 * (UDWtype) (UWtype) vv.s.low};
322 DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.high
323 * (UDWtype) (UWtype) vv.s.low};
324
325 if (uu.s.high < 0)
326 w1.s.high -= vv.s.low;
327 if (vv.s.low < 0)
328 w1.ll -= uu.ll;
329 w1.ll += (UWtype) w0.s.high;
330 if (__builtin_expect (w1.s.high == w1.s.low >> (WORD_SIZE - 1), 1))
331 {
332 w0.s.high = w1.s.low;
333 return w0.ll;
334 }
335 }
336 else
337 {
338 /* A few sign checks and a single multiplication. */
339 if (uu.s.high >= 0)
340 {
341 if (vv.s.high >= 0)
342 {
343 if (uu.s.high == 0 && vv.s.high == 0)
344 {
345 const DWtype w = (UDWtype) (UWtype) uu.s.low
346 * (UDWtype) (UWtype) vv.s.low;
347 if (__builtin_expect (w >= 0, 1))
348 return w;
349 }
350 }
351 else
352 {
353 if (uu.s.high == 0 && vv.s.high == (Wtype) -1)
354 {
355 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
356 * (UDWtype) (UWtype) vv.s.low};
357
358 ww.s.high -= uu.s.low;
359 if (__builtin_expect (ww.s.high < 0, 1))
360 return ww.ll;
361 }
362 }
363 }
364 else
365 {
366 if (vv.s.high >= 0)
367 {
368 if (uu.s.high == (Wtype) -1 && vv.s.high == 0)
369 {
370 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
371 * (UDWtype) (UWtype) vv.s.low};
372
373 ww.s.high -= vv.s.low;
374 if (__builtin_expect (ww.s.high < 0, 1))
375 return ww.ll;
376 }
377 }
378 else
379 {
380 if (uu.s.high == (Wtype) -1 && vv.s.high == (Wtype) - 1)
381 {
382 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
383 * (UDWtype) (UWtype) vv.s.low};
384
385 ww.s.high -= uu.s.low;
386 ww.s.high -= vv.s.low;
387 if (__builtin_expect (ww.s.high >= 0, 1))
388 return ww.ll;
389 }
390 }
391 }
392 }
393 }
394
395 /* Overflow. */
396 abort ();
397}
398#endif
399
400
401/* Unless shift functions are defined with full ANSI prototypes,
402 parameter b will be promoted to int if word_type is smaller than an int. */
403#ifdef L_lshrdi3
404DWtype
405__lshrdi3 (DWtype u, word_type b)
406{
407 if (b == 0)
408 return u;
409
410 const DWunion uu = {.ll = u};
411 const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
412 DWunion w;
413
414 if (bm <= 0)
415 {
416 w.s.high = 0;
417 w.s.low = (UWtype) uu.s.high >> -bm;
418 }
419 else
420 {
421 const UWtype carries = (UWtype) uu.s.high << bm;
422
423 w.s.high = (UWtype) uu.s.high >> b;
424 w.s.low = ((UWtype) uu.s.low >> b) | carries;
425 }
426
427 return w.ll;
428}
429#endif
430
431#ifdef L_ashldi3
432DWtype
433__ashldi3 (DWtype u, word_type b)
434{
435 if (b == 0)
436 return u;
437
438 const DWunion uu = {.ll = u};
439 const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
440 DWunion w;
441
442 if (bm <= 0)
443 {
444 w.s.low = 0;
445 w.s.high = (UWtype) uu.s.low << -bm;
446 }
447 else
448 {
449 const UWtype carries = (UWtype) uu.s.low >> bm;
450
451 w.s.low = (UWtype) uu.s.low << b;
452 w.s.high = ((UWtype) uu.s.high << b) | carries;
453 }
454
455 return w.ll;
456}
457#endif
458
459#ifdef L_ashrdi3
460DWtype
461__ashrdi3 (DWtype u, word_type b)
462{
463 if (b == 0)
464 return u;
465
466 const DWunion uu = {.ll = u};
467 const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
468 DWunion w;
469
470 if (bm <= 0)
471 {
472 /* w.s.high = 1..1 or 0..0 */
473 w.s.high = uu.s.high >> (sizeof (Wtype) * BITS_PER_UNIT - 1);
474 w.s.low = uu.s.high >> -bm;
475 }
476 else
477 {
478 const UWtype carries = (UWtype) uu.s.high << bm;
479
480 w.s.high = uu.s.high >> b;
481 w.s.low = ((UWtype) uu.s.low >> b) | carries;
482 }
483
484 return w.ll;
485}
486#endif
487
488#ifdef L_ffssi2
489#undef int
490extern int __ffsSI2 (UWtype u);
491int
492__ffsSI2 (UWtype u)
493{
494 UWtype count;
495
496 if (u == 0)
497 return 0;
498
499 count_trailing_zeros (count, u);
500 return count + 1;
501}
502#endif
503
504#ifdef L_ffsdi2
505#undef int
506extern int __ffsDI2 (DWtype u);
507int
508__ffsDI2 (DWtype u)
509{
510 const DWunion uu = {.ll = u};
511 UWtype word, count, add;
512
513 if (uu.s.low != 0)
514 word = uu.s.low, add = 0;
515 else if (uu.s.high != 0)
516 word = uu.s.high, add = BITS_PER_UNIT * sizeof (Wtype);
517 else
518 return 0;
519
520 count_trailing_zeros (count, word);
521 return count + add + 1;
522}
523#endif
524
525#ifdef L_muldi3
526DWtype
527__muldi3 (DWtype u, DWtype v)
528{
529 const DWunion uu = {.ll = u};
530 const DWunion vv = {.ll = v};
531 DWunion w = {.ll = __umulsidi3 (uu.s.low, vv.s.low)};
532
533 w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
534 + (UWtype) uu.s.high * (UWtype) vv.s.low);
535
536 return w.ll;
537}
538#endif
539
540#if (defined (L_udivdi3) || defined (L_divdi3) || \
541 defined (L_umoddi3) || defined (L_moddi3))
542#if defined (sdiv_qrnnd)
543#define L_udiv_w_sdiv
544#endif
545#endif
546
547#ifdef L_udiv_w_sdiv
548#if defined (sdiv_qrnnd)
549#if (defined (L_udivdi3) || defined (L_divdi3) || \
550 defined (L_umoddi3) || defined (L_moddi3))
551static inline __attribute__ ((__always_inline__))
552#endif
553UWtype
554__udiv_w_sdiv (UWtype *rp, UWtype a1, UWtype a0, UWtype d)
555{
556 UWtype q, r;
557 UWtype c0, c1, b1;
558
559 if ((Wtype) d >= 0)
560 {
561 if (a1 < d - a1 - (a0 >> (W_TYPE_SIZE - 1)))
562 {
563 /* dividend, divisor, and quotient are nonnegative */
564 sdiv_qrnnd (q, r, a1, a0, d);
565 }
566 else
567 {
568 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
569 sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (W_TYPE_SIZE - 1));
570 /* Divide (c1*2^32 + c0) by d */
571 sdiv_qrnnd (q, r, c1, c0, d);
572 /* Add 2^31 to quotient */
573 q += (UWtype) 1 << (W_TYPE_SIZE - 1);
574 }
575 }
576 else
577 {
578 b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
579 c1 = a1 >> 1; /* A/2 */
580 c0 = (a1 << (W_TYPE_SIZE - 1)) + (a0 >> 1);
581
582 if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */
583 {
584 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
585
586 r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */
587 if ((d & 1) != 0)
588 {
589 if (r >= q)
590 r = r - q;
591 else if (q - r <= d)
592 {
593 r = r - q + d;
594 q--;
595 }
596 else
597 {
598 r = r - q + 2*d;
599 q -= 2;
600 }
601 }
602 }
603 else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */
604 {
605 c1 = (b1 - 1) - c1;
606 c0 = ~c0; /* logical NOT */
607
608 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
609
610 q = ~q; /* (A/2)/b1 */
611 r = (b1 - 1) - r;
612
613 r = 2*r + (a0 & 1); /* A/(2*b1) */
614
615 if ((d & 1) != 0)
616 {
617 if (r >= q)
618 r = r - q;
619 else if (q - r <= d)
620 {
621 r = r - q + d;
622 q--;
623 }
624 else
625 {
626 r = r - q + 2*d;
627 q -= 2;
628 }
629 }
630 }
631 else /* Implies c1 = b1 */
632 { /* Hence a1 = d - 1 = 2*b1 - 1 */
633 if (a0 >= -d)
634 {
635 q = -1;
636 r = a0 + d;
637 }
638 else
639 {
640 q = -2;
641 r = a0 + 2*d;
642 }
643 }
644 }
645
646 *rp = r;
647 return q;
648}
649#else
650/* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
651UWtype
652__udiv_w_sdiv (UWtype *rp __attribute__ ((__unused__)),
653 UWtype a1 __attribute__ ((__unused__)),
654 UWtype a0 __attribute__ ((__unused__)),
655 UWtype d __attribute__ ((__unused__)))
656{
657 return 0;
658}
659#endif
660#endif
661
662#if (defined (L_udivdi3) || defined (L_divdi3) || \
663 defined (L_umoddi3) || defined (L_moddi3))
664#define L_udivmoddi4
665#endif
666
667#ifdef L_clz
668const UQItype __clz_tab[] =
669{
670 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,
671 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,
672 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,
673 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,
674 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,
675 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,
676 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,
677 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,
678};
679#endif
680
681#ifdef L_clzsi2
682#undef int
683extern int __clzSI2 (UWtype x);
684int
685__clzSI2 (UWtype x)
686{
687 Wtype ret;
688
689 count_leading_zeros (ret, x);
690
691 return ret;
692}
693#endif
694
695#ifdef L_clzdi2
696#undef int
697extern int __clzDI2 (UDWtype x);
698int
699__clzDI2 (UDWtype x)
700{
701 const DWunion uu = {.ll = x};
702 UWtype word;
703 Wtype ret, add;
704
705 if (uu.s.high)
706 word = uu.s.high, add = 0;
707 else
708 word = uu.s.low, add = W_TYPE_SIZE;
709
710 count_leading_zeros (ret, word);
711 return ret + add;
712}
713#endif
714
715#ifdef L_ctzsi2
716#undef int
717extern int __ctzSI2 (UWtype x);
718int
719__ctzSI2 (UWtype x)
720{
721 Wtype ret;
722
723 count_trailing_zeros (ret, x);
724
725 return ret;
726}
727#endif
728
729#ifdef L_ctzdi2
730#undef int
731extern int __ctzDI2 (UDWtype x);
732int
733__ctzDI2 (UDWtype x)
734{
735 const DWunion uu = {.ll = x};
736 UWtype word;
737 Wtype ret, add;
738
739 if (uu.s.low)
740 word = uu.s.low, add = 0;
741 else
742 word = uu.s.high, add = W_TYPE_SIZE;
743
744 count_trailing_zeros (ret, word);
745 return ret + add;
746}
747#endif
748
749#if (defined (L_popcountsi2) || defined (L_popcountdi2) \
750 || defined (L_popcount_tab))
751extern const UQItype __popcount_tab[] ATTRIBUTE_HIDDEN;
752#endif
753
754#ifdef L_popcount_tab
755const UQItype __popcount_tab[] =
756{
757 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,
758 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,
759 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,
760 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,
761 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,
762 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,
763 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,
764 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,
765};
766#endif
767
768#ifdef L_popcountsi2
769#undef int
770extern int __popcountSI2 (UWtype x);
771int
772__popcountSI2 (UWtype x)
773{
774 UWtype i, ret = 0;
775
776 for (i = 0; i < W_TYPE_SIZE; i += 8)
777 ret += __popcount_tab[(x >> i) & 0xff];
778
779 return ret;
780}
781#endif
782
783#ifdef L_popcountdi2
784#undef int
785extern int __popcountDI2 (UDWtype x);
786int
787__popcountDI2 (UDWtype x)
788{
789 UWtype i, ret = 0;
790
791 for (i = 0; i < 2*W_TYPE_SIZE; i += 8)
792 ret += __popcount_tab[(x >> i) & 0xff];
793
794 return ret;
795}
796#endif
797
798#ifdef L_paritysi2
799#undef int
800extern int __paritySI2 (UWtype x);
801int
802__paritySI2 (UWtype x)
803{
804#if W_TYPE_SIZE > 64
805# error "fill out the table"
806#endif
807#if W_TYPE_SIZE > 32
808 x ^= x >> 32;
809#endif
810#if W_TYPE_SIZE > 16
811 x ^= x >> 16;
812#endif
813 x ^= x >> 8;
814 x ^= x >> 4;
815 x &= 0xf;
816 return (0x6996 >> x) & 1;
817}
818#endif
819
820#ifdef L_paritydi2
821#undef int
822extern int __parityDI2 (UDWtype x);
823int
824__parityDI2 (UDWtype x)
825{
826 const DWunion uu = {.ll = x};
827 UWtype nx = uu.s.low ^ uu.s.high;
828
829#if W_TYPE_SIZE > 64
830# error "fill out the table"
831#endif
832#if W_TYPE_SIZE > 32
833 nx ^= nx >> 32;
834#endif
835#if W_TYPE_SIZE > 16
836 nx ^= nx >> 16;
837#endif
838 nx ^= nx >> 8;
839 nx ^= nx >> 4;
840 nx &= 0xf;
841 return (0x6996 >> nx) & 1;
842}
843#endif
844
845#ifdef L_udivmoddi4
846
847#if (defined (L_udivdi3) || defined (L_divdi3) || \
848 defined (L_umoddi3) || defined (L_moddi3))
849static inline __attribute__ ((__always_inline__))
850#endif
851UDWtype
852__udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
853{
854 const DWunion nn = {.ll = n};
855 const DWunion dd = {.ll = d};
856 DWunion rr;
857 UWtype d0, d1, n0, n1, n2;
858 UWtype q0, q1;
859 UWtype b, bm;
860
861 d0 = dd.s.low;
862 d1 = dd.s.high;
863 n0 = nn.s.low;
864 n1 = nn.s.high;
865
866#if !UDIV_NEEDS_NORMALIZATION
867 if (d1 == 0)
868 {
869 if (d0 > n1)
870 {
871 /* 0q = nn / 0D */
872
873 udiv_qrnnd (q0, n0, n1, n0, d0);
874 q1 = 0;
875
876 /* Remainder in n0. */
877 }
878 else
879 {
880 /* qq = NN / 0d */
881
882 if (d0 == 0)
883 d0 = 1 / d0; /* Divide intentionally by zero. */
884
885 udiv_qrnnd (q1, n1, 0, n1, d0);
886 udiv_qrnnd (q0, n0, n1, n0, d0);
887
888 /* Remainder in n0. */
889 }
890
891 if (rp != 0)
892 {
893 rr.s.low = n0;
894 rr.s.high = 0;
895 *rp = rr.ll;
896 }
897 }
898
899#else /* UDIV_NEEDS_NORMALIZATION */
900
901 if (d1 == 0)
902 {
903 if (d0 > n1)
904 {
905 /* 0q = nn / 0D */
906
907 count_leading_zeros (bm, d0);
908
909 if (bm != 0)
910 {
911 /* Normalize, i.e. make the most significant bit of the
912 denominator set. */
913
914 d0 = d0 << bm;
915 n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
916 n0 = n0 << bm;
917 }
918
919 udiv_qrnnd (q0, n0, n1, n0, d0);
920 q1 = 0;
921
922 /* Remainder in n0 >> bm. */
923 }
924 else
925 {
926 /* qq = NN / 0d */
927
928 if (d0 == 0)
929 d0 = 1 / d0; /* Divide intentionally by zero. */
930
931 count_leading_zeros (bm, d0);
932
933 if (bm == 0)
934 {
935 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
936 conclude (the most significant bit of n1 is set) /\ (the
937 leading quotient digit q1 = 1).
938
939 This special case is necessary, not an optimization.
940 (Shifts counts of W_TYPE_SIZE are undefined.) */
941
942 n1 -= d0;
943 q1 = 1;
944 }
945 else
946 {
947 /* Normalize. */
948
949 b = W_TYPE_SIZE - bm;
950
951 d0 = d0 << bm;
952 n2 = n1 >> b;
953 n1 = (n1 << bm) | (n0 >> b);
954 n0 = n0 << bm;
955
956 udiv_qrnnd (q1, n1, n2, n1, d0);
957 }
958
959 /* n1 != d0... */
960
961 udiv_qrnnd (q0, n0, n1, n0, d0);
962
963 /* Remainder in n0 >> bm. */
964 }
965
966 if (rp != 0)
967 {
968 rr.s.low = n0 >> bm;
969 rr.s.high = 0;
970 *rp = rr.ll;
971 }
972 }
973#endif /* UDIV_NEEDS_NORMALIZATION */
974
975 else
976 {
977 if (d1 > n1)
978 {
979 /* 00 = nn / DD */
980
981 q0 = 0;
982 q1 = 0;
983
984 /* Remainder in n1n0. */
985 if (rp != 0)
986 {
987 rr.s.low = n0;
988 rr.s.high = n1;
989 *rp = rr.ll;
990 }
991 }
992 else
993 {
994 /* 0q = NN / dd */
995
996 count_leading_zeros (bm, d1);
997 if (bm == 0)
998 {
999 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
1000 conclude (the most significant bit of n1 is set) /\ (the
1001 quotient digit q0 = 0 or 1).
1002
1003 This special case is necessary, not an optimization. */
1004
1005 /* The condition on the next line takes advantage of that
1006 n1 >= d1 (true due to program flow). */
1007 if (n1 > d1 || n0 >= d0)
1008 {
1009 q0 = 1;
1010 sub_ddmmss (n1, n0, n1, n0, d1, d0);
1011 }
1012 else
1013 q0 = 0;
1014
1015 q1 = 0;
1016
1017 if (rp != 0)
1018 {
1019 rr.s.low = n0;
1020 rr.s.high = n1;
1021 *rp = rr.ll;
1022 }
1023 }
1024 else
1025 {
1026 UWtype m1, m0;
1027 /* Normalize. */
1028
1029 b = W_TYPE_SIZE - bm;
1030
1031 d1 = (d1 << bm) | (d0 >> b);
1032 d0 = d0 << bm;
1033 n2 = n1 >> b;
1034 n1 = (n1 << bm) | (n0 >> b);
1035 n0 = n0 << bm;
1036
1037 udiv_qrnnd (q0, n1, n2, n1, d1);
1038 umul_ppmm (m1, m0, q0, d0);
1039
1040 if (m1 > n1 || (m1 == n1 && m0 > n0))
1041 {
1042 q0--;
1043 sub_ddmmss (m1, m0, m1, m0, d1, d0);
1044 }
1045
1046 q1 = 0;
1047
1048 /* Remainder in (n1n0 - m1m0) >> bm. */
1049 if (rp != 0)
1050 {
1051 sub_ddmmss (n1, n0, n1, n0, m1, m0);
1052 rr.s.low = (n1 << b) | (n0 >> bm);
1053 rr.s.high = n1 >> bm;
1054 *rp = rr.ll;
1055 }
1056 }
1057 }
1058 }
1059
1060 const DWunion ww = {{.low = q0, .high = q1}};
1061 return ww.ll;
1062}
1063#endif
1064
1065#ifdef L_divdi3
1066DWtype
1067__divdi3 (DWtype u, DWtype v)
1068{
1069 word_type c = 0;
1070 DWunion uu = {.ll = u};
1071 DWunion vv = {.ll = v};
1072 DWtype w;
1073
1074 if (uu.s.high < 0)
1075 c = ~c,
1076 uu.ll = -uu.ll;
1077 if (vv.s.high < 0)
1078 c = ~c,
1079 vv.ll = -vv.ll;
1080
1081 w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0);
1082 if (c)
1083 w = -w;
1084
1085 return w;
1086}
1087#endif
1088
1089#ifdef L_moddi3
1090DWtype
1091__moddi3 (DWtype u, DWtype v)
1092{
1093 word_type c = 0;
1094 DWunion uu = {.ll = u};
1095 DWunion vv = {.ll = v};
1096 DWtype w;
1097
1098 if (uu.s.high < 0)
1099 c = ~c,
1100 uu.ll = -uu.ll;
1101 if (vv.s.high < 0)
1102 vv.ll = -vv.ll;
1103
1104 (void) __udivmoddi4 (uu.ll, vv.ll, &w);
1105 if (c)
1106 w = -w;
1107
1108 return w;
1109}
1110#endif
1111
1112#ifdef L_umoddi3
1113UDWtype
1114__umoddi3 (UDWtype u, UDWtype v)
1115{
1116 UDWtype w;
1117
1118 (void) __udivmoddi4 (u, v, &w);
1119
1120 return w;
1121}
1122#endif
1123
1124#ifdef L_udivdi3
1125UDWtype
1126__udivdi3 (UDWtype n, UDWtype d)
1127{
1128 return __udivmoddi4 (n, d, (UDWtype *) 0);
1129}
1130#endif
1131
1132#ifdef L_cmpdi2
1133word_type
1134__cmpdi2 (DWtype a, DWtype b)
1135{
1136 const DWunion au = {.ll = a};
1137 const DWunion bu = {.ll = b};
1138
1139 if (au.s.high < bu.s.high)
1140 return 0;
1141 else if (au.s.high > bu.s.high)
1142 return 2;
1143 if ((UWtype) au.s.low < (UWtype) bu.s.low)
1144 return 0;
1145 else if ((UWtype) au.s.low > (UWtype) bu.s.low)
1146 return 2;
1147 return 1;
1148}
1149#endif
1150
1151#ifdef L_ucmpdi2
1152word_type
1153__ucmpdi2 (DWtype a, DWtype b)
1154{
1155 const DWunion au = {.ll = a};
1156 const DWunion bu = {.ll = b};
1157
1158 if ((UWtype) au.s.high < (UWtype) bu.s.high)
1159 return 0;
1160 else if ((UWtype) au.s.high > (UWtype) bu.s.high)
1161 return 2;
1162 if ((UWtype) au.s.low < (UWtype) bu.s.low)
1163 return 0;
1164 else if ((UWtype) au.s.low > (UWtype) bu.s.low)
1165 return 2;
1166 return 1;
1167}
1168#endif
1169
1170#if defined(L_fixunstfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1171#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1172#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1173
1174DWtype
1175__fixunstfDI (TFtype a)
1176{
1177 if (a < 0)
1178 return 0;
1179
1180 /* Compute high word of result, as a flonum. */
1181 const TFtype b = (a / HIGH_WORD_COEFF);
1182 /* Convert that to fixed (but not to DWtype!),
1183 and shift it into the high word. */
1184 UDWtype v = (UWtype) b;
1185 v <<= WORD_SIZE;
1186 /* Remove high part from the TFtype, leaving the low part as flonum. */
1187 a -= (TFtype)v;
1188 /* Convert that to fixed (but not to DWtype!) and add it in.
1189 Sometimes A comes out negative. This is significant, since
1190 A has more bits than a long int does. */
1191 if (a < 0)
1192 v -= (UWtype) (- a);
1193 else
1194 v += (UWtype) a;
1195 return v;
1196}
1197#endif
1198
1199#if defined(L_fixtfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1200DWtype
1201__fixtfdi (TFtype a)
1202{
1203 if (a < 0)
1204 return - __fixunstfDI (-a);
1205 return __fixunstfDI (a);
1206}
1207#endif
1208
1209#if defined(L_fixunsxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1210#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1211#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1212
1213DWtype
1214__fixunsxfDI (XFtype a)
1215{
1216 if (a < 0)
1217 return 0;
1218
1219 /* Compute high word of result, as a flonum. */
1220 const XFtype b = (a / HIGH_WORD_COEFF);
1221 /* Convert that to fixed (but not to DWtype!),
1222 and shift it into the high word. */
1223 UDWtype v = (UWtype) b;
1224 v <<= WORD_SIZE;
1225 /* Remove high part from the XFtype, leaving the low part as flonum. */
1226 a -= (XFtype)v;
1227 /* Convert that to fixed (but not to DWtype!) and add it in.
1228 Sometimes A comes out negative. This is significant, since
1229 A has more bits than a long int does. */
1230 if (a < 0)
1231 v -= (UWtype) (- a);
1232 else
1233 v += (UWtype) a;
1234 return v;
1235}
1236#endif
1237
1238#if defined(L_fixxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1239DWtype
1240__fixxfdi (XFtype a)
1241{
1242 if (a < 0)
1243 return - __fixunsxfDI (-a);
1244 return __fixunsxfDI (a);
1245}
1246#endif
1247
1248#ifdef L_fixunsdfdi
1249#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1250#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1251
1252DWtype
1253__fixunsdfDI (DFtype a)
1254{
1255 /* Get high part of result. The division here will just moves the radix
1256 point and will not cause any rounding. Then the conversion to integral
1257 type chops result as desired. */
1258 const UWtype hi = a / HIGH_WORD_COEFF;
1259
1260 /* Get low part of result. Convert `hi' to floating type and scale it back,
1261 then subtract this from the number being converted. This leaves the low
1262 part. Convert that to integral type. */
1263 const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
1264
1265 /* Assemble result from the two parts. */
1266 return ((UDWtype) hi << WORD_SIZE) | lo;
1267}
1268#endif
1269
1270#ifdef L_fixdfdi
1271DWtype
1272__fixdfdi (DFtype a)
1273{
1274 if (a < 0)
1275 return - __fixunsdfDI (-a);
1276 return __fixunsdfDI (a);
1277}
1278#endif
1279
1280#ifdef L_fixunssfdi
1281#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1282#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1283
1284DWtype
1285__fixunssfDI (SFtype original_a)
1286{
1287 /* Convert the SFtype to a DFtype, because that is surely not going
1288 to lose any bits. Some day someone else can write a faster version
1289 that avoids converting to DFtype, and verify it really works right. */
1290 const DFtype a = original_a;
1291
1292 /* Get high part of result. The division here will just moves the radix
1293 point and will not cause any rounding. Then the conversion to integral
1294 type chops result as desired. */
1295 const UWtype hi = a / HIGH_WORD_COEFF;
1296
1297 /* Get low part of result. Convert `hi' to floating type and scale it back,
1298 then subtract this from the number being converted. This leaves the low
1299 part. Convert that to integral type. */
1300 const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
1301
1302 /* Assemble result from the two parts. */
1303 return ((UDWtype) hi << WORD_SIZE) | lo;
1304}
1305#endif
1306
1307#ifdef L_fixsfdi
1308DWtype
1309__fixsfdi (SFtype a)
1310{
1311 if (a < 0)
1312 return - __fixunssfDI (-a);
1313 return __fixunssfDI (a);
1314}
1315#endif
1316
1317#if defined(L_floatdixf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1318#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1319#define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1320#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1321
1322XFtype
1323__floatdixf (DWtype u)
1324{
1325 XFtype d = (Wtype) (u >> WORD_SIZE);
1326 d *= HIGH_HALFWORD_COEFF;
1327 d *= HIGH_HALFWORD_COEFF;
1328 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1329
1330 return d;
1331}
1332#endif
1333
1334#if defined(L_floatditf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1335#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1336#define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1337#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1338
1339TFtype
1340__floatditf (DWtype u)
1341{
1342 TFtype d = (Wtype) (u >> WORD_SIZE);
1343 d *= HIGH_HALFWORD_COEFF;
1344 d *= HIGH_HALFWORD_COEFF;
1345 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1346
1347 return d;
1348}
1349#endif
1350
1351#ifdef L_floatdidf
1352#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1353#define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1354#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1355
1356DFtype
1357__floatdidf (DWtype u)
1358{
1359 DFtype d = (Wtype) (u >> WORD_SIZE);
1360 d *= HIGH_HALFWORD_COEFF;
1361 d *= HIGH_HALFWORD_COEFF;
1362 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1363
1364 return d;
1365}
1366#endif
1367
1368#ifdef L_floatdisf
1369#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1370#define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1371#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1372
1373#define DI_SIZE (sizeof (DWtype) * BITS_PER_UNIT)
1374#define DF_SIZE DBL_MANT_DIG
1375#define SF_SIZE FLT_MANT_DIG
1376
1377SFtype
1378__floatdisf (DWtype u)
1379{
1380 /* Protect against double-rounding error.
1381 Represent any low-order bits, that might be truncated in DFmode,
1382 by a bit that won't be lost. The bit can go in anywhere below the
1383 rounding position of the SFmode. A fixed mask and bit position
1384 handles all usual configurations. It doesn't handle the case
1385 of 128-bit DImode, however. */
1386 if (DF_SIZE < DI_SIZE
1387 && DF_SIZE > (DI_SIZE - DF_SIZE + SF_SIZE))
1388 {
1389#define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE))
1390 if (! (- ((DWtype) 1 << DF_SIZE) < u
1391 && u < ((DWtype) 1 << DF_SIZE)))
1392 {
1393 if ((UDWtype) u & (REP_BIT - 1))
1394 {
1395 u &= ~ (REP_BIT - 1);
1396 u |= REP_BIT;
1397 }
1398 }
1399 }
1400 /* Do the calculation in DFmode
1401 so that we don't lose any of the precision of the high word
1402 while multiplying it. */
1403 DFtype f = (Wtype) (u >> WORD_SIZE);
1404 f *= HIGH_HALFWORD_COEFF;
1405 f *= HIGH_HALFWORD_COEFF;
1406 f += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1407
1408 return (SFtype) f;
1409}
1410#endif
1411
1412#if defined(L_fixunsxfsi) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96
1413/* Reenable the normal types, in case limits.h needs them. */
1414#undef char
1415#undef short
1416#undef int
1417#undef long
1418#undef unsigned
1419#undef float
1420#undef double
1421#undef MIN
1422#undef MAX
1423#include <limits.h>
1424
1425UWtype
1426__fixunsxfSI (XFtype a)
1427{
1428 if (a >= - (DFtype) Wtype_MIN)
1429 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1430 return (Wtype) a;
1431}
1432#endif
1433
1434#ifdef L_fixunsdfsi
1435/* Reenable the normal types, in case limits.h needs them. */
1436#undef char
1437#undef short
1438#undef int
1439#undef long
1440#undef unsigned
1441#undef float
1442#undef double
1443#undef MIN
1444#undef MAX
1445#include <limits.h>
1446
1447UWtype
1448__fixunsdfSI (DFtype a)
1449{
1450 if (a >= - (DFtype) Wtype_MIN)
1451 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1452 return (Wtype) a;
1453}
1454#endif
1455
1456#ifdef L_fixunssfsi
1457/* Reenable the normal types, in case limits.h needs them. */
1458#undef char
1459#undef short
1460#undef int
1461#undef long
1462#undef unsigned
1463#undef float
1464#undef double
1465#undef MIN
1466#undef MAX
1467#include <limits.h>
1468
1469UWtype
1470__fixunssfSI (SFtype a)
1471{
1472 if (a >= - (SFtype) Wtype_MIN)
1473 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1474 return (Wtype) a;
1475}
1476#endif
1477
1478/* From here on down, the routines use normal data types. */
1479
1480#define SItype bogus_type
1481#define USItype bogus_type
1482#define DItype bogus_type
1483#define UDItype bogus_type
1484#define SFtype bogus_type
1485#define DFtype bogus_type
1486#undef Wtype
1487#undef UWtype
1488#undef HWtype
1489#undef UHWtype
1490#undef DWtype
1491#undef UDWtype
1492
1493#undef char
1494#undef short
1495#undef int
1496#undef long
1497#undef unsigned
1498#undef float
1499#undef double
1500
1501#ifdef L__gcc_bcmp
1502
1503/* Like bcmp except the sign is meaningful.
1504 Result is negative if S1 is less than S2,
1505 positive if S1 is greater, 0 if S1 and S2 are equal. */
1506
1507int
1508__gcc_bcmp (const unsigned char *s1, const unsigned char *s2, size_t size)
1509{
1510 while (size > 0)
1511 {
1512 const unsigned char c1 = *s1++, c2 = *s2++;
1513 if (c1 != c2)
1514 return c1 - c2;
1515 size--;
1516 }
1517 return 0;
1518}
1519
1520#endif
1521
1522/* __eprintf used to be used by GCC's private version of <assert.h>.
1523 We no longer provide that header, but this routine remains in libgcc.a
1524 for binary backward compatibility. Note that it is not included in
1525 the shared version of libgcc. */
1526#ifdef L_eprintf
1527#ifndef inhibit_libc
1528
1529#undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1530#include <stdio.h>
1531
1532void
1533__eprintf (const char *string, const char *expression,
1534 unsigned int line, const char *filename)
1535{
1536 fprintf (stderr, string, expression, line, filename);
1537 fflush (stderr);
1538 abort ();
1539}
1540
1541#endif
1542#endif
1543
1544
1545#ifdef L_clear_cache
1546/* Clear part of an instruction cache. */
1547
1548void
1549__clear_cache (char *beg __attribute__((__unused__)),
1550 char *end __attribute__((__unused__)))
1551{
1552#ifdef CLEAR_INSN_CACHE
1553 CLEAR_INSN_CACHE (beg, end);
1554#endif /* CLEAR_INSN_CACHE */
1555}
1556
1557#endif /* L_clear_cache */
1558
1559#ifdef L_enable_execute_stack
1560/* Attempt to turn on execute permission for the stack. */
1561
1562#ifdef ENABLE_EXECUTE_STACK
1563 ENABLE_EXECUTE_STACK
1564#else
1565void
1566__enable_execute_stack (void *addr __attribute__((__unused__)))
1567{}
1568#endif /* ENABLE_EXECUTE_STACK */
1569
1570#endif /* L_enable_execute_stack */
1571
1572#ifdef L_trampoline
1573
1574/* Jump to a trampoline, loading the static chain address. */
1575
1576#if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
1577
1578long
1579getpagesize (void)
1580{
1581#ifdef _ALPHA_
1582 return 8192;
1583#else
1584 return 4096;
1585#endif
1586}
1587
1588#ifdef __i386__
1589extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
1590#endif
1591
1592int
1593mprotect (char *addr, int len, int prot)
1594{
1595 int np, op;
1596
1597 if (prot == 7)
1598 np = 0x40;
1599 else if (prot == 5)
1600 np = 0x20;
1601 else if (prot == 4)
1602 np = 0x10;
1603 else if (prot == 3)
1604 np = 0x04;
1605 else if (prot == 1)
1606 np = 0x02;
1607 else if (prot == 0)
1608 np = 0x01;
1609
1610 if (VirtualProtect (addr, len, np, &op))
1611 return 0;
1612 else
1613 return -1;
1614}
1615
1616#endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
1617
1618#ifdef TRANSFER_FROM_TRAMPOLINE
1619TRANSFER_FROM_TRAMPOLINE
1620#endif
1621#endif /* L_trampoline */
1622
1623#ifndef __CYGWIN__
1624#ifdef L__main
1625
1626#include "gbl-ctors.h"
1627/* Some systems use __main in a way incompatible with its use in gcc, in these
1628 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1629 give the same symbol without quotes for an alternative entry point. You
1630 must define both, or neither. */
1631#ifndef NAME__MAIN
1632#define NAME__MAIN "__main"
1633#define SYMBOL__MAIN __main
1634#endif
1635
1636#ifdef INIT_SECTION_ASM_OP
1637#undef HAS_INIT_SECTION
1638#define HAS_INIT_SECTION
1639#endif
1640
1641#if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
1642
1643/* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
1644 code to run constructors. In that case, we need to handle EH here, too. */
1645
1646#ifdef EH_FRAME_SECTION_NAME
1647#include "unwind-dw2-fde.h"
1648extern unsigned char __EH_FRAME_BEGIN__[];
1649#endif
1650
1651/* Run all the global destructors on exit from the program. */
1652
1653void
1654__do_global_dtors (void)
1655{
1656#ifdef DO_GLOBAL_DTORS_BODY
1657 DO_GLOBAL_DTORS_BODY;
1658#else
1659 static func_ptr *p = __DTOR_LIST__ + 1;
1660 while (*p)
1661 {
1662 p++;
1663 (*(p-1)) ();
1664 }
1665#endif
1666#if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
1667 {
1668 static int completed = 0;
1669 if (! completed)
1670 {
1671 completed = 1;
1672 __deregister_frame_info (__EH_FRAME_BEGIN__);
1673 }
1674 }
1675#endif
1676}
1677#endif
1678
1679#ifndef HAS_INIT_SECTION
1680/* Run all the global constructors on entry to the program. */
1681
1682void
1683__do_global_ctors (void)
1684{
1685#ifdef EH_FRAME_SECTION_NAME
1686 {
1687 static struct object object;
1688 __register_frame_info (__EH_FRAME_BEGIN__, &object);
1689 }
1690#endif
1691 DO_GLOBAL_CTORS_BODY;
1692 atexit (__do_global_dtors);
1693}
1694#endif /* no HAS_INIT_SECTION */
1695
1696#if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
1697/* Subroutine called automatically by `main'.
1698 Compiling a global function named `main'
1699 produces an automatic call to this function at the beginning.
1700
1701 For many systems, this routine calls __do_global_ctors.
1702 For systems which support a .init section we use the .init section
1703 to run __do_global_ctors, so we need not do anything here. */
1704
1705extern void SYMBOL__MAIN (void);
1706void
1707SYMBOL__MAIN (void)
1708{
1709 /* Support recursive calls to `main': run initializers just once. */
1710 static int initialized;
1711 if (! initialized)
1712 {
1713 initialized = 1;
1714 __do_global_ctors ();
1715 }
1716}
1717#endif /* no HAS_INIT_SECTION or INVOKE__main */
1718
1719#endif /* L__main */
1720#endif /* __CYGWIN__ */
1721
1722#ifdef L_ctors
1723
1724#include "gbl-ctors.h"
1725
1726/* Provide default definitions for the lists of constructors and
1727 destructors, so that we don't get linker errors. These symbols are
1728 intentionally bss symbols, so that gld and/or collect will provide
1729 the right values. */
1730
1731/* We declare the lists here with two elements each,
1732 so that they are valid empty lists if no other definition is loaded.
1733
1734 If we are using the old "set" extensions to have the gnu linker
1735 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
1736 must be in the bss/common section.
1737
1738 Long term no port should use those extensions. But many still do. */
1739#if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
1740#if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
1741func_ptr __CTOR_LIST__[2] = {0, 0};
1742func_ptr __DTOR_LIST__[2] = {0, 0};
1743#else
1744func_ptr __CTOR_LIST__[2];
1745func_ptr __DTOR_LIST__[2];
1746#endif
1747#endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
1748#endif /* L_ctors */
1749