1 /* Subroutines for insn-output.c for Clipper
2 Copyright (C) 1987, 1988, 1991, 1997 Free Software Foundation, Inc.
3 Contributed by Holger Teutsch (holger@hotbso.rhein-main.de)
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, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 #include "hard-reg-set.h"
28 #include "insn-config.h"
29 #include "conditions.h"
30 #include "insn-flags.h"
32 #include "insn-attr.h"
39 extern char regs_ever_live
[];
41 extern int frame_pointer_needed
;
43 static int frame_size
;
46 * compute size of a clipper stack frame where 'lsize' is the required
47 * space for local variables.
51 clipper_frame_size (lsize
)
54 int i
,size
; /* total size of frame */
56 save_size
= 0; /* compute size for reg saves */
58 for (i
= 16; i
< 32; i
++)
59 if (regs_ever_live
[i
] && !call_used_regs
[i
])
62 for (i
= 0; i
< 16; i
++)
63 if (regs_ever_live
[i
] && !call_used_regs
[i
])
66 size
= lsize
+ save_size
;
68 size
= (size
+ 7) & ~7; /* align to 64 Bit */
73 * prologue and epilogue output
74 * function is entered with pc pushed, i.e. stack is 32 bit aligned
76 * current_function_args_size == 0 means that the current function's args
77 * are passed totally in registers i.e fp is not used as ap.
78 * If frame_size is also 0 the current function does not push anything and
79 * can run with misaligned stack -> subq $4,sp / add $4,sp on entry and exit
84 output_function_prologue (file
, lsize
)
86 int lsize
; /* size for locals */
91 frame_size
= size
= clipper_frame_size (lsize
);
93 if (frame_pointer_needed
)
95 fputs ("\tpushw fp,sp\n", file
);
96 fputs ("\tmovw sp,fp\n", file
);
98 else if (size
!= 0 || current_function_args_size
!= 0)
100 size
+= 4; /* keep stack aligned */
101 frame_size
= size
; /* must push data or access args */
107 fprintf (file
, "\tsubq $%d,sp\n", size
);
109 fprintf (file
, "\tsubi $%d,sp\n", size
);
111 /* register save slots are relative to sp, because we have small positive
112 displacements and this works whether we have a frame pointer or not */
115 for (i
= 16; i
< 32; i
++)
116 if (regs_ever_live
[i
] && !call_used_regs
[i
])
119 fprintf (file
, "\tstord f%d,(sp)\n", i
-16);
121 fprintf (file
, "\tstord f%d,%d(sp)\n", i
-16, offset
);
125 for (i
= 0; i
< 16; i
++)
126 if (regs_ever_live
[i
] && !call_used_regs
[i
])
129 fprintf (file
, "\tstorw r%d,(sp)\n", i
);
131 fprintf (file
, "\tstorw r%d,%d(sp)\n", i
, offset
);
138 output_function_epilogue (file
, size
)
140 int size
; /* ignored */
144 if (frame_pointer_needed
)
146 offset
= -frame_size
;
148 for (i
= 16; i
< 32; i
++)
149 if (regs_ever_live
[i
] && !call_used_regs
[i
])
151 fprintf (file
, "\tloadd %d(fp),f%d\n", offset
, i
-16);
155 for (i
= 0; i
< 16; i
++)
156 if (regs_ever_live
[i
] && !call_used_regs
[i
])
158 fprintf (file
, "\tloadw %d(fp),r%d\n", offset
, i
);
162 fputs ("\tmovw fp,sp\n\tpopw sp,fp\n\tret sp\n",
166 else /* no frame pointer */
170 for (i
= 16; i
< 32; i
++)
171 if (regs_ever_live
[i
] && !call_used_regs
[i
])
174 fprintf (file
, "\tloadd (sp),f%d\n", i
-16);
176 fprintf (file
, "\tloadd %d(sp),f%d\n", offset
, i
-16);
180 for (i
= 0; i
< 16; i
++)
181 if (regs_ever_live
[i
] && !call_used_regs
[i
])
184 fprintf (file
, "\tloadw (sp),r%d\n", i
);
186 fprintf (file
, "\tloadw %d(sp),r%d\n", offset
, i
);
193 fprintf (file
, "\taddq $%d,sp\n", frame_size
);
195 fprintf (file
, "\taddi $%d,sp\n", frame_size
);
198 fputs ("\tret sp\n", file
);
208 clipper_movstr (operands
)
211 rtx dst
,src
,cnt
,tmp
,top
,bottom
,xops
[3];
215 extern FILE *asm_out_file
;
219 /* don't change this operands[2]; gcc 2.3.3 doesn't honor clobber note */
220 align
= INTVAL (operands
[3]);
224 if (GET_CODE (operands
[2]) == CONST_INT
) /* fixed size move */
226 if ((fixed
= INTVAL (operands
[2])) <= 0)
230 output_asm_insn ("loadq %2,%5", operands
);
232 output_asm_insn ("loadi %2,%5", operands
);
237 bottom
= (rtx
)gen_label_rtx (); /* need a bottom label */
238 xops
[0] = cnt
; xops
[1] = bottom
;
239 output_asm_insn ("movw %2,%5", operands
); /* count is scratch reg 5 */
240 output_asm_insn ("brle %l1", xops
);
244 top
= (rtx
)gen_label_rtx (); /* top of loop label */
245 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "L", CODE_LABEL_NUMBER (top
));
248 xops
[0] = src
; xops
[1] = tmp
; xops
[2] = dst
;
250 if (fixed
&& (align
& 0x3) == 0) /* word aligned move with known size */
256 "loadw %a0,%1\n\taddq $4,%0\n\tstorw %1,%a2\n\taddq $4,%2",
259 xops1
[0] = cnt
; xops1
[1] = top
;
260 output_asm_insn ("subq $4,%0\n\tbrgt %l1", xops1
);
265 output_asm_insn ("loadh %a0,%1\n\tstorh %1,%a2", xops
);
267 output_asm_insn ("loadb 2%a0,%1\n\tstorb %1,2%a2", xops
);
271 output_asm_insn ("loadb %a0,%1\n\tstorb %1,%a2", xops
);
276 "loadb %a0,%1\n\taddq $1,%0\n\tstorb %1,%a2\n\taddq $1,%2",
279 xops
[0] = cnt
; xops
[1] = top
;
280 output_asm_insn ("subq $1,%0\n\tbrgt %l1", xops
);
284 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "L", CODE_LABEL_NUMBER (bottom
));
288 print_operand_address (file
, addr
)
295 switch (GET_CODE (addr
))
298 fprintf (file
, "(%s)", reg_names
[REGNO (addr
)]);
302 /* can be 'symbol + reg' or 'reg + reg' */
304 op0
= XEXP (addr
, 0);
305 op1
= XEXP (addr
, 1);
307 if (GET_CODE (op0
) == REG
&& GET_CODE (op1
) == REG
)
309 fprintf (file
, "[%s](%s)",
310 reg_names
[REGNO (op0
)], reg_names
[REGNO (op1
)]);
314 if (GET_CODE (op0
) == REG
&& CONSTANT_ADDRESS_P (op1
))
316 output_addr_const (file
, op1
);
317 fprintf (file
, "(%s)", reg_names
[REGNO (op0
)]);
321 if (GET_CODE (op1
) == REG
&& CONSTANT_ADDRESS_P (op0
))
323 output_addr_const (file
, op0
);
324 fprintf (file
, "(%s)", reg_names
[REGNO (op1
)]);
327 abort (); /* Oh no */
330 output_addr_const (file
, addr
);
339 switch (GET_CODE (op
))
368 /* Do what is necessary for `va_start'. The argument is ignored;
369 We fill in an initial va_list. A pointer to this constructor
374 clipper_builtin_saveregs (arglist
)
377 extern int current_function_varargs
;
378 rtx block
, addr
, argsize
, scratch
, r0_addr
,r1_addr
,f0_addr
,f1_addr
;
380 /* Allocate the va_list constructor + save area for r0,r1,f0,f1 */
382 block
= assign_stack_local (BLKmode
,
383 (6 + 6) * UNITS_PER_WORD
, 2 * BITS_PER_WORD
);
385 RTX_UNCHANGING_P (block
) = 1;
386 RTX_UNCHANGING_P (XEXP (block
, 0)) = 1;
388 addr
= copy_to_reg (XEXP (block
, 0));
390 f0_addr
= gen_rtx (PLUS
, Pmode
, addr
, GEN_INT (24));
391 f1_addr
= gen_rtx (PLUS
, Pmode
, addr
, GEN_INT (32));
392 r0_addr
= gen_rtx (PLUS
, Pmode
, addr
, GEN_INT (40));
393 r1_addr
= gen_rtx (PLUS
, Pmode
, addr
, GEN_INT (44));
396 /* Store float regs */
398 emit_move_insn (gen_rtx (MEM
, DFmode
, f0_addr
), gen_rtx (REG
, DFmode
, 16));
399 emit_move_insn (gen_rtx (MEM
, DFmode
, f1_addr
), gen_rtx (REG
, DFmode
, 17));
403 emit_move_insn (gen_rtx (MEM
, SImode
, r0_addr
), gen_rtx (REG
, SImode
, 0));
404 emit_move_insn (gen_rtx (MEM
, SImode
, r1_addr
), gen_rtx (REG
, SImode
, 1));
406 /* Store the arg pointer in the __va_stk member. */
408 emit_move_insn (gen_rtx (MEM
, SImode
, addr
),
409 copy_to_reg (virtual_incoming_args_rtx
));
412 /* now move addresses of the saved regs into the pointer array */
414 scratch
= gen_reg_rtx (Pmode
);
416 emit_move_insn (scratch
, r0_addr
);
417 emit_move_insn (gen_rtx (MEM
, SImode
,
418 gen_rtx (PLUS
, Pmode
, addr
,
422 emit_move_insn (scratch
, f0_addr
);
423 emit_move_insn (gen_rtx (MEM
, SImode
,
424 gen_rtx (PLUS
, Pmode
, addr
,
428 emit_move_insn (scratch
, r1_addr
);
429 emit_move_insn (gen_rtx (MEM
, SImode
,
430 gen_rtx (PLUS
, Pmode
, addr
,
434 emit_move_insn (scratch
, f1_addr
);
435 emit_move_insn (gen_rtx (MEM
, SImode
,
436 gen_rtx (PLUS
, Pmode
, addr
,
441 if (flag_check_memory_usage
)
443 emit_library_call (chkr_set_right_libfunc
, 1, VOIDmode
, 3,
445 GEN_INT (5 * GET_MODE_SIZE (SImode
)),
446 TYPE_MODE (sizetype
),
447 GEN_INT (MEMORY_USE_RW
),
448 TYPE_MODE (integer_type_node
));
450 emit_library_call (chkr_set_right_libfunc
, 1, VOIDmode
, 3,
452 GEN_INT (GET_MODE_SIZE (DFmode
)),
453 TYPE_MODE (sizetype
),
454 GEN_INT (MEMORY_USE_RW
),
455 TYPE_MODE (integer_type_node
));
456 emit_library_call (chkr_set_right_libfunc
, 1, VOIDmode
, 3,
458 GEN_INT (GET_MODE_SIZE (DFmode
)),
459 TYPE_MODE (sizetype
),
460 GEN_INT (MEMORY_USE_RW
),
461 TYPE_MODE (integer_type_node
));
462 emit_library_call (chkr_set_right_libfunc
, 1, VOIDmode
, 3,
464 GEN_INT (GET_MODE_SIZE (SImode
)),
465 TYPE_MODE (sizetype
),
466 GEN_INT (MEMORY_USE_RW
),
467 TYPE_MODE (integer_type_node
));
468 emit_library_call (chkr_set_right_libfunc
, 1, VOIDmode
, 3,
470 GEN_INT (GET_MODE_SIZE (SImode
)),
471 TYPE_MODE (sizetype
),
472 GEN_INT (MEMORY_USE_RW
),
473 TYPE_MODE (integer_type_node
));
476 /* Return the address of the va_list constructor, but don't put it in a
477 register. This fails when not optimizing and produces worse code when
479 return XEXP (block
, 0);
483 /* Return truth value of whether OP can be used as an word register
484 operand. Reject (SUBREG:SI (REG:SF )) */
487 int_reg_operand (op
, mode
)
489 enum machine_mode mode
;
491 return (register_operand (op
, mode
) &&
492 (GET_CODE (op
) != SUBREG
||
493 GET_MODE_CLASS (GET_MODE (SUBREG_REG (op
))) == MODE_INT
));
496 /* Return truth value of whether OP can be used as a float register
497 operand. Reject (SUBREG:SF (REG:SI )) )) */
500 fp_reg_operand (op
, mode
)
502 enum machine_mode mode
;
504 return (register_operand (op
, mode
) &&
505 (GET_CODE (op
) != SUBREG
||
506 GET_MODE_CLASS (GET_MODE (SUBREG_REG (op
))) == MODE_FLOAT
));