1 /* FR30 specific functions.
2 Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions.
5 This file is part of GCC.
7 GCC 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 GCC 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 GCC; 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 "coretypes.h"
30 #include "hard-reg-set.h"
32 #include "insn-config.h"
33 #include "conditions.h"
34 #include "insn-attr.h"
46 #include "target-def.h"
49 /*{{{ Function Prologues & Epilogues */
51 /* Define the information needed to generate branch and scc insns. This is
52 stored from the compare operation. */
54 struct rtx_def * fr30_compare_op0;
55 struct rtx_def * fr30_compare_op1;
57 /* The FR30 stack looks like this:
59 Before call After call
61 +-----------------------+ +-----------------------+ high
63 | local variables, | | local variables, |
64 | reg save area, etc. | | reg save area, etc. |
66 +-----------------------+ +-----------------------+
68 | args to the func that | | args to this func. |
69 | is being called that | | |
70 SP ->| do not fit in regs | | |
71 +-----------------------+ +-----------------------+
72 | args that used to be | \
73 | in regs; only created | | pretend_size
74 AP-> | for vararg funcs | /
75 +-----------------------+
77 | register save area | |
79 +-----------------------+ | reg_size
81 +-----------------------+ |
82 FP ->| previous frame ptr | /
83 +-----------------------+
85 | local variables | | var_size
87 +-----------------------+
89 low | room for args to | |
90 memory | other funcs called | | args_size
93 +-----------------------+
95 Note, AP is a fake hard register. It will be eliminated in favor of
96 SP or FP as appropriate.
98 Note, Some or all of the stack sections above may be omitted if they
101 /* Structure to be filled in by fr30_compute_frame_size() with register
102 save masks, and offsets for the current function. */
103 struct fr30_frame_info
105 unsigned int total_size; /* # Bytes that the entire frame takes up. */
106 unsigned int pretend_size; /* # Bytes we push and pretend caller did. */
107 unsigned int args_size; /* # Bytes that outgoing arguments take up. */
108 unsigned int reg_size; /* # Bytes needed to store regs. */
109 unsigned int var_size; /* # Bytes that variables take up. */
110 unsigned int frame_size; /* # Bytes in current frame. */
111 unsigned int gmask; /* Mask of saved registers. */
112 unsigned int save_fp; /* Nonzero if frame pointer must be saved. */
113 unsigned int save_rp; /* Nonzero if return pointer must be saved. */
114 int initialised; /* Nonzero if frame size already calculated. */
117 /* Current frame information calculated by fr30_compute_frame_size(). */
118 static struct fr30_frame_info current_frame_info;
120 /* Zero structure to initialize current_frame_info. */
121 static struct fr30_frame_info zero_frame_info;
123 static rtx fr30_pass_by_reference (tree, tree);
124 static rtx fr30_pass_by_value (tree, tree);
126 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
127 #define RETURN_POINTER_MASK (1 << (RETURN_POINTER_REGNUM))
129 /* Tell prologue and epilogue if register REGNO should be saved / restored.
130 The return address and frame pointer are treated separately.
131 Don't consider them here. */
132 #define MUST_SAVE_REGISTER(regno) \
133 ( (regno) != RETURN_POINTER_REGNUM \
134 && (regno) != FRAME_POINTER_REGNUM \
135 && regs_ever_live [regno] \
136 && ! call_used_regs [regno] )
138 #define MUST_SAVE_FRAME_POINTER (regs_ever_live [FRAME_POINTER_REGNUM] || frame_pointer_needed)
139 #define MUST_SAVE_RETURN_POINTER (regs_ever_live [RETURN_POINTER_REGNUM] || current_function_profile)
141 #if UNITS_PER_WORD == 4
142 #define WORD_ALIGN(SIZE) (((SIZE) + 3) & ~3)
145 /* Initialize the GCC target structure. */
146 #undef TARGET_ASM_ALIGNED_HI_OP
147 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
148 #undef TARGET_ASM_ALIGNED_SI_OP
149 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
151 struct gcc_target targetm = TARGET_INITIALIZER;
153 /* Returns the number of bytes offset between FROM_REG and TO_REG
154 for the current function. As a side effect it fills in the
155 current_frame_info structure, if the data is available. */
157 fr30_compute_frame_size (from_reg, to_reg)
162 unsigned int return_value;
163 unsigned int var_size;
164 unsigned int args_size;
165 unsigned int pretend_size;
166 unsigned int reg_size;
169 var_size = WORD_ALIGN (get_frame_size ());
170 args_size = WORD_ALIGN (current_function_outgoing_args_size);
171 pretend_size = current_function_pretend_args_size;
176 /* Calculate space needed for registers. */
177 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno ++)
179 if (MUST_SAVE_REGISTER (regno))
181 reg_size += UNITS_PER_WORD;
186 current_frame_info.save_fp = MUST_SAVE_FRAME_POINTER;
187 current_frame_info.save_rp = MUST_SAVE_RETURN_POINTER;
189 reg_size += (current_frame_info.save_fp + current_frame_info.save_rp)
192 /* Save computed information. */
193 current_frame_info.pretend_size = pretend_size;
194 current_frame_info.var_size = var_size;
195 current_frame_info.args_size = args_size;
196 current_frame_info.reg_size = reg_size;
197 current_frame_info.frame_size = args_size + var_size;
198 current_frame_info.total_size = args_size + var_size + reg_size + pretend_size;
199 current_frame_info.gmask = gmask;
200 current_frame_info.initialised = reload_completed;
202 /* Calculate the required distance. */
205 if (to_reg == STACK_POINTER_REGNUM)
206 return_value += args_size + var_size;
208 if (from_reg == ARG_POINTER_REGNUM)
209 return_value += reg_size;
214 /* Called after register allocation to add any instructions needed for the
215 prologue. Using a prologue insn is favored compared to putting all of the
216 instructions in output_function_prologue(), since it allows the scheduler
217 to intermix instructions with the saves of the caller saved registers. In
218 some cases, it might be necessary to emit a barrier instruction as the last
219 insn to prevent such scheduling. */
222 fr30_expand_prologue ()
227 if (! current_frame_info.initialised)
228 fr30_compute_frame_size (0, 0);
230 /* This cases shouldn't happen. Catch it now. */
231 if (current_frame_info.total_size == 0
232 && current_frame_info.gmask)
235 /* Allocate space for register arguments if this is a variadic function. */
236 if (current_frame_info.pretend_size)
238 int regs_to_save = current_frame_info.pretend_size / UNITS_PER_WORD;
240 /* Push argument registers into the pretend arg area. */
241 for (regno = FIRST_ARG_REGNUM + FR30_NUM_ARG_REGS; regno --, regs_to_save --;)
243 insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));
244 RTX_FRAME_RELATED_P (insn) = 1;
248 if (current_frame_info.gmask)
250 /* Save any needed call-saved regs. */
251 for (regno = STACK_POINTER_REGNUM; regno--;)
253 if ((current_frame_info.gmask & (1 << regno)) != 0)
255 insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode, regno)));
256 RTX_FRAME_RELATED_P (insn) = 1;
261 /* Save return address if necessary. */
262 if (current_frame_info.save_rp)
264 insn = emit_insn (gen_movsi_push (gen_rtx_REG (Pmode,
265 RETURN_POINTER_REGNUM)));
266 RTX_FRAME_RELATED_P (insn) = 1;
269 /* Save old frame pointer and create new one, if necessary. */
270 if (current_frame_info.save_fp)
272 if (current_frame_info.frame_size < ((1 << 10) - UNITS_PER_WORD))
274 int enter_size = current_frame_info.frame_size + UNITS_PER_WORD;
277 insn = emit_insn (gen_enter_func (GEN_INT (enter_size)));
278 RTX_FRAME_RELATED_P (insn) = 1;
280 pattern = PATTERN (insn);
282 /* Also mark all 3 subexpressions as RTX_FRAME_RELATED_P. */
283 if (GET_CODE (pattern) == PARALLEL)
286 for (x = XVECLEN (pattern, 0); x--;)
288 rtx part = XVECEXP (pattern, 0, x);
290 /* One of the insns in the ENTER pattern updates the
291 frame pointer. If we do not actually need the frame
292 pointer in this function then this is a side effect
293 rather than a desired effect, so we do not mark that
294 insn as being related to the frame set up. Doing this
295 allows us to compile the crash66.C test file in the
297 if (! frame_pointer_needed
298 && GET_CODE (part) == SET
299 && REGNO (SET_DEST (part)) == HARD_FRAME_POINTER_REGNUM)
300 RTX_FRAME_RELATED_P (part) = 0;
302 RTX_FRAME_RELATED_P (part) = 1;
308 insn = emit_insn (gen_movsi_push (frame_pointer_rtx));
309 RTX_FRAME_RELATED_P (insn) = 1;
311 if (frame_pointer_needed)
313 insn = emit_insn (gen_movsi (frame_pointer_rtx, stack_pointer_rtx));
314 RTX_FRAME_RELATED_P (insn) = 1;
319 /* Allocate the stack frame. */
320 if (current_frame_info.frame_size == 0)
321 ; /* Nothing to do. */
322 else if (current_frame_info.save_fp
323 && current_frame_info.frame_size < ((1 << 10) - UNITS_PER_WORD))
324 ; /* Nothing to do. */
325 else if (current_frame_info.frame_size <= 512)
327 insn = emit_insn (gen_add_to_stack (GEN_INT (- current_frame_info.frame_size)));
328 RTX_FRAME_RELATED_P (insn) = 1;
332 rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
333 insn = emit_insn (gen_movsi (tmp, GEN_INT (current_frame_info.frame_size)));
334 RTX_FRAME_RELATED_P (insn) = 1;
335 insn = emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
336 RTX_FRAME_RELATED_P (insn) = 1;
339 if (current_function_profile)
340 emit_insn (gen_blockage ());
343 /* Called after register allocation to add any instructions needed for the
344 epilogue. Using an epilogue insn is favored compared to putting all of the
345 instructions in output_function_epilogue(), since it allows the scheduler
346 to intermix instructions with the restores of the caller saved registers.
347 In some cases, it might be necessary to emit a barrier instruction as the
348 first insn to prevent such scheduling. */
350 fr30_expand_epilogue ()
354 /* Perform the inversion operations of the prologue. */
355 if (! current_frame_info.initialised)
358 /* Pop local variables and arguments off the stack.
359 If frame_pointer_needed is TRUE then the frame pointer register
360 has actually been used as a frame pointer, and we can recover
361 the stack pointer from it, otherwise we must unwind the stack
363 if (current_frame_info.frame_size > 0)
365 if (current_frame_info.save_fp && frame_pointer_needed)
367 emit_insn (gen_leave_func ());
368 current_frame_info.save_fp = 0;
370 else if (current_frame_info.frame_size <= 508)
371 emit_insn (gen_add_to_stack
372 (GEN_INT (current_frame_info.frame_size)));
375 rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
376 emit_insn (gen_movsi (tmp, GEN_INT (current_frame_info.frame_size)));
377 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
381 if (current_frame_info.save_fp)
382 emit_insn (gen_movsi_pop (frame_pointer_rtx));
384 /* Pop all the registers that were pushed. */
385 if (current_frame_info.save_rp)
386 emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode, RETURN_POINTER_REGNUM)));
388 for (regno = 0; regno < STACK_POINTER_REGNUM; regno ++)
389 if (current_frame_info.gmask & (1 << regno))
390 emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode, regno)));
392 if (current_frame_info.pretend_size)
393 emit_insn (gen_add_to_stack (GEN_INT (current_frame_info.pretend_size)));
395 /* Reset state info for each function. */
396 current_frame_info = zero_frame_info;
398 emit_jump_insn (gen_return_from_func ());
401 /* Do any needed setup for a variadic function. We must create a register
402 parameter block, and then copy any anonymous arguments, plus the last
403 named argument, from registers into memory. * copying actually done in
404 fr30_expand_prologue().
406 ARG_REGS_USED_SO_FAR has *not* been updated for the last named argument
407 which has type TYPE and mode MODE, and we rely on this fact. */
409 fr30_setup_incoming_varargs (arg_regs_used_so_far, int_mode, type, pretend_size)
410 CUMULATIVE_ARGS arg_regs_used_so_far;
412 tree type ATTRIBUTE_UNUSED;
415 enum machine_mode mode = (enum machine_mode)int_mode;
419 /* All BLKmode values are passed by reference. */
423 #if STRICT_ARGUMENT_NAMING
424 /* If STRICT_ARGUMENT_NAMING is true then the last named
425 arg must not be treated as an anonymous arg. */
426 arg_regs_used_so_far += fr30_num_arg_regs (int_mode, type);
429 size = FR30_NUM_ARG_REGS - arg_regs_used_so_far;
434 * pretend_size = (size * UNITS_PER_WORD);
438 /*{{{ Printing operands */
440 /* Print a memory address as an operand to reference that memory location. */
443 fr30_print_operand_address (stream, address)
447 switch (GET_CODE (address))
450 output_addr_const (stream, address);
454 fprintf (stderr, "code = %x\n", GET_CODE (address));
456 output_operand_lossage ("fr30_print_operand_address: unhandled address");
461 /* Print an operand. */
464 fr30_print_operand (file, x, code)
474 /* Output a :D if this instruction is delayed. */
475 if (dbr_sequence_length () != 0)
480 /* Compute the register name of the second register in a hi/lo
482 if (GET_CODE (x) != REG)
483 output_operand_lossage ("fr30_print_operand: unrecognized %%p code");
485 fprintf (file, "r%d", REGNO (x) + 1);
489 /* Convert GCC's comparison operators into FR30 comparison codes. */
490 switch (GET_CODE (x))
492 case EQ: fprintf (file, "eq"); break;
493 case NE: fprintf (file, "ne"); break;
494 case LT: fprintf (file, "lt"); break;
495 case LE: fprintf (file, "le"); break;
496 case GT: fprintf (file, "gt"); break;
497 case GE: fprintf (file, "ge"); break;
498 case LTU: fprintf (file, "c"); break;
499 case LEU: fprintf (file, "ls"); break;
500 case GTU: fprintf (file, "hi"); break;
501 case GEU: fprintf (file, "nc"); break;
503 output_operand_lossage ("fr30_print_operand: unrecognized %%b code");
509 /* Convert GCC's comparison operators into the complimentary FR30
511 switch (GET_CODE (x))
513 case EQ: fprintf (file, "ne"); break;
514 case NE: fprintf (file, "eq"); break;
515 case LT: fprintf (file, "ge"); break;
516 case LE: fprintf (file, "gt"); break;
517 case GT: fprintf (file, "le"); break;
518 case GE: fprintf (file, "lt"); break;
519 case LTU: fprintf (file, "nc"); break;
520 case LEU: fprintf (file, "hi"); break;
521 case GTU: fprintf (file, "ls"); break;
522 case GEU: fprintf (file, "c"); break;
524 output_operand_lossage ("fr30_print_operand: unrecognized %%B code");
530 /* Print a signed byte value as an unsigned value. */
531 if (GET_CODE (x) != CONST_INT)
532 output_operand_lossage ("fr30_print_operand: invalid operand to %%A code");
541 fprintf (file, HOST_WIDE_INT_PRINT_DEC, val);
546 if (GET_CODE (x) != CONST_INT
549 output_operand_lossage ("fr30_print_operand: invalid %%x code");
551 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) - 16);
555 if (GET_CODE (x) != CONST_DOUBLE)
556 output_operand_lossage ("fr30_print_operand: invalid %%F code");
561 real_to_decimal (str, CONST_DOUBLE_REAL_VALUE (x),
572 fprintf (stderr, "unknown code = %x\n", code);
573 output_operand_lossage ("fr30_print_operand: unknown code");
577 switch (GET_CODE (x))
580 fputs (reg_names [REGNO (x)], file);
586 switch (GET_CODE (x0))
589 if ((unsigned) REGNO (x0) >= ARRAY_SIZE (reg_names))
591 fprintf (file, "@%s", reg_names [REGNO (x0)]);
595 if (GET_CODE (XEXP (x0, 0)) != REG
596 || REGNO (XEXP (x0, 0)) < FRAME_POINTER_REGNUM
597 || REGNO (XEXP (x0, 0)) > STACK_POINTER_REGNUM
598 || GET_CODE (XEXP (x0, 1)) != CONST_INT)
600 fprintf (stderr, "bad INDEXed address:");
602 output_operand_lossage ("fr30_print_operand: unhandled MEM");
604 else if (REGNO (XEXP (x0, 0)) == FRAME_POINTER_REGNUM)
606 HOST_WIDE_INT val = INTVAL (XEXP (x0, 1));
607 if (val < -(1 << 9) || val > ((1 << 9) - 4))
609 fprintf (stderr, "frame INDEX out of range:");
611 output_operand_lossage ("fr30_print_operand: unhandled MEM");
613 fprintf (file, "@(r14, #" HOST_WIDE_INT_PRINT_DEC ")", val);
617 HOST_WIDE_INT val = INTVAL (XEXP (x0, 1));
618 if (val < 0 || val > ((1 << 6) - 4))
620 fprintf (stderr, "stack INDEX out of range:");
622 output_operand_lossage ("fr30_print_operand: unhandled MEM");
624 fprintf (file, "@(r15, #" HOST_WIDE_INT_PRINT_DEC ")", val);
633 fprintf (stderr, "bad MEM code = %x\n", GET_CODE (x0));
635 output_operand_lossage ("fr30_print_operand: unhandled MEM");
641 /* We handle SFmode constants here as output_addr_const doesn't. */
642 if (GET_MODE (x) == SFmode)
647 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
648 REAL_VALUE_TO_TARGET_SINGLE (d, l);
649 fprintf (file, "0x%08lx", l);
653 /* Fall through. Let output_addr_const deal with it. */
655 output_addr_const (file, x);
663 /*{{{ Function arguments */
665 /* Compute the number of word sized registers needed to hold a
666 function argument of mode INT_MODE and tree type TYPE. */
668 fr30_num_arg_regs (int_mode, type)
672 enum machine_mode mode = (enum machine_mode) int_mode;
675 if (MUST_PASS_IN_STACK (mode, type))
678 if (type && mode == BLKmode)
679 size = int_size_in_bytes (type);
681 size = GET_MODE_SIZE (mode);
683 return (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
686 /* Implements the FUNCTION_ARG_PARTIAL_NREGS macro.
687 Returns the number of argument registers required to hold *part* of
688 a parameter of machine mode MODE and tree type TYPE (which may be
689 NULL if the type is not known). If the argument fits entirely in
690 the argument registers, or entirely on the stack, then 0 is returned.
691 CUM is the number of argument registers already used by earlier
692 parameters to the function. */
695 fr30_function_arg_partial_nregs (cum, int_mode, type, named)
701 /* Unnamed arguments, ie those that are prototyped as ...
702 are always passed on the stack.
703 Also check here to see if all the argument registers are full. */
704 if (named == 0 || cum >= FR30_NUM_ARG_REGS)
707 /* Work out how many argument registers would be needed if this
708 parameter were to be passed entirely in registers. If there
709 are sufficient argument registers available (or if no registers
710 are needed because the parameter must be passed on the stack)
711 then return zero, as this parameter does not require partial
712 register, partial stack stack space. */
713 if (cum + fr30_num_arg_regs (int_mode, type) <= FR30_NUM_ARG_REGS)
716 /* Otherwise return the number of registers that would be used. */
717 return FR30_NUM_ARG_REGS - cum;
721 fr30_pass_by_reference (valist, type)
729 type_ptr = build_pointer_type (type);
730 type_ptr_ptr = build_pointer_type (type_ptr);
732 t = build (POSTINCREMENT_EXPR, va_list_type_node, valist, build_int_2 (UNITS_PER_WORD, 0));
733 TREE_SIDE_EFFECTS (t) = 1;
734 t = build1 (NOP_EXPR, type_ptr_ptr, t);
735 TREE_SIDE_EFFECTS (t) = 1;
736 t = build1 (INDIRECT_REF, type_ptr, t);
738 return expand_expr (t, NULL_RTX, Pmode, EXPAND_NORMAL);
742 fr30_pass_by_value (valist, type)
746 HOST_WIDE_INT size = int_size_in_bytes (type);
751 if ((size % UNITS_PER_WORD) == 0)
753 t = build (POSTINCREMENT_EXPR, va_list_type_node, valist, build_int_2 (size, 0));
754 TREE_SIDE_EFFECTS (t) = 1;
756 return expand_expr (t, NULL_RTX, Pmode, EXPAND_NORMAL);
759 rsize = (size + UNITS_PER_WORD - 1) & - UNITS_PER_WORD;
761 /* Care for bigendian correction on the aligned address. */
762 t = build (PLUS_EXPR, ptr_type_node, valist, build_int_2 (rsize - size, 0));
763 addr_rtx = expand_expr (t, NULL_RTX, Pmode, EXPAND_NORMAL);
764 addr_rtx = copy_to_reg (addr_rtx);
767 t = build (PLUS_EXPR, va_list_type_node, valist, build_int_2 (rsize, 0));
768 t = build (MODIFY_EXPR, va_list_type_node, valist, t);
769 TREE_SIDE_EFFECTS (t) = 1;
770 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
775 /* Implement `va_arg'. */
778 fr30_va_arg (valist, type)
784 if (AGGREGATE_TYPE_P (type))
785 return fr30_pass_by_reference (valist, type);
787 size = int_size_in_bytes (type);
789 if ((size % sizeof (int)) == 0
791 return fr30_pass_by_value (valist, type);
793 return fr30_pass_by_reference (valist, type);
797 /*{{{ Operand predicates */
800 #define Mmode enum machine_mode
803 /* Returns true if OPERAND is an integer value suitable for use in
804 an ADDSP instruction. */
806 stack_add_operand (operand, mode)
808 Mmode mode ATTRIBUTE_UNUSED;
811 (GET_CODE (operand) == CONST_INT
812 && INTVAL (operand) >= -512
813 && INTVAL (operand) <= 508
814 && ((INTVAL (operand) & 3) == 0));
817 /* Returns true if OPERAND is an integer value suitable for use in
818 an ADD por ADD2 instruction, or if it is a register. */
820 add_immediate_operand (operand, mode)
822 Mmode mode ATTRIBUTE_UNUSED;
825 (GET_CODE (operand) == REG
826 || (GET_CODE (operand) == CONST_INT
827 && INTVAL (operand) >= -16
828 && INTVAL (operand) <= 15));
831 /* Returns true if OPERAND is hard register in the range 8 - 15. */
833 high_register_operand (operand, mode)
835 Mmode mode ATTRIBUTE_UNUSED;
838 (GET_CODE (operand) == REG
839 && REGNO (operand) <= 15
840 && REGNO (operand) >= 8);
843 /* Returns true if OPERAND is hard register in the range 0 - 7. */
845 low_register_operand (operand, mode)
847 Mmode mode ATTRIBUTE_UNUSED;
850 (GET_CODE (operand) == REG
851 && REGNO (operand) <= 7);
854 /* Returns true if OPERAND is suitable for use in a CALL insn. */
856 call_operand (operand, mode)
858 Mmode mode ATTRIBUTE_UNUSED;
860 return (GET_CODE (operand) == MEM
861 && (GET_CODE (XEXP (operand, 0)) == SYMBOL_REF
862 || GET_CODE (XEXP (operand, 0)) == REG));
865 /* Returns TRUE if OP is a valid operand of a DImode operation. */
867 di_operand (op, mode)
871 if (register_operand (op, mode))
874 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && GET_MODE (op) != DImode)
877 if (GET_CODE (op) == SUBREG)
878 op = SUBREG_REG (op);
880 switch (GET_CODE (op))
887 return memory_address_p (DImode, XEXP (op, 0));
894 /* Returns TRUE if OP is a DImode register or MEM. */
896 nonimmediate_di_operand (op, mode)
900 if (register_operand (op, mode))
903 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && GET_MODE (op) != DImode)
906 if (GET_CODE (op) == SUBREG)
907 op = SUBREG_REG (op);
909 if (GET_CODE (op) == MEM)
910 return memory_address_p (DImode, XEXP (op, 0));
915 /* Returns true iff all the registers in the operands array
916 are in descending or ascending order. */
918 fr30_check_multiple_regs (operands, num_operands, descending)
925 unsigned int prev_regno = 0;
927 while (num_operands --)
929 if (GET_CODE (operands [num_operands]) != REG)
932 if (REGNO (operands [num_operands]) < prev_regno)
935 prev_regno = REGNO (operands [num_operands]);
940 unsigned int prev_regno = CONDITION_CODE_REGNUM;
942 while (num_operands --)
944 if (GET_CODE (operands [num_operands]) != REG)
947 if (REGNO (operands [num_operands]) > prev_regno)
950 prev_regno = REGNO (operands [num_operands]);
958 fr30_const_double_is_zero (operand)
963 if (operand == NULL || GET_CODE (operand) != CONST_DOUBLE)
966 REAL_VALUE_FROM_CONST_DOUBLE (d, operand);
968 return REAL_VALUES_EQUAL (d, dconst0);
972 /*{{{ Instruction Output Routines */
974 /* Output a double word move.
975 It must be REG<-REG, REG<-MEM, MEM<-REG or REG<-CONST.
976 On the FR30 we are constrained by the fact that it does not
977 support offsetable addresses, and so we have to load the
978 address of the secnd word into the second destination register
979 before we can use it. */
982 fr30_move_double (operands)
985 rtx src = operands[1];
986 rtx dest = operands[0];
987 enum rtx_code src_code = GET_CODE (src);
988 enum rtx_code dest_code = GET_CODE (dest);
989 enum machine_mode mode = GET_MODE (dest);
994 if (dest_code == REG)
998 int reverse = (REGNO (dest) == REGNO (src) + 1);
1000 /* We normally copy the low-numbered register first. However, if
1001 the first register of operand 0 is the same as the second register
1002 of operand 1, we must copy in the opposite order. */
1003 emit_insn (gen_rtx_SET (VOIDmode,
1004 operand_subword (dest, reverse, TRUE, mode),
1005 operand_subword (src, reverse, TRUE, mode)));
1007 emit_insn (gen_rtx_SET (VOIDmode,
1008 operand_subword (dest, !reverse, TRUE, mode),
1009 operand_subword (src, !reverse, TRUE, mode)));
1011 else if (src_code == MEM)
1013 rtx addr = XEXP (src, 0);
1014 int dregno = REGNO (dest);
1019 /* If the high-address word is used in the address, we
1020 must load it last. Otherwise, load it first. */
1021 int reverse = (refers_to_regno_p (dregno, dregno + 1, addr, 0) != 0);
1023 if (GET_CODE (addr) != REG)
1026 dest0 = operand_subword (dest, reverse, TRUE, mode);
1027 dest1 = operand_subword (dest, !reverse, TRUE, mode);
1031 emit_insn (gen_rtx_SET (VOIDmode, dest1,
1032 adjust_address (src, SImode, 0)));
1033 emit_insn (gen_rtx_SET (SImode, dest0,
1034 gen_rtx_REG (SImode, REGNO (addr))));
1035 emit_insn (gen_rtx_SET (SImode, dest0,
1036 plus_constant (dest0, UNITS_PER_WORD)));
1038 new_mem = gen_rtx_MEM (SImode, dest0);
1039 MEM_COPY_ATTRIBUTES (new_mem, src);
1041 emit_insn (gen_rtx_SET (VOIDmode, dest0, new_mem));
1045 emit_insn (gen_rtx_SET (VOIDmode, dest0,
1046 adjust_address (src, SImode, 0)));
1047 emit_insn (gen_rtx_SET (SImode, dest1,
1048 gen_rtx_REG (SImode, REGNO (addr))));
1049 emit_insn (gen_rtx_SET (SImode, dest1,
1050 plus_constant (dest1, UNITS_PER_WORD)));
1052 new_mem = gen_rtx_MEM (SImode, dest1);
1053 MEM_COPY_ATTRIBUTES (new_mem, src);
1055 emit_insn (gen_rtx_SET (VOIDmode, dest1, new_mem));
1058 else if (src_code == CONST_INT || src_code == CONST_DOUBLE)
1061 split_double (src, &words[0], &words[1]);
1062 emit_insn (gen_rtx_SET (VOIDmode,
1063 operand_subword (dest, 0, TRUE, mode),
1066 emit_insn (gen_rtx_SET (VOIDmode,
1067 operand_subword (dest, 1, TRUE, mode),
1071 else if (src_code == REG && dest_code == MEM)
1073 rtx addr = XEXP (dest, 0);
1077 if (GET_CODE (addr) != REG)
1080 src0 = operand_subword (src, 0, TRUE, mode);
1081 src1 = operand_subword (src, 1, TRUE, mode);
1083 emit_insn (gen_rtx_SET (VOIDmode, adjust_address (dest, SImode, 0),
1086 if (REGNO (addr) == STACK_POINTER_REGNUM
1087 || REGNO (addr) == FRAME_POINTER_REGNUM)
1088 emit_insn (gen_rtx_SET (VOIDmode,
1089 adjust_address (dest, SImode, UNITS_PER_WORD),
1095 /* We need a scratch register to hold the value of 'address + 4'.
1096 We ought to allow gcc to find one for us, but for now, just
1097 push one of the source registers. */
1098 emit_insn (gen_movsi_push (src0));
1099 emit_insn (gen_movsi_internal (src0, addr));
1100 emit_insn (gen_addsi_small_int (src0, src0, GEN_INT (UNITS_PER_WORD)));
1102 new_mem = gen_rtx_MEM (SImode, src0);
1103 MEM_COPY_ATTRIBUTES (new_mem, dest);
1105 emit_insn (gen_rtx_SET (VOIDmode, new_mem, src1));
1106 emit_insn (gen_movsi_pop (src0));
1110 /* This should have been prevented by the constraints on movdi_insn. */
1119 /* Local Variables: */
1120 /* folded-file: t */