1 /* More subroutines needed by GCC output code on some machines. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1989, 1992, 1993, 1994 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* As a special exception, if you link this library with files
22 compiled with GCC to produce an executable, this does not cause
23 the resulting executable to be covered by the GNU General Public License.
24 This exception does not however invalidate any other reasons why
25 the executable file might be covered by the GNU General Public License. */
27 /* It is incorrect to include config.h here, because this file is being
28 compiled for the target, and hence definitions concerning only the host
37 /* Don't use `fancy_abort' here even if config.h says to use it. */
42 /* In the first part of this file, we are interfacing to calls generated
43 by the compiler itself. These calls pass values into these routines
44 which have very specific modes (rather than very specific types), and
45 these compiler-generated calls also expect any return values to have
46 very specific modes (rather than very specific types). Thus, we need
47 to avoid using regular C language type names in this part of the file
48 because the sizes for those types can be configured to be anything.
49 Instead we use the following special type names. */
51 typedef unsigned int UQItype __attribute__ ((mode ("QI")));
52 typedef int SItype __attribute__ ((mode ("SI")));
53 typedef unsigned int USItype __attribute__ ((mode ("SI")));
54 typedef int DItype __attribute__ ((mode ("DI")));
55 typedef unsigned int UDItype __attribute__ ((mode ("DI")));
56 typedef float SFtype __attribute__ ((mode ("SF")));
57 typedef float DFtype __attribute__ ((mode ("DF")));
58 #if LONG_DOUBLE_TYPE_SIZE == 96
59 typedef float XFtype __attribute__ ((mode ("XF")));
61 #if LONG_DOUBLE_TYPE_SIZE == 128
62 typedef float TFtype __attribute__ ((mode ("TF")));
66 typedef int word_type __attribute__ ((mode ("HI")));
69 typedef int word_type __attribute__ ((mode ("SI")));
72 typedef int word_type __attribute__ ((mode ("DI")));
75 /* Make sure that we don't accidentally use any normal C language built-in
76 type names in the first part of this file. Instead we want to use *only*
77 the type names defined above. The following macro definitions insure
78 that if we *do* accidentally use some normal C language built-in type name,
79 we will get a syntax error. */
81 #define char bogus_type
82 #define short bogus_type
83 #define int bogus_type
84 #define long bogus_type
85 #define unsigned bogus_type
86 #define float bogus_type
87 #define double bogus_type
89 #define SI_TYPE_SIZE (sizeof (SItype) * BITS_PER_UNIT)
91 /* DIstructs are pairs of SItype values in the order determined by
95 struct DIstruct {SItype high, low;};
97 struct DIstruct {SItype low, high;};
100 /* We need this union to unpack/pack DImode values, since we don't have
101 any arithmetic yet. Incoming DImode parameters are stored into the
102 `ll' field, and the unpacked result is read from the struct `s'. */
110 #if defined (L_udivmoddi4) || defined (L_muldi3) || defined (L_udiv_w_sdiv)
112 #include "longlong.h"
114 #endif /* udiv or mul */
116 extern DItype __fixunssfdi (SFtype a);
117 extern DItype __fixunsdfdi (DFtype a);
118 #if LONG_DOUBLE_TYPE_SIZE == 96
119 extern DItype __fixunsxfdi (XFtype a);
121 #if LONG_DOUBLE_TYPE_SIZE == 128
122 extern DItype __fixunstfdi (TFtype a);
125 #if defined (L_negdi2) || defined (L_divdi3) || defined (L_moddi3)
126 #if defined (L_divdi3) || defined (L_moddi3)
139 w.s.high = -uu.s.high - ((USItype) w.s.low > 0);
160 bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
164 w.s.high = (USItype)uu.s.low << -bm;
168 USItype carries = (USItype)uu.s.low >> bm;
169 w.s.low = (USItype)uu.s.low << b;
170 w.s.high = ((USItype)uu.s.high << b) | carries;
192 bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
196 w.s.low = (USItype)uu.s.high >> -bm;
200 USItype carries = (USItype)uu.s.high << bm;
201 w.s.high = (USItype)uu.s.high >> b;
202 w.s.low = ((USItype)uu.s.low >> b) | carries;
224 bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
228 w.s.high = (USItype)uu.s.low << -bm;
232 USItype carries = (USItype)uu.s.low >> bm;
233 w.s.low = (USItype)uu.s.low << b;
234 w.s.high = ((USItype)uu.s.high << b) | carries;
256 bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
259 /* w.s.high = 1..1 or 0..0 */
260 w.s.high = uu.s.high >> (sizeof (SItype) * BITS_PER_UNIT - 1);
261 w.s.low = uu.s.high >> -bm;
265 USItype carries = (USItype)uu.s.high << bm;
266 w.s.high = uu.s.high >> b;
267 w.s.low = ((USItype)uu.s.low >> b) | carries;
282 w.s.low = ffs (uu.s.low);
285 w.s.low = ffs (uu.s.high);
288 w.s.low += BITS_PER_UNIT * sizeof (SItype);
306 w.ll = __umulsidi3 (uu.s.low, vv.s.low);
307 w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high
308 + (USItype) uu.s.high * (USItype) vv.s.low);
316 __udiv_w_sdiv (rp, a1, a0, d)
317 USItype *rp, a1, a0, d;
324 if (a1 < d - a1 - (a0 >> (SI_TYPE_SIZE - 1)))
326 /* dividend, divisor, and quotient are nonnegative */
327 sdiv_qrnnd (q, r, a1, a0, d);
331 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
332 sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (SI_TYPE_SIZE - 1));
333 /* Divide (c1*2^32 + c0) by d */
334 sdiv_qrnnd (q, r, c1, c0, d);
335 /* Add 2^31 to quotient */
336 q += (USItype) 1 << (SI_TYPE_SIZE - 1);
341 b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
342 c1 = a1 >> 1; /* A/2 */
343 c0 = (a1 << (SI_TYPE_SIZE - 1)) + (a0 >> 1);
345 if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */
347 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
349 r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */
366 else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */
369 c0 = ~c0; /* logical NOT */
371 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
373 q = ~q; /* (A/2)/b1 */
376 r = 2*r + (a0 & 1); /* A/(2*b1) */
394 else /* Implies c1 = b1 */
395 { /* Hence a1 = d - 1 = 2*b1 - 1 */
415 static const UQItype __clz_tab[] =
417 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,
418 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,
419 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,
420 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,
421 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,
422 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,
423 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,
424 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,
428 __udivmoddi4 (n, d, rp)
435 USItype d0, d1, n0, n1, n2;
447 #if !UDIV_NEEDS_NORMALIZATION
454 udiv_qrnnd (q0, n0, n1, n0, d0);
457 /* Remainder in n0. */
464 d0 = 1 / d0; /* Divide intentionally by zero. */
466 udiv_qrnnd (q1, n1, 0, n1, d0);
467 udiv_qrnnd (q0, n0, n1, n0, d0);
469 /* Remainder in n0. */
480 #else /* UDIV_NEEDS_NORMALIZATION */
488 count_leading_zeros (bm, d0);
492 /* Normalize, i.e. make the most significant bit of the
496 n1 = (n1 << bm) | (n0 >> (SI_TYPE_SIZE - bm));
500 udiv_qrnnd (q0, n0, n1, n0, d0);
503 /* Remainder in n0 >> bm. */
510 d0 = 1 / d0; /* Divide intentionally by zero. */
512 count_leading_zeros (bm, d0);
516 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
517 conclude (the most significant bit of n1 is set) /\ (the
518 leading quotient digit q1 = 1).
520 This special case is necessary, not an optimization.
521 (Shifts counts of SI_TYPE_SIZE are undefined.) */
530 b = SI_TYPE_SIZE - bm;
534 n1 = (n1 << bm) | (n0 >> b);
537 udiv_qrnnd (q1, n1, n2, n1, d0);
542 udiv_qrnnd (q0, n0, n1, n0, d0);
544 /* Remainder in n0 >> bm. */
554 #endif /* UDIV_NEEDS_NORMALIZATION */
565 /* Remainder in n1n0. */
577 count_leading_zeros (bm, d1);
580 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
581 conclude (the most significant bit of n1 is set) /\ (the
582 quotient digit q0 = 0 or 1).
584 This special case is necessary, not an optimization. */
586 /* The condition on the next line takes advantage of that
587 n1 >= d1 (true due to program flow). */
588 if (n1 > d1 || n0 >= d0)
591 sub_ddmmss (n1, n0, n1, n0, d1, d0);
610 b = SI_TYPE_SIZE - bm;
612 d1 = (d1 << bm) | (d0 >> b);
615 n1 = (n1 << bm) | (n0 >> b);
618 udiv_qrnnd (q0, n1, n2, n1, d1);
619 umul_ppmm (m1, m0, q0, d0);
621 if (m1 > n1 || (m1 == n1 && m0 > n0))
624 sub_ddmmss (m1, m0, m1, m0, d1, d0);
629 /* Remainder in (n1n0 - m1m0) >> bm. */
632 sub_ddmmss (n1, n0, n1, n0, m1, m0);
633 rr.s.low = (n1 << b) | (n0 >> bm);
634 rr.s.high = n1 >> bm;
648 UDItype __udivmoddi4 ();
663 uu.ll = __negdi2 (uu.ll);
666 vv.ll = __negdi2 (vv.ll);
668 w = __udivmoddi4 (uu.ll, vv.ll, (UDItype *) 0);
677 UDItype __udivmoddi4 ();
691 uu.ll = __negdi2 (uu.ll);
693 vv.ll = __negdi2 (vv.ll);
695 (void) __udivmoddi4 (uu.ll, vv.ll, &w);
704 UDItype __udivmoddi4 ();
711 (void) __udivmoddi4 (u, v, &w);
718 UDItype __udivmoddi4 ();
723 return __udivmoddi4 (n, d, (UDItype *) 0);
734 au.ll = a, bu.ll = b;
736 if (au.s.high < bu.s.high)
738 else if (au.s.high > bu.s.high)
740 if ((USItype) au.s.low < (USItype) bu.s.low)
742 else if ((USItype) au.s.low > (USItype) bu.s.low)
755 au.ll = a, bu.ll = b;
757 if ((USItype) au.s.high < (USItype) bu.s.high)
759 else if ((USItype) au.s.high > (USItype) bu.s.high)
761 if ((USItype) au.s.low < (USItype) bu.s.low)
763 else if ((USItype) au.s.low > (USItype) bu.s.low)
769 #if defined(L_fixunstfdi) && (LONG_DOUBLE_TYPE_SIZE == 128)
770 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
771 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
783 /* Compute high word of result, as a flonum. */
784 b = (a / HIGH_WORD_COEFF);
785 /* Convert that to fixed (but not to DItype!),
786 and shift it into the high word. */
789 /* Remove high part from the TFtype, leaving the low part as flonum. */
791 /* Convert that to fixed (but not to DItype!) and add it in.
792 Sometimes A comes out negative. This is significant, since
793 A has more bits than a long int does. */
795 v -= (USItype) (- a);
802 #if defined(L_fixtfdi) && (LONG_DOUBLE_TYPE_SIZE == 128)
808 return - __fixunstfdi (-a);
809 return __fixunstfdi (a);
813 #if defined(L_fixunsxfdi) && (LONG_DOUBLE_TYPE_SIZE == 96)
814 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
815 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
827 /* Compute high word of result, as a flonum. */
828 b = (a / HIGH_WORD_COEFF);
829 /* Convert that to fixed (but not to DItype!),
830 and shift it into the high word. */
833 /* Remove high part from the XFtype, leaving the low part as flonum. */
835 /* Convert that to fixed (but not to DItype!) and add it in.
836 Sometimes A comes out negative. This is significant, since
837 A has more bits than a long int does. */
839 v -= (USItype) (- a);
846 #if defined(L_fixxfdi) && (LONG_DOUBLE_TYPE_SIZE == 96)
852 return - __fixunsxfdi (-a);
853 return __fixunsxfdi (a);
858 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
859 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
871 /* Compute high word of result, as a flonum. */
872 b = (a / HIGH_WORD_COEFF);
873 /* Convert that to fixed (but not to DItype!),
874 and shift it into the high word. */
877 /* Remove high part from the DFtype, leaving the low part as flonum. */
879 /* Convert that to fixed (but not to DItype!) and add it in.
880 Sometimes A comes out negative. This is significant, since
881 A has more bits than a long int does. */
883 v -= (USItype) (- a);
896 return - __fixunsdfdi (-a);
897 return __fixunsdfdi (a);
902 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
903 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
906 __fixunssfdi (SFtype original_a)
908 /* Convert the SFtype to a DFtype, because that is surely not going
909 to lose any bits. Some day someone else can write a faster version
910 that avoids converting to DFtype, and verify it really works right. */
911 DFtype a = original_a;
918 /* Compute high word of result, as a flonum. */
919 b = (a / HIGH_WORD_COEFF);
920 /* Convert that to fixed (but not to DItype!),
921 and shift it into the high word. */
924 /* Remove high part from the DFtype, leaving the low part as flonum. */
926 /* Convert that to fixed (but not to DItype!) and add it in.
927 Sometimes A comes out negative. This is significant, since
928 A has more bits than a long int does. */
930 v -= (USItype) (- a);
942 return - __fixunssfdi (-a);
943 return __fixunssfdi (a);
947 #if defined(L_floatdixf) && (LONG_DOUBLE_TYPE_SIZE == 96)
948 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
949 #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
950 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
962 d = (USItype) (u >> WORD_SIZE);
963 d *= HIGH_HALFWORD_COEFF;
964 d *= HIGH_HALFWORD_COEFF;
965 d += (USItype) (u & (HIGH_WORD_COEFF - 1));
967 return (negate ? -d : d);
971 #if defined(L_floatditf) && (LONG_DOUBLE_TYPE_SIZE == 128)
972 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
973 #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
974 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
986 d = (USItype) (u >> WORD_SIZE);
987 d *= HIGH_HALFWORD_COEFF;
988 d *= HIGH_HALFWORD_COEFF;
989 d += (USItype) (u & (HIGH_WORD_COEFF - 1));
991 return (negate ? -d : d);
996 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
997 #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
998 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
1010 d = (USItype) (u >> WORD_SIZE);
1011 d *= HIGH_HALFWORD_COEFF;
1012 d *= HIGH_HALFWORD_COEFF;
1013 d += (USItype) (u & (HIGH_WORD_COEFF - 1));
1015 return (negate ? -d : d);
1020 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
1021 #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
1022 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
1028 /* Do the calculation in DFmode
1029 so that we don't lose any of the precision of the high word
1030 while multiplying it. */
1037 f = (USItype) (u >> WORD_SIZE);
1038 f *= HIGH_HALFWORD_COEFF;
1039 f *= HIGH_HALFWORD_COEFF;
1040 f += (USItype) (u & (HIGH_WORD_COEFF - 1));
1042 return (SFtype) (negate ? -f : f);
1046 #if defined(L_fixunsxfsi) && LONG_DOUBLE_TYPE_SIZE == 96
1047 #include "glimits.h"
1053 if (a >= - (DFtype) LONG_MIN)
1054 return (SItype) (a + LONG_MIN) - LONG_MIN;
1060 #include "glimits.h"
1066 if (a >= - (DFtype) LONG_MIN)
1067 return (SItype) (a + LONG_MIN) - LONG_MIN;
1073 #include "glimits.h"
1076 __fixunssfsi (SFtype a)
1078 if (a >= - (SFtype) LONG_MIN)
1079 return (SItype) (a + LONG_MIN) - LONG_MIN;
1084 /* From here on down, the routines use normal data types. */
1086 #define SItype bogus_type
1087 #define USItype bogus_type
1088 #define DItype bogus_type
1089 #define UDItype bogus_type
1090 #define SFtype bogus_type
1091 #define DFtype bogus_type
1103 /* Like bcmp except the sign is meaningful.
1104 Reult is negative if S1 is less than S2,
1105 positive if S1 is greater, 0 if S1 and S2 are equal. */
1108 __gcc_bcmp (s1, s2, size)
1109 unsigned char *s1, *s2;
1114 unsigned char c1 = *s1++, c2 = *s2++;
1126 #if defined(__svr4__) || defined(__alliant__)
1130 /* The Alliant needs the added underscore. */
1131 asm (".globl __builtin_saveregs");
1132 asm ("__builtin_saveregs:");
1133 asm (".globl ___builtin_saveregs");
1134 asm ("___builtin_saveregs:");
1136 asm (" andnot 0x0f,%sp,%sp"); /* round down to 16-byte boundary */
1137 asm (" adds -96,%sp,%sp"); /* allocate stack space for reg save
1138 area and also for a new va_list
1140 /* Save all argument registers in the arg reg save area. The
1141 arg reg save area must have the following layout (according
1153 asm (" fst.q %f8, 0(%sp)"); /* save floating regs (f8-f15) */
1154 asm (" fst.q %f12,16(%sp)");
1156 asm (" st.l %r16,32(%sp)"); /* save integer regs (r16-r27) */
1157 asm (" st.l %r17,36(%sp)");
1158 asm (" st.l %r18,40(%sp)");
1159 asm (" st.l %r19,44(%sp)");
1160 asm (" st.l %r20,48(%sp)");
1161 asm (" st.l %r21,52(%sp)");
1162 asm (" st.l %r22,56(%sp)");
1163 asm (" st.l %r23,60(%sp)");
1164 asm (" st.l %r24,64(%sp)");
1165 asm (" st.l %r25,68(%sp)");
1166 asm (" st.l %r26,72(%sp)");
1167 asm (" st.l %r27,76(%sp)");
1169 asm (" adds 80,%sp,%r16"); /* compute the address of the new
1170 va_list structure. Put in into
1171 r16 so that it will be returned
1174 /* Initialize all fields of the new va_list structure. This
1175 structure looks like:
1178 unsigned long ireg_used;
1179 unsigned long freg_used;
1185 asm (" st.l %r0, 0(%r16)"); /* nfixed */
1186 asm (" st.l %r0, 4(%r16)"); /* nfloating */
1187 asm (" st.l %sp, 8(%r16)"); /* __va_ctl points to __va_struct. */
1188 asm (" bri %r1"); /* delayed return */
1189 asm (" st.l %r28,12(%r16)"); /* pointer to overflow args */
1191 #else /* not __svr4__ */
1192 #if defined(__PARAGON__)
1194 * we'll use SVR4-ish varargs but need SVR3.2 assembler syntax,
1195 * and we stand a better chance of hooking into libraries
1196 * compiled by PGI. [andyp@ssd.intel.com]
1200 asm (".globl __builtin_saveregs");
1201 asm ("__builtin_saveregs:");
1202 asm (".globl ___builtin_saveregs");
1203 asm ("___builtin_saveregs:");
1205 asm (" andnot 0x0f,sp,sp"); /* round down to 16-byte boundary */
1206 asm (" adds -96,sp,sp"); /* allocate stack space for reg save
1207 area and also for a new va_list
1209 /* Save all argument registers in the arg reg save area. The
1210 arg reg save area must have the following layout (according
1222 asm (" fst.q f8, 0(sp)");
1223 asm (" fst.q f12,16(sp)");
1224 asm (" st.l r16,32(sp)");
1225 asm (" st.l r17,36(sp)");
1226 asm (" st.l r18,40(sp)");
1227 asm (" st.l r19,44(sp)");
1228 asm (" st.l r20,48(sp)");
1229 asm (" st.l r21,52(sp)");
1230 asm (" st.l r22,56(sp)");
1231 asm (" st.l r23,60(sp)");
1232 asm (" st.l r24,64(sp)");
1233 asm (" st.l r25,68(sp)");
1234 asm (" st.l r26,72(sp)");
1235 asm (" st.l r27,76(sp)");
1237 asm (" adds 80,sp,r16"); /* compute the address of the new
1238 va_list structure. Put in into
1239 r16 so that it will be returned
1242 /* Initialize all fields of the new va_list structure. This
1243 structure looks like:
1246 unsigned long ireg_used;
1247 unsigned long freg_used;
1253 asm (" st.l r0, 0(r16)"); /* nfixed */
1254 asm (" st.l r0, 4(r16)"); /* nfloating */
1255 asm (" st.l sp, 8(r16)"); /* __va_ctl points to __va_struct. */
1256 asm (" bri r1"); /* delayed return */
1257 asm (" st.l r28,12(r16)"); /* pointer to overflow args */
1258 #else /* not __PARAGON__ */
1262 asm (".globl ___builtin_saveregs");
1263 asm ("___builtin_saveregs:");
1264 asm (" mov sp,r30");
1265 asm (" andnot 0x0f,sp,sp");
1266 asm (" adds -96,sp,sp"); /* allocate sufficient space on the stack */
1268 /* Fill in the __va_struct. */
1269 asm (" st.l r16, 0(sp)"); /* save integer regs (r16-r27) */
1270 asm (" st.l r17, 4(sp)"); /* int fixed[12] */
1271 asm (" st.l r18, 8(sp)");
1272 asm (" st.l r19,12(sp)");
1273 asm (" st.l r20,16(sp)");
1274 asm (" st.l r21,20(sp)");
1275 asm (" st.l r22,24(sp)");
1276 asm (" st.l r23,28(sp)");
1277 asm (" st.l r24,32(sp)");
1278 asm (" st.l r25,36(sp)");
1279 asm (" st.l r26,40(sp)");
1280 asm (" st.l r27,44(sp)");
1282 asm (" fst.q f8, 48(sp)"); /* save floating regs (f8-f15) */
1283 asm (" fst.q f12,64(sp)"); /* int floating[8] */
1285 /* Fill in the __va_ctl. */
1286 asm (" st.l sp, 80(sp)"); /* __va_ctl points to __va_struct. */
1287 asm (" st.l r28,84(sp)"); /* pointer to more args */
1288 asm (" st.l r0, 88(sp)"); /* nfixed */
1289 asm (" st.l r0, 92(sp)"); /* nfloating */
1291 asm (" adds 80,sp,r16"); /* return address of the __va_ctl. */
1293 asm (" mov r30,sp");
1294 /* recover stack and pass address to start
1296 #endif /* not __PARAGON__ */
1297 #endif /* not __svr4__ */
1298 #else /* not __i860__ */
1300 asm (".global __builtin_saveregs");
1301 asm ("__builtin_saveregs:");
1302 asm (".global ___builtin_saveregs");
1303 asm ("___builtin_saveregs:");
1304 #ifdef NEED_PROC_COMMAND
1307 asm ("st %i0,[%fp+68]");
1308 asm ("st %i1,[%fp+72]");
1309 asm ("st %i2,[%fp+76]");
1310 asm ("st %i3,[%fp+80]");
1311 asm ("st %i4,[%fp+84]");
1313 asm ("st %i5,[%fp+88]");
1314 #ifdef NEED_TYPE_COMMAND
1315 asm (".type __builtin_saveregs,#function");
1316 asm (".size __builtin_saveregs,.-__builtin_saveregs");
1318 #else /* not __sparc__ */
1319 #if defined(__MIPSEL__) | defined(__R3000__) | defined(__R2000__) | defined(__mips__)
1322 asm (" .ent __builtin_saveregs");
1323 asm (" .globl __builtin_saveregs");
1324 asm ("__builtin_saveregs:");
1325 asm (" sw $4,0($30)");
1326 asm (" sw $5,4($30)");
1327 asm (" sw $6,8($30)");
1328 asm (" sw $7,12($30)");
1330 asm (" .end __builtin_saveregs");
1331 #else /* not __mips__, etc. */
1334 __builtin_saveregs ()
1339 #endif /* not __mips__ */
1340 #endif /* not __sparc__ */
1341 #endif /* not __i860__ */
1345 #ifndef inhibit_libc
1347 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1349 /* This is used by the `assert' macro. */
1351 __eprintf (string, expression, line, filename)
1353 const char *expression;
1355 const char *filename;
1357 fprintf (stderr, string, expression, line, filename);
1367 /* Structure emitted by -a */
1371 const char *filename;
1375 const unsigned long *addresses;
1377 /* Older GCC's did not emit these fields. */
1379 const char **functions;
1380 const long *line_nums;
1381 const char **filenames;
1384 #ifdef BLOCK_PROFILER_CODE
1387 #ifndef inhibit_libc
1389 /* Simple minded basic block profiling output dumper for
1390 systems that don't provde tcov support. At present,
1391 it requires atexit and stdio. */
1393 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1397 extern void atexit (void (*) (void));
1398 #define ON_EXIT(FUNC,ARG) atexit ((FUNC))
1401 extern void on_exit (void*, void*);
1402 #define ON_EXIT(FUNC,ARG) on_exit ((FUNC), (ARG))
1406 static struct bb *bb_head = (struct bb *)0;
1408 /* Return the number of digits needed to print a value */
1409 /* __inline__ */ static int num_digits (long value, int base)
1411 int minus = (value < 0 && base != 16);
1412 unsigned long v = (minus) ? -value : value;
1426 __bb_exit_func (void)
1428 FILE *file = fopen ("bb.out", "a");
1438 /* This is somewhat type incorrect, but it avoids worrying about
1439 exactly where time.h is included from. It should be ok unless
1440 a void * differs from other pointer formats, or if sizeof(long)
1441 is < sizeof (time_t). It would be nice if we could assume the
1442 use of rationale standards here. */
1444 time((void *) &time_value);
1445 fprintf (file, "Basic block profiling finished on %s\n", ctime ((void *) &time_value));
1447 /* We check the length field explicitly in order to allow compatibility
1448 with older GCC's which did not provide it. */
1450 for (ptr = bb_head; ptr != (struct bb *)0; ptr = ptr->next)
1453 int func_p = (ptr->nwords >= sizeof (struct bb) && ptr->nwords <= 1000);
1454 int line_p = (func_p && ptr->line_nums);
1455 int file_p = (func_p && ptr->filenames);
1456 long ncounts = ptr->ncounts;
1462 int blk_len = num_digits (ncounts, 10);
1467 fprintf (file, "File %s, %ld basic blocks \n\n",
1468 ptr->filename, ncounts);
1470 /* Get max values for each field. */
1471 for (i = 0; i < ncounts; i++)
1476 if (cnt_max < ptr->counts[i])
1477 cnt_max = ptr->counts[i];
1479 if (addr_max < ptr->addresses[i])
1480 addr_max = ptr->addresses[i];
1482 if (line_p && line_max < ptr->line_nums[i])
1483 line_max = ptr->line_nums[i];
1487 p = (ptr->functions[i]) ? (ptr->functions[i]) : "<none>";
1495 p = (ptr->filenames[i]) ? (ptr->filenames[i]) : "<none>";
1502 addr_len = num_digits (addr_max, 16);
1503 cnt_len = num_digits (cnt_max, 10);
1504 line_len = num_digits (line_max, 10);
1506 /* Now print out the basic block information. */
1507 for (i = 0; i < ncounts; i++)
1510 " Block #%*d: executed %*ld time(s) address= 0x%.*lx",
1512 cnt_len, ptr->counts[i],
1513 addr_len, ptr->addresses[i]);
1516 fprintf (file, " function= %-*s", func_len,
1517 (ptr->functions[i]) ? ptr->functions[i] : "<none>");
1520 fprintf (file, " line= %*ld", line_len, ptr->line_nums[i]);
1523 fprintf (file, " file= %s",
1524 (ptr->filenames[i]) ? ptr->filenames[i] : "<none>");
1526 fprintf (file, "\n");
1529 fprintf (file, "\n");
1533 fprintf (file, "\n\n");
1539 __bb_init_func (struct bb *blocks)
1541 /* User is supposed to check whether the first word is non-0,
1542 but just in case.... */
1544 if (blocks->zero_word)
1548 /* Initialize destructor. */
1550 ON_EXIT (__bb_exit_func, 0);
1553 /* Set up linked list. */
1554 blocks->zero_word = 1;
1555 blocks->next = bb_head;
1559 #endif /* not inhibit_libc */
1560 #endif /* not BLOCK_PROFILER_CODE */
1563 /* Default free-store management functions for C++, per sections 12.5 and
1564 17.3.3 of the Working Paper. */
1567 /* operator new (size_t), described in 17.3.3.5. This function is used by
1568 C++ programs to allocate a block of memory to hold a single object. */
1570 typedef void (*vfp)(void);
1571 extern vfp __new_handler;
1574 __builtin_new (size_t sz)
1578 /* malloc (0) is unpredictable; avoid it. */
1581 p = (void *) malloc (sz);
1584 (*__new_handler) ();
1585 p = (void *) malloc (sz);
1590 #endif /* L_op_new */
1593 /* void * operator new [] (size_t), described in 17.3.3.6. This function
1594 is used by C++ programs to allocate a block of memory for an array. */
1596 extern void * __builtin_new (size_t);
1599 __builtin_vec_new (size_t sz)
1601 return __builtin_new (sz);
1603 #endif /* L_op_vec_new */
1605 #ifdef L_new_handler
1606 /* set_new_handler (fvoid_t *) and the default new handler, described in
1607 17.3.3.2 and 17.3.3.5. These functions define the result of a failure
1608 to allocate the amount of memory requested from operator new or new []. */
1610 #ifndef inhibit_libc
1611 /* This gets us __GNU_LIBRARY__. */
1612 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1615 #ifdef __GNU_LIBRARY__
1616 /* Avoid forcing the library's meaning of `write' on the user program
1617 by using the "internal" name (for use within the library) */
1618 #define write(fd, buf, n) __write((fd), (buf), (n))
1620 #endif /* inhibit_libc */
1622 typedef void (*vfp)(void);
1623 void __default_new_handler (void);
1625 vfp __new_handler = __default_new_handler;
1628 set_new_handler (vfp handler)
1632 prev_handler = __new_handler;
1633 if (handler == 0) handler = __default_new_handler;
1634 __new_handler = handler;
1635 return prev_handler;
1638 #define MESSAGE "Virtual memory exceeded in `new'\n"
1641 __default_new_handler ()
1643 /* don't use fprintf (stderr, ...) because it may need to call malloc. */
1644 /* This should really print the name of the program, but that is hard to
1645 do. We need a standard, clean way to get at the name. */
1646 write (2, MESSAGE, sizeof (MESSAGE));
1647 /* don't call exit () because that may call global destructors which
1648 may cause a loop. */
1654 /* operator delete (void *), described in 17.3.3.3. This function is used
1655 by C++ programs to return to the free store a block of memory allocated
1656 as a single object. */
1659 __builtin_delete (void *ptr)
1667 /* operator delete [] (void *), described in 17.3.3.4. This function is
1668 used by C++ programs to return to the free store a block of memory
1669 allocated as an array. */
1671 extern void __builtin_delete (void *);
1674 __builtin_vec_delete (void *ptr)
1676 __builtin_delete (ptr);
1680 /* End of C++ free-store management functions */
1683 unsigned int __shtab[] = {
1684 0x00000001, 0x00000002, 0x00000004, 0x00000008,
1685 0x00000010, 0x00000020, 0x00000040, 0x00000080,
1686 0x00000100, 0x00000200, 0x00000400, 0x00000800,
1687 0x00001000, 0x00002000, 0x00004000, 0x00008000,
1688 0x00010000, 0x00020000, 0x00040000, 0x00080000,
1689 0x00100000, 0x00200000, 0x00400000, 0x00800000,
1690 0x01000000, 0x02000000, 0x04000000, 0x08000000,
1691 0x10000000, 0x20000000, 0x40000000, 0x80000000
1695 #ifdef L_clear_cache
1696 /* Clear part of an instruction cache. */
1698 #define INSN_CACHE_PLANE_SIZE (INSN_CACHE_SIZE / INSN_CACHE_DEPTH)
1701 __clear_cache (beg, end)
1704 #ifdef CLEAR_INSN_CACHE
1705 CLEAR_INSN_CACHE (beg, end);
1707 #ifdef INSN_CACHE_SIZE
1708 static char array[INSN_CACHE_SIZE + INSN_CACHE_PLANE_SIZE + INSN_CACHE_LINE_WIDTH];
1709 static int initialized = 0;
1713 typedef (*function_ptr) ();
1715 #if (INSN_CACHE_SIZE / INSN_CACHE_LINE_WIDTH) < 16
1716 /* It's cheaper to clear the whole cache.
1717 Put in a series of jump instructions so that calling the beginning
1718 of the cache will clear the whole thing. */
1722 int ptr = (((int) array + INSN_CACHE_LINE_WIDTH - 1)
1723 & -INSN_CACHE_LINE_WIDTH);
1724 int end_ptr = ptr + INSN_CACHE_SIZE;
1726 while (ptr < end_ptr)
1728 *(INSTRUCTION_TYPE *)ptr
1729 = JUMP_AHEAD_INSTRUCTION + INSN_CACHE_LINE_WIDTH;
1730 ptr += INSN_CACHE_LINE_WIDTH;
1732 *(INSTRUCTION_TYPE *)(ptr - INSN_CACHE_LINE_WIDTH) = RETURN_INSTRUCTION;
1737 /* Call the beginning of the sequence. */
1738 (((function_ptr) (((int) array + INSN_CACHE_LINE_WIDTH - 1)
1739 & -INSN_CACHE_LINE_WIDTH))
1742 #else /* Cache is large. */
1746 int ptr = (((int) array + INSN_CACHE_LINE_WIDTH - 1)
1747 & -INSN_CACHE_LINE_WIDTH);
1749 while (ptr < (int) array + sizeof array)
1751 *(INSTRUCTION_TYPE *)ptr = RETURN_INSTRUCTION;
1752 ptr += INSN_CACHE_LINE_WIDTH;
1758 /* Find the location in array that occupies the same cache line as BEG. */
1760 offset = ((int) beg & -INSN_CACHE_LINE_WIDTH) & (INSN_CACHE_PLANE_SIZE - 1);
1761 start_addr = (((int) (array + INSN_CACHE_PLANE_SIZE - 1)
1762 & -INSN_CACHE_PLANE_SIZE)
1765 /* Compute the cache alignment of the place to stop clearing. */
1766 #if 0 /* This is not needed for gcc's purposes. */
1767 /* If the block to clear is bigger than a cache plane,
1768 we clear the entire cache, and OFFSET is already correct. */
1769 if (end < beg + INSN_CACHE_PLANE_SIZE)
1771 offset = (((int) (end + INSN_CACHE_LINE_WIDTH - 1)
1772 & -INSN_CACHE_LINE_WIDTH)
1773 & (INSN_CACHE_PLANE_SIZE - 1));
1775 #if INSN_CACHE_DEPTH > 1
1776 end_addr = (start_addr & -INSN_CACHE_PLANE_SIZE) + offset;
1777 if (end_addr <= start_addr)
1778 end_addr += INSN_CACHE_PLANE_SIZE;
1780 for (plane = 0; plane < INSN_CACHE_DEPTH; plane++)
1782 int addr = start_addr + plane * INSN_CACHE_PLANE_SIZE;
1783 int stop = end_addr + plane * INSN_CACHE_PLANE_SIZE;
1785 while (addr != stop)
1787 /* Call the return instruction at ADDR. */
1788 ((function_ptr) addr) ();
1790 addr += INSN_CACHE_LINE_WIDTH;
1793 #else /* just one plane */
1796 /* Call the return instruction at START_ADDR. */
1797 ((function_ptr) start_addr) ();
1799 start_addr += INSN_CACHE_LINE_WIDTH;
1801 while ((start_addr % INSN_CACHE_SIZE) != offset);
1802 #endif /* just one plane */
1803 #endif /* Cache is large */
1804 #endif /* Cache exists */
1805 #endif /* CLEAR_INSN_CACHE */
1808 #endif /* L_clear_cache */
1812 /* Jump to a trampoline, loading the static chain address. */
1814 #ifdef TRANSFER_FROM_TRAMPOLINE
1815 TRANSFER_FROM_TRAMPOLINE
1818 #if defined (NeXT) && defined (__MACH__)
1820 /* Make stack executable so we can call trampolines on stack.
1821 This is called from INITIALIZE_TRAMPOLINE in next.h. */
1825 #include <mach/mach.h>
1829 __enable_execute_stack (addr)
1833 char *eaddr = addr + TRAMPOLINE_SIZE;
1834 vm_address_t a = (vm_address_t) addr;
1836 /* turn on execute access on stack */
1837 r = vm_protect (task_self (), a, TRAMPOLINE_SIZE, FALSE, VM_PROT_ALL);
1838 if (r != KERN_SUCCESS)
1840 mach_error("vm_protect VM_PROT_ALL", r);
1844 /* We inline the i-cache invalidation for speed */
1846 #ifdef CLEAR_INSN_CACHE
1847 CLEAR_INSN_CACHE (addr, eaddr);
1849 __clear_cache ((int) addr, (int) eaddr);
1853 #endif /* defined (NeXT) && defined (__MACH__) */
1857 /* Make stack executable so we can call trampolines on stack.
1858 This is called from INITIALIZE_TRAMPOLINE in convex.h. */
1860 #include <sys/mman.h>
1861 #include <sys/vmparam.h>
1862 #include <machine/machparam.h>
1865 __enable_execute_stack ()
1868 static unsigned lowest = USRSTACK;
1869 unsigned current = (unsigned) &fp & -NBPG;
1871 if (lowest > current)
1873 unsigned len = lowest - current;
1874 mremap (current, &len, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
1878 /* Clear instruction cache in case an old trampoline is in it. */
1881 #endif /* __convex__ */
1885 /* Modified from the convex -code above. */
1887 #include <sys/param.h>
1889 #include <sys/m88kbcs.h>
1892 __enable_execute_stack ()
1895 static unsigned long lowest = USRSTACK;
1896 unsigned long current = (unsigned long) &save_errno & -NBPC;
1898 /* Ignore errno being set. memctl sets errno to EINVAL whenever the
1899 address is seen as 'negative'. That is the case with the stack. */
1902 if (lowest > current)
1904 unsigned len=lowest-current;
1905 memctl(current,len,MCT_TEXT);
1909 memctl(current,NBPC,MCT_TEXT);
1913 #endif /* __DOLPHIN__ */
1917 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1919 #include <sys/mman.h>
1920 #include <sys/types.h>
1921 #include <sys/param.h>
1922 #include <sys/vmmac.h>
1924 /* Modified from the convex -code above.
1925 mremap promises to clear the i-cache. */
1928 __enable_execute_stack ()
1931 if (mprotect (((unsigned int)&fp/PAGSIZ)*PAGSIZ, PAGSIZ,
1932 PROT_READ|PROT_WRITE|PROT_EXEC))
1934 perror ("mprotect in __enable_execute_stack");
1939 #endif /* __pyr__ */
1940 #endif /* L_trampoline */
1944 #include "gbl-ctors.h"
1945 /* Some systems use __main in a way incompatible with its use in gcc, in these
1946 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1947 give the same symbol without quotes for an alternative entry point. You
1948 must define both, or niether. */
1950 #define NAME__MAIN "__main"
1951 #define SYMBOL__MAIN __main
1954 /* Run all the global destructors on exit from the program. */
1957 __do_global_dtors ()
1959 #ifdef DO_GLOBAL_DTORS_BODY
1960 DO_GLOBAL_DTORS_BODY;
1962 unsigned nptrs = (unsigned HOST_WIDE_INT) __DTOR_LIST__[0];
1965 /* Some systems place the number of pointers
1966 in the first word of the table.
1967 On other systems, that word is -1.
1968 In all cases, the table is null-terminated. */
1970 /* If the length is not recorded, count up to the null. */
1972 for (nptrs = 0; __DTOR_LIST__[nptrs + 1] != 0; nptrs++);
1974 /* GNU LD format. */
1975 for (i = nptrs; i >= 1; i--)
1976 __DTOR_LIST__[i] ();
1980 #ifndef INIT_SECTION_ASM_OP
1981 /* Run all the global constructors on entry to the program. */
1984 #define ON_EXIT(a, b)
1986 /* Make sure the exit routine is pulled in to define the globals as
1987 bss symbols, just in case the linker does not automatically pull
1988 bss definitions from the library. */
1990 extern int _exit_dummy_decl;
1991 int *_exit_dummy_ref = &_exit_dummy_decl;
1992 #endif /* ON_EXIT */
1995 __do_global_ctors ()
1997 DO_GLOBAL_CTORS_BODY;
1998 ON_EXIT (__do_global_dtors, 0);
2000 #endif /* no INIT_SECTION_ASM_OP */
2002 #if !defined (INIT_SECTION_ASM_OP) || defined (INVOKE__main)
2003 /* Subroutine called automatically by `main'.
2004 Compiling a global function named `main'
2005 produces an automatic call to this function at the beginning.
2007 For many systems, this routine calls __do_global_ctors.
2008 For systems which support a .init section we use the .init section
2009 to run __do_global_ctors, so we need not do anything here. */
2014 /* Support recursive calls to `main': run initializers just once. */
2015 static int initialized = 0;
2019 __do_global_ctors ();
2022 #endif /* no INIT_SECTION_ASM_OP or INVOKE__main */
2024 #endif /* L__main */
2028 #include "gbl-ctors.h"
2030 /* Provide default definitions for the lists of constructors and
2031 destructors, so that we don't get linker errors. These symbols are
2032 intentionally bss symbols, so that gld and/or collect will provide
2033 the right values. */
2035 /* We declare the lists here with two elements each,
2036 so that they are valid empty lists if no other definition is loaded. */
2037 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
2039 /* After 2.3, try this definition on all systems. */
2040 func_ptr __CTOR_LIST__[2] = {0, 0};
2041 func_ptr __DTOR_LIST__[2] = {0, 0};
2043 func_ptr __CTOR_LIST__[2];
2044 func_ptr __DTOR_LIST__[2];
2046 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
2047 #endif /* L_ctors */
2051 #include "gbl-ctors.h"
2055 /* If we have no known way of registering our own __do_global_dtors
2056 routine so that it will be invoked at program exit time, then we
2057 have to define our own exit routine which will get this to happen. */
2059 extern void __do_global_dtors ();
2060 extern void _cleanup ();
2061 extern void _exit () __attribute__ ((noreturn));
2067 __do_global_dtors ();
2077 int _exit_dummy_decl = 0; /* prevent compiler & linker warnings */
2082 /* In a.out systems, we need to have these dummy constructor and destructor
2083 lists in the library.
2085 When using `collect', the first link will resolve __CTOR_LIST__
2086 and __DTOR_LIST__ to these symbols. We will then run "nm" on the
2087 result, build the correct __CTOR_LIST__ and __DTOR_LIST__, and relink.
2088 Since we don't do the second link if no constructors existed, these
2089 dummies must be fully functional empty lists.
2091 When using `gnu ld', these symbols will be used if there are no
2092 constructors. If there are constructors, the N_SETV symbol defined
2093 by the linker from the N_SETT's in input files will define __CTOR_LIST__
2094 and __DTOR_LIST__ rather than its being allocated as common storage
2095 by the definitions below.
2097 When using a linker that supports constructor and destructor segments,
2098 these definitions will not be used, since crtbegin.o and crtend.o
2099 (from crtstuff.c) will have already defined __CTOR_LIST__ and
2100 __DTOR_LIST__. The crt*.o files are passed directly to the linker
2101 on its command line, by gcc. */
2103 /* The list needs two elements: one is ignored (the old count); the
2104 second is the terminating zero. Since both values are zero, this
2105 declaration is not initialized, and it becomes `common'. */
2108 #include "gbl-ctors.h"
2109 func_ptr __CTOR_LIST__[2];
2113 #include "gbl-ctors.h"
2114 func_ptr __DTOR_LIST__[2];