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