gcc:
[official-gcc.git] / gcc / config / m68k / m68k.c
blob2af20a480c32609c229ce56825e27f4862feff2a
1 /* Subroutines for insn-output.c for Motorola 68000 family.
2 Copyright (C) 1987, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2003, 2004, 2005
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "tree.h"
28 #include "rtl.h"
29 #include "function.h"
30 #include "regs.h"
31 #include "hard-reg-set.h"
32 #include "real.h"
33 #include "insn-config.h"
34 #include "conditions.h"
35 #include "output.h"
36 #include "insn-attr.h"
37 #include "recog.h"
38 #include "toplev.h"
39 #include "expr.h"
40 #include "reload.h"
41 #include "tm_p.h"
42 #include "target.h"
43 #include "target-def.h"
44 #include "debug.h"
45 #include "flags.h"
47 enum reg_class regno_reg_class[] =
49 DATA_REGS, DATA_REGS, DATA_REGS, DATA_REGS,
50 DATA_REGS, DATA_REGS, DATA_REGS, DATA_REGS,
51 ADDR_REGS, ADDR_REGS, ADDR_REGS, ADDR_REGS,
52 ADDR_REGS, ADDR_REGS, ADDR_REGS, ADDR_REGS,
53 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
54 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
55 ADDR_REGS
59 /* The ASM_DOT macro allows easy string pasting to handle the differences
60 between MOTOROLA and MIT syntaxes in asm_fprintf(), which doesn't
61 support the %. option. */
62 #if MOTOROLA
63 # define ASM_DOT "."
64 # define ASM_DOTW ".w"
65 # define ASM_DOTL ".l"
66 #else
67 # define ASM_DOT ""
68 # define ASM_DOTW ""
69 # define ASM_DOTL ""
70 #endif
73 /* Structure describing stack frame layout. */
74 struct m68k_frame
76 /* Stack pointer to frame pointer offset. */
77 HOST_WIDE_INT offset;
79 /* Offset of FPU registers. */
80 HOST_WIDE_INT foffset;
82 /* Frame size in bytes (rounded up). */
83 HOST_WIDE_INT size;
85 /* Data and address register. */
86 int reg_no;
87 unsigned int reg_mask;
88 unsigned int reg_rev_mask;
90 /* FPU registers. */
91 int fpu_no;
92 unsigned int fpu_mask;
93 unsigned int fpu_rev_mask;
95 /* Offsets relative to ARG_POINTER. */
96 HOST_WIDE_INT frame_pointer_offset;
97 HOST_WIDE_INT stack_pointer_offset;
99 /* Function which the above information refers to. */
100 int funcdef_no;
103 /* Current frame information calculated by m68k_compute_frame_layout(). */
104 static struct m68k_frame current_frame;
106 static bool m68k_handle_option (size_t, const char *, int);
107 static rtx find_addr_reg (rtx);
108 static const char *singlemove_string (rtx *);
109 static void m68k_output_function_prologue (FILE *, HOST_WIDE_INT);
110 static void m68k_output_function_epilogue (FILE *, HOST_WIDE_INT);
111 #ifdef M68K_TARGET_COFF
112 static void m68k_coff_asm_named_section (const char *, unsigned int, tree);
113 #endif /* M68K_TARGET_COFF */
114 static void m68k_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
115 HOST_WIDE_INT, tree);
116 static rtx m68k_struct_value_rtx (tree, int);
117 static bool m68k_interrupt_function_p (tree func);
118 static tree m68k_handle_fndecl_attribute (tree *node, tree name,
119 tree args, int flags,
120 bool *no_add_attrs);
121 static void m68k_compute_frame_layout (void);
122 static bool m68k_save_reg (unsigned int regno, bool interrupt_handler);
123 static int const_int_cost (rtx);
124 static bool m68k_rtx_costs (rtx, int, int, int *);
127 /* Specify the identification number of the library being built */
128 const char *m68k_library_id_string = "_current_shared_library_a5_offset_";
130 /* Nonzero if the last compare/test insn had FP operands. The
131 sCC expanders peek at this to determine what to do for the
132 68060, which has no fsCC instructions. */
133 int m68k_last_compare_had_fp_operands;
135 /* Initialize the GCC target structure. */
137 #if INT_OP_GROUP == INT_OP_DOT_WORD
138 #undef TARGET_ASM_ALIGNED_HI_OP
139 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
140 #endif
142 #if INT_OP_GROUP == INT_OP_NO_DOT
143 #undef TARGET_ASM_BYTE_OP
144 #define TARGET_ASM_BYTE_OP "\tbyte\t"
145 #undef TARGET_ASM_ALIGNED_HI_OP
146 #define TARGET_ASM_ALIGNED_HI_OP "\tshort\t"
147 #undef TARGET_ASM_ALIGNED_SI_OP
148 #define TARGET_ASM_ALIGNED_SI_OP "\tlong\t"
149 #endif
151 #if INT_OP_GROUP == INT_OP_DC
152 #undef TARGET_ASM_BYTE_OP
153 #define TARGET_ASM_BYTE_OP "\tdc.b\t"
154 #undef TARGET_ASM_ALIGNED_HI_OP
155 #define TARGET_ASM_ALIGNED_HI_OP "\tdc.w\t"
156 #undef TARGET_ASM_ALIGNED_SI_OP
157 #define TARGET_ASM_ALIGNED_SI_OP "\tdc.l\t"
158 #endif
160 #undef TARGET_ASM_UNALIGNED_HI_OP
161 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
162 #undef TARGET_ASM_UNALIGNED_SI_OP
163 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
165 #undef TARGET_ASM_FUNCTION_PROLOGUE
166 #define TARGET_ASM_FUNCTION_PROLOGUE m68k_output_function_prologue
167 #undef TARGET_ASM_FUNCTION_EPILOGUE
168 #define TARGET_ASM_FUNCTION_EPILOGUE m68k_output_function_epilogue
170 #undef TARGET_ASM_OUTPUT_MI_THUNK
171 #define TARGET_ASM_OUTPUT_MI_THUNK m68k_output_mi_thunk
172 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
173 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
175 #undef TARGET_ASM_FILE_START_APP_OFF
176 #define TARGET_ASM_FILE_START_APP_OFF true
178 #undef TARGET_DEFAULT_TARGET_FLAGS
179 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | MASK_STRICT_ALIGNMENT)
180 #undef TARGET_HANDLE_OPTION
181 #define TARGET_HANDLE_OPTION m68k_handle_option
183 #undef TARGET_RTX_COSTS
184 #define TARGET_RTX_COSTS m68k_rtx_costs
186 #undef TARGET_ATTRIBUTE_TABLE
187 #define TARGET_ATTRIBUTE_TABLE m68k_attribute_table
189 #undef TARGET_PROMOTE_PROTOTYPES
190 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
192 #undef TARGET_STRUCT_VALUE_RTX
193 #define TARGET_STRUCT_VALUE_RTX m68k_struct_value_rtx
195 static const struct attribute_spec m68k_attribute_table[] =
197 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
198 { "interrupt_handler", 0, 0, true, false, false, m68k_handle_fndecl_attribute },
199 { NULL, 0, 0, false, false, false, NULL }
202 struct gcc_target targetm = TARGET_INITIALIZER;
204 /* These bits are controlled by all CPU selection options. Many options
205 also control MASK_68881, but some (notably -m68020) leave it alone. */
207 #define MASK_ALL_CPU_BITS \
208 (MASK_COLDFIRE | MASK_CF_HWDIV | MASK_68060 | MASK_68040 \
209 | MASK_68040_ONLY | MASK_68030 | MASK_68020 | MASK_BITFIELD)
211 /* Implement TARGET_HANDLE_OPTION. */
213 static bool
214 m68k_handle_option (size_t code, const char *arg, int value)
216 switch (code)
218 case OPT_m5200:
219 target_flags &= ~(MASK_ALL_CPU_BITS | MASK_68881);
220 target_flags |= MASK_5200;
221 return true;
223 case OPT_m5206e:
224 target_flags &= ~(MASK_ALL_CPU_BITS | MASK_68881);
225 target_flags |= MASK_5200 | MASK_CF_HWDIV;
226 return true;
228 case OPT_m528x:
229 target_flags &= ~(MASK_ALL_CPU_BITS | MASK_68881);
230 target_flags |= MASK_528x | MASK_CF_HWDIV;
231 return true;
233 case OPT_m5307:
234 target_flags &= ~(MASK_ALL_CPU_BITS | MASK_68881);
235 target_flags |= MASK_CFV3 | MASK_CF_HWDIV;
236 return true;
238 case OPT_m5407:
239 target_flags &= ~(MASK_ALL_CPU_BITS | MASK_68881);
240 target_flags |= MASK_CFV4 | MASK_CF_HWDIV;
241 return true;
243 case OPT_m68000:
244 case OPT_mc68000:
245 target_flags &= ~(MASK_ALL_CPU_BITS | MASK_68881);
246 return true;
248 case OPT_m68020:
249 case OPT_mc68020:
250 target_flags &= ~MASK_ALL_CPU_BITS;
251 target_flags |= MASK_68020 | MASK_BITFIELD;
252 return true;
254 case OPT_m68020_40:
255 target_flags &= ~MASK_ALL_CPU_BITS;
256 target_flags |= MASK_BITFIELD | MASK_68881 | MASK_68020 | MASK_68040;
257 return true;
259 case OPT_m68020_60:
260 target_flags &= ~MASK_ALL_CPU_BITS;
261 target_flags |= (MASK_BITFIELD | MASK_68881 | MASK_68020
262 | MASK_68040 | MASK_68060);
263 return true;
265 case OPT_m68030:
266 target_flags &= ~MASK_ALL_CPU_BITS;
267 target_flags |= MASK_68020 | MASK_68030 | MASK_BITFIELD;
268 return true;
270 case OPT_m68040:
271 target_flags &= ~MASK_ALL_CPU_BITS;
272 target_flags |= (MASK_68020 | MASK_68881 | MASK_BITFIELD
273 | MASK_68040_ONLY | MASK_68040);
274 return true;
276 case OPT_m68060:
277 target_flags &= ~MASK_ALL_CPU_BITS;
278 target_flags |= (MASK_68020 | MASK_68881 | MASK_BITFIELD
279 | MASK_68040_ONLY | MASK_68060);
280 return true;
282 case OPT_m68302:
283 target_flags &= ~(MASK_ALL_CPU_BITS | MASK_68881);
284 return true;
286 case OPT_m68332:
287 case OPT_mcpu32:
288 target_flags &= ~(MASK_ALL_CPU_BITS | MASK_68881);
289 target_flags |= MASK_68020;
290 return true;
292 case OPT_mshared_library_id_:
293 if (value > MAX_LIBRARY_ID)
294 error ("-mshared-library-id=%s is not between 0 and %d",
295 arg, MAX_LIBRARY_ID);
296 else
297 asprintf ((char **) &m68k_library_id_string, "%d", (value * -4) - 4);
298 return true;
300 default:
301 return true;
305 /* Sometimes certain combinations of command options do not make
306 sense on a particular target machine. You can define a macro
307 `OVERRIDE_OPTIONS' to take account of this. This macro, if
308 defined, is executed once just after all the command options have
309 been parsed.
311 Don't use this macro to turn on various extra optimizations for
312 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
314 void
315 override_options (void)
317 /* Sanity check to ensure that msep-data and mid-sahred-library are not
318 * both specified together. Doing so simply doesn't make sense.
320 if (TARGET_SEP_DATA && TARGET_ID_SHARED_LIBRARY)
321 error ("cannot specify both -msep-data and -mid-shared-library");
323 /* If we're generating code for a separate A5 relative data segment,
324 * we've got to enable -fPIC as well. This might be relaxable to
325 * -fpic but it hasn't been tested properly.
327 if (TARGET_SEP_DATA || TARGET_ID_SHARED_LIBRARY)
328 flag_pic = 2;
330 /* -fPIC uses 32-bit pc-relative displacements, which don't exist
331 until the 68020. */
332 if (!TARGET_68020 && !TARGET_COLDFIRE && (flag_pic == 2))
333 error ("-fPIC is not currently supported on the 68000 or 68010");
335 /* ??? A historic way of turning on pic, or is this intended to
336 be an embedded thing that doesn't have the same name binding
337 significance that it does on hosted ELF systems? */
338 if (TARGET_PCREL && flag_pic == 0)
339 flag_pic = 1;
341 /* Turn off function cse if we are doing PIC. We always want function call
342 to be done as `bsr foo@PLTPC', so it will force the assembler to create
343 the PLT entry for `foo'. Doing function cse will cause the address of
344 `foo' to be loaded into a register, which is exactly what we want to
345 avoid when we are doing PIC on svr4 m68k. */
346 if (flag_pic)
347 flag_no_function_cse = 1;
349 SUBTARGET_OVERRIDE_OPTIONS;
352 /* Return nonzero if FUNC is an interrupt function as specified by the
353 "interrupt_handler" attribute. */
354 static bool
355 m68k_interrupt_function_p(tree func)
357 tree a;
359 if (TREE_CODE (func) != FUNCTION_DECL)
360 return false;
362 a = lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func));
363 return (a != NULL_TREE);
366 /* Handle an attribute requiring a FUNCTION_DECL; arguments as in
367 struct attribute_spec.handler. */
368 static tree
369 m68k_handle_fndecl_attribute (tree *node, tree name,
370 tree args ATTRIBUTE_UNUSED,
371 int flags ATTRIBUTE_UNUSED,
372 bool *no_add_attrs)
374 if (TREE_CODE (*node) != FUNCTION_DECL)
376 warning (OPT_Wattributes, "%qs attribute only applies to functions",
377 IDENTIFIER_POINTER (name));
378 *no_add_attrs = true;
381 return NULL_TREE;
384 static void
385 m68k_compute_frame_layout (void)
387 int regno, saved;
388 unsigned int mask, rmask;
389 bool interrupt_handler = m68k_interrupt_function_p (current_function_decl);
391 /* Only compute the frame once per function.
392 Don't cache information until reload has been completed. */
393 if (current_frame.funcdef_no == current_function_funcdef_no
394 && reload_completed)
395 return;
397 current_frame.size = (get_frame_size () + 3) & -4;
399 mask = rmask = saved = 0;
400 for (regno = 0; regno < 16; regno++)
401 if (m68k_save_reg (regno, interrupt_handler))
403 mask |= 1 << regno;
404 rmask |= 1 << (15 - regno);
405 saved++;
407 current_frame.offset = saved * 4;
408 current_frame.reg_no = saved;
409 current_frame.reg_mask = mask;
410 current_frame.reg_rev_mask = rmask;
412 current_frame.foffset = 0;
413 mask = rmask = saved = 0;
414 if (TARGET_68881 /* || TARGET_CFV4E */)
416 for (regno = 16; regno < 24; regno++)
417 if (m68k_save_reg (regno, interrupt_handler))
419 mask |= 1 << (regno - 16);
420 rmask |= 1 << (23 - regno);
421 saved++;
423 current_frame.foffset = saved * 12 /* (TARGET_CFV4E ? 8 : 12) */;
424 current_frame.offset += current_frame.foffset;
426 current_frame.fpu_no = saved;
427 current_frame.fpu_mask = mask;
428 current_frame.fpu_rev_mask = rmask;
430 /* Remember what function this frame refers to. */
431 current_frame.funcdef_no = current_function_funcdef_no;
434 HOST_WIDE_INT
435 m68k_initial_elimination_offset (int from, int to)
437 /* FIXME: The correct offset to compute here would appear to be
438 (frame_pointer_needed ? -UNITS_PER_WORD * 2 : -UNITS_PER_WORD);
439 but for some obscure reason, this must be 0 to get correct code. */
440 if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
441 return 0;
443 m68k_compute_frame_layout ();
445 gcc_assert (to == STACK_POINTER_REGNUM);
446 switch (from)
448 case ARG_POINTER_REGNUM:
449 return current_frame.offset + current_frame.size
450 + (frame_pointer_needed ? -UNITS_PER_WORD * 2 : -UNITS_PER_WORD);
451 case FRAME_POINTER_REGNUM:
452 return current_frame.offset + current_frame.size;
453 default:
454 gcc_unreachable ();
458 /* Refer to the array `regs_ever_live' to determine which registers
459 to save; `regs_ever_live[I]' is nonzero if register number I
460 is ever used in the function. This function is responsible for
461 knowing which registers should not be saved even if used.
462 Return true if we need to save REGNO. */
464 static bool
465 m68k_save_reg (unsigned int regno, bool interrupt_handler)
467 if (flag_pic && regno == PIC_OFFSET_TABLE_REGNUM)
469 if (current_function_uses_pic_offset_table)
470 return true;
471 if (!current_function_is_leaf && TARGET_ID_SHARED_LIBRARY)
472 return true;
475 if (current_function_calls_eh_return)
477 unsigned int i;
478 for (i = 0; ; i++)
480 unsigned int test = EH_RETURN_DATA_REGNO (i);
481 if (test == INVALID_REGNUM)
482 break;
483 if (test == regno)
484 return true;
488 /* Fixed regs we never touch. */
489 if (fixed_regs[regno])
490 return false;
492 /* The frame pointer (if it is such) is handled specially. */
493 if (regno == FRAME_POINTER_REGNUM && frame_pointer_needed)
494 return false;
496 /* Interrupt handlers must also save call_used_regs
497 if they are live or when calling nested functions. */
498 if (interrupt_handler)
500 if (regs_ever_live[regno])
501 return true;
503 if (!current_function_is_leaf && call_used_regs[regno])
504 return true;
507 /* Never need to save registers that aren't touched. */
508 if (!regs_ever_live[regno])
509 return false;
511 /* Otherwise save everything that isn't call-clobbered. */
512 return !call_used_regs[regno];
515 /* This function generates the assembly code for function entry.
516 STREAM is a stdio stream to output the code to.
517 SIZE is an int: how many units of temporary storage to allocate. */
519 static void
520 m68k_output_function_prologue (FILE *stream, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
522 HOST_WIDE_INT fsize_with_regs;
523 HOST_WIDE_INT cfa_offset = INCOMING_FRAME_SP_OFFSET;
525 m68k_compute_frame_layout();
527 /* If the stack limit is a symbol, we can check it here,
528 before actually allocating the space. */
529 if (current_function_limit_stack
530 && GET_CODE (stack_limit_rtx) == SYMBOL_REF)
531 asm_fprintf (stream, "\tcmp" ASM_DOT "l %I%s+%wd,%Rsp\n\ttrapcs\n",
532 XSTR (stack_limit_rtx, 0), current_frame.size + 4);
534 /* On ColdFire add register save into initial stack frame setup, if possible. */
535 fsize_with_regs = current_frame.size;
536 if (TARGET_COLDFIRE && current_frame.reg_no > 2)
537 fsize_with_regs += current_frame.reg_no * 4;
539 if (frame_pointer_needed)
541 if (current_frame.size == 0 && TARGET_68040)
542 /* on the 68040, pea + move is faster than link.w 0 */
543 fprintf (stream, MOTOROLA ?
544 "\tpea (%s)\n\tmove.l %s,%s\n" :
545 "\tpea %s@\n\tmovel %s,%s\n",
546 M68K_REGNAME(FRAME_POINTER_REGNUM),
547 M68K_REGNAME(STACK_POINTER_REGNUM),
548 M68K_REGNAME(FRAME_POINTER_REGNUM));
549 else if (fsize_with_regs < 0x8000)
550 asm_fprintf (stream, "\tlink" ASM_DOTW " %s,%I%wd\n",
551 M68K_REGNAME(FRAME_POINTER_REGNUM), -fsize_with_regs);
552 else if (TARGET_68020)
553 asm_fprintf (stream, "\tlink" ASM_DOTL " %s,%I%wd\n",
554 M68K_REGNAME(FRAME_POINTER_REGNUM), -fsize_with_regs);
555 else
556 /* Adding negative number is faster on the 68040. */
557 asm_fprintf (stream, "\tlink" ASM_DOTW " %s,%I0\n"
558 "\tadd" ASM_DOT "l %I%wd,%Rsp\n",
559 M68K_REGNAME(FRAME_POINTER_REGNUM), -fsize_with_regs);
561 if (dwarf2out_do_frame ())
563 char *l;
564 l = (char *) dwarf2out_cfi_label ();
565 cfa_offset += 4;
566 dwarf2out_reg_save (l, FRAME_POINTER_REGNUM, -cfa_offset);
567 dwarf2out_def_cfa (l, FRAME_POINTER_REGNUM, cfa_offset);
568 cfa_offset += current_frame.size;
571 else if (fsize_with_regs) /* !frame_pointer_needed */
573 if (fsize_with_regs < 0x8000)
575 if (fsize_with_regs <= 8)
577 if (!TARGET_COLDFIRE)
578 asm_fprintf (stream, "\tsubq" ASM_DOT "w %I%wd,%Rsp\n",
579 fsize_with_regs);
580 else
581 asm_fprintf (stream, "\tsubq" ASM_DOT "l %I%wd,%Rsp\n",
582 fsize_with_regs);
584 else if (fsize_with_regs <= 16 && TARGET_CPU32)
585 /* On the CPU32 it is faster to use two subqw instructions to
586 subtract a small integer (8 < N <= 16) to a register. */
587 asm_fprintf (stream,
588 "\tsubq" ASM_DOT "w %I8,%Rsp\n"
589 "\tsubq" ASM_DOT "w %I%wd,%Rsp\n",
590 fsize_with_regs - 8);
591 else if (TARGET_68040)
592 /* Adding negative number is faster on the 68040. */
593 asm_fprintf (stream, "\tadd" ASM_DOT "w %I%wd,%Rsp\n",
594 -fsize_with_regs);
595 else
596 asm_fprintf (stream, MOTOROLA ?
597 "\tlea (%wd,%Rsp),%Rsp\n" :
598 "\tlea %Rsp@(%wd),%Rsp\n",
599 -fsize_with_regs);
601 else /* fsize_with_regs >= 0x8000 */
602 asm_fprintf (stream, "\tadd" ASM_DOT "l %I%wd,%Rsp\n", -fsize_with_regs);
604 if (dwarf2out_do_frame ())
606 cfa_offset += current_frame.size + 4;
607 dwarf2out_def_cfa ("", STACK_POINTER_REGNUM, cfa_offset);
609 } /* !frame_pointer_needed */
611 if (current_frame.fpu_mask)
613 asm_fprintf (stream, MOTOROLA ?
614 "\tfmovm %I0x%x,-(%Rsp)\n" :
615 "\tfmovem %I0x%x,%Rsp@-\n",
616 current_frame.fpu_mask);
618 if (dwarf2out_do_frame ())
620 char *l = (char *) dwarf2out_cfi_label ();
621 int n_regs, regno;
623 cfa_offset += current_frame.fpu_no * 12;
624 if (! frame_pointer_needed)
625 dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, cfa_offset);
626 for (regno = 16, n_regs = 0; regno < 24; regno++)
627 if (current_frame.fpu_mask & (1 << (regno - 16)))
628 dwarf2out_reg_save (l, regno, -cfa_offset + n_regs++ * 12);
632 /* If the stack limit is not a symbol, check it here.
633 This has the disadvantage that it may be too late... */
634 if (current_function_limit_stack)
636 if (REG_P (stack_limit_rtx))
637 asm_fprintf (stream, "\tcmp" ASM_DOT "l %s,%Rsp\n\ttrapcs\n",
638 M68K_REGNAME(REGNO (stack_limit_rtx)));
639 else if (GET_CODE (stack_limit_rtx) != SYMBOL_REF)
640 warning (0, "stack limit expression is not supported");
643 if (current_frame.reg_no <= 2)
645 /* Store each separately in the same order moveml uses.
646 Using two movel instructions instead of a single moveml
647 is about 15% faster for the 68020 and 68030 at no expense
648 in code size. */
650 int i;
652 for (i = 0; i < 16; i++)
653 if (current_frame.reg_rev_mask & (1 << i))
655 asm_fprintf (stream, MOTOROLA ?
656 "\t%Omove.l %s,-(%Rsp)\n" :
657 "\tmovel %s,%Rsp@-\n",
658 M68K_REGNAME(15 - i));
659 if (dwarf2out_do_frame ())
661 char *l = (char *) dwarf2out_cfi_label ();
663 cfa_offset += 4;
664 if (! frame_pointer_needed)
665 dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, cfa_offset);
666 dwarf2out_reg_save (l, 15 - i, -cfa_offset);
670 else if (current_frame.reg_rev_mask)
672 if (TARGET_COLDFIRE)
673 /* The ColdFire does not support the predecrement form of the
674 MOVEM instruction, so we must adjust the stack pointer and
675 then use the plain address register indirect mode.
676 The required register save space was combined earlier with
677 the fsize_with_regs amount. */
679 asm_fprintf (stream, MOTOROLA ?
680 "\tmovm.l %I0x%x,(%Rsp)\n" :
681 "\tmoveml %I0x%x,%Rsp@\n",
682 current_frame.reg_mask);
683 else
684 asm_fprintf (stream, MOTOROLA ?
685 "\tmovm.l %I0x%x,-(%Rsp)\n" :
686 "\tmoveml %I0x%x,%Rsp@-\n",
687 current_frame.reg_rev_mask);
688 if (dwarf2out_do_frame ())
690 char *l = (char *) dwarf2out_cfi_label ();
691 int n_regs, regno;
693 cfa_offset += current_frame.reg_no * 4;
694 if (! frame_pointer_needed)
695 dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, cfa_offset);
696 for (regno = 0, n_regs = 0; regno < 16; regno++)
697 if (current_frame.reg_mask & (1 << regno))
698 dwarf2out_reg_save (l, regno, -cfa_offset + n_regs++ * 4);
701 if (!TARGET_SEP_DATA && flag_pic &&
702 (current_function_uses_pic_offset_table ||
703 (!current_function_is_leaf && TARGET_ID_SHARED_LIBRARY)))
705 if (TARGET_ID_SHARED_LIBRARY)
707 asm_fprintf (stream, "\tmovel %s@(%s), %s\n",
708 M68K_REGNAME(PIC_OFFSET_TABLE_REGNUM),
709 m68k_library_id_string,
710 M68K_REGNAME(PIC_OFFSET_TABLE_REGNUM));
712 else
714 if (MOTOROLA)
715 asm_fprintf (stream, "\t%Olea (%Rpc, %U_GLOBAL_OFFSET_TABLE_@GOTPC), %s\n",
716 M68K_REGNAME(PIC_OFFSET_TABLE_REGNUM));
717 else
719 asm_fprintf (stream, "\tmovel %I%U_GLOBAL_OFFSET_TABLE_, %s\n",
720 M68K_REGNAME(PIC_OFFSET_TABLE_REGNUM));
721 asm_fprintf (stream, "\tlea %Rpc@(0,%s:l),%s\n",
722 M68K_REGNAME(PIC_OFFSET_TABLE_REGNUM),
723 M68K_REGNAME(PIC_OFFSET_TABLE_REGNUM));
729 /* Return true if this function's epilogue can be output as RTL. */
731 bool
732 use_return_insn (void)
734 if (!reload_completed || frame_pointer_needed || get_frame_size () != 0)
735 return false;
737 /* We can output the epilogue as RTL only if no registers need to be
738 restored. */
739 m68k_compute_frame_layout();
740 return current_frame.reg_no ? false : true;
743 /* This function generates the assembly code for function exit,
744 on machines that need it.
746 The function epilogue should not depend on the current stack pointer!
747 It should use the frame pointer only, if there is a frame pointer.
748 This is mandatory because of alloca; we also take advantage of it to
749 omit stack adjustments before returning. */
751 static void
752 m68k_output_function_epilogue (FILE *stream, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
754 HOST_WIDE_INT fsize, fsize_with_regs;
755 bool big = false;
756 bool restore_from_sp = false;
757 rtx insn = get_last_insn ();
759 m68k_compute_frame_layout();
761 /* If the last insn was a BARRIER, we don't have to write any code. */
762 if (GET_CODE (insn) == NOTE)
763 insn = prev_nonnote_insn (insn);
764 if (insn && GET_CODE (insn) == BARRIER)
766 /* Output just a no-op so that debuggers don't get confused
767 about which function the pc is in at this address. */
768 fprintf (stream, "\tnop\n");
769 return;
772 #ifdef FUNCTION_EXTRA_EPILOGUE
773 FUNCTION_EXTRA_EPILOGUE (stream, size);
774 #endif
776 fsize = current_frame.size;
778 /* FIXME : leaf_function_p below is too strong.
779 What we really need to know there is if there could be pending
780 stack adjustment needed at that point. */
781 restore_from_sp = ! frame_pointer_needed
782 || (! current_function_calls_alloca && leaf_function_p ());
784 /* fsize_with_regs is the size we need to adjust the sp when
785 popping the frame. */
786 fsize_with_regs = fsize;
788 /* Because the ColdFire doesn't support moveml with
789 complex address modes, we must adjust the stack manually
790 after restoring registers. When the frame pointer isn't used,
791 we can merge movem adjustment into frame unlinking
792 made immediately after it. */
793 if (TARGET_COLDFIRE && restore_from_sp && (current_frame.reg_no > 2))
794 fsize_with_regs += current_frame.reg_no * 4;
796 if (current_frame.offset + fsize >= 0x8000
797 && ! restore_from_sp
798 && (current_frame.reg_mask || current_frame.fpu_mask))
800 /* Because the ColdFire doesn't support moveml with
801 complex address modes we make an extra correction here. */
802 if (TARGET_COLDFIRE)
803 fsize += current_frame.offset;
805 asm_fprintf (stream, "\t%Omove" ASM_DOT "l %I%wd,%Ra1\n", -fsize);
806 fsize = 0, big = true;
808 if (current_frame.reg_no <= 2)
810 /* Restore each separately in the same order moveml does.
811 Using two movel instructions instead of a single moveml
812 is about 15% faster for the 68020 and 68030 at no expense
813 in code size. */
815 int i;
816 HOST_WIDE_INT offset = current_frame.offset + fsize;
818 for (i = 0; i < 16; i++)
819 if (current_frame.reg_mask & (1 << i))
821 if (big)
823 if (MOTOROLA)
824 asm_fprintf (stream, "\t%Omove.l -%wd(%s,%Ra1.l),%s\n",
825 offset,
826 M68K_REGNAME(FRAME_POINTER_REGNUM),
827 M68K_REGNAME(i));
828 else
829 asm_fprintf (stream, "\tmovel %s@(-%wd,%Ra1:l),%s\n",
830 M68K_REGNAME(FRAME_POINTER_REGNUM),
831 offset,
832 M68K_REGNAME(i));
834 else if (restore_from_sp)
835 asm_fprintf (stream, MOTOROLA ?
836 "\t%Omove.l (%Rsp)+,%s\n" :
837 "\tmovel %Rsp@+,%s\n",
838 M68K_REGNAME(i));
839 else
841 if (MOTOROLA)
842 asm_fprintf (stream, "\t%Omove.l -%wd(%s),%s\n",
843 offset,
844 M68K_REGNAME(FRAME_POINTER_REGNUM),
845 M68K_REGNAME(i));
846 else
847 asm_fprintf (stream, "\tmovel %s@(-%wd),%s\n",
848 M68K_REGNAME(FRAME_POINTER_REGNUM),
849 offset,
850 M68K_REGNAME(i));
852 offset -= 4;
855 else if (current_frame.reg_mask)
857 /* The ColdFire requires special handling due to its limited moveml insn. */
858 if (TARGET_COLDFIRE)
860 if (big)
862 asm_fprintf (stream, "\tadd" ASM_DOT "l %s,%Ra1\n",
863 M68K_REGNAME(FRAME_POINTER_REGNUM));
864 asm_fprintf (stream, MOTOROLA ?
865 "\tmovm.l (%Ra1),%I0x%x\n" :
866 "\tmoveml %Ra1@,%I0x%x\n",
867 current_frame.reg_mask);
869 else if (restore_from_sp)
870 asm_fprintf (stream, MOTOROLA ?
871 "\tmovm.l (%Rsp),%I0x%x\n" :
872 "\tmoveml %Rsp@,%I0x%x\n",
873 current_frame.reg_mask);
874 else
876 if (MOTOROLA)
877 asm_fprintf (stream, "\tmovm.l -%wd(%s),%I0x%x\n",
878 current_frame.offset + fsize,
879 M68K_REGNAME(FRAME_POINTER_REGNUM),
880 current_frame.reg_mask);
881 else
882 asm_fprintf (stream, "\tmoveml %s@(-%wd),%I0x%x\n",
883 M68K_REGNAME(FRAME_POINTER_REGNUM),
884 current_frame.offset + fsize,
885 current_frame.reg_mask);
888 else /* !TARGET_COLDFIRE */
890 if (big)
892 if (MOTOROLA)
893 asm_fprintf (stream, "\tmovm.l -%wd(%s,%Ra1.l),%I0x%x\n",
894 current_frame.offset + fsize,
895 M68K_REGNAME(FRAME_POINTER_REGNUM),
896 current_frame.reg_mask);
897 else
898 asm_fprintf (stream, "\tmoveml %s@(-%wd,%Ra1:l),%I0x%x\n",
899 M68K_REGNAME(FRAME_POINTER_REGNUM),
900 current_frame.offset + fsize,
901 current_frame.reg_mask);
903 else if (restore_from_sp)
905 asm_fprintf (stream, MOTOROLA ?
906 "\tmovm.l (%Rsp)+,%I0x%x\n" :
907 "\tmoveml %Rsp@+,%I0x%x\n",
908 current_frame.reg_mask);
910 else
912 if (MOTOROLA)
913 asm_fprintf (stream, "\tmovm.l -%wd(%s),%I0x%x\n",
914 current_frame.offset + fsize,
915 M68K_REGNAME(FRAME_POINTER_REGNUM),
916 current_frame.reg_mask);
917 else
918 asm_fprintf (stream, "\tmoveml %s@(-%wd),%I0x%x\n",
919 M68K_REGNAME(FRAME_POINTER_REGNUM),
920 current_frame.offset + fsize,
921 current_frame.reg_mask);
925 if (current_frame.fpu_rev_mask)
927 if (big)
929 if (MOTOROLA)
930 asm_fprintf (stream, "\tfmovm -%wd(%s,%Ra1.l),%I0x%x\n",
931 current_frame.foffset + fsize,
932 M68K_REGNAME(FRAME_POINTER_REGNUM),
933 current_frame.fpu_rev_mask);
934 else
935 asm_fprintf (stream, "\tfmovem %s@(-%wd,%Ra1:l),%I0x%x\n",
936 M68K_REGNAME(FRAME_POINTER_REGNUM),
937 current_frame.foffset + fsize,
938 current_frame.fpu_rev_mask);
940 else if (restore_from_sp)
942 if (MOTOROLA)
943 asm_fprintf (stream, "\tfmovm (%Rsp)+,%I0x%x\n",
944 current_frame.fpu_rev_mask);
945 else
946 asm_fprintf (stream, "\tfmovem %Rsp@+,%I0x%x\n",
947 current_frame.fpu_rev_mask);
949 else
951 if (MOTOROLA)
952 asm_fprintf (stream, "\tfmovm -%wd(%s),%I0x%x\n",
953 current_frame.foffset + fsize,
954 M68K_REGNAME(FRAME_POINTER_REGNUM),
955 current_frame.fpu_rev_mask);
956 else
957 asm_fprintf (stream, "\tfmovem %s@(-%wd),%I0x%x\n",
958 M68K_REGNAME(FRAME_POINTER_REGNUM),
959 current_frame.foffset + fsize,
960 current_frame.fpu_rev_mask);
963 if (frame_pointer_needed)
964 fprintf (stream, "\tunlk %s\n", M68K_REGNAME(FRAME_POINTER_REGNUM));
965 else if (fsize_with_regs)
967 if (fsize_with_regs <= 8)
969 if (!TARGET_COLDFIRE)
970 asm_fprintf (stream, "\taddq" ASM_DOT "w %I%wd,%Rsp\n",
971 fsize_with_regs);
972 else
973 asm_fprintf (stream, "\taddq" ASM_DOT "l %I%wd,%Rsp\n",
974 fsize_with_regs);
976 else if (fsize_with_regs <= 16 && TARGET_CPU32)
978 /* On the CPU32 it is faster to use two addqw instructions to
979 add a small integer (8 < N <= 16) to a register. */
980 asm_fprintf (stream, "\taddq" ASM_DOT "w %I8,%Rsp\n"
981 "\taddq" ASM_DOT "w %I%wd,%Rsp\n",
982 fsize_with_regs - 8);
984 else if (fsize_with_regs < 0x8000)
986 if (TARGET_68040)
987 asm_fprintf (stream, "\tadd" ASM_DOT "w %I%wd,%Rsp\n",
988 fsize_with_regs);
989 else
990 asm_fprintf (stream, MOTOROLA ?
991 "\tlea (%wd,%Rsp),%Rsp\n" :
992 "\tlea %Rsp@(%wd),%Rsp\n",
993 fsize_with_regs);
995 else
996 asm_fprintf (stream, "\tadd" ASM_DOT "l %I%wd,%Rsp\n", fsize_with_regs);
998 if (current_function_calls_eh_return)
999 asm_fprintf (stream, "\tadd" ASM_DOT"l %Ra0,%Rsp\n");
1000 if (m68k_interrupt_function_p (current_function_decl))
1001 fprintf (stream, "\trte\n");
1002 else if (current_function_pops_args)
1003 asm_fprintf (stream, "\trtd %I%d\n", current_function_pops_args);
1004 else
1005 fprintf (stream, "\trts\n");
1008 /* Return true if X is a valid comparison operator for the dbcc
1009 instruction.
1011 Note it rejects floating point comparison operators.
1012 (In the future we could use Fdbcc).
1014 It also rejects some comparisons when CC_NO_OVERFLOW is set. */
1017 valid_dbcc_comparison_p_2 (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
1019 switch (GET_CODE (x))
1021 case EQ: case NE: case GTU: case LTU:
1022 case GEU: case LEU:
1023 return 1;
1025 /* Reject some when CC_NO_OVERFLOW is set. This may be over
1026 conservative */
1027 case GT: case LT: case GE: case LE:
1028 return ! (cc_prev_status.flags & CC_NO_OVERFLOW);
1029 default:
1030 return 0;
1034 /* Return nonzero if flags are currently in the 68881 flag register. */
1036 flags_in_68881 (void)
1038 /* We could add support for these in the future */
1039 return cc_status.flags & CC_IN_68881;
1042 /* Output a BSR instruction suitable for PIC code. */
1043 void
1044 m68k_output_pic_call(rtx dest)
1046 const char *out;
1048 if (!(GET_CODE (dest) == MEM && GET_CODE (XEXP (dest, 0)) == SYMBOL_REF))
1049 out = "jsr %0";
1050 /* We output a BSR instruction if we're using -fpic or we're building for
1051 * a target that supports long branches. If we're building -fPIC on the
1052 * 68000, 68010 or ColdFire we generate one of two sequences:
1053 * a shorter one that uses a GOT entry or a longer one that doesn't.
1054 * We'll use the -Os command-line flag to decide which to generate.
1055 * Both sequences take the same time to execute on the ColdFire.
1057 else if (TARGET_PCREL)
1058 out = "bsr.l %o0";
1059 else if ((flag_pic == 1) || TARGET_68020)
1060 #if defined(USE_GAS)
1061 out = "bsr.l %0@PLTPC";
1062 #else
1063 out = "bsr %0@PLTPC";
1064 #endif
1065 else if (optimize_size || TARGET_ID_SHARED_LIBRARY)
1066 out = "move.l %0@GOT(%%a5), %%a1\n\tjsr (%%a1)";
1067 else
1068 out = "lea %0-.-8,%%a1\n\tjsr 0(%%pc,%%a1)";
1070 output_asm_insn(out, &dest);
1073 /* Output a dbCC; jCC sequence. Note we do not handle the
1074 floating point version of this sequence (Fdbcc). We also
1075 do not handle alternative conditions when CC_NO_OVERFLOW is
1076 set. It is assumed that valid_dbcc_comparison_p and flags_in_68881 will
1077 kick those out before we get here. */
1079 void
1080 output_dbcc_and_branch (rtx *operands)
1082 switch (GET_CODE (operands[3]))
1084 case EQ:
1085 output_asm_insn (MOTOROLA ?
1086 "dbeq %0,%l1\n\tjbeq %l2" :
1087 "dbeq %0,%l1\n\tjeq %l2",
1088 operands);
1089 break;
1091 case NE:
1092 output_asm_insn (MOTOROLA ?
1093 "dbne %0,%l1\n\tjbne %l2" :
1094 "dbne %0,%l1\n\tjne %l2",
1095 operands);
1096 break;
1098 case GT:
1099 output_asm_insn (MOTOROLA ?
1100 "dbgt %0,%l1\n\tjbgt %l2" :
1101 "dbgt %0,%l1\n\tjgt %l2",
1102 operands);
1103 break;
1105 case GTU:
1106 output_asm_insn (MOTOROLA ?
1107 "dbhi %0,%l1\n\tjbhi %l2" :
1108 "dbhi %0,%l1\n\tjhi %l2",
1109 operands);
1110 break;
1112 case LT:
1113 output_asm_insn (MOTOROLA ?
1114 "dblt %0,%l1\n\tjblt %l2" :
1115 "dblt %0,%l1\n\tjlt %l2",
1116 operands);
1117 break;
1119 case LTU:
1120 output_asm_insn (MOTOROLA ?
1121 "dbcs %0,%l1\n\tjbcs %l2" :
1122 "dbcs %0,%l1\n\tjcs %l2",
1123 operands);
1124 break;
1126 case GE:
1127 output_asm_insn (MOTOROLA ?
1128 "dbge %0,%l1\n\tjbge %l2" :
1129 "dbge %0,%l1\n\tjge %l2",
1130 operands);
1131 break;
1133 case GEU:
1134 output_asm_insn (MOTOROLA ?
1135 "dbcc %0,%l1\n\tjbcc %l2" :
1136 "dbcc %0,%l1\n\tjcc %l2",
1137 operands);
1138 break;
1140 case LE:
1141 output_asm_insn (MOTOROLA ?
1142 "dble %0,%l1\n\tjble %l2" :
1143 "dble %0,%l1\n\tjle %l2",
1144 operands);
1145 break;
1147 case LEU:
1148 output_asm_insn (MOTOROLA ?
1149 "dbls %0,%l1\n\tjbls %l2" :
1150 "dbls %0,%l1\n\tjls %l2",
1151 operands);
1152 break;
1154 default:
1155 gcc_unreachable ();
1158 /* If the decrement is to be done in SImode, then we have
1159 to compensate for the fact that dbcc decrements in HImode. */
1160 switch (GET_MODE (operands[0]))
1162 case SImode:
1163 output_asm_insn (MOTOROLA ?
1164 "clr%.w %0\n\tsubq%.l #1,%0\n\tjbpl %l1" :
1165 "clr%.w %0\n\tsubq%.l #1,%0\n\tjpl %l1",
1166 operands);
1167 break;
1169 case HImode:
1170 break;
1172 default:
1173 gcc_unreachable ();
1177 const char *
1178 output_scc_di (rtx op, rtx operand1, rtx operand2, rtx dest)
1180 rtx loperands[7];
1181 enum rtx_code op_code = GET_CODE (op);
1183 /* This does not produce a useful cc. */
1184 CC_STATUS_INIT;
1186 /* The m68k cmp.l instruction requires operand1 to be a reg as used
1187 below. Swap the operands and change the op if these requirements
1188 are not fulfilled. */
1189 if (GET_CODE (operand2) == REG && GET_CODE (operand1) != REG)
1191 rtx tmp = operand1;
1193 operand1 = operand2;
1194 operand2 = tmp;
1195 op_code = swap_condition (op_code);
1197 loperands[0] = operand1;
1198 if (GET_CODE (operand1) == REG)
1199 loperands[1] = gen_rtx_REG (SImode, REGNO (operand1) + 1);
1200 else
1201 loperands[1] = adjust_address (operand1, SImode, 4);
1202 if (operand2 != const0_rtx)
1204 loperands[2] = operand2;
1205 if (GET_CODE (operand2) == REG)
1206 loperands[3] = gen_rtx_REG (SImode, REGNO (operand2) + 1);
1207 else
1208 loperands[3] = adjust_address (operand2, SImode, 4);
1210 loperands[4] = gen_label_rtx ();
1211 if (operand2 != const0_rtx)
1213 output_asm_insn (MOTOROLA ?
1214 "cmp%.l %2,%0\n\tjbne %l4\n\tcmp%.l %3,%1" :
1215 "cmp%.l %2,%0\n\tjne %l4\n\tcmp%.l %3,%1",
1216 loperands);
1218 else
1220 if (TARGET_68020 || TARGET_COLDFIRE || ! ADDRESS_REG_P (loperands[0]))
1221 output_asm_insn ("tst%.l %0", loperands);
1222 else
1224 output_asm_insn ("cmp%.w #0,%0", loperands);
1227 output_asm_insn (MOTOROLA ? "jbne %l4" : "jne %l4", loperands);
1229 if (TARGET_68020 || TARGET_COLDFIRE || ! ADDRESS_REG_P (loperands[1]))
1230 output_asm_insn ("tst%.l %1", loperands);
1231 else
1232 output_asm_insn ("cmp%.w #0,%1", loperands);
1235 loperands[5] = dest;
1237 switch (op_code)
1239 case EQ:
1240 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1241 CODE_LABEL_NUMBER (loperands[4]));
1242 output_asm_insn ("seq %5", loperands);
1243 break;
1245 case NE:
1246 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1247 CODE_LABEL_NUMBER (loperands[4]));
1248 output_asm_insn ("sne %5", loperands);
1249 break;
1251 case GT:
1252 loperands[6] = gen_label_rtx ();
1253 output_asm_insn (MOTOROLA ?
1254 "shi %5\n\tjbra %l6" :
1255 "shi %5\n\tjra %l6",
1256 loperands);
1257 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1258 CODE_LABEL_NUMBER (loperands[4]));
1259 output_asm_insn ("sgt %5", loperands);
1260 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1261 CODE_LABEL_NUMBER (loperands[6]));
1262 break;
1264 case GTU:
1265 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1266 CODE_LABEL_NUMBER (loperands[4]));
1267 output_asm_insn ("shi %5", loperands);
1268 break;
1270 case LT:
1271 loperands[6] = gen_label_rtx ();
1272 output_asm_insn (MOTOROLA ?
1273 "scs %5\n\tjbra %l6" :
1274 "scs %5\n\tjra %l6",
1275 loperands);
1276 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1277 CODE_LABEL_NUMBER (loperands[4]));
1278 output_asm_insn ("slt %5", loperands);
1279 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1280 CODE_LABEL_NUMBER (loperands[6]));
1281 break;
1283 case LTU:
1284 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1285 CODE_LABEL_NUMBER (loperands[4]));
1286 output_asm_insn ("scs %5", loperands);
1287 break;
1289 case GE:
1290 loperands[6] = gen_label_rtx ();
1291 output_asm_insn (MOTOROLA ?
1292 "scc %5\n\tjbra %l6" :
1293 "scc %5\n\tjra %l6",
1294 loperands);
1295 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1296 CODE_LABEL_NUMBER (loperands[4]));
1297 output_asm_insn ("sge %5", loperands);
1298 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1299 CODE_LABEL_NUMBER (loperands[6]));
1300 break;
1302 case GEU:
1303 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1304 CODE_LABEL_NUMBER (loperands[4]));
1305 output_asm_insn ("scc %5", loperands);
1306 break;
1308 case LE:
1309 loperands[6] = gen_label_rtx ();
1310 output_asm_insn (MOTOROLA ?
1311 "sls %5\n\tjbra %l6" :
1312 "sls %5\n\tjra %l6",
1313 loperands);
1314 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1315 CODE_LABEL_NUMBER (loperands[4]));
1316 output_asm_insn ("sle %5", loperands);
1317 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1318 CODE_LABEL_NUMBER (loperands[6]));
1319 break;
1321 case LEU:
1322 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1323 CODE_LABEL_NUMBER (loperands[4]));
1324 output_asm_insn ("sls %5", loperands);
1325 break;
1327 default:
1328 gcc_unreachable ();
1330 return "";
1333 const char *
1334 output_btst (rtx *operands, rtx countop, rtx dataop, rtx insn, int signpos)
1336 operands[0] = countop;
1337 operands[1] = dataop;
1339 if (GET_CODE (countop) == CONST_INT)
1341 register int count = INTVAL (countop);
1342 /* If COUNT is bigger than size of storage unit in use,
1343 advance to the containing unit of same size. */
1344 if (count > signpos)
1346 int offset = (count & ~signpos) / 8;
1347 count = count & signpos;
1348 operands[1] = dataop = adjust_address (dataop, QImode, offset);
1350 if (count == signpos)
1351 cc_status.flags = CC_NOT_POSITIVE | CC_Z_IN_NOT_N;
1352 else
1353 cc_status.flags = CC_NOT_NEGATIVE | CC_Z_IN_NOT_N;
1355 /* These three statements used to use next_insns_test_no...
1356 but it appears that this should do the same job. */
1357 if (count == 31
1358 && next_insn_tests_no_inequality (insn))
1359 return "tst%.l %1";
1360 if (count == 15
1361 && next_insn_tests_no_inequality (insn))
1362 return "tst%.w %1";
1363 if (count == 7
1364 && next_insn_tests_no_inequality (insn))
1365 return "tst%.b %1";
1367 cc_status.flags = CC_NOT_NEGATIVE;
1369 return "btst %0,%1";
1372 /* Legitimize PIC addresses. If the address is already
1373 position-independent, we return ORIG. Newly generated
1374 position-independent addresses go to REG. If we need more
1375 than one register, we lose.
1377 An address is legitimized by making an indirect reference
1378 through the Global Offset Table with the name of the symbol
1379 used as an offset.
1381 The assembler and linker are responsible for placing the
1382 address of the symbol in the GOT. The function prologue
1383 is responsible for initializing a5 to the starting address
1384 of the GOT.
1386 The assembler is also responsible for translating a symbol name
1387 into a constant displacement from the start of the GOT.
1389 A quick example may make things a little clearer:
1391 When not generating PIC code to store the value 12345 into _foo
1392 we would generate the following code:
1394 movel #12345, _foo
1396 When generating PIC two transformations are made. First, the compiler
1397 loads the address of foo into a register. So the first transformation makes:
1399 lea _foo, a0
1400 movel #12345, a0@
1402 The code in movsi will intercept the lea instruction and call this
1403 routine which will transform the instructions into:
1405 movel a5@(_foo:w), a0
1406 movel #12345, a0@
1409 That (in a nutshell) is how *all* symbol and label references are
1410 handled. */
1413 legitimize_pic_address (rtx orig, enum machine_mode mode ATTRIBUTE_UNUSED,
1414 rtx reg)
1416 rtx pic_ref = orig;
1418 /* First handle a simple SYMBOL_REF or LABEL_REF */
1419 if (GET_CODE (orig) == SYMBOL_REF || GET_CODE (orig) == LABEL_REF)
1421 gcc_assert (reg);
1423 pic_ref = gen_rtx_MEM (Pmode,
1424 gen_rtx_PLUS (Pmode,
1425 pic_offset_table_rtx, orig));
1426 current_function_uses_pic_offset_table = 1;
1427 MEM_READONLY_P (pic_ref) = 1;
1428 emit_move_insn (reg, pic_ref);
1429 return reg;
1431 else if (GET_CODE (orig) == CONST)
1433 rtx base;
1435 /* Make sure this has not already been legitimized. */
1436 if (GET_CODE (XEXP (orig, 0)) == PLUS
1437 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
1438 return orig;
1440 gcc_assert (reg);
1442 /* legitimize both operands of the PLUS */
1443 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
1445 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
1446 orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
1447 base == reg ? 0 : reg);
1449 if (GET_CODE (orig) == CONST_INT)
1450 return plus_constant (base, INTVAL (orig));
1451 pic_ref = gen_rtx_PLUS (Pmode, base, orig);
1452 /* Likewise, should we set special REG_NOTEs here? */
1454 return pic_ref;
1458 typedef enum { MOVL, SWAP, NEGW, NOTW, NOTB, MOVQ, MVS, MVZ } CONST_METHOD;
1460 static CONST_METHOD const_method (rtx);
1462 #define USE_MOVQ(i) ((unsigned)((i) + 128) <= 255)
1464 static CONST_METHOD
1465 const_method (rtx constant)
1467 int i;
1468 unsigned u;
1470 i = INTVAL (constant);
1471 if (USE_MOVQ (i))
1472 return MOVQ;
1474 /* The ColdFire doesn't have byte or word operations. */
1475 /* FIXME: This may not be useful for the m68060 either. */
1476 if (!TARGET_COLDFIRE)
1478 /* if -256 < N < 256 but N is not in range for a moveq
1479 N^ff will be, so use moveq #N^ff, dreg; not.b dreg. */
1480 if (USE_MOVQ (i ^ 0xff))
1481 return NOTB;
1482 /* Likewise, try with not.w */
1483 if (USE_MOVQ (i ^ 0xffff))
1484 return NOTW;
1485 /* This is the only value where neg.w is useful */
1486 if (i == -65408)
1487 return NEGW;
1490 /* Try also with swap. */
1491 u = i;
1492 if (USE_MOVQ ((u >> 16) | (u << 16)))
1493 return SWAP;
1495 if (TARGET_CFV4)
1497 /* Try using MVZ/MVS with an immediate value to load constants. */
1498 if (i >= 0 && i <= 65535)
1499 return MVZ;
1500 if (i >= -32768 && i <= 32767)
1501 return MVS;
1504 /* Otherwise, use move.l */
1505 return MOVL;
1508 static int
1509 const_int_cost (rtx constant)
1511 switch (const_method (constant))
1513 case MOVQ :
1514 /* Constants between -128 and 127 are cheap due to moveq */
1515 return 0;
1516 case MVZ:
1517 case MVS:
1518 case NOTB :
1519 case NOTW :
1520 case NEGW :
1521 case SWAP :
1522 /* Constants easily generated by moveq + not.b/not.w/neg.w/swap */
1523 return 1;
1524 case MOVL :
1525 return 2;
1526 default :
1527 gcc_unreachable ();
1531 static bool
1532 m68k_rtx_costs (rtx x, int code, int outer_code, int *total)
1534 switch (code)
1536 case CONST_INT:
1537 /* Constant zero is super cheap due to clr instruction. */
1538 if (x == const0_rtx)
1539 *total = 0;
1540 else
1541 *total = const_int_cost (x);
1542 return true;
1544 case CONST:
1545 case LABEL_REF:
1546 case SYMBOL_REF:
1547 *total = 3;
1548 return true;
1550 case CONST_DOUBLE:
1551 /* Make 0.0 cheaper than other floating constants to
1552 encourage creating tstsf and tstdf insns. */
1553 if (outer_code == COMPARE
1554 && (x == CONST0_RTX (SFmode) || x == CONST0_RTX (DFmode)))
1555 *total = 4;
1556 else
1557 *total = 5;
1558 return true;
1560 /* These are vaguely right for a 68020. */
1561 /* The costs for long multiply have been adjusted to work properly
1562 in synth_mult on the 68020, relative to an average of the time
1563 for add and the time for shift, taking away a little more because
1564 sometimes move insns are needed. */
1565 /* div?.w is relatively cheaper on 68000 counted in COSTS_N_INSNS terms. */
1566 #define MULL_COST (TARGET_68060 ? 2 : TARGET_68040 ? 5 : (TARGET_COLDFIRE && !TARGET_5200) ? 3 : TARGET_COLDFIRE ? 10 : 13)
1567 #define MULW_COST (TARGET_68060 ? 2 : TARGET_68040 ? 3 : TARGET_68020 ? 8 : \
1568 (TARGET_COLDFIRE && !TARGET_5200) ? 2 : 5)
1569 #define DIVW_COST (TARGET_68020 ? 27 : TARGET_CF_HWDIV ? 11 : 12)
1571 case PLUS:
1572 /* An lea costs about three times as much as a simple add. */
1573 if (GET_MODE (x) == SImode
1574 && GET_CODE (XEXP (x, 1)) == REG
1575 && GET_CODE (XEXP (x, 0)) == MULT
1576 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
1577 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1578 && (INTVAL (XEXP (XEXP (x, 0), 1)) == 2
1579 || INTVAL (XEXP (XEXP (x, 0), 1)) == 4
1580 || INTVAL (XEXP (XEXP (x, 0), 1)) == 8))
1582 /* lea an@(dx:l:i),am */
1583 *total = COSTS_N_INSNS (TARGET_COLDFIRE ? 2 : 3);
1584 return true;
1586 return false;
1588 case ASHIFT:
1589 case ASHIFTRT:
1590 case LSHIFTRT:
1591 if (TARGET_68060)
1593 *total = COSTS_N_INSNS(1);
1594 return true;
1596 if (! TARGET_68020 && ! TARGET_COLDFIRE)
1598 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
1600 if (INTVAL (XEXP (x, 1)) < 16)
1601 *total = COSTS_N_INSNS (2) + INTVAL (XEXP (x, 1)) / 2;
1602 else
1603 /* We're using clrw + swap for these cases. */
1604 *total = COSTS_N_INSNS (4) + (INTVAL (XEXP (x, 1)) - 16) / 2;
1606 else
1607 *total = COSTS_N_INSNS (10); /* worst case */
1608 return true;
1610 /* A shift by a big integer takes an extra instruction. */
1611 if (GET_CODE (XEXP (x, 1)) == CONST_INT
1612 && (INTVAL (XEXP (x, 1)) == 16))
1614 *total = COSTS_N_INSNS (2); /* clrw;swap */
1615 return true;
1617 if (GET_CODE (XEXP (x, 1)) == CONST_INT
1618 && !(INTVAL (XEXP (x, 1)) > 0
1619 && INTVAL (XEXP (x, 1)) <= 8))
1621 *total = COSTS_N_INSNS (TARGET_COLDFIRE ? 1 : 3); /* lsr #i,dn */
1622 return true;
1624 return false;
1626 case MULT:
1627 if ((GET_CODE (XEXP (x, 0)) == ZERO_EXTEND
1628 || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)
1629 && GET_MODE (x) == SImode)
1630 *total = COSTS_N_INSNS (MULW_COST);
1631 else if (GET_MODE (x) == QImode || GET_MODE (x) == HImode)
1632 *total = COSTS_N_INSNS (MULW_COST);
1633 else
1634 *total = COSTS_N_INSNS (MULL_COST);
1635 return true;
1637 case DIV:
1638 case UDIV:
1639 case MOD:
1640 case UMOD:
1641 if (GET_MODE (x) == QImode || GET_MODE (x) == HImode)
1642 *total = COSTS_N_INSNS (DIVW_COST); /* div.w */
1643 else if (TARGET_CF_HWDIV)
1644 *total = COSTS_N_INSNS (18);
1645 else
1646 *total = COSTS_N_INSNS (43); /* div.l */
1647 return true;
1649 default:
1650 return false;
1654 const char *
1655 output_move_const_into_data_reg (rtx *operands)
1657 int i;
1659 i = INTVAL (operands[1]);
1660 switch (const_method (operands[1]))
1662 case MVZ:
1663 return "mvsw %1,%0";
1664 case MVS:
1665 return "mvzw %1,%0";
1666 case MOVQ :
1667 return "moveq %1,%0";
1668 case NOTB :
1669 CC_STATUS_INIT;
1670 operands[1] = GEN_INT (i ^ 0xff);
1671 return "moveq %1,%0\n\tnot%.b %0";
1672 case NOTW :
1673 CC_STATUS_INIT;
1674 operands[1] = GEN_INT (i ^ 0xffff);
1675 return "moveq %1,%0\n\tnot%.w %0";
1676 case NEGW :
1677 CC_STATUS_INIT;
1678 return "moveq #-128,%0\n\tneg%.w %0";
1679 case SWAP :
1681 unsigned u = i;
1683 operands[1] = GEN_INT ((u << 16) | (u >> 16));
1684 return "moveq %1,%0\n\tswap %0";
1686 case MOVL :
1687 return "move%.l %1,%0";
1688 default :
1689 gcc_unreachable ();
1693 /* Return 1 if 'constant' can be represented by
1694 mov3q on a ColdFire V4 core. */
1696 valid_mov3q_const (rtx constant)
1698 int i;
1700 if (TARGET_CFV4 && GET_CODE (constant) == CONST_INT)
1702 i = INTVAL (constant);
1703 if ((i == -1) || (i >= 1 && i <= 7))
1704 return 1;
1706 return 0;
1710 const char *
1711 output_move_simode_const (rtx *operands)
1713 if (operands[1] == const0_rtx
1714 && (DATA_REG_P (operands[0])
1715 || GET_CODE (operands[0]) == MEM)
1716 /* clr insns on 68000 read before writing.
1717 This isn't so on the 68010, but we have no TARGET_68010. */
1718 && ((TARGET_68020 || TARGET_COLDFIRE)
1719 || !(GET_CODE (operands[0]) == MEM
1720 && MEM_VOLATILE_P (operands[0]))))
1721 return "clr%.l %0";
1722 else if ((GET_MODE (operands[0]) == SImode)
1723 && valid_mov3q_const (operands[1]))
1724 return "mov3q%.l %1,%0";
1725 else if (operands[1] == const0_rtx
1726 && ADDRESS_REG_P (operands[0]))
1727 return "sub%.l %0,%0";
1728 else if (DATA_REG_P (operands[0]))
1729 return output_move_const_into_data_reg (operands);
1730 else if (ADDRESS_REG_P (operands[0])
1731 && INTVAL (operands[1]) < 0x8000
1732 && INTVAL (operands[1]) >= -0x8000)
1734 if (valid_mov3q_const (operands[1]))
1735 return "mov3q%.l %1,%0";
1736 return "move%.w %1,%0";
1738 else if (GET_CODE (operands[0]) == MEM
1739 && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
1740 && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM
1741 && INTVAL (operands[1]) < 0x8000
1742 && INTVAL (operands[1]) >= -0x8000)
1744 if (valid_mov3q_const (operands[1]))
1745 return "mov3q%.l %1,%-";
1746 return "pea %a1";
1748 return "move%.l %1,%0";
1751 const char *
1752 output_move_simode (rtx *operands)
1754 if (GET_CODE (operands[1]) == CONST_INT)
1755 return output_move_simode_const (operands);
1756 else if ((GET_CODE (operands[1]) == SYMBOL_REF
1757 || GET_CODE (operands[1]) == CONST)
1758 && push_operand (operands[0], SImode))
1759 return "pea %a1";
1760 else if ((GET_CODE (operands[1]) == SYMBOL_REF
1761 || GET_CODE (operands[1]) == CONST)
1762 && ADDRESS_REG_P (operands[0]))
1763 return "lea %a1,%0";
1764 return "move%.l %1,%0";
1767 const char *
1768 output_move_himode (rtx *operands)
1770 if (GET_CODE (operands[1]) == CONST_INT)
1772 if (operands[1] == const0_rtx
1773 && (DATA_REG_P (operands[0])
1774 || GET_CODE (operands[0]) == MEM)
1775 /* clr insns on 68000 read before writing.
1776 This isn't so on the 68010, but we have no TARGET_68010. */
1777 && ((TARGET_68020 || TARGET_COLDFIRE)
1778 || !(GET_CODE (operands[0]) == MEM
1779 && MEM_VOLATILE_P (operands[0]))))
1780 return "clr%.w %0";
1781 else if (operands[1] == const0_rtx
1782 && ADDRESS_REG_P (operands[0]))
1783 return "sub%.l %0,%0";
1784 else if (DATA_REG_P (operands[0])
1785 && INTVAL (operands[1]) < 128
1786 && INTVAL (operands[1]) >= -128)
1788 return "moveq %1,%0";
1790 else if (INTVAL (operands[1]) < 0x8000
1791 && INTVAL (operands[1]) >= -0x8000)
1792 return "move%.w %1,%0";
1794 else if (CONSTANT_P (operands[1]))
1795 return "move%.l %1,%0";
1796 /* Recognize the insn before a tablejump, one that refers
1797 to a table of offsets. Such an insn will need to refer
1798 to a label on the insn. So output one. Use the label-number
1799 of the table of offsets to generate this label. This code,
1800 and similar code below, assumes that there will be at most one
1801 reference to each table. */
1802 if (GET_CODE (operands[1]) == MEM
1803 && GET_CODE (XEXP (operands[1], 0)) == PLUS
1804 && GET_CODE (XEXP (XEXP (operands[1], 0), 1)) == LABEL_REF
1805 && GET_CODE (XEXP (XEXP (operands[1], 0), 0)) != PLUS)
1807 rtx labelref = XEXP (XEXP (operands[1], 0), 1);
1808 if (MOTOROLA)
1809 asm_fprintf (asm_out_file, "\t.set %LLI%d,.+2\n",
1810 CODE_LABEL_NUMBER (XEXP (labelref, 0)));
1811 else
1812 (*targetm.asm_out.internal_label) (asm_out_file, "LI",
1813 CODE_LABEL_NUMBER (XEXP (labelref, 0)));
1815 return "move%.w %1,%0";
1818 const char *
1819 output_move_qimode (rtx *operands)
1821 /* 68k family always modifies the stack pointer by at least 2, even for
1822 byte pushes. The 5200 (ColdFire) does not do this. */
1824 /* This case is generated by pushqi1 pattern now */
1825 gcc_assert (!(GET_CODE (operands[0]) == MEM
1826 && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
1827 && XEXP (XEXP (operands[0], 0), 0) == stack_pointer_rtx
1828 && ! ADDRESS_REG_P (operands[1])
1829 && ! TARGET_COLDFIRE));
1831 /* clr and st insns on 68000 read before writing.
1832 This isn't so on the 68010, but we have no TARGET_68010. */
1833 if (!ADDRESS_REG_P (operands[0])
1834 && ((TARGET_68020 || TARGET_COLDFIRE)
1835 || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))))
1837 if (operands[1] == const0_rtx)
1838 return "clr%.b %0";
1839 if ((!TARGET_COLDFIRE || DATA_REG_P (operands[0]))
1840 && GET_CODE (operands[1]) == CONST_INT
1841 && (INTVAL (operands[1]) & 255) == 255)
1843 CC_STATUS_INIT;
1844 return "st %0";
1847 if (GET_CODE (operands[1]) == CONST_INT
1848 && DATA_REG_P (operands[0])
1849 && INTVAL (operands[1]) < 128
1850 && INTVAL (operands[1]) >= -128)
1852 return "moveq %1,%0";
1854 if (operands[1] == const0_rtx && ADDRESS_REG_P (operands[0]))
1855 return "sub%.l %0,%0";
1856 if (GET_CODE (operands[1]) != CONST_INT && CONSTANT_P (operands[1]))
1857 return "move%.l %1,%0";
1858 /* 68k family (including the 5200 ColdFire) does not support byte moves to
1859 from address registers. */
1860 if (ADDRESS_REG_P (operands[0]) || ADDRESS_REG_P (operands[1]))
1861 return "move%.w %1,%0";
1862 return "move%.b %1,%0";
1865 const char *
1866 output_move_stricthi (rtx *operands)
1868 if (operands[1] == const0_rtx
1869 /* clr insns on 68000 read before writing.
1870 This isn't so on the 68010, but we have no TARGET_68010. */
1871 && ((TARGET_68020 || TARGET_COLDFIRE)
1872 || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))))
1873 return "clr%.w %0";
1874 return "move%.w %1,%0";
1877 const char *
1878 output_move_strictqi (rtx *operands)
1880 if (operands[1] == const0_rtx
1881 /* clr insns on 68000 read before writing.
1882 This isn't so on the 68010, but we have no TARGET_68010. */
1883 && ((TARGET_68020 || TARGET_COLDFIRE)
1884 || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))))
1885 return "clr%.b %0";
1886 return "move%.b %1,%0";
1889 /* Return the best assembler insn template
1890 for moving operands[1] into operands[0] as a fullword. */
1892 static const char *
1893 singlemove_string (rtx *operands)
1895 if (GET_CODE (operands[1]) == CONST_INT)
1896 return output_move_simode_const (operands);
1897 return "move%.l %1,%0";
1901 /* Output assembler code to perform a doubleword move insn
1902 with operands OPERANDS. */
1904 const char *
1905 output_move_double (rtx *operands)
1907 enum
1909 REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP
1910 } optype0, optype1;
1911 rtx latehalf[2];
1912 rtx middlehalf[2];
1913 rtx xops[2];
1914 rtx addreg0 = 0, addreg1 = 0;
1915 int dest_overlapped_low = 0;
1916 int size = GET_MODE_SIZE (GET_MODE (operands[0]));
1918 middlehalf[0] = 0;
1919 middlehalf[1] = 0;
1921 /* First classify both operands. */
1923 if (REG_P (operands[0]))
1924 optype0 = REGOP;
1925 else if (offsettable_memref_p (operands[0]))
1926 optype0 = OFFSOP;
1927 else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
1928 optype0 = POPOP;
1929 else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
1930 optype0 = PUSHOP;
1931 else if (GET_CODE (operands[0]) == MEM)
1932 optype0 = MEMOP;
1933 else
1934 optype0 = RNDOP;
1936 if (REG_P (operands[1]))
1937 optype1 = REGOP;
1938 else if (CONSTANT_P (operands[1]))
1939 optype1 = CNSTOP;
1940 else if (offsettable_memref_p (operands[1]))
1941 optype1 = OFFSOP;
1942 else if (GET_CODE (XEXP (operands[1], 0)) == POST_INC)
1943 optype1 = POPOP;
1944 else if (GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)
1945 optype1 = PUSHOP;
1946 else if (GET_CODE (operands[1]) == MEM)
1947 optype1 = MEMOP;
1948 else
1949 optype1 = RNDOP;
1951 /* Check for the cases that the operand constraints are not supposed
1952 to allow to happen. Generating code for these cases is
1953 painful. */
1954 gcc_assert (optype0 != RNDOP && optype1 != RNDOP);
1956 /* If one operand is decrementing and one is incrementing
1957 decrement the former register explicitly
1958 and change that operand into ordinary indexing. */
1960 if (optype0 == PUSHOP && optype1 == POPOP)
1962 operands[0] = XEXP (XEXP (operands[0], 0), 0);
1963 if (size == 12)
1964 output_asm_insn ("sub%.l #12,%0", operands);
1965 else
1966 output_asm_insn ("subq%.l #8,%0", operands);
1967 if (GET_MODE (operands[1]) == XFmode)
1968 operands[0] = gen_rtx_MEM (XFmode, operands[0]);
1969 else if (GET_MODE (operands[0]) == DFmode)
1970 operands[0] = gen_rtx_MEM (DFmode, operands[0]);
1971 else
1972 operands[0] = gen_rtx_MEM (DImode, operands[0]);
1973 optype0 = OFFSOP;
1975 if (optype0 == POPOP && optype1 == PUSHOP)
1977 operands[1] = XEXP (XEXP (operands[1], 0), 0);
1978 if (size == 12)
1979 output_asm_insn ("sub%.l #12,%1", operands);
1980 else
1981 output_asm_insn ("subq%.l #8,%1", operands);
1982 if (GET_MODE (operands[1]) == XFmode)
1983 operands[1] = gen_rtx_MEM (XFmode, operands[1]);
1984 else if (GET_MODE (operands[1]) == DFmode)
1985 operands[1] = gen_rtx_MEM (DFmode, operands[1]);
1986 else
1987 operands[1] = gen_rtx_MEM (DImode, operands[1]);
1988 optype1 = OFFSOP;
1991 /* If an operand is an unoffsettable memory ref, find a register
1992 we can increment temporarily to make it refer to the second word. */
1994 if (optype0 == MEMOP)
1995 addreg0 = find_addr_reg (XEXP (operands[0], 0));
1997 if (optype1 == MEMOP)
1998 addreg1 = find_addr_reg (XEXP (operands[1], 0));
2000 /* Ok, we can do one word at a time.
2001 Normally we do the low-numbered word first,
2002 but if either operand is autodecrementing then we
2003 do the high-numbered word first.
2005 In either case, set up in LATEHALF the operands to use
2006 for the high-numbered word and in some cases alter the
2007 operands in OPERANDS to be suitable for the low-numbered word. */
2009 if (size == 12)
2011 if (optype0 == REGOP)
2013 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 2);
2014 middlehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2016 else if (optype0 == OFFSOP)
2018 middlehalf[0] = adjust_address (operands[0], SImode, 4);
2019 latehalf[0] = adjust_address (operands[0], SImode, size - 4);
2021 else
2023 middlehalf[0] = operands[0];
2024 latehalf[0] = operands[0];
2027 if (optype1 == REGOP)
2029 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 2);
2030 middlehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2032 else if (optype1 == OFFSOP)
2034 middlehalf[1] = adjust_address (operands[1], SImode, 4);
2035 latehalf[1] = adjust_address (operands[1], SImode, size - 4);
2037 else if (optype1 == CNSTOP)
2039 if (GET_CODE (operands[1]) == CONST_DOUBLE)
2041 REAL_VALUE_TYPE r;
2042 long l[3];
2044 REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
2045 REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
2046 operands[1] = GEN_INT (l[0]);
2047 middlehalf[1] = GEN_INT (l[1]);
2048 latehalf[1] = GEN_INT (l[2]);
2050 else
2052 /* No non-CONST_DOUBLE constant should ever appear
2053 here. */
2054 gcc_assert (!CONSTANT_P (operands[1]));
2057 else
2059 middlehalf[1] = operands[1];
2060 latehalf[1] = operands[1];
2063 else
2064 /* size is not 12: */
2066 if (optype0 == REGOP)
2067 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2068 else if (optype0 == OFFSOP)
2069 latehalf[0] = adjust_address (operands[0], SImode, size - 4);
2070 else
2071 latehalf[0] = operands[0];
2073 if (optype1 == REGOP)
2074 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2075 else if (optype1 == OFFSOP)
2076 latehalf[1] = adjust_address (operands[1], SImode, size - 4);
2077 else if (optype1 == CNSTOP)
2078 split_double (operands[1], &operands[1], &latehalf[1]);
2079 else
2080 latehalf[1] = operands[1];
2083 /* If insn is effectively movd N(sp),-(sp) then we will do the
2084 high word first. We should use the adjusted operand 1 (which is N+4(sp))
2085 for the low word as well, to compensate for the first decrement of sp. */
2086 if (optype0 == PUSHOP
2087 && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM
2088 && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
2089 operands[1] = middlehalf[1] = latehalf[1];
2091 /* For (set (reg:DI N) (mem:DI ... (reg:SI N) ...)),
2092 if the upper part of reg N does not appear in the MEM, arrange to
2093 emit the move late-half first. Otherwise, compute the MEM address
2094 into the upper part of N and use that as a pointer to the memory
2095 operand. */
2096 if (optype0 == REGOP
2097 && (optype1 == OFFSOP || optype1 == MEMOP))
2099 rtx testlow = gen_rtx_REG (SImode, REGNO (operands[0]));
2101 if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0))
2102 && reg_overlap_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
2104 /* If both halves of dest are used in the src memory address,
2105 compute the address into latehalf of dest.
2106 Note that this can't happen if the dest is two data regs. */
2107 compadr:
2108 xops[0] = latehalf[0];
2109 xops[1] = XEXP (operands[1], 0);
2110 output_asm_insn ("lea %a1,%0", xops);
2111 if (GET_MODE (operands[1]) == XFmode )
2113 operands[1] = gen_rtx_MEM (XFmode, latehalf[0]);
2114 middlehalf[1] = adjust_address (operands[1], DImode, size - 8);
2115 latehalf[1] = adjust_address (operands[1], DImode, size - 4);
2117 else
2119 operands[1] = gen_rtx_MEM (DImode, latehalf[0]);
2120 latehalf[1] = adjust_address (operands[1], DImode, size - 4);
2123 else if (size == 12
2124 && reg_overlap_mentioned_p (middlehalf[0],
2125 XEXP (operands[1], 0)))
2127 /* Check for two regs used by both source and dest.
2128 Note that this can't happen if the dest is all data regs.
2129 It can happen if the dest is d6, d7, a0.
2130 But in that case, latehalf is an addr reg, so
2131 the code at compadr does ok. */
2133 if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0))
2134 || reg_overlap_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
2135 goto compadr;
2137 /* JRV says this can't happen: */
2138 gcc_assert (!addreg0 && !addreg1);
2140 /* Only the middle reg conflicts; simply put it last. */
2141 output_asm_insn (singlemove_string (operands), operands);
2142 output_asm_insn (singlemove_string (latehalf), latehalf);
2143 output_asm_insn (singlemove_string (middlehalf), middlehalf);
2144 return "";
2146 else if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0)))
2147 /* If the low half of dest is mentioned in the source memory
2148 address, the arrange to emit the move late half first. */
2149 dest_overlapped_low = 1;
2152 /* If one or both operands autodecrementing,
2153 do the two words, high-numbered first. */
2155 /* Likewise, the first move would clobber the source of the second one,
2156 do them in the other order. This happens only for registers;
2157 such overlap can't happen in memory unless the user explicitly
2158 sets it up, and that is an undefined circumstance. */
2160 if (optype0 == PUSHOP || optype1 == PUSHOP
2161 || (optype0 == REGOP && optype1 == REGOP
2162 && ((middlehalf[1] && REGNO (operands[0]) == REGNO (middlehalf[1]))
2163 || REGNO (operands[0]) == REGNO (latehalf[1])))
2164 || dest_overlapped_low)
2166 /* Make any unoffsettable addresses point at high-numbered word. */
2167 if (addreg0)
2169 if (size == 12)
2170 output_asm_insn ("addq%.l #8,%0", &addreg0);
2171 else
2172 output_asm_insn ("addq%.l #4,%0", &addreg0);
2174 if (addreg1)
2176 if (size == 12)
2177 output_asm_insn ("addq%.l #8,%0", &addreg1);
2178 else
2179 output_asm_insn ("addq%.l #4,%0", &addreg1);
2182 /* Do that word. */
2183 output_asm_insn (singlemove_string (latehalf), latehalf);
2185 /* Undo the adds we just did. */
2186 if (addreg0)
2187 output_asm_insn ("subq%.l #4,%0", &addreg0);
2188 if (addreg1)
2189 output_asm_insn ("subq%.l #4,%0", &addreg1);
2191 if (size == 12)
2193 output_asm_insn (singlemove_string (middlehalf), middlehalf);
2194 if (addreg0)
2195 output_asm_insn ("subq%.l #4,%0", &addreg0);
2196 if (addreg1)
2197 output_asm_insn ("subq%.l #4,%0", &addreg1);
2200 /* Do low-numbered word. */
2201 return singlemove_string (operands);
2204 /* Normal case: do the two words, low-numbered first. */
2206 output_asm_insn (singlemove_string (operands), operands);
2208 /* Do the middle one of the three words for long double */
2209 if (size == 12)
2211 if (addreg0)
2212 output_asm_insn ("addq%.l #4,%0", &addreg0);
2213 if (addreg1)
2214 output_asm_insn ("addq%.l #4,%0", &addreg1);
2216 output_asm_insn (singlemove_string (middlehalf), middlehalf);
2219 /* Make any unoffsettable addresses point at high-numbered word. */
2220 if (addreg0)
2221 output_asm_insn ("addq%.l #4,%0", &addreg0);
2222 if (addreg1)
2223 output_asm_insn ("addq%.l #4,%0", &addreg1);
2225 /* Do that word. */
2226 output_asm_insn (singlemove_string (latehalf), latehalf);
2228 /* Undo the adds we just did. */
2229 if (addreg0)
2231 if (size == 12)
2232 output_asm_insn ("subq%.l #8,%0", &addreg0);
2233 else
2234 output_asm_insn ("subq%.l #4,%0", &addreg0);
2236 if (addreg1)
2238 if (size == 12)
2239 output_asm_insn ("subq%.l #8,%0", &addreg1);
2240 else
2241 output_asm_insn ("subq%.l #4,%0", &addreg1);
2244 return "";
2247 /* Return a REG that occurs in ADDR with coefficient 1.
2248 ADDR can be effectively incremented by incrementing REG. */
2250 static rtx
2251 find_addr_reg (rtx addr)
2253 while (GET_CODE (addr) == PLUS)
2255 if (GET_CODE (XEXP (addr, 0)) == REG)
2256 addr = XEXP (addr, 0);
2257 else if (GET_CODE (XEXP (addr, 1)) == REG)
2258 addr = XEXP (addr, 1);
2259 else if (CONSTANT_P (XEXP (addr, 0)))
2260 addr = XEXP (addr, 1);
2261 else if (CONSTANT_P (XEXP (addr, 1)))
2262 addr = XEXP (addr, 0);
2263 else
2264 gcc_unreachable ();
2266 gcc_assert (GET_CODE (addr) == REG);
2267 return addr;
2270 /* Output assembler code to perform a 32-bit 3-operand add. */
2272 const char *
2273 output_addsi3 (rtx *operands)
2275 if (! operands_match_p (operands[0], operands[1]))
2277 if (!ADDRESS_REG_P (operands[1]))
2279 rtx tmp = operands[1];
2281 operands[1] = operands[2];
2282 operands[2] = tmp;
2285 /* These insns can result from reloads to access
2286 stack slots over 64k from the frame pointer. */
2287 if (GET_CODE (operands[2]) == CONST_INT
2288 && (INTVAL (operands[2]) < -32768 || INTVAL (operands[2]) > 32767))
2289 return "move%.l %2,%0\n\tadd%.l %1,%0";
2290 if (GET_CODE (operands[2]) == REG)
2291 return MOTOROLA ? "lea (%1,%2.l),%0" : "lea %1@(0,%2:l),%0";
2292 return MOTOROLA ? "lea (%c2,%1),%0" : "lea %1@(%c2),%0";
2294 if (GET_CODE (operands[2]) == CONST_INT)
2296 if (INTVAL (operands[2]) > 0
2297 && INTVAL (operands[2]) <= 8)
2298 return "addq%.l %2,%0";
2299 if (INTVAL (operands[2]) < 0
2300 && INTVAL (operands[2]) >= -8)
2302 operands[2] = GEN_INT (- INTVAL (operands[2]));
2303 return "subq%.l %2,%0";
2305 /* On the CPU32 it is faster to use two addql instructions to
2306 add a small integer (8 < N <= 16) to a register.
2307 Likewise for subql. */
2308 if (TARGET_CPU32 && REG_P (operands[0]))
2310 if (INTVAL (operands[2]) > 8
2311 && INTVAL (operands[2]) <= 16)
2313 operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
2314 return "addq%.l #8,%0\n\taddq%.l %2,%0";
2316 if (INTVAL (operands[2]) < -8
2317 && INTVAL (operands[2]) >= -16)
2319 operands[2] = GEN_INT (- INTVAL (operands[2]) - 8);
2320 return "subq%.l #8,%0\n\tsubq%.l %2,%0";
2323 if (ADDRESS_REG_P (operands[0])
2324 && INTVAL (operands[2]) >= -0x8000
2325 && INTVAL (operands[2]) < 0x8000)
2327 if (TARGET_68040)
2328 return "add%.w %2,%0";
2329 else
2330 return MOTOROLA ? "lea (%c2,%0),%0" : "lea %0@(%c2),%0";
2333 return "add%.l %2,%0";
2336 /* Store in cc_status the expressions that the condition codes will
2337 describe after execution of an instruction whose pattern is EXP.
2338 Do not alter them if the instruction would not alter the cc's. */
2340 /* On the 68000, all the insns to store in an address register fail to
2341 set the cc's. However, in some cases these instructions can make it
2342 possibly invalid to use the saved cc's. In those cases we clear out
2343 some or all of the saved cc's so they won't be used. */
2345 void
2346 notice_update_cc (rtx exp, rtx insn)
2348 if (GET_CODE (exp) == SET)
2350 if (GET_CODE (SET_SRC (exp)) == CALL)
2352 CC_STATUS_INIT;
2354 else if (ADDRESS_REG_P (SET_DEST (exp)))
2356 if (cc_status.value1 && modified_in_p (cc_status.value1, insn))
2357 cc_status.value1 = 0;
2358 if (cc_status.value2 && modified_in_p (cc_status.value2, insn))
2359 cc_status.value2 = 0;
2361 else if (!FP_REG_P (SET_DEST (exp))
2362 && SET_DEST (exp) != cc0_rtx
2363 && (FP_REG_P (SET_SRC (exp))
2364 || GET_CODE (SET_SRC (exp)) == FIX
2365 || GET_CODE (SET_SRC (exp)) == FLOAT_TRUNCATE
2366 || GET_CODE (SET_SRC (exp)) == FLOAT_EXTEND))
2368 CC_STATUS_INIT;
2370 /* A pair of move insns doesn't produce a useful overall cc. */
2371 else if (!FP_REG_P (SET_DEST (exp))
2372 && !FP_REG_P (SET_SRC (exp))
2373 && GET_MODE_SIZE (GET_MODE (SET_SRC (exp))) > 4
2374 && (GET_CODE (SET_SRC (exp)) == REG
2375 || GET_CODE (SET_SRC (exp)) == MEM
2376 || GET_CODE (SET_SRC (exp)) == CONST_DOUBLE))
2378 CC_STATUS_INIT;
2380 else if (GET_CODE (SET_SRC (exp)) == CALL)
2382 CC_STATUS_INIT;
2384 else if (XEXP (exp, 0) != pc_rtx)
2386 cc_status.flags = 0;
2387 cc_status.value1 = XEXP (exp, 0);
2388 cc_status.value2 = XEXP (exp, 1);
2391 else if (GET_CODE (exp) == PARALLEL
2392 && GET_CODE (XVECEXP (exp, 0, 0)) == SET)
2394 if (ADDRESS_REG_P (XEXP (XVECEXP (exp, 0, 0), 0)))
2395 CC_STATUS_INIT;
2396 else if (XEXP (XVECEXP (exp, 0, 0), 0) != pc_rtx)
2398 cc_status.flags = 0;
2399 cc_status.value1 = XEXP (XVECEXP (exp, 0, 0), 0);
2400 cc_status.value2 = XEXP (XVECEXP (exp, 0, 0), 1);
2403 else
2404 CC_STATUS_INIT;
2405 if (cc_status.value2 != 0
2406 && ADDRESS_REG_P (cc_status.value2)
2407 && GET_MODE (cc_status.value2) == QImode)
2408 CC_STATUS_INIT;
2409 if (cc_status.value2 != 0)
2410 switch (GET_CODE (cc_status.value2))
2412 case ASHIFT: case ASHIFTRT: case LSHIFTRT:
2413 case ROTATE: case ROTATERT:
2414 /* These instructions always clear the overflow bit, and set
2415 the carry to the bit shifted out. */
2416 /* ??? We don't currently have a way to signal carry not valid,
2417 nor do we check for it in the branch insns. */
2418 CC_STATUS_INIT;
2419 break;
2421 case PLUS: case MINUS: case MULT:
2422 case DIV: case UDIV: case MOD: case UMOD: case NEG:
2423 if (GET_MODE (cc_status.value2) != VOIDmode)
2424 cc_status.flags |= CC_NO_OVERFLOW;
2425 break;
2426 case ZERO_EXTEND:
2427 /* (SET r1 (ZERO_EXTEND r2)) on this machine
2428 ends with a move insn moving r2 in r2's mode.
2429 Thus, the cc's are set for r2.
2430 This can set N bit spuriously. */
2431 cc_status.flags |= CC_NOT_NEGATIVE;
2433 default:
2434 break;
2436 if (cc_status.value1 && GET_CODE (cc_status.value1) == REG
2437 && cc_status.value2
2438 && reg_overlap_mentioned_p (cc_status.value1, cc_status.value2))
2439 cc_status.value2 = 0;
2440 if (((cc_status.value1 && FP_REG_P (cc_status.value1))
2441 || (cc_status.value2 && FP_REG_P (cc_status.value2))))
2442 cc_status.flags = CC_IN_68881;
2445 const char *
2446 output_move_const_double (rtx *operands)
2448 int code = standard_68881_constant_p (operands[1]);
2450 if (code != 0)
2452 static char buf[40];
2454 sprintf (buf, "fmovecr #0x%x,%%0", code & 0xff);
2455 return buf;
2457 return "fmove%.d %1,%0";
2460 const char *
2461 output_move_const_single (rtx *operands)
2463 int code = standard_68881_constant_p (operands[1]);
2465 if (code != 0)
2467 static char buf[40];
2469 sprintf (buf, "fmovecr #0x%x,%%0", code & 0xff);
2470 return buf;
2472 return "fmove%.s %f1,%0";
2475 /* Return nonzero if X, a CONST_DOUBLE, has a value that we can get
2476 from the "fmovecr" instruction.
2477 The value, anded with 0xff, gives the code to use in fmovecr
2478 to get the desired constant. */
2480 /* This code has been fixed for cross-compilation. */
2482 static int inited_68881_table = 0;
2484 static const char *const strings_68881[7] = {
2485 "0.0",
2486 "1.0",
2487 "10.0",
2488 "100.0",
2489 "10000.0",
2490 "1e8",
2491 "1e16"
2494 static const int codes_68881[7] = {
2495 0x0f,
2496 0x32,
2497 0x33,
2498 0x34,
2499 0x35,
2500 0x36,
2501 0x37
2504 REAL_VALUE_TYPE values_68881[7];
2506 /* Set up values_68881 array by converting the decimal values
2507 strings_68881 to binary. */
2509 void
2510 init_68881_table (void)
2512 int i;
2513 REAL_VALUE_TYPE r;
2514 enum machine_mode mode;
2516 mode = SFmode;
2517 for (i = 0; i < 7; i++)
2519 if (i == 6)
2520 mode = DFmode;
2521 r = REAL_VALUE_ATOF (strings_68881[i], mode);
2522 values_68881[i] = r;
2524 inited_68881_table = 1;
2528 standard_68881_constant_p (rtx x)
2530 REAL_VALUE_TYPE r;
2531 int i;
2533 /* fmovecr must be emulated on the 68040 and 68060, so it shouldn't be
2534 used at all on those chips. */
2535 if (TARGET_68040 || TARGET_68060)
2536 return 0;
2538 if (! inited_68881_table)
2539 init_68881_table ();
2541 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
2543 /* Use REAL_VALUES_IDENTICAL instead of REAL_VALUES_EQUAL so that -0.0
2544 is rejected. */
2545 for (i = 0; i < 6; i++)
2547 if (REAL_VALUES_IDENTICAL (r, values_68881[i]))
2548 return (codes_68881[i]);
2551 if (GET_MODE (x) == SFmode)
2552 return 0;
2554 if (REAL_VALUES_EQUAL (r, values_68881[6]))
2555 return (codes_68881[6]);
2557 /* larger powers of ten in the constants ram are not used
2558 because they are not equal to a `double' C constant. */
2559 return 0;
2562 /* If X is a floating-point constant, return the logarithm of X base 2,
2563 or 0 if X is not a power of 2. */
2566 floating_exact_log2 (rtx x)
2568 REAL_VALUE_TYPE r, r1;
2569 int exp;
2571 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
2573 if (REAL_VALUES_LESS (r, dconst1))
2574 return 0;
2576 exp = real_exponent (&r);
2577 real_2expN (&r1, exp);
2578 if (REAL_VALUES_EQUAL (r1, r))
2579 return exp;
2581 return 0;
2584 /* A C compound statement to output to stdio stream STREAM the
2585 assembler syntax for an instruction operand X. X is an RTL
2586 expression.
2588 CODE is a value that can be used to specify one of several ways
2589 of printing the operand. It is used when identical operands
2590 must be printed differently depending on the context. CODE
2591 comes from the `%' specification that was used to request
2592 printing of the operand. If the specification was just `%DIGIT'
2593 then CODE is 0; if the specification was `%LTR DIGIT' then CODE
2594 is the ASCII code for LTR.
2596 If X is a register, this macro should print the register's name.
2597 The names can be found in an array `reg_names' whose type is
2598 `char *[]'. `reg_names' is initialized from `REGISTER_NAMES'.
2600 When the machine description has a specification `%PUNCT' (a `%'
2601 followed by a punctuation character), this macro is called with
2602 a null pointer for X and the punctuation character for CODE.
2604 The m68k specific codes are:
2606 '.' for dot needed in Motorola-style opcode names.
2607 '-' for an operand pushing on the stack:
2608 sp@-, -(sp) or -(%sp) depending on the style of syntax.
2609 '+' for an operand pushing on the stack:
2610 sp@+, (sp)+ or (%sp)+ depending on the style of syntax.
2611 '@' for a reference to the top word on the stack:
2612 sp@, (sp) or (%sp) depending on the style of syntax.
2613 '#' for an immediate operand prefix (# in MIT and Motorola syntax
2614 but & in SGS syntax).
2615 '!' for the cc register (used in an `and to cc' insn).
2616 '$' for the letter `s' in an op code, but only on the 68040.
2617 '&' for the letter `d' in an op code, but only on the 68040.
2618 '/' for register prefix needed by longlong.h.
2620 'b' for byte insn (no effect, on the Sun; this is for the ISI).
2621 'd' to force memory addressing to be absolute, not relative.
2622 'f' for float insn (print a CONST_DOUBLE as a float rather than in hex)
2623 'o' for operands to go directly to output_operand_address (bypassing
2624 print_operand_address--used only for SYMBOL_REFs under TARGET_PCREL)
2625 'x' for float insn (print a CONST_DOUBLE as a float rather than in hex),
2626 or print pair of registers as rx:ry.
2630 void
2631 print_operand (FILE *file, rtx op, int letter)
2633 if (letter == '.')
2635 if (MOTOROLA)
2636 fprintf (file, ".");
2638 else if (letter == '#')
2639 asm_fprintf (file, "%I");
2640 else if (letter == '-')
2641 asm_fprintf (file, MOTOROLA ? "-(%Rsp)" : "%Rsp@-");
2642 else if (letter == '+')
2643 asm_fprintf (file, MOTOROLA ? "(%Rsp)+" : "%Rsp@+");
2644 else if (letter == '@')
2645 asm_fprintf (file, MOTOROLA ? "(%Rsp)" : "%Rsp@");
2646 else if (letter == '!')
2647 asm_fprintf (file, "%Rfpcr");
2648 else if (letter == '$')
2650 if (TARGET_68040_ONLY)
2651 fprintf (file, "s");
2653 else if (letter == '&')
2655 if (TARGET_68040_ONLY)
2656 fprintf (file, "d");
2658 else if (letter == '/')
2659 asm_fprintf (file, "%R");
2660 else if (letter == 'o')
2662 /* This is only for direct addresses with TARGET_PCREL */
2663 gcc_assert (GET_CODE (op) == MEM
2664 && GET_CODE (XEXP (op, 0)) == SYMBOL_REF
2665 && TARGET_PCREL);
2666 output_addr_const (file, XEXP (op, 0));
2668 else if (GET_CODE (op) == REG)
2670 if (letter == 'R')
2671 /* Print out the second register name of a register pair.
2672 I.e., R (6) => 7. */
2673 fputs (M68K_REGNAME(REGNO (op) + 1), file);
2674 else
2675 fputs (M68K_REGNAME(REGNO (op)), file);
2677 else if (GET_CODE (op) == MEM)
2679 output_address (XEXP (op, 0));
2680 if (letter == 'd' && ! TARGET_68020
2681 && CONSTANT_ADDRESS_P (XEXP (op, 0))
2682 && !(GET_CODE (XEXP (op, 0)) == CONST_INT
2683 && INTVAL (XEXP (op, 0)) < 0x8000
2684 && INTVAL (XEXP (op, 0)) >= -0x8000))
2685 fprintf (file, MOTOROLA ? ".l" : ":l");
2687 else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == SFmode)
2689 REAL_VALUE_TYPE r;
2690 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
2691 ASM_OUTPUT_FLOAT_OPERAND (letter, file, r);
2693 else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == XFmode)
2695 REAL_VALUE_TYPE r;
2696 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
2697 ASM_OUTPUT_LONG_DOUBLE_OPERAND (file, r);
2699 else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == DFmode)
2701 REAL_VALUE_TYPE r;
2702 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
2703 ASM_OUTPUT_DOUBLE_OPERAND (file, r);
2705 else
2707 /* Use `print_operand_address' instead of `output_addr_const'
2708 to ensure that we print relevant PIC stuff. */
2709 asm_fprintf (file, "%I");
2710 if (TARGET_PCREL
2711 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST))
2712 print_operand_address (file, op);
2713 else
2714 output_addr_const (file, op);
2719 /* A C compound statement to output to stdio stream STREAM the
2720 assembler syntax for an instruction operand that is a memory
2721 reference whose address is ADDR. ADDR is an RTL expression.
2723 Note that this contains a kludge that knows that the only reason
2724 we have an address (plus (label_ref...) (reg...)) when not generating
2725 PIC code is in the insn before a tablejump, and we know that m68k.md
2726 generates a label LInnn: on such an insn.
2728 It is possible for PIC to generate a (plus (label_ref...) (reg...))
2729 and we handle that just like we would a (plus (symbol_ref...) (reg...)).
2731 Some SGS assemblers have a bug such that "Lnnn-LInnn-2.b(pc,d0.l*2)"
2732 fails to assemble. Luckily "Lnnn(pc,d0.l*2)" produces the results
2733 we want. This difference can be accommodated by using an assembler
2734 define such "LDnnn" to be either "Lnnn-LInnn-2.b", "Lnnn", or any other
2735 string, as necessary. This is accomplished via the ASM_OUTPUT_CASE_END
2736 macro. See m68k/sgs.h for an example; for versions without the bug.
2737 Some assemblers refuse all the above solutions. The workaround is to
2738 emit "K(pc,d0.l*2)" with K being a small constant known to give the
2739 right behavior.
2741 They also do not like things like "pea 1.w", so we simple leave off
2742 the .w on small constants.
2744 This routine is responsible for distinguishing between -fpic and -fPIC
2745 style relocations in an address. When generating -fpic code the
2746 offset is output in word mode (e.g. movel a5@(_foo:w), a0). When generating
2747 -fPIC code the offset is output in long mode (e.g. movel a5@(_foo:l), a0) */
2749 #if MOTOROLA
2750 # define ASM_OUTPUT_CASE_FETCH(file, labelno, regname)\
2751 asm_fprintf (file, "%LL%d-%LLI%d.b(%Rpc,%s.", labelno, labelno, regname)
2752 #else /* !MOTOROLA */
2753 # define ASM_OUTPUT_CASE_FETCH(file, labelno, regname)\
2754 asm_fprintf (file, "%Rpc@(%LL%d-%LLI%d-2:b,%s:", labelno, labelno, regname)
2755 #endif /* !MOTOROLA */
2757 void
2758 print_operand_address (FILE *file, rtx addr)
2760 register rtx reg1, reg2, breg, ireg;
2761 rtx offset;
2763 switch (GET_CODE (addr))
2765 case REG:
2766 fprintf (file, MOTOROLA ? "(%s)" : "%s@", M68K_REGNAME(REGNO (addr)));
2767 break;
2768 case PRE_DEC:
2769 fprintf (file, MOTOROLA ? "-(%s)" : "%s@-",
2770 M68K_REGNAME(REGNO (XEXP (addr, 0))));
2771 break;
2772 case POST_INC:
2773 fprintf (file, MOTOROLA ? "(%s)+" : "%s@+",
2774 M68K_REGNAME(REGNO (XEXP (addr, 0))));
2775 break;
2776 case PLUS:
2777 reg1 = reg2 = ireg = breg = offset = 0;
2778 if (CONSTANT_ADDRESS_P (XEXP (addr, 0)))
2780 offset = XEXP (addr, 0);
2781 addr = XEXP (addr, 1);
2783 else if (CONSTANT_ADDRESS_P (XEXP (addr, 1)))
2785 offset = XEXP (addr, 1);
2786 addr = XEXP (addr, 0);
2788 if (GET_CODE (addr) != PLUS)
2792 else if (GET_CODE (XEXP (addr, 0)) == SIGN_EXTEND)
2794 reg1 = XEXP (addr, 0);
2795 addr = XEXP (addr, 1);
2797 else if (GET_CODE (XEXP (addr, 1)) == SIGN_EXTEND)
2799 reg1 = XEXP (addr, 1);
2800 addr = XEXP (addr, 0);
2802 else if (GET_CODE (XEXP (addr, 0)) == MULT)
2804 reg1 = XEXP (addr, 0);
2805 addr = XEXP (addr, 1);
2807 else if (GET_CODE (XEXP (addr, 1)) == MULT)
2809 reg1 = XEXP (addr, 1);
2810 addr = XEXP (addr, 0);
2812 else if (GET_CODE (XEXP (addr, 0)) == REG)
2814 reg1 = XEXP (addr, 0);
2815 addr = XEXP (addr, 1);
2817 else if (GET_CODE (XEXP (addr, 1)) == REG)
2819 reg1 = XEXP (addr, 1);
2820 addr = XEXP (addr, 0);
2822 if (GET_CODE (addr) == REG || GET_CODE (addr) == MULT
2823 || GET_CODE (addr) == SIGN_EXTEND)
2825 if (reg1 == 0)
2827 reg1 = addr;
2829 else
2831 reg2 = addr;
2833 addr = 0;
2835 #if 0 /* for OLD_INDEXING */
2836 else if (GET_CODE (addr) == PLUS)
2838 if (GET_CODE (XEXP (addr, 0)) == REG)
2840 reg2 = XEXP (addr, 0);
2841 addr = XEXP (addr, 1);
2843 else if (GET_CODE (XEXP (addr, 1)) == REG)
2845 reg2 = XEXP (addr, 1);
2846 addr = XEXP (addr, 0);
2849 #endif
2850 if (offset != 0)
2852 gcc_assert (!addr);
2853 addr = offset;
2855 if ((reg1 && (GET_CODE (reg1) == SIGN_EXTEND
2856 || GET_CODE (reg1) == MULT))
2857 || (reg2 != 0 && REGNO_OK_FOR_BASE_P (REGNO (reg2))))
2859 breg = reg2;
2860 ireg = reg1;
2862 else if (reg1 != 0 && REGNO_OK_FOR_BASE_P (REGNO (reg1)))
2864 breg = reg1;
2865 ireg = reg2;
2867 if (ireg != 0 && breg == 0 && GET_CODE (addr) == LABEL_REF
2868 && ! (flag_pic && ireg == pic_offset_table_rtx))
2870 int scale = 1;
2871 if (GET_CODE (ireg) == MULT)
2873 scale = INTVAL (XEXP (ireg, 1));
2874 ireg = XEXP (ireg, 0);
2876 if (GET_CODE (ireg) == SIGN_EXTEND)
2878 ASM_OUTPUT_CASE_FETCH (file,
2879 CODE_LABEL_NUMBER (XEXP (addr, 0)),
2880 M68K_REGNAME(REGNO (XEXP (ireg, 0))));
2881 fprintf (file, "w");
2883 else
2885 ASM_OUTPUT_CASE_FETCH (file,
2886 CODE_LABEL_NUMBER (XEXP (addr, 0)),
2887 M68K_REGNAME(REGNO (ireg)));
2888 fprintf (file, "l");
2890 if (scale != 1)
2891 fprintf (file, MOTOROLA ? "*%d" : ":%d", scale);
2892 putc (')', file);
2893 break;
2895 if (breg != 0 && ireg == 0 && GET_CODE (addr) == LABEL_REF
2896 && ! (flag_pic && breg == pic_offset_table_rtx))
2898 ASM_OUTPUT_CASE_FETCH (file,
2899 CODE_LABEL_NUMBER (XEXP (addr, 0)),
2900 M68K_REGNAME(REGNO (breg)));
2901 fprintf (file, "l)");
2902 break;
2904 if (ireg != 0 || breg != 0)
2906 int scale = 1;
2908 gcc_assert (breg);
2909 gcc_assert (flag_pic || !addr || GET_CODE (addr) != LABEL_REF);
2911 if (MOTOROLA)
2913 if (addr != 0)
2915 output_addr_const (file, addr);
2916 if (flag_pic && (breg == pic_offset_table_rtx))
2918 fprintf (file, "@GOT");
2919 if (flag_pic == 1)
2920 fprintf (file, ".w");
2923 fprintf (file, "(%s", M68K_REGNAME(REGNO (breg)));
2924 if (ireg != 0)
2925 putc (',', file);
2927 else /* !MOTOROLA */
2929 fprintf (file, "%s@(", M68K_REGNAME(REGNO (breg)));
2930 if (addr != 0)
2932 output_addr_const (file, addr);
2933 if (breg == pic_offset_table_rtx)
2934 switch (flag_pic)
2936 case 1:
2937 fprintf (file, ":w"); break;
2938 case 2:
2939 fprintf (file, ":l"); break;
2940 default:
2941 break;
2943 if (ireg != 0)
2944 putc (',', file);
2946 } /* !MOTOROLA */
2947 if (ireg != 0 && GET_CODE (ireg) == MULT)
2949 scale = INTVAL (XEXP (ireg, 1));
2950 ireg = XEXP (ireg, 0);
2952 if (ireg != 0 && GET_CODE (ireg) == SIGN_EXTEND)
2953 fprintf (file, MOTOROLA ? "%s.w" : "%s:w",
2954 M68K_REGNAME(REGNO (XEXP (ireg, 0))));
2955 else if (ireg != 0)
2956 fprintf (file, MOTOROLA ? "%s.l" : "%s:l",
2957 M68K_REGNAME(REGNO (ireg)));
2958 if (scale != 1)
2959 fprintf (file, MOTOROLA ? "*%d" : ":%d", scale);
2960 putc (')', file);
2961 break;
2963 else if (reg1 != 0 && GET_CODE (addr) == LABEL_REF
2964 && ! (flag_pic && reg1 == pic_offset_table_rtx))
2966 ASM_OUTPUT_CASE_FETCH (file,
2967 CODE_LABEL_NUMBER (XEXP (addr, 0)),
2968 M68K_REGNAME(REGNO (reg1)));
2969 fprintf (file, "l)");
2970 break;
2972 /* FALL-THROUGH (is this really what we want?) */
2973 default:
2974 if (GET_CODE (addr) == CONST_INT
2975 && INTVAL (addr) < 0x8000
2976 && INTVAL (addr) >= -0x8000)
2978 fprintf (file, MOTOROLA ? "%d.w" : "%d:w", (int) INTVAL (addr));
2980 else if (GET_CODE (addr) == CONST_INT)
2982 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (addr));
2984 else if (TARGET_PCREL)
2986 fputc ('(', file);
2987 output_addr_const (file, addr);
2988 if (flag_pic == 1)
2989 asm_fprintf (file, ":w,%Rpc)");
2990 else
2991 asm_fprintf (file, ":l,%Rpc)");
2993 else
2995 /* Special case for SYMBOL_REF if the symbol name ends in
2996 `.<letter>', this can be mistaken as a size suffix. Put
2997 the name in parentheses. */
2998 if (GET_CODE (addr) == SYMBOL_REF
2999 && strlen (XSTR (addr, 0)) > 2
3000 && XSTR (addr, 0)[strlen (XSTR (addr, 0)) - 2] == '.')
3002 putc ('(', file);
3003 output_addr_const (file, addr);
3004 putc (')', file);
3006 else
3007 output_addr_const (file, addr);
3009 break;
3013 /* Check for cases where a clr insns can be omitted from code using
3014 strict_low_part sets. For example, the second clrl here is not needed:
3015 clrl d0; movw a0@+,d0; use d0; clrl d0; movw a0@+; use d0; ...
3017 MODE is the mode of this STRICT_LOW_PART set. FIRST_INSN is the clear
3018 insn we are checking for redundancy. TARGET is the register set by the
3019 clear insn. */
3021 bool
3022 strict_low_part_peephole_ok (enum machine_mode mode, rtx first_insn,
3023 rtx target)
3025 rtx p;
3027 p = prev_nonnote_insn (first_insn);
3029 while (p)
3031 /* If it isn't an insn, then give up. */
3032 if (GET_CODE (p) != INSN)
3033 return false;
3035 if (reg_set_p (target, p))
3037 rtx set = single_set (p);
3038 rtx dest;
3040 /* If it isn't an easy to recognize insn, then give up. */
3041 if (! set)
3042 return false;
3044 dest = SET_DEST (set);
3046 /* If this sets the entire target register to zero, then our
3047 first_insn is redundant. */
3048 if (rtx_equal_p (dest, target)
3049 && SET_SRC (set) == const0_rtx)
3050 return true;
3051 else if (GET_CODE (dest) == STRICT_LOW_PART
3052 && GET_CODE (XEXP (dest, 0)) == REG
3053 && REGNO (XEXP (dest, 0)) == REGNO (target)
3054 && (GET_MODE_SIZE (GET_MODE (XEXP (dest, 0)))
3055 <= GET_MODE_SIZE (mode)))
3056 /* This is a strict low part set which modifies less than
3057 we are using, so it is safe. */
3059 else
3060 return false;
3063 p = prev_nonnote_insn (p);
3066 return false;
3069 /* Operand predicates for implementing asymmetric pc-relative addressing
3070 on m68k. The m68k supports pc-relative addressing (mode 7, register 2)
3071 when used as a source operand, but not as a destination operand.
3073 We model this by restricting the meaning of the basic predicates
3074 (general_operand, memory_operand, etc) to forbid the use of this
3075 addressing mode, and then define the following predicates that permit
3076 this addressing mode. These predicates can then be used for the
3077 source operands of the appropriate instructions.
3079 n.b. While it is theoretically possible to change all machine patterns
3080 to use this addressing more where permitted by the architecture,
3081 it has only been implemented for "common" cases: SImode, HImode, and
3082 QImode operands, and only for the principle operations that would
3083 require this addressing mode: data movement and simple integer operations.
3085 In parallel with these new predicates, two new constraint letters
3086 were defined: 'S' and 'T'. 'S' is the -mpcrel analog of 'm'.
3087 'T' replaces 's' in the non-pcrel case. It is a no-op in the pcrel case.
3088 In the pcrel case 's' is only valid in combination with 'a' registers.
3089 See addsi3, subsi3, cmpsi, and movsi patterns for a better understanding
3090 of how these constraints are used.
3092 The use of these predicates is strictly optional, though patterns that
3093 don't will cause an extra reload register to be allocated where one
3094 was not necessary:
3096 lea (abc:w,%pc),%a0 ; need to reload address
3097 moveq &1,%d1 ; since write to pc-relative space
3098 movel %d1,%a0@ ; is not allowed
3100 lea (abc:w,%pc),%a1 ; no need to reload address here
3101 movel %a1@,%d0 ; since "movel (abc:w,%pc),%d0" is ok
3103 For more info, consult tiemann@cygnus.com.
3106 All of the ugliness with predicates and constraints is due to the
3107 simple fact that the m68k does not allow a pc-relative addressing
3108 mode as a destination. gcc does not distinguish between source and
3109 destination addresses. Hence, if we claim that pc-relative address
3110 modes are valid, e.g. GO_IF_LEGITIMATE_ADDRESS accepts them, then we
3111 end up with invalid code. To get around this problem, we left
3112 pc-relative modes as invalid addresses, and then added special
3113 predicates and constraints to accept them.
3115 A cleaner way to handle this is to modify gcc to distinguish
3116 between source and destination addresses. We can then say that
3117 pc-relative is a valid source address but not a valid destination
3118 address, and hopefully avoid a lot of the predicate and constraint
3119 hackery. Unfortunately, this would be a pretty big change. It would
3120 be a useful change for a number of ports, but there aren't any current
3121 plans to undertake this.
3123 ***************************************************************************/
3126 const char *
3127 output_andsi3 (rtx *operands)
3129 int logval;
3130 if (GET_CODE (operands[2]) == CONST_INT
3131 && (INTVAL (operands[2]) | 0xffff) == -1
3132 && (DATA_REG_P (operands[0])
3133 || offsettable_memref_p (operands[0]))
3134 && !TARGET_COLDFIRE)
3136 if (GET_CODE (operands[0]) != REG)
3137 operands[0] = adjust_address (operands[0], HImode, 2);
3138 operands[2] = GEN_INT (INTVAL (operands[2]) & 0xffff);
3139 /* Do not delete a following tstl %0 insn; that would be incorrect. */
3140 CC_STATUS_INIT;
3141 if (operands[2] == const0_rtx)
3142 return "clr%.w %0";
3143 return "and%.w %2,%0";
3145 if (GET_CODE (operands[2]) == CONST_INT
3146 && (logval = exact_log2 (~ INTVAL (operands[2]))) >= 0
3147 && (DATA_REG_P (operands[0])
3148 || offsettable_memref_p (operands[0])))
3150 if (DATA_REG_P (operands[0]))
3152 operands[1] = GEN_INT (logval);
3154 else
3156 operands[0] = adjust_address (operands[0], SImode, 3 - (logval / 8));
3157 operands[1] = GEN_INT (logval % 8);
3159 /* This does not set condition codes in a standard way. */
3160 CC_STATUS_INIT;
3161 return "bclr %1,%0";
3163 return "and%.l %2,%0";
3166 const char *
3167 output_iorsi3 (rtx *operands)
3169 register int logval;
3170 if (GET_CODE (operands[2]) == CONST_INT
3171 && INTVAL (operands[2]) >> 16 == 0
3172 && (DATA_REG_P (operands[0])
3173 || offsettable_memref_p (operands[0]))
3174 && !TARGET_COLDFIRE)
3176 if (GET_CODE (operands[0]) != REG)
3177 operands[0] = adjust_address (operands[0], HImode, 2);
3178 /* Do not delete a following tstl %0 insn; that would be incorrect. */
3179 CC_STATUS_INIT;
3180 if (INTVAL (operands[2]) == 0xffff)
3181 return "mov%.w %2,%0";
3182 return "or%.w %2,%0";
3184 if (GET_CODE (operands[2]) == CONST_INT
3185 && (logval = exact_log2 (INTVAL (operands[2]))) >= 0
3186 && (DATA_REG_P (operands[0])
3187 || offsettable_memref_p (operands[0])))
3189 if (DATA_REG_P (operands[0]))
3190 operands[1] = GEN_INT (logval);
3191 else
3193 operands[0] = adjust_address (operands[0], SImode, 3 - (logval / 8));
3194 operands[1] = GEN_INT (logval % 8);
3196 CC_STATUS_INIT;
3197 return "bset %1,%0";
3199 return "or%.l %2,%0";
3202 const char *
3203 output_xorsi3 (rtx *operands)
3205 register int logval;
3206 if (GET_CODE (operands[2]) == CONST_INT
3207 && INTVAL (operands[2]) >> 16 == 0
3208 && (offsettable_memref_p (operands[0]) || DATA_REG_P (operands[0]))
3209 && !TARGET_COLDFIRE)
3211 if (! DATA_REG_P (operands[0]))
3212 operands[0] = adjust_address (operands[0], HImode, 2);
3213 /* Do not delete a following tstl %0 insn; that would be incorrect. */
3214 CC_STATUS_INIT;
3215 if (INTVAL (operands[2]) == 0xffff)
3216 return "not%.w %0";
3217 return "eor%.w %2,%0";
3219 if (GET_CODE (operands[2]) == CONST_INT
3220 && (logval = exact_log2 (INTVAL (operands[2]))) >= 0
3221 && (DATA_REG_P (operands[0])
3222 || offsettable_memref_p (operands[0])))
3224 if (DATA_REG_P (operands[0]))
3225 operands[1] = GEN_INT (logval);
3226 else
3228 operands[0] = adjust_address (operands[0], SImode, 3 - (logval / 8));
3229 operands[1] = GEN_INT (logval % 8);
3231 CC_STATUS_INIT;
3232 return "bchg %1,%0";
3234 return "eor%.l %2,%0";
3237 #ifdef M68K_TARGET_COFF
3239 /* Output assembly to switch to section NAME with attribute FLAGS. */
3241 static void
3242 m68k_coff_asm_named_section (const char *name, unsigned int flags,
3243 tree decl ATTRIBUTE_UNUSED)
3245 char flagchar;
3247 if (flags & SECTION_WRITE)
3248 flagchar = 'd';
3249 else
3250 flagchar = 'x';
3252 fprintf (asm_out_file, "\t.section\t%s,\"%c\"\n", name, flagchar);
3255 #endif /* M68K_TARGET_COFF */
3257 static void
3258 m68k_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED,
3259 HOST_WIDE_INT delta,
3260 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
3261 tree function)
3263 rtx xops[1];
3264 const char *fmt;
3266 if (delta > 0 && delta <= 8)
3267 asm_fprintf (file, MOTOROLA ?
3268 "\taddq.l %I%d,4(%Rsp)\n" :
3269 "\taddql %I%d,%Rsp@(4)\n",
3270 (int) delta);
3271 else if (delta < 0 && delta >= -8)
3272 asm_fprintf (file, MOTOROLA ?
3273 "\tsubq.l %I%d,4(%Rsp)\n" :
3274 "\tsubql %I%d,%Rsp@(4)\n",
3275 (int) -delta);
3276 else if (TARGET_COLDFIRE)
3278 /* ColdFire can't add/sub a constant to memory unless it is in
3279 the range of addq/subq. So load the value into %d0 and
3280 then add it to 4(%sp). */
3281 if (delta >= -128 && delta <= 127)
3282 asm_fprintf (file, MOTOROLA ?
3283 "\tmoveq.l %I%wd,%Rd0\n" :
3284 "\tmoveql %I%wd,%Rd0\n", delta);
3285 else
3286 asm_fprintf (file, MOTOROLA ?
3287 "\tmove.l %I%wd,%Rd0\n" :
3288 "\tmovel %I%wd,%Rd0\n", delta);
3289 asm_fprintf (file, MOTOROLA ?
3290 "\tadd.l %Rd0,4(%Rsp)\n" :
3291 "\taddl %Rd0,%Rsp@(4)\n");
3293 else
3294 asm_fprintf (file, MOTOROLA ?
3295 "\tadd.l %I%wd,4(%Rsp)\n" :
3296 "\taddl %I%wd,%Rsp@(4)\n",
3297 delta);
3299 xops[0] = DECL_RTL (function);
3301 /* Logic taken from call patterns in m68k.md. */
3302 if (flag_pic)
3304 if (TARGET_PCREL)
3305 fmt = "bra.l %o0";
3306 else if ((flag_pic == 1) || TARGET_68020)
3308 if (MOTOROLA)
3309 #if defined(USE_GAS)
3310 fmt = "bra.l %0@PLTPC";
3311 #else
3312 fmt = "bra %0@PLTPC";
3313 #endif
3314 else /* !MOTOROLA */
3315 #ifdef USE_GAS
3316 fmt = "bra.l %0";
3317 #else
3318 fmt = "jra %0,a1";
3319 #endif
3321 else if (optimize_size || TARGET_ID_SHARED_LIBRARY)
3322 fmt = "move.l %0@GOT(%%a5), %%a1\n\tjmp (%%a1)";
3323 else
3324 fmt = "lea %0-.-8,%%a1\n\tjsr 0(%%pc,%%a1)";
3326 else
3328 #if MOTOROLA && !defined (USE_GAS)
3329 fmt = "jmp %0";
3330 #else
3331 fmt = "jra %0";
3332 #endif
3335 output_asm_insn (fmt, xops);
3338 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
3340 static rtx
3341 m68k_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
3342 int incoming ATTRIBUTE_UNUSED)
3344 return gen_rtx_REG (Pmode, M68K_STRUCT_VALUE_REGNUM);
3347 /* Return nonzero if register old_reg can be renamed to register new_reg. */
3349 m68k_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED,
3350 unsigned int new_reg)
3353 /* Interrupt functions can only use registers that have already been
3354 saved by the prologue, even if they would normally be
3355 call-clobbered. */
3357 if (m68k_interrupt_function_p (current_function_decl)
3358 && !regs_ever_live[new_reg])
3359 return 0;
3361 return 1;
3364 /* Value is true if hard register REGNO can hold a value of machine-mode MODE.
3365 On the 68000, the cpu registers can hold any mode except bytes in address
3366 registers, but the 68881 registers can hold only SFmode or DFmode. */
3367 bool
3368 m68k_regno_mode_ok (int regno, enum machine_mode mode)
3370 if (regno < 8)
3372 /* Data Registers, can hold aggregate if fits in. */
3373 if (regno + GET_MODE_SIZE (mode) / 4 <= 8)
3374 return true;
3376 else if (regno < 16)
3378 /* Address Registers, can't hold bytes, can hold aggregate if
3379 fits in. */
3380 if (GET_MODE_SIZE (mode) == 1)
3381 return false;
3382 if (regno + GET_MODE_SIZE (mode) / 4 <= 16)
3383 return true;
3385 else if (regno < 24)
3387 /* FPU registers, hold float or complex float of long double or
3388 smaller. */
3389 if ((GET_MODE_CLASS (mode) == MODE_FLOAT
3390 || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
3391 && GET_MODE_UNIT_SIZE (mode) <= 12)
3392 return true;
3394 return false;