OSDN Git Service

* calls.c, function.c: Always define PREFERRED_STACK_BOUNDARY
[pf3gnuchains/gcc-fork.git] / gcc / config / elxsi / elxsi.c
1 /* Subroutines for insn-output.c for GNU compiler.  Elxsi version.
2    Copyright (C) 1987, 1992, 1998, 1999, 2000 Free Software Foundation, Inc
3    Contributrd by Mike Stump <mrs@cygnus.com> in 1988 and is the first
4    64 bit port of GNU CC.
5    Based upon the VAX port.
6
7 This file is part of GNU CC.
8
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING.  If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA.  */
23
24 #include "config.h"
25 #include "system.h"
26 #include "rtl.h"
27 #include "function.h"
28 #include "output.h"
29 #include "tree.h"
30 #include "expr.h"
31 #include "regs.h"
32 #include "flags.h"
33 #include "tm_p.h"
34 #include "target.h"
35 #include "target-def.h"
36
37 extern const char *reg_names[];
38 rtx cmp_op0=0, cmp_op1=0;
39
40 /* table of relations for compares and branches */
41 static const char *const cmp_tab[] = {
42     "gt", "gt", "eq", "eq", "ge", "ge", "lt", "lt", "ne", "ne",
43     "le", "le" };
44
45 static void elxsi_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
46 static void elxsi_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
47 \f
48 /* Initialize the GCC target structure.  */
49 #undef TARGET_ASM_FUNCTION_PROLOGUE
50 #define TARGET_ASM_FUNCTION_PROLOGUE elxsi_output_function_prologue
51 #undef TARGET_ASM_FUNCTION_EPILOGUE
52 #define TARGET_ASM_FUNCTION_EPILOGUE elxsi_output_function_epilogue
53
54 struct gcc_target targetm = TARGET_INITIALIZER;
55 \f
56 /* Generate the assembly code for function entry.  FILE is a stdio
57    stream to output the code to.  SIZE is an int: how many units of
58    temporary storage to allocate.
59
60    Refer to the array `regs_ever_live' to determine which registers to
61    save; `regs_ever_live[I]' is nonzero if register number I is ever
62    used in the function.  This function is responsible for knowing
63    which registers should not be saved even if used.  */
64
65 static void
66 elxsi_output_function_prologue (file, size)
67      FILE *file;
68      HOST_WIDE_INT size;
69 {
70   register int regno;
71   register int cnt = 0;
72   extern char call_used_regs[];
73
74   /* the below two lines are a HACK, and should be deleted, but
75      for now are very much needed (1.35) */
76   if (frame_pointer_needed)
77     regs_ever_live[14] = 1, call_used_regs[14] = 0;
78
79   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
80     if (regs_ever_live[regno] && !call_used_regs[regno])
81       cnt += 8;
82
83   if (size + cnt)
84     fprintf (file, "\tadd.64\t.sp,=%d\n", -size - cnt);
85
86   cnt = 0;
87   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
88     if (regs_ever_live[regno] && !call_used_regs[regno])
89       fprintf (file, "\tst.64\t.r%d,[.sp]%d\n", regno, (cnt += 8) - 12);
90
91   if (frame_pointer_needed)
92     fprintf (file, "\tadd.64\t.r14,.sp,=%d\n", size + cnt);
93 }
94
95 /* This function generates the assembly code for function exit.
96    Args are as for output_function_prologue ().
97
98    The function epilogue should not depend on the current stack
99    pointer!  It should use the frame pointer only.  This is mandatory
100    because of alloca; we also take advantage of it to omit stack
101    adjustments before returning. */
102
103 static void
104 elxsi_output_function_epilogue (file, size)
105      FILE *file;
106      HOST_WIDE_INT size;
107 {
108   register int regno;
109   register int cnt = 0;
110   extern char call_used_regs[];
111
112   /* this conditional is ONLY here because there is a BUG;
113      EXIT_IGNORE_STACK is ignored itself when the first part of
114      the condition is true! (at least in version 1.35) */
115   /* the 8*10 is for 64 bits of .r5 - .r14 */
116   if (current_function_calls_alloca || size >= (256 - 8 * 10))
117     {
118       /* use .r4 as a temporary! Ok for now.... */
119       fprintf (file, "\tld.64\t.r4,.r14\n");
120
121       for (regno = FIRST_PSEUDO_REGISTER-1; regno >= 0; --regno)
122         if (regs_ever_live[regno] && !call_used_regs[regno])
123           cnt += 8;
124
125       for (regno = 0; regno < FIRST_PSEUDO_REGISTER; ++regno)
126         if (regs_ever_live[regno] && !call_used_regs[regno])
127           fprintf (file, "\tld.64\t.r%d,[.r14]%d\n", regno,
128                    -((cnt -= 8) + 8) - 4 - size);
129
130       fprintf (file, "\tld.64\t.sp,.r4\n\texit\t0\n");
131     }
132   else
133     {
134       for (regno = 0; regno < FIRST_PSEUDO_REGISTER; ++regno)
135         if (regs_ever_live[regno] && !call_used_regs[regno])
136           fprintf (file, "\tld.64\t.r%d,[.sp]%d\n", regno, (cnt += 8) - 12);
137
138       fprintf (file, "\texit\t%d\n", size + cnt);
139     }
140 }
141
142 /* type is the index into the above table */
143 /* s is "" for signed, or "u" for unsigned */
144 const char *
145 cmp_jmp (s, type, where)
146      const char *s;
147      int type;
148      rtx where;
149 {
150     rtx br_ops[3];
151     char template[50];
152     const char *f = "";
153     const char *bits = "64";
154     if (GET_MODE (cmp_op0) == SFmode) f = "f", bits = "32";
155     if (GET_MODE (cmp_op0) == DFmode) f = "f";
156     br_ops[0] = where;
157     br_ops[1] = cmp_op0;
158     br_ops[2] = cmp_op1;
159     if (cmp_op1)
160         sprintf(template, "%scmp%s.br.%s\t%%1,%%2:j%s\t%%l0",
161                 f, s, bits, cmp_tab[type]);
162     else if (*f)
163         sprintf(template, "fcmp.br.%s\t%%1,=0:j%s\t%%l0",
164                 bits, cmp_tab[type]);
165     else if (*s) /* can turn the below in to a jmp ... */
166         sprintf(template, "cmpu.br.64\t%%1,=0:j%s\t%%l0", s);
167     else
168         sprintf(template, "jmp.%s\t%%1,%%l0", cmp_tab[type+1]);
169     output_asm_insn(template, br_ops);
170     return "";
171 }
172
173 const char *
174 cmp_set (s, type, reg)
175      const char *s, *type;
176      rtx reg;
177 {
178     rtx br_ops[3];
179     char template[50];
180     const char *f = "";
181     const char *bits = "64";
182     if (GET_MODE (cmp_op0) == SFmode) f = "f", bits = "32";
183     else if (GET_MODE (cmp_op0) == DFmode) f = "f";
184     else if (GET_MODE (cmp_op0) == SImode) bits = "32";
185     else if (GET_MODE (cmp_op0) == HImode) bits = "16";
186     else if (GET_MODE (cmp_op0) == QImode) bits = "8";
187     br_ops[0] = reg;
188     br_ops[1] = cmp_op0;
189     br_ops[2] = cmp_op1;
190     if (cmp_op1)
191         sprintf(template, "%scmp%s.%s\t%%0,%%1,%%2:%s",
192                 f, s, bits, type);
193     else
194         sprintf(template, "%scmp%s.%s\t%%0,%%1,=0:%s",
195                 f, s, bits, type);
196     output_asm_insn(template, br_ops);
197     return "";
198 }
199
200 void
201 print_operand_address (file, addr)
202      FILE *file;
203      register rtx addr;
204 {
205   register rtx reg1, reg2, breg, ireg;
206   rtx offset;
207
208   switch (GET_CODE (addr))
209     {
210
211     case MEM:
212       if (GET_CODE (XEXP (addr, 0)) == REG)
213         fprintf (file, "%s", reg_names[REGNO (addr)]);
214       else abort();
215       break;
216
217     case REG:
218       fprintf (file, "[%s]", reg_names[REGNO (addr)]);
219       break;
220
221     case PLUS:
222       reg1 = 0; reg2 = 0;
223       ireg = 0; breg = 0;
224       offset = 0;
225       if (GET_CODE (XEXP (addr, 0)) == REG)
226         {
227           offset = XEXP (addr, 1);
228           addr = XEXP (addr, 0);
229         }
230       else if (GET_CODE (XEXP (addr, 1)) == REG)
231         {
232           offset = XEXP (addr, 0);
233           addr = XEXP (addr, 1);
234         }
235       fprintf (file, "[%s]", reg_names[REGNO (addr)]);
236       output_address (offset);
237       break;
238
239     default:
240       output_addr_const (file, addr);
241     }
242 }