* target.h (asm_out.byte_op, asm_out.aligned_op, asm_out.unaligned_op,
[official-gcc.git] / gcc / config / elxsi / elxsi.c
blobc2b9c57e2d58e9cbafe5332f4233caf6bf5e8acd
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.
7 This file is part of GNU CC.
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.
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.
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. */
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"
37 extern const char *reg_names[];
38 rtx cmp_op0=0, cmp_op1=0;
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" };
45 static bool elxsi_assemble_integer PARAMS ((rtx, unsigned int, int));
46 static void elxsi_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
47 static void elxsi_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
49 /* Initialize the GCC target structure. */
50 #undef TARGET_ASM_BYTE_OP
51 #define TARGET_ASM_BYTE_OP NULL
52 #undef TARGET_ASM_ALIGNED_HI_OP
53 #define TARGET_ASM_ALIGNED_HI_OP NULL
54 #undef TARGET_ASM_ALIGNED_SI_OP
55 #define TARGET_ASM_ALIGNED_SI_OP NULL
56 #undef TARGET_ASM_INTEGER
57 #define TARGET_ASM_INTEGER elxsi_assemble_integer
59 #undef TARGET_ASM_FUNCTION_PROLOGUE
60 #define TARGET_ASM_FUNCTION_PROLOGUE elxsi_output_function_prologue
61 #undef TARGET_ASM_FUNCTION_EPILOGUE
62 #define TARGET_ASM_FUNCTION_EPILOGUE elxsi_output_function_epilogue
64 struct gcc_target targetm = TARGET_INITIALIZER;
66 /* Target hook for assembling integer objects. The ELXSI assembler
67 syntax uses a suffix to indicate the size of data, so we can't use
68 the usual string hooks. */
70 static bool
71 elxsi_assemble_integer (x, size, aligned_p)
72 rtx x;
73 unsigned int size;
74 int aligned_p;
76 if (aligned_p)
77 switch (size)
79 case 1:
80 case 2:
81 case 4:
82 fputs ("\t.data\t", asm_out_file);
83 output_addr_const (asm_out_file, x);
84 fprintf (asm_out_file, "{%d}\n", size * BITS_PER_UNIT);
85 return true;
87 return default_assemble_integer (x, size, aligned_p);
90 /* Generate the assembly code for function entry. FILE is a stdio
91 stream to output the code to. SIZE is an int: how many units of
92 temporary storage to allocate.
94 Refer to the array `regs_ever_live' to determine which registers to
95 save; `regs_ever_live[I]' is nonzero if register number I is ever
96 used in the function. This function is responsible for knowing
97 which registers should not be saved even if used. */
99 static void
100 elxsi_output_function_prologue (file, size)
101 FILE *file;
102 HOST_WIDE_INT size;
104 register int regno;
105 register int cnt = 0;
106 extern char call_used_regs[];
108 /* the below two lines are a HACK, and should be deleted, but
109 for now are very much needed (1.35) */
110 if (frame_pointer_needed)
111 regs_ever_live[14] = 1, call_used_regs[14] = 0;
113 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
114 if (regs_ever_live[regno] && !call_used_regs[regno])
115 cnt += 8;
117 if (size + cnt)
118 fprintf (file, "\tadd.64\t.sp,=%d\n", -size - cnt);
120 cnt = 0;
121 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
122 if (regs_ever_live[regno] && !call_used_regs[regno])
123 fprintf (file, "\tst.64\t.r%d,[.sp]%d\n", regno, (cnt += 8) - 12);
125 if (frame_pointer_needed)
126 fprintf (file, "\tadd.64\t.r14,.sp,=%d\n", size + cnt);
129 /* This function generates the assembly code for function exit.
130 Args are as for output_function_prologue ().
132 The function epilogue should not depend on the current stack
133 pointer! It should use the frame pointer only. This is mandatory
134 because of alloca; we also take advantage of it to omit stack
135 adjustments before returning. */
137 static void
138 elxsi_output_function_epilogue (file, size)
139 FILE *file;
140 HOST_WIDE_INT size;
142 register int regno;
143 register int cnt = 0;
144 extern char call_used_regs[];
146 /* this conditional is ONLY here because there is a BUG;
147 EXIT_IGNORE_STACK is ignored itself when the first part of
148 the condition is true! (at least in version 1.35) */
149 /* the 8*10 is for 64 bits of .r5 - .r14 */
150 if (current_function_calls_alloca || size >= (256 - 8 * 10))
152 /* use .r4 as a temporary! Ok for now.... */
153 fprintf (file, "\tld.64\t.r4,.r14\n");
155 for (regno = FIRST_PSEUDO_REGISTER-1; regno >= 0; --regno)
156 if (regs_ever_live[regno] && !call_used_regs[regno])
157 cnt += 8;
159 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; ++regno)
160 if (regs_ever_live[regno] && !call_used_regs[regno])
161 fprintf (file, "\tld.64\t.r%d,[.r14]%d\n", regno,
162 -((cnt -= 8) + 8) - 4 - size);
164 fprintf (file, "\tld.64\t.sp,.r4\n\texit\t0\n");
166 else
168 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; ++regno)
169 if (regs_ever_live[regno] && !call_used_regs[regno])
170 fprintf (file, "\tld.64\t.r%d,[.sp]%d\n", regno, (cnt += 8) - 12);
172 fprintf (file, "\texit\t%d\n", size + cnt);
176 /* type is the index into the above table */
177 /* s is "" for signed, or "u" for unsigned */
178 const char *
179 cmp_jmp (s, type, where)
180 const char *s;
181 int type;
182 rtx where;
184 rtx br_ops[3];
185 char template[50];
186 const char *f = "";
187 const char *bits = "64";
188 if (GET_MODE (cmp_op0) == SFmode) f = "f", bits = "32";
189 if (GET_MODE (cmp_op0) == DFmode) f = "f";
190 br_ops[0] = where;
191 br_ops[1] = cmp_op0;
192 br_ops[2] = cmp_op1;
193 if (cmp_op1)
194 sprintf(template, "%scmp%s.br.%s\t%%1,%%2:j%s\t%%l0",
195 f, s, bits, cmp_tab[type]);
196 else if (*f)
197 sprintf(template, "fcmp.br.%s\t%%1,=0:j%s\t%%l0",
198 bits, cmp_tab[type]);
199 else if (*s) /* can turn the below in to a jmp ... */
200 sprintf(template, "cmpu.br.64\t%%1,=0:j%s\t%%l0", s);
201 else
202 sprintf(template, "jmp.%s\t%%1,%%l0", cmp_tab[type+1]);
203 output_asm_insn(template, br_ops);
204 return "";
207 const char *
208 cmp_set (s, type, reg)
209 const char *s, *type;
210 rtx reg;
212 rtx br_ops[3];
213 char template[50];
214 const char *f = "";
215 const char *bits = "64";
216 if (GET_MODE (cmp_op0) == SFmode) f = "f", bits = "32";
217 else if (GET_MODE (cmp_op0) == DFmode) f = "f";
218 else if (GET_MODE (cmp_op0) == SImode) bits = "32";
219 else if (GET_MODE (cmp_op0) == HImode) bits = "16";
220 else if (GET_MODE (cmp_op0) == QImode) bits = "8";
221 br_ops[0] = reg;
222 br_ops[1] = cmp_op0;
223 br_ops[2] = cmp_op1;
224 if (cmp_op1)
225 sprintf(template, "%scmp%s.%s\t%%0,%%1,%%2:%s",
226 f, s, bits, type);
227 else
228 sprintf(template, "%scmp%s.%s\t%%0,%%1,=0:%s",
229 f, s, bits, type);
230 output_asm_insn(template, br_ops);
231 return "";
234 void
235 print_operand_address (file, addr)
236 FILE *file;
237 register rtx addr;
239 register rtx reg1, reg2, breg, ireg;
240 rtx offset;
242 switch (GET_CODE (addr))
245 case MEM:
246 if (GET_CODE (XEXP (addr, 0)) == REG)
247 fprintf (file, "%s", reg_names[REGNO (addr)]);
248 else abort();
249 break;
251 case REG:
252 fprintf (file, "[%s]", reg_names[REGNO (addr)]);
253 break;
255 case PLUS:
256 reg1 = 0; reg2 = 0;
257 ireg = 0; breg = 0;
258 offset = 0;
259 if (GET_CODE (XEXP (addr, 0)) == REG)
261 offset = XEXP (addr, 1);
262 addr = XEXP (addr, 0);
264 else if (GET_CODE (XEXP (addr, 1)) == REG)
266 offset = XEXP (addr, 0);
267 addr = XEXP (addr, 1);
269 fprintf (file, "[%s]", reg_names[REGNO (addr)]);
270 output_address (offset);
271 break;
273 default:
274 output_addr_const (file, addr);