Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / gcc4 / gcc / config / m68k / m68k.c
blob666d196b17da0a885822425ccea402c39dc275f6
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 building for a target that
1051 supports long branches. Otherwise we generate one of two sequences:
1052 a shorter one that uses a GOT entry or a longer one that doesn't.
1053 We use the -Os command-line flag to decide which to generate.
1054 Both sequences take the same time to execute on the ColdFire. */
1055 else if (TARGET_PCREL)
1056 out = "bsr.l %o0";
1057 else if (TARGET_68020)
1058 #if defined(USE_GAS)
1059 out = "bsr.l %0@PLTPC";
1060 #else
1061 out = "bsr %0@PLTPC";
1062 #endif
1063 else if (optimize_size || TARGET_ID_SHARED_LIBRARY)
1064 out = "move.l %0@GOT(%%a5), %%a1\n\tjsr (%%a1)";
1065 else
1066 out = "lea %0-.-8,%%a1\n\tjsr 0(%%pc,%%a1)";
1068 output_asm_insn(out, &dest);
1071 /* Output a dbCC; jCC sequence. Note we do not handle the
1072 floating point version of this sequence (Fdbcc). We also
1073 do not handle alternative conditions when CC_NO_OVERFLOW is
1074 set. It is assumed that valid_dbcc_comparison_p and flags_in_68881 will
1075 kick those out before we get here. */
1077 void
1078 output_dbcc_and_branch (rtx *operands)
1080 switch (GET_CODE (operands[3]))
1082 case EQ:
1083 output_asm_insn (MOTOROLA ?
1084 "dbeq %0,%l1\n\tjbeq %l2" :
1085 "dbeq %0,%l1\n\tjeq %l2",
1086 operands);
1087 break;
1089 case NE:
1090 output_asm_insn (MOTOROLA ?
1091 "dbne %0,%l1\n\tjbne %l2" :
1092 "dbne %0,%l1\n\tjne %l2",
1093 operands);
1094 break;
1096 case GT:
1097 output_asm_insn (MOTOROLA ?
1098 "dbgt %0,%l1\n\tjbgt %l2" :
1099 "dbgt %0,%l1\n\tjgt %l2",
1100 operands);
1101 break;
1103 case GTU:
1104 output_asm_insn (MOTOROLA ?
1105 "dbhi %0,%l1\n\tjbhi %l2" :
1106 "dbhi %0,%l1\n\tjhi %l2",
1107 operands);
1108 break;
1110 case LT:
1111 output_asm_insn (MOTOROLA ?
1112 "dblt %0,%l1\n\tjblt %l2" :
1113 "dblt %0,%l1\n\tjlt %l2",
1114 operands);
1115 break;
1117 case LTU:
1118 output_asm_insn (MOTOROLA ?
1119 "dbcs %0,%l1\n\tjbcs %l2" :
1120 "dbcs %0,%l1\n\tjcs %l2",
1121 operands);
1122 break;
1124 case GE:
1125 output_asm_insn (MOTOROLA ?
1126 "dbge %0,%l1\n\tjbge %l2" :
1127 "dbge %0,%l1\n\tjge %l2",
1128 operands);
1129 break;
1131 case GEU:
1132 output_asm_insn (MOTOROLA ?
1133 "dbcc %0,%l1\n\tjbcc %l2" :
1134 "dbcc %0,%l1\n\tjcc %l2",
1135 operands);
1136 break;
1138 case LE:
1139 output_asm_insn (MOTOROLA ?
1140 "dble %0,%l1\n\tjble %l2" :
1141 "dble %0,%l1\n\tjle %l2",
1142 operands);
1143 break;
1145 case LEU:
1146 output_asm_insn (MOTOROLA ?
1147 "dbls %0,%l1\n\tjbls %l2" :
1148 "dbls %0,%l1\n\tjls %l2",
1149 operands);
1150 break;
1152 default:
1153 gcc_unreachable ();
1156 /* If the decrement is to be done in SImode, then we have
1157 to compensate for the fact that dbcc decrements in HImode. */
1158 switch (GET_MODE (operands[0]))
1160 case SImode:
1161 output_asm_insn (MOTOROLA ?
1162 "clr%.w %0\n\tsubq%.l #1,%0\n\tjbpl %l1" :
1163 "clr%.w %0\n\tsubq%.l #1,%0\n\tjpl %l1",
1164 operands);
1165 break;
1167 case HImode:
1168 break;
1170 default:
1171 gcc_unreachable ();
1175 const char *
1176 output_scc_di (rtx op, rtx operand1, rtx operand2, rtx dest)
1178 rtx loperands[7];
1179 enum rtx_code op_code = GET_CODE (op);
1181 /* This does not produce a useful cc. */
1182 CC_STATUS_INIT;
1184 /* The m68k cmp.l instruction requires operand1 to be a reg as used
1185 below. Swap the operands and change the op if these requirements
1186 are not fulfilled. */
1187 if (GET_CODE (operand2) == REG && GET_CODE (operand1) != REG)
1189 rtx tmp = operand1;
1191 operand1 = operand2;
1192 operand2 = tmp;
1193 op_code = swap_condition (op_code);
1195 loperands[0] = operand1;
1196 if (GET_CODE (operand1) == REG)
1197 loperands[1] = gen_rtx_REG (SImode, REGNO (operand1) + 1);
1198 else
1199 loperands[1] = adjust_address (operand1, SImode, 4);
1200 if (operand2 != const0_rtx)
1202 loperands[2] = operand2;
1203 if (GET_CODE (operand2) == REG)
1204 loperands[3] = gen_rtx_REG (SImode, REGNO (operand2) + 1);
1205 else
1206 loperands[3] = adjust_address (operand2, SImode, 4);
1208 loperands[4] = gen_label_rtx ();
1209 if (operand2 != const0_rtx)
1211 output_asm_insn (MOTOROLA ?
1212 "cmp%.l %2,%0\n\tjbne %l4\n\tcmp%.l %3,%1" :
1213 "cmp%.l %2,%0\n\tjne %l4\n\tcmp%.l %3,%1",
1214 loperands);
1216 else
1218 if (TARGET_68020 || TARGET_COLDFIRE || ! ADDRESS_REG_P (loperands[0]))
1219 output_asm_insn ("tst%.l %0", loperands);
1220 else
1222 output_asm_insn ("cmp%.w #0,%0", loperands);
1225 output_asm_insn (MOTOROLA ? "jbne %l4" : "jne %l4", loperands);
1227 if (TARGET_68020 || TARGET_COLDFIRE || ! ADDRESS_REG_P (loperands[1]))
1228 output_asm_insn ("tst%.l %1", loperands);
1229 else
1230 output_asm_insn ("cmp%.w #0,%1", loperands);
1233 loperands[5] = dest;
1235 switch (op_code)
1237 case EQ:
1238 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1239 CODE_LABEL_NUMBER (loperands[4]));
1240 output_asm_insn ("seq %5", loperands);
1241 break;
1243 case NE:
1244 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1245 CODE_LABEL_NUMBER (loperands[4]));
1246 output_asm_insn ("sne %5", loperands);
1247 break;
1249 case GT:
1250 loperands[6] = gen_label_rtx ();
1251 output_asm_insn (MOTOROLA ?
1252 "shi %5\n\tjbra %l6" :
1253 "shi %5\n\tjra %l6",
1254 loperands);
1255 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1256 CODE_LABEL_NUMBER (loperands[4]));
1257 output_asm_insn ("sgt %5", loperands);
1258 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1259 CODE_LABEL_NUMBER (loperands[6]));
1260 break;
1262 case GTU:
1263 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1264 CODE_LABEL_NUMBER (loperands[4]));
1265 output_asm_insn ("shi %5", loperands);
1266 break;
1268 case LT:
1269 loperands[6] = gen_label_rtx ();
1270 output_asm_insn (MOTOROLA ?
1271 "scs %5\n\tjbra %l6" :
1272 "scs %5\n\tjra %l6",
1273 loperands);
1274 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1275 CODE_LABEL_NUMBER (loperands[4]));
1276 output_asm_insn ("slt %5", loperands);
1277 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1278 CODE_LABEL_NUMBER (loperands[6]));
1279 break;
1281 case LTU:
1282 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1283 CODE_LABEL_NUMBER (loperands[4]));
1284 output_asm_insn ("scs %5", loperands);
1285 break;
1287 case GE:
1288 loperands[6] = gen_label_rtx ();
1289 output_asm_insn (MOTOROLA ?
1290 "scc %5\n\tjbra %l6" :
1291 "scc %5\n\tjra %l6",
1292 loperands);
1293 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1294 CODE_LABEL_NUMBER (loperands[4]));
1295 output_asm_insn ("sge %5", loperands);
1296 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1297 CODE_LABEL_NUMBER (loperands[6]));
1298 break;
1300 case GEU:
1301 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1302 CODE_LABEL_NUMBER (loperands[4]));
1303 output_asm_insn ("scc %5", loperands);
1304 break;
1306 case LE:
1307 loperands[6] = gen_label_rtx ();
1308 output_asm_insn (MOTOROLA ?
1309 "sls %5\n\tjbra %l6" :
1310 "sls %5\n\tjra %l6",
1311 loperands);
1312 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1313 CODE_LABEL_NUMBER (loperands[4]));
1314 output_asm_insn ("sle %5", loperands);
1315 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1316 CODE_LABEL_NUMBER (loperands[6]));
1317 break;
1319 case LEU:
1320 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1321 CODE_LABEL_NUMBER (loperands[4]));
1322 output_asm_insn ("sls %5", loperands);
1323 break;
1325 default:
1326 gcc_unreachable ();
1328 return "";
1331 const char *
1332 output_btst (rtx *operands, rtx countop, rtx dataop, rtx insn, int signpos)
1334 operands[0] = countop;
1335 operands[1] = dataop;
1337 if (GET_CODE (countop) == CONST_INT)
1339 register int count = INTVAL (countop);
1340 /* If COUNT is bigger than size of storage unit in use,
1341 advance to the containing unit of same size. */
1342 if (count > signpos)
1344 int offset = (count & ~signpos) / 8;
1345 count = count & signpos;
1346 operands[1] = dataop = adjust_address (dataop, QImode, offset);
1348 if (count == signpos)
1349 cc_status.flags = CC_NOT_POSITIVE | CC_Z_IN_NOT_N;
1350 else
1351 cc_status.flags = CC_NOT_NEGATIVE | CC_Z_IN_NOT_N;
1353 /* These three statements used to use next_insns_test_no...
1354 but it appears that this should do the same job. */
1355 if (count == 31
1356 && next_insn_tests_no_inequality (insn))
1357 return "tst%.l %1";
1358 if (count == 15
1359 && next_insn_tests_no_inequality (insn))
1360 return "tst%.w %1";
1361 if (count == 7
1362 && next_insn_tests_no_inequality (insn))
1363 return "tst%.b %1";
1365 cc_status.flags = CC_NOT_NEGATIVE;
1367 return "btst %0,%1";
1370 /* Legitimize PIC addresses. If the address is already
1371 position-independent, we return ORIG. Newly generated
1372 position-independent addresses go to REG. If we need more
1373 than one register, we lose.
1375 An address is legitimized by making an indirect reference
1376 through the Global Offset Table with the name of the symbol
1377 used as an offset.
1379 The assembler and linker are responsible for placing the
1380 address of the symbol in the GOT. The function prologue
1381 is responsible for initializing a5 to the starting address
1382 of the GOT.
1384 The assembler is also responsible for translating a symbol name
1385 into a constant displacement from the start of the GOT.
1387 A quick example may make things a little clearer:
1389 When not generating PIC code to store the value 12345 into _foo
1390 we would generate the following code:
1392 movel #12345, _foo
1394 When generating PIC two transformations are made. First, the compiler
1395 loads the address of foo into a register. So the first transformation makes:
1397 lea _foo, a0
1398 movel #12345, a0@
1400 The code in movsi will intercept the lea instruction and call this
1401 routine which will transform the instructions into:
1403 movel a5@(_foo:w), a0
1404 movel #12345, a0@
1407 That (in a nutshell) is how *all* symbol and label references are
1408 handled. */
1411 legitimize_pic_address (rtx orig, enum machine_mode mode ATTRIBUTE_UNUSED,
1412 rtx reg)
1414 rtx pic_ref = orig;
1416 /* First handle a simple SYMBOL_REF or LABEL_REF */
1417 if (GET_CODE (orig) == SYMBOL_REF || GET_CODE (orig) == LABEL_REF)
1419 gcc_assert (reg);
1421 pic_ref = gen_rtx_MEM (Pmode,
1422 gen_rtx_PLUS (Pmode,
1423 pic_offset_table_rtx, orig));
1424 current_function_uses_pic_offset_table = 1;
1425 MEM_READONLY_P (pic_ref) = 1;
1426 emit_move_insn (reg, pic_ref);
1427 return reg;
1429 else if (GET_CODE (orig) == CONST)
1431 rtx base;
1433 /* Make sure this has not already been legitimized. */
1434 if (GET_CODE (XEXP (orig, 0)) == PLUS
1435 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
1436 return orig;
1438 gcc_assert (reg);
1440 /* legitimize both operands of the PLUS */
1441 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
1443 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
1444 orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
1445 base == reg ? 0 : reg);
1447 if (GET_CODE (orig) == CONST_INT)
1448 return plus_constant (base, INTVAL (orig));
1449 pic_ref = gen_rtx_PLUS (Pmode, base, orig);
1450 /* Likewise, should we set special REG_NOTEs here? */
1452 return pic_ref;
1456 typedef enum { MOVL, SWAP, NEGW, NOTW, NOTB, MOVQ, MVS, MVZ } CONST_METHOD;
1458 static CONST_METHOD const_method (rtx);
1460 #define USE_MOVQ(i) ((unsigned)((i) + 128) <= 255)
1462 static CONST_METHOD
1463 const_method (rtx constant)
1465 int i;
1466 unsigned u;
1468 i = INTVAL (constant);
1469 if (USE_MOVQ (i))
1470 return MOVQ;
1472 /* The ColdFire doesn't have byte or word operations. */
1473 /* FIXME: This may not be useful for the m68060 either. */
1474 if (!TARGET_COLDFIRE)
1476 /* if -256 < N < 256 but N is not in range for a moveq
1477 N^ff will be, so use moveq #N^ff, dreg; not.b dreg. */
1478 if (USE_MOVQ (i ^ 0xff))
1479 return NOTB;
1480 /* Likewise, try with not.w */
1481 if (USE_MOVQ (i ^ 0xffff))
1482 return NOTW;
1483 /* This is the only value where neg.w is useful */
1484 if (i == -65408)
1485 return NEGW;
1488 /* Try also with swap. */
1489 u = i;
1490 if (USE_MOVQ ((u >> 16) | (u << 16)))
1491 return SWAP;
1493 if (TARGET_CFV4)
1495 /* Try using MVZ/MVS with an immediate value to load constants. */
1496 if (i >= 0 && i <= 65535)
1497 return MVZ;
1498 if (i >= -32768 && i <= 32767)
1499 return MVS;
1502 /* Otherwise, use move.l */
1503 return MOVL;
1506 static int
1507 const_int_cost (rtx constant)
1509 switch (const_method (constant))
1511 case MOVQ :
1512 /* Constants between -128 and 127 are cheap due to moveq */
1513 return 0;
1514 case MVZ:
1515 case MVS:
1516 case NOTB :
1517 case NOTW :
1518 case NEGW :
1519 case SWAP :
1520 /* Constants easily generated by moveq + not.b/not.w/neg.w/swap */
1521 return 1;
1522 case MOVL :
1523 return 2;
1524 default :
1525 gcc_unreachable ();
1529 static bool
1530 m68k_rtx_costs (rtx x, int code, int outer_code, int *total)
1532 switch (code)
1534 case CONST_INT:
1535 /* Constant zero is super cheap due to clr instruction. */
1536 if (x == const0_rtx)
1537 *total = 0;
1538 else
1539 *total = const_int_cost (x);
1540 return true;
1542 case CONST:
1543 case LABEL_REF:
1544 case SYMBOL_REF:
1545 *total = 3;
1546 return true;
1548 case CONST_DOUBLE:
1549 /* Make 0.0 cheaper than other floating constants to
1550 encourage creating tstsf and tstdf insns. */
1551 if (outer_code == COMPARE
1552 && (x == CONST0_RTX (SFmode) || x == CONST0_RTX (DFmode)))
1553 *total = 4;
1554 else
1555 *total = 5;
1556 return true;
1558 /* These are vaguely right for a 68020. */
1559 /* The costs for long multiply have been adjusted to work properly
1560 in synth_mult on the 68020, relative to an average of the time
1561 for add and the time for shift, taking away a little more because
1562 sometimes move insns are needed. */
1563 /* div?.w is relatively cheaper on 68000 counted in COSTS_N_INSNS terms. */
1564 #define MULL_COST (TARGET_68060 ? 2 : TARGET_68040 ? 5 : (TARGET_COLDFIRE && !TARGET_5200) ? 3 : TARGET_COLDFIRE ? 10 : 13)
1565 #define MULW_COST (TARGET_68060 ? 2 : TARGET_68040 ? 3 : TARGET_68020 ? 8 : \
1566 (TARGET_COLDFIRE && !TARGET_5200) ? 2 : 5)
1567 #define DIVW_COST (TARGET_68020 ? 27 : TARGET_CF_HWDIV ? 11 : 12)
1569 case PLUS:
1570 /* An lea costs about three times as much as a simple add. */
1571 if (GET_MODE (x) == SImode
1572 && GET_CODE (XEXP (x, 1)) == REG
1573 && GET_CODE (XEXP (x, 0)) == MULT
1574 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
1575 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1576 && (INTVAL (XEXP (XEXP (x, 0), 1)) == 2
1577 || INTVAL (XEXP (XEXP (x, 0), 1)) == 4
1578 || INTVAL (XEXP (XEXP (x, 0), 1)) == 8))
1580 /* lea an@(dx:l:i),am */
1581 *total = COSTS_N_INSNS (TARGET_COLDFIRE ? 2 : 3);
1582 return true;
1584 return false;
1586 case ASHIFT:
1587 case ASHIFTRT:
1588 case LSHIFTRT:
1589 if (TARGET_68060)
1591 *total = COSTS_N_INSNS(1);
1592 return true;
1594 if (! TARGET_68020 && ! TARGET_COLDFIRE)
1596 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
1598 if (INTVAL (XEXP (x, 1)) < 16)
1599 *total = COSTS_N_INSNS (2) + INTVAL (XEXP (x, 1)) / 2;
1600 else
1601 /* We're using clrw + swap for these cases. */
1602 *total = COSTS_N_INSNS (4) + (INTVAL (XEXP (x, 1)) - 16) / 2;
1604 else
1605 *total = COSTS_N_INSNS (10); /* worst case */
1606 return true;
1608 /* A shift by a big integer takes an extra instruction. */
1609 if (GET_CODE (XEXP (x, 1)) == CONST_INT
1610 && (INTVAL (XEXP (x, 1)) == 16))
1612 *total = COSTS_N_INSNS (2); /* clrw;swap */
1613 return true;
1615 if (GET_CODE (XEXP (x, 1)) == CONST_INT
1616 && !(INTVAL (XEXP (x, 1)) > 0
1617 && INTVAL (XEXP (x, 1)) <= 8))
1619 *total = COSTS_N_INSNS (TARGET_COLDFIRE ? 1 : 3); /* lsr #i,dn */
1620 return true;
1622 return false;
1624 case MULT:
1625 if ((GET_CODE (XEXP (x, 0)) == ZERO_EXTEND
1626 || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)
1627 && GET_MODE (x) == SImode)
1628 *total = COSTS_N_INSNS (MULW_COST);
1629 else if (GET_MODE (x) == QImode || GET_MODE (x) == HImode)
1630 *total = COSTS_N_INSNS (MULW_COST);
1631 else
1632 *total = COSTS_N_INSNS (MULL_COST);
1633 return true;
1635 case DIV:
1636 case UDIV:
1637 case MOD:
1638 case UMOD:
1639 if (GET_MODE (x) == QImode || GET_MODE (x) == HImode)
1640 *total = COSTS_N_INSNS (DIVW_COST); /* div.w */
1641 else if (TARGET_CF_HWDIV)
1642 *total = COSTS_N_INSNS (18);
1643 else
1644 *total = COSTS_N_INSNS (43); /* div.l */
1645 return true;
1647 default:
1648 return false;
1652 const char *
1653 output_move_const_into_data_reg (rtx *operands)
1655 int i;
1657 i = INTVAL (operands[1]);
1658 switch (const_method (operands[1]))
1660 case MVZ:
1661 return "mvsw %1,%0";
1662 case MVS:
1663 return "mvzw %1,%0";
1664 case MOVQ :
1665 return "moveq %1,%0";
1666 case NOTB :
1667 CC_STATUS_INIT;
1668 operands[1] = GEN_INT (i ^ 0xff);
1669 return "moveq %1,%0\n\tnot%.b %0";
1670 case NOTW :
1671 CC_STATUS_INIT;
1672 operands[1] = GEN_INT (i ^ 0xffff);
1673 return "moveq %1,%0\n\tnot%.w %0";
1674 case NEGW :
1675 CC_STATUS_INIT;
1676 return "moveq #-128,%0\n\tneg%.w %0";
1677 case SWAP :
1679 unsigned u = i;
1681 operands[1] = GEN_INT ((u << 16) | (u >> 16));
1682 return "moveq %1,%0\n\tswap %0";
1684 case MOVL :
1685 return "move%.l %1,%0";
1686 default :
1687 gcc_unreachable ();
1691 /* Return 1 if 'constant' can be represented by
1692 mov3q on a ColdFire V4 core. */
1694 valid_mov3q_const (rtx constant)
1696 int i;
1698 if (TARGET_CFV4 && GET_CODE (constant) == CONST_INT)
1700 i = INTVAL (constant);
1701 if ((i == -1) || (i >= 1 && i <= 7))
1702 return 1;
1704 return 0;
1708 const char *
1709 output_move_simode_const (rtx *operands)
1711 if (operands[1] == const0_rtx
1712 && (DATA_REG_P (operands[0])
1713 || GET_CODE (operands[0]) == MEM)
1714 /* clr insns on 68000 read before writing.
1715 This isn't so on the 68010, but we have no TARGET_68010. */
1716 && ((TARGET_68020 || TARGET_COLDFIRE)
1717 || !(GET_CODE (operands[0]) == MEM
1718 && MEM_VOLATILE_P (operands[0]))))
1719 return "clr%.l %0";
1720 else if ((GET_MODE (operands[0]) == SImode)
1721 && valid_mov3q_const (operands[1]))
1722 return "mov3q%.l %1,%0";
1723 else if (operands[1] == const0_rtx
1724 && ADDRESS_REG_P (operands[0]))
1725 return "sub%.l %0,%0";
1726 else if (DATA_REG_P (operands[0]))
1727 return output_move_const_into_data_reg (operands);
1728 else if (ADDRESS_REG_P (operands[0])
1729 && INTVAL (operands[1]) < 0x8000
1730 && INTVAL (operands[1]) >= -0x8000)
1732 if (valid_mov3q_const (operands[1]))
1733 return "mov3q%.l %1,%0";
1734 return "move%.w %1,%0";
1736 else if (GET_CODE (operands[0]) == MEM
1737 && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
1738 && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM
1739 && INTVAL (operands[1]) < 0x8000
1740 && INTVAL (operands[1]) >= -0x8000)
1742 if (valid_mov3q_const (operands[1]))
1743 return "mov3q%.l %1,%-";
1744 return "pea %a1";
1746 return "move%.l %1,%0";
1749 const char *
1750 output_move_simode (rtx *operands)
1752 if (GET_CODE (operands[1]) == CONST_INT)
1753 return output_move_simode_const (operands);
1754 else if ((GET_CODE (operands[1]) == SYMBOL_REF
1755 || GET_CODE (operands[1]) == CONST)
1756 && push_operand (operands[0], SImode))
1757 return "pea %a1";
1758 else if ((GET_CODE (operands[1]) == SYMBOL_REF
1759 || GET_CODE (operands[1]) == CONST)
1760 && ADDRESS_REG_P (operands[0]))
1761 return "lea %a1,%0";
1762 return "move%.l %1,%0";
1765 const char *
1766 output_move_himode (rtx *operands)
1768 if (GET_CODE (operands[1]) == CONST_INT)
1770 if (operands[1] == const0_rtx
1771 && (DATA_REG_P (operands[0])
1772 || GET_CODE (operands[0]) == MEM)
1773 /* clr insns on 68000 read before writing.
1774 This isn't so on the 68010, but we have no TARGET_68010. */
1775 && ((TARGET_68020 || TARGET_COLDFIRE)
1776 || !(GET_CODE (operands[0]) == MEM
1777 && MEM_VOLATILE_P (operands[0]))))
1778 return "clr%.w %0";
1779 else if (operands[1] == const0_rtx
1780 && ADDRESS_REG_P (operands[0]))
1781 return "sub%.l %0,%0";
1782 else if (DATA_REG_P (operands[0])
1783 && INTVAL (operands[1]) < 128
1784 && INTVAL (operands[1]) >= -128)
1786 return "moveq %1,%0";
1788 else if (INTVAL (operands[1]) < 0x8000
1789 && INTVAL (operands[1]) >= -0x8000)
1790 return "move%.w %1,%0";
1792 else if (CONSTANT_P (operands[1]))
1793 return "move%.l %1,%0";
1794 return "move%.w %1,%0";
1797 const char *
1798 output_move_qimode (rtx *operands)
1800 /* 68k family always modifies the stack pointer by at least 2, even for
1801 byte pushes. The 5200 (ColdFire) does not do this. */
1803 /* This case is generated by pushqi1 pattern now */
1804 gcc_assert (!(GET_CODE (operands[0]) == MEM
1805 && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
1806 && XEXP (XEXP (operands[0], 0), 0) == stack_pointer_rtx
1807 && ! ADDRESS_REG_P (operands[1])
1808 && ! TARGET_COLDFIRE));
1810 /* clr and st insns on 68000 read before writing.
1811 This isn't so on the 68010, but we have no TARGET_68010. */
1812 if (!ADDRESS_REG_P (operands[0])
1813 && ((TARGET_68020 || TARGET_COLDFIRE)
1814 || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))))
1816 if (operands[1] == const0_rtx)
1817 return "clr%.b %0";
1818 if ((!TARGET_COLDFIRE || DATA_REG_P (operands[0]))
1819 && GET_CODE (operands[1]) == CONST_INT
1820 && (INTVAL (operands[1]) & 255) == 255)
1822 CC_STATUS_INIT;
1823 return "st %0";
1826 if (GET_CODE (operands[1]) == CONST_INT
1827 && DATA_REG_P (operands[0])
1828 && INTVAL (operands[1]) < 128
1829 && INTVAL (operands[1]) >= -128)
1831 return "moveq %1,%0";
1833 if (operands[1] == const0_rtx && ADDRESS_REG_P (operands[0]))
1834 return "sub%.l %0,%0";
1835 if (GET_CODE (operands[1]) != CONST_INT && CONSTANT_P (operands[1]))
1836 return "move%.l %1,%0";
1837 /* 68k family (including the 5200 ColdFire) does not support byte moves to
1838 from address registers. */
1839 if (ADDRESS_REG_P (operands[0]) || ADDRESS_REG_P (operands[1]))
1840 return "move%.w %1,%0";
1841 return "move%.b %1,%0";
1844 const char *
1845 output_move_stricthi (rtx *operands)
1847 if (operands[1] == const0_rtx
1848 /* clr insns on 68000 read before writing.
1849 This isn't so on the 68010, but we have no TARGET_68010. */
1850 && ((TARGET_68020 || TARGET_COLDFIRE)
1851 || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))))
1852 return "clr%.w %0";
1853 return "move%.w %1,%0";
1856 const char *
1857 output_move_strictqi (rtx *operands)
1859 if (operands[1] == const0_rtx
1860 /* clr insns on 68000 read before writing.
1861 This isn't so on the 68010, but we have no TARGET_68010. */
1862 && ((TARGET_68020 || TARGET_COLDFIRE)
1863 || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))))
1864 return "clr%.b %0";
1865 return "move%.b %1,%0";
1868 /* Return the best assembler insn template
1869 for moving operands[1] into operands[0] as a fullword. */
1871 static const char *
1872 singlemove_string (rtx *operands)
1874 if (GET_CODE (operands[1]) == CONST_INT)
1875 return output_move_simode_const (operands);
1876 return "move%.l %1,%0";
1880 /* Output assembler code to perform a doubleword move insn
1881 with operands OPERANDS. */
1883 const char *
1884 output_move_double (rtx *operands)
1886 enum
1888 REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP
1889 } optype0, optype1;
1890 rtx latehalf[2];
1891 rtx middlehalf[2];
1892 rtx xops[2];
1893 rtx addreg0 = 0, addreg1 = 0;
1894 int dest_overlapped_low = 0;
1895 int size = GET_MODE_SIZE (GET_MODE (operands[0]));
1897 middlehalf[0] = 0;
1898 middlehalf[1] = 0;
1900 /* First classify both operands. */
1902 if (REG_P (operands[0]))
1903 optype0 = REGOP;
1904 else if (offsettable_memref_p (operands[0]))
1905 optype0 = OFFSOP;
1906 else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
1907 optype0 = POPOP;
1908 else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
1909 optype0 = PUSHOP;
1910 else if (GET_CODE (operands[0]) == MEM)
1911 optype0 = MEMOP;
1912 else
1913 optype0 = RNDOP;
1915 if (REG_P (operands[1]))
1916 optype1 = REGOP;
1917 else if (CONSTANT_P (operands[1]))
1918 optype1 = CNSTOP;
1919 else if (offsettable_memref_p (operands[1]))
1920 optype1 = OFFSOP;
1921 else if (GET_CODE (XEXP (operands[1], 0)) == POST_INC)
1922 optype1 = POPOP;
1923 else if (GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)
1924 optype1 = PUSHOP;
1925 else if (GET_CODE (operands[1]) == MEM)
1926 optype1 = MEMOP;
1927 else
1928 optype1 = RNDOP;
1930 /* Check for the cases that the operand constraints are not supposed
1931 to allow to happen. Generating code for these cases is
1932 painful. */
1933 gcc_assert (optype0 != RNDOP && optype1 != RNDOP);
1935 /* If one operand is decrementing and one is incrementing
1936 decrement the former register explicitly
1937 and change that operand into ordinary indexing. */
1939 if (optype0 == PUSHOP && optype1 == POPOP)
1941 operands[0] = XEXP (XEXP (operands[0], 0), 0);
1942 if (size == 12)
1943 output_asm_insn ("sub%.l #12,%0", operands);
1944 else
1945 output_asm_insn ("subq%.l #8,%0", operands);
1946 if (GET_MODE (operands[1]) == XFmode)
1947 operands[0] = gen_rtx_MEM (XFmode, operands[0]);
1948 else if (GET_MODE (operands[0]) == DFmode)
1949 operands[0] = gen_rtx_MEM (DFmode, operands[0]);
1950 else
1951 operands[0] = gen_rtx_MEM (DImode, operands[0]);
1952 optype0 = OFFSOP;
1954 if (optype0 == POPOP && optype1 == PUSHOP)
1956 operands[1] = XEXP (XEXP (operands[1], 0), 0);
1957 if (size == 12)
1958 output_asm_insn ("sub%.l #12,%1", operands);
1959 else
1960 output_asm_insn ("subq%.l #8,%1", operands);
1961 if (GET_MODE (operands[1]) == XFmode)
1962 operands[1] = gen_rtx_MEM (XFmode, operands[1]);
1963 else if (GET_MODE (operands[1]) == DFmode)
1964 operands[1] = gen_rtx_MEM (DFmode, operands[1]);
1965 else
1966 operands[1] = gen_rtx_MEM (DImode, operands[1]);
1967 optype1 = OFFSOP;
1970 /* If an operand is an unoffsettable memory ref, find a register
1971 we can increment temporarily to make it refer to the second word. */
1973 if (optype0 == MEMOP)
1974 addreg0 = find_addr_reg (XEXP (operands[0], 0));
1976 if (optype1 == MEMOP)
1977 addreg1 = find_addr_reg (XEXP (operands[1], 0));
1979 /* Ok, we can do one word at a time.
1980 Normally we do the low-numbered word first,
1981 but if either operand is autodecrementing then we
1982 do the high-numbered word first.
1984 In either case, set up in LATEHALF the operands to use
1985 for the high-numbered word and in some cases alter the
1986 operands in OPERANDS to be suitable for the low-numbered word. */
1988 if (size == 12)
1990 if (optype0 == REGOP)
1992 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 2);
1993 middlehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1995 else if (optype0 == OFFSOP)
1997 middlehalf[0] = adjust_address (operands[0], SImode, 4);
1998 latehalf[0] = adjust_address (operands[0], SImode, size - 4);
2000 else
2002 middlehalf[0] = operands[0];
2003 latehalf[0] = operands[0];
2006 if (optype1 == REGOP)
2008 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 2);
2009 middlehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2011 else if (optype1 == OFFSOP)
2013 middlehalf[1] = adjust_address (operands[1], SImode, 4);
2014 latehalf[1] = adjust_address (operands[1], SImode, size - 4);
2016 else if (optype1 == CNSTOP)
2018 if (GET_CODE (operands[1]) == CONST_DOUBLE)
2020 REAL_VALUE_TYPE r;
2021 long l[3];
2023 REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
2024 REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
2025 operands[1] = GEN_INT (l[0]);
2026 middlehalf[1] = GEN_INT (l[1]);
2027 latehalf[1] = GEN_INT (l[2]);
2029 else
2031 /* No non-CONST_DOUBLE constant should ever appear
2032 here. */
2033 gcc_assert (!CONSTANT_P (operands[1]));
2036 else
2038 middlehalf[1] = operands[1];
2039 latehalf[1] = operands[1];
2042 else
2043 /* size is not 12: */
2045 if (optype0 == REGOP)
2046 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2047 else if (optype0 == OFFSOP)
2048 latehalf[0] = adjust_address (operands[0], SImode, size - 4);
2049 else
2050 latehalf[0] = operands[0];
2052 if (optype1 == REGOP)
2053 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2054 else if (optype1 == OFFSOP)
2055 latehalf[1] = adjust_address (operands[1], SImode, size - 4);
2056 else if (optype1 == CNSTOP)
2057 split_double (operands[1], &operands[1], &latehalf[1]);
2058 else
2059 latehalf[1] = operands[1];
2062 /* If insn is effectively movd N(sp),-(sp) then we will do the
2063 high word first. We should use the adjusted operand 1 (which is N+4(sp))
2064 for the low word as well, to compensate for the first decrement of sp. */
2065 if (optype0 == PUSHOP
2066 && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM
2067 && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
2068 operands[1] = middlehalf[1] = latehalf[1];
2070 /* For (set (reg:DI N) (mem:DI ... (reg:SI N) ...)),
2071 if the upper part of reg N does not appear in the MEM, arrange to
2072 emit the move late-half first. Otherwise, compute the MEM address
2073 into the upper part of N and use that as a pointer to the memory
2074 operand. */
2075 if (optype0 == REGOP
2076 && (optype1 == OFFSOP || optype1 == MEMOP))
2078 rtx testlow = gen_rtx_REG (SImode, REGNO (operands[0]));
2080 if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0))
2081 && reg_overlap_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
2083 /* If both halves of dest are used in the src memory address,
2084 compute the address into latehalf of dest.
2085 Note that this can't happen if the dest is two data regs. */
2086 compadr:
2087 xops[0] = latehalf[0];
2088 xops[1] = XEXP (operands[1], 0);
2089 output_asm_insn ("lea %a1,%0", xops);
2090 if (GET_MODE (operands[1]) == XFmode )
2092 operands[1] = gen_rtx_MEM (XFmode, latehalf[0]);
2093 middlehalf[1] = adjust_address (operands[1], DImode, size - 8);
2094 latehalf[1] = adjust_address (operands[1], DImode, size - 4);
2096 else
2098 operands[1] = gen_rtx_MEM (DImode, latehalf[0]);
2099 latehalf[1] = adjust_address (operands[1], DImode, size - 4);
2102 else if (size == 12
2103 && reg_overlap_mentioned_p (middlehalf[0],
2104 XEXP (operands[1], 0)))
2106 /* Check for two regs used by both source and dest.
2107 Note that this can't happen if the dest is all data regs.
2108 It can happen if the dest is d6, d7, a0.
2109 But in that case, latehalf is an addr reg, so
2110 the code at compadr does ok. */
2112 if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0))
2113 || reg_overlap_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
2114 goto compadr;
2116 /* JRV says this can't happen: */
2117 gcc_assert (!addreg0 && !addreg1);
2119 /* Only the middle reg conflicts; simply put it last. */
2120 output_asm_insn (singlemove_string (operands), operands);
2121 output_asm_insn (singlemove_string (latehalf), latehalf);
2122 output_asm_insn (singlemove_string (middlehalf), middlehalf);
2123 return "";
2125 else if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0)))
2126 /* If the low half of dest is mentioned in the source memory
2127 address, the arrange to emit the move late half first. */
2128 dest_overlapped_low = 1;
2131 /* If one or both operands autodecrementing,
2132 do the two words, high-numbered first. */
2134 /* Likewise, the first move would clobber the source of the second one,
2135 do them in the other order. This happens only for registers;
2136 such overlap can't happen in memory unless the user explicitly
2137 sets it up, and that is an undefined circumstance. */
2139 if (optype0 == PUSHOP || optype1 == PUSHOP
2140 || (optype0 == REGOP && optype1 == REGOP
2141 && ((middlehalf[1] && REGNO (operands[0]) == REGNO (middlehalf[1]))
2142 || REGNO (operands[0]) == REGNO (latehalf[1])))
2143 || dest_overlapped_low)
2145 /* Make any unoffsettable addresses point at high-numbered word. */
2146 if (addreg0)
2148 if (size == 12)
2149 output_asm_insn ("addq%.l #8,%0", &addreg0);
2150 else
2151 output_asm_insn ("addq%.l #4,%0", &addreg0);
2153 if (addreg1)
2155 if (size == 12)
2156 output_asm_insn ("addq%.l #8,%0", &addreg1);
2157 else
2158 output_asm_insn ("addq%.l #4,%0", &addreg1);
2161 /* Do that word. */
2162 output_asm_insn (singlemove_string (latehalf), latehalf);
2164 /* Undo the adds we just did. */
2165 if (addreg0)
2166 output_asm_insn ("subq%.l #4,%0", &addreg0);
2167 if (addreg1)
2168 output_asm_insn ("subq%.l #4,%0", &addreg1);
2170 if (size == 12)
2172 output_asm_insn (singlemove_string (middlehalf), middlehalf);
2173 if (addreg0)
2174 output_asm_insn ("subq%.l #4,%0", &addreg0);
2175 if (addreg1)
2176 output_asm_insn ("subq%.l #4,%0", &addreg1);
2179 /* Do low-numbered word. */
2180 return singlemove_string (operands);
2183 /* Normal case: do the two words, low-numbered first. */
2185 output_asm_insn (singlemove_string (operands), operands);
2187 /* Do the middle one of the three words for long double */
2188 if (size == 12)
2190 if (addreg0)
2191 output_asm_insn ("addq%.l #4,%0", &addreg0);
2192 if (addreg1)
2193 output_asm_insn ("addq%.l #4,%0", &addreg1);
2195 output_asm_insn (singlemove_string (middlehalf), middlehalf);
2198 /* Make any unoffsettable addresses point at high-numbered word. */
2199 if (addreg0)
2200 output_asm_insn ("addq%.l #4,%0", &addreg0);
2201 if (addreg1)
2202 output_asm_insn ("addq%.l #4,%0", &addreg1);
2204 /* Do that word. */
2205 output_asm_insn (singlemove_string (latehalf), latehalf);
2207 /* Undo the adds we just did. */
2208 if (addreg0)
2210 if (size == 12)
2211 output_asm_insn ("subq%.l #8,%0", &addreg0);
2212 else
2213 output_asm_insn ("subq%.l #4,%0", &addreg0);
2215 if (addreg1)
2217 if (size == 12)
2218 output_asm_insn ("subq%.l #8,%0", &addreg1);
2219 else
2220 output_asm_insn ("subq%.l #4,%0", &addreg1);
2223 return "";
2226 /* Return a REG that occurs in ADDR with coefficient 1.
2227 ADDR can be effectively incremented by incrementing REG. */
2229 static rtx
2230 find_addr_reg (rtx addr)
2232 while (GET_CODE (addr) == PLUS)
2234 if (GET_CODE (XEXP (addr, 0)) == REG)
2235 addr = XEXP (addr, 0);
2236 else if (GET_CODE (XEXP (addr, 1)) == REG)
2237 addr = XEXP (addr, 1);
2238 else if (CONSTANT_P (XEXP (addr, 0)))
2239 addr = XEXP (addr, 1);
2240 else if (CONSTANT_P (XEXP (addr, 1)))
2241 addr = XEXP (addr, 0);
2242 else
2243 gcc_unreachable ();
2245 gcc_assert (GET_CODE (addr) == REG);
2246 return addr;
2249 /* Output assembler code to perform a 32-bit 3-operand add. */
2251 const char *
2252 output_addsi3 (rtx *operands)
2254 if (! operands_match_p (operands[0], operands[1]))
2256 if (!ADDRESS_REG_P (operands[1]))
2258 rtx tmp = operands[1];
2260 operands[1] = operands[2];
2261 operands[2] = tmp;
2264 /* These insns can result from reloads to access
2265 stack slots over 64k from the frame pointer. */
2266 if (GET_CODE (operands[2]) == CONST_INT
2267 && (INTVAL (operands[2]) < -32768 || INTVAL (operands[2]) > 32767))
2268 return "move%.l %2,%0\n\tadd%.l %1,%0";
2269 if (GET_CODE (operands[2]) == REG)
2270 return MOTOROLA ? "lea (%1,%2.l),%0" : "lea %1@(0,%2:l),%0";
2271 return MOTOROLA ? "lea (%c2,%1),%0" : "lea %1@(%c2),%0";
2273 if (GET_CODE (operands[2]) == CONST_INT)
2275 if (INTVAL (operands[2]) > 0
2276 && INTVAL (operands[2]) <= 8)
2277 return "addq%.l %2,%0";
2278 if (INTVAL (operands[2]) < 0
2279 && INTVAL (operands[2]) >= -8)
2281 operands[2] = GEN_INT (- INTVAL (operands[2]));
2282 return "subq%.l %2,%0";
2284 /* On the CPU32 it is faster to use two addql instructions to
2285 add a small integer (8 < N <= 16) to a register.
2286 Likewise for subql. */
2287 if (TARGET_CPU32 && REG_P (operands[0]))
2289 if (INTVAL (operands[2]) > 8
2290 && INTVAL (operands[2]) <= 16)
2292 operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
2293 return "addq%.l #8,%0\n\taddq%.l %2,%0";
2295 if (INTVAL (operands[2]) < -8
2296 && INTVAL (operands[2]) >= -16)
2298 operands[2] = GEN_INT (- INTVAL (operands[2]) - 8);
2299 return "subq%.l #8,%0\n\tsubq%.l %2,%0";
2302 if (ADDRESS_REG_P (operands[0])
2303 && INTVAL (operands[2]) >= -0x8000
2304 && INTVAL (operands[2]) < 0x8000)
2306 if (TARGET_68040)
2307 return "add%.w %2,%0";
2308 else
2309 return MOTOROLA ? "lea (%c2,%0),%0" : "lea %0@(%c2),%0";
2312 return "add%.l %2,%0";
2315 /* Store in cc_status the expressions that the condition codes will
2316 describe after execution of an instruction whose pattern is EXP.
2317 Do not alter them if the instruction would not alter the cc's. */
2319 /* On the 68000, all the insns to store in an address register fail to
2320 set the cc's. However, in some cases these instructions can make it
2321 possibly invalid to use the saved cc's. In those cases we clear out
2322 some or all of the saved cc's so they won't be used. */
2324 void
2325 notice_update_cc (rtx exp, rtx insn)
2327 if (GET_CODE (exp) == SET)
2329 if (GET_CODE (SET_SRC (exp)) == CALL)
2331 CC_STATUS_INIT;
2333 else if (ADDRESS_REG_P (SET_DEST (exp)))
2335 if (cc_status.value1 && modified_in_p (cc_status.value1, insn))
2336 cc_status.value1 = 0;
2337 if (cc_status.value2 && modified_in_p (cc_status.value2, insn))
2338 cc_status.value2 = 0;
2340 else if (!FP_REG_P (SET_DEST (exp))
2341 && SET_DEST (exp) != cc0_rtx
2342 && (FP_REG_P (SET_SRC (exp))
2343 || GET_CODE (SET_SRC (exp)) == FIX
2344 || GET_CODE (SET_SRC (exp)) == FLOAT_TRUNCATE
2345 || GET_CODE (SET_SRC (exp)) == FLOAT_EXTEND))
2347 CC_STATUS_INIT;
2349 /* A pair of move insns doesn't produce a useful overall cc. */
2350 else if (!FP_REG_P (SET_DEST (exp))
2351 && !FP_REG_P (SET_SRC (exp))
2352 && GET_MODE_SIZE (GET_MODE (SET_SRC (exp))) > 4
2353 && (GET_CODE (SET_SRC (exp)) == REG
2354 || GET_CODE (SET_SRC (exp)) == MEM
2355 || GET_CODE (SET_SRC (exp)) == CONST_DOUBLE))
2357 CC_STATUS_INIT;
2359 else if (GET_CODE (SET_SRC (exp)) == CALL)
2361 CC_STATUS_INIT;
2363 else if (XEXP (exp, 0) != pc_rtx)
2365 cc_status.flags = 0;
2366 cc_status.value1 = XEXP (exp, 0);
2367 cc_status.value2 = XEXP (exp, 1);
2370 else if (GET_CODE (exp) == PARALLEL
2371 && GET_CODE (XVECEXP (exp, 0, 0)) == SET)
2373 if (ADDRESS_REG_P (XEXP (XVECEXP (exp, 0, 0), 0)))
2374 CC_STATUS_INIT;
2375 else if (XEXP (XVECEXP (exp, 0, 0), 0) != pc_rtx)
2377 cc_status.flags = 0;
2378 cc_status.value1 = XEXP (XVECEXP (exp, 0, 0), 0);
2379 cc_status.value2 = XEXP (XVECEXP (exp, 0, 0), 1);
2382 else
2383 CC_STATUS_INIT;
2384 if (cc_status.value2 != 0
2385 && ADDRESS_REG_P (cc_status.value2)
2386 && GET_MODE (cc_status.value2) == QImode)
2387 CC_STATUS_INIT;
2388 if (cc_status.value2 != 0)
2389 switch (GET_CODE (cc_status.value2))
2391 case ASHIFT: case ASHIFTRT: case LSHIFTRT:
2392 case ROTATE: case ROTATERT:
2393 /* These instructions always clear the overflow bit, and set
2394 the carry to the bit shifted out. */
2395 /* ??? We don't currently have a way to signal carry not valid,
2396 nor do we check for it in the branch insns. */
2397 CC_STATUS_INIT;
2398 break;
2400 case PLUS: case MINUS: case MULT:
2401 case DIV: case UDIV: case MOD: case UMOD: case NEG:
2402 if (GET_MODE (cc_status.value2) != VOIDmode)
2403 cc_status.flags |= CC_NO_OVERFLOW;
2404 break;
2405 case ZERO_EXTEND:
2406 /* (SET r1 (ZERO_EXTEND r2)) on this machine
2407 ends with a move insn moving r2 in r2's mode.
2408 Thus, the cc's are set for r2.
2409 This can set N bit spuriously. */
2410 cc_status.flags |= CC_NOT_NEGATIVE;
2412 default:
2413 break;
2415 if (cc_status.value1 && GET_CODE (cc_status.value1) == REG
2416 && cc_status.value2
2417 && reg_overlap_mentioned_p (cc_status.value1, cc_status.value2))
2418 cc_status.value2 = 0;
2419 if (((cc_status.value1 && FP_REG_P (cc_status.value1))
2420 || (cc_status.value2 && FP_REG_P (cc_status.value2))))
2421 cc_status.flags = CC_IN_68881;
2424 const char *
2425 output_move_const_double (rtx *operands)
2427 int code = standard_68881_constant_p (operands[1]);
2429 if (code != 0)
2431 static char buf[40];
2433 sprintf (buf, "fmovecr #0x%x,%%0", code & 0xff);
2434 return buf;
2436 return "fmove%.d %1,%0";
2439 const char *
2440 output_move_const_single (rtx *operands)
2442 int code = standard_68881_constant_p (operands[1]);
2444 if (code != 0)
2446 static char buf[40];
2448 sprintf (buf, "fmovecr #0x%x,%%0", code & 0xff);
2449 return buf;
2451 return "fmove%.s %f1,%0";
2454 /* Return nonzero if X, a CONST_DOUBLE, has a value that we can get
2455 from the "fmovecr" instruction.
2456 The value, anded with 0xff, gives the code to use in fmovecr
2457 to get the desired constant. */
2459 /* This code has been fixed for cross-compilation. */
2461 static int inited_68881_table = 0;
2463 static const char *const strings_68881[7] = {
2464 "0.0",
2465 "1.0",
2466 "10.0",
2467 "100.0",
2468 "10000.0",
2469 "1e8",
2470 "1e16"
2473 static const int codes_68881[7] = {
2474 0x0f,
2475 0x32,
2476 0x33,
2477 0x34,
2478 0x35,
2479 0x36,
2480 0x37
2483 REAL_VALUE_TYPE values_68881[7];
2485 /* Set up values_68881 array by converting the decimal values
2486 strings_68881 to binary. */
2488 void
2489 init_68881_table (void)
2491 int i;
2492 REAL_VALUE_TYPE r;
2493 enum machine_mode mode;
2495 mode = SFmode;
2496 for (i = 0; i < 7; i++)
2498 if (i == 6)
2499 mode = DFmode;
2500 r = REAL_VALUE_ATOF (strings_68881[i], mode);
2501 values_68881[i] = r;
2503 inited_68881_table = 1;
2507 standard_68881_constant_p (rtx x)
2509 REAL_VALUE_TYPE r;
2510 int i;
2512 /* fmovecr must be emulated on the 68040 and 68060, so it shouldn't be
2513 used at all on those chips. */
2514 if (TARGET_68040 || TARGET_68060)
2515 return 0;
2517 if (! inited_68881_table)
2518 init_68881_table ();
2520 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
2522 /* Use REAL_VALUES_IDENTICAL instead of REAL_VALUES_EQUAL so that -0.0
2523 is rejected. */
2524 for (i = 0; i < 6; i++)
2526 if (REAL_VALUES_IDENTICAL (r, values_68881[i]))
2527 return (codes_68881[i]);
2530 if (GET_MODE (x) == SFmode)
2531 return 0;
2533 if (REAL_VALUES_EQUAL (r, values_68881[6]))
2534 return (codes_68881[6]);
2536 /* larger powers of ten in the constants ram are not used
2537 because they are not equal to a `double' C constant. */
2538 return 0;
2541 /* If X is a floating-point constant, return the logarithm of X base 2,
2542 or 0 if X is not a power of 2. */
2545 floating_exact_log2 (rtx x)
2547 REAL_VALUE_TYPE r, r1;
2548 int exp;
2550 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
2552 if (REAL_VALUES_LESS (r, dconst1))
2553 return 0;
2555 exp = real_exponent (&r);
2556 real_2expN (&r1, exp);
2557 if (REAL_VALUES_EQUAL (r1, r))
2558 return exp;
2560 return 0;
2563 /* A C compound statement to output to stdio stream STREAM the
2564 assembler syntax for an instruction operand X. X is an RTL
2565 expression.
2567 CODE is a value that can be used to specify one of several ways
2568 of printing the operand. It is used when identical operands
2569 must be printed differently depending on the context. CODE
2570 comes from the `%' specification that was used to request
2571 printing of the operand. If the specification was just `%DIGIT'
2572 then CODE is 0; if the specification was `%LTR DIGIT' then CODE
2573 is the ASCII code for LTR.
2575 If X is a register, this macro should print the register's name.
2576 The names can be found in an array `reg_names' whose type is
2577 `char *[]'. `reg_names' is initialized from `REGISTER_NAMES'.
2579 When the machine description has a specification `%PUNCT' (a `%'
2580 followed by a punctuation character), this macro is called with
2581 a null pointer for X and the punctuation character for CODE.
2583 The m68k specific codes are:
2585 '.' for dot needed in Motorola-style opcode names.
2586 '-' for an operand pushing on the stack:
2587 sp@-, -(sp) or -(%sp) depending on the style of syntax.
2588 '+' for an operand pushing on the stack:
2589 sp@+, (sp)+ or (%sp)+ depending on the style of syntax.
2590 '@' for a reference to the top word on the stack:
2591 sp@, (sp) or (%sp) depending on the style of syntax.
2592 '#' for an immediate operand prefix (# in MIT and Motorola syntax
2593 but & in SGS syntax).
2594 '!' for the cc register (used in an `and to cc' insn).
2595 '$' for the letter `s' in an op code, but only on the 68040.
2596 '&' for the letter `d' in an op code, but only on the 68040.
2597 '/' for register prefix needed by longlong.h.
2599 'b' for byte insn (no effect, on the Sun; this is for the ISI).
2600 'd' to force memory addressing to be absolute, not relative.
2601 'f' for float insn (print a CONST_DOUBLE as a float rather than in hex)
2602 'o' for operands to go directly to output_operand_address (bypassing
2603 print_operand_address--used only for SYMBOL_REFs under TARGET_PCREL)
2604 'x' for float insn (print a CONST_DOUBLE as a float rather than in hex),
2605 or print pair of registers as rx:ry.
2609 void
2610 print_operand (FILE *file, rtx op, int letter)
2612 if (letter == '.')
2614 if (MOTOROLA)
2615 fprintf (file, ".");
2617 else if (letter == '#')
2618 asm_fprintf (file, "%I");
2619 else if (letter == '-')
2620 asm_fprintf (file, MOTOROLA ? "-(%Rsp)" : "%Rsp@-");
2621 else if (letter == '+')
2622 asm_fprintf (file, MOTOROLA ? "(%Rsp)+" : "%Rsp@+");
2623 else if (letter == '@')
2624 asm_fprintf (file, MOTOROLA ? "(%Rsp)" : "%Rsp@");
2625 else if (letter == '!')
2626 asm_fprintf (file, "%Rfpcr");
2627 else if (letter == '$')
2629 if (TARGET_68040_ONLY)
2630 fprintf (file, "s");
2632 else if (letter == '&')
2634 if (TARGET_68040_ONLY)
2635 fprintf (file, "d");
2637 else if (letter == '/')
2638 asm_fprintf (file, "%R");
2639 else if (letter == 'o')
2641 /* This is only for direct addresses with TARGET_PCREL */
2642 gcc_assert (GET_CODE (op) == MEM
2643 && GET_CODE (XEXP (op, 0)) == SYMBOL_REF
2644 && TARGET_PCREL);
2645 output_addr_const (file, XEXP (op, 0));
2647 else if (GET_CODE (op) == REG)
2649 if (letter == 'R')
2650 /* Print out the second register name of a register pair.
2651 I.e., R (6) => 7. */
2652 fputs (M68K_REGNAME(REGNO (op) + 1), file);
2653 else
2654 fputs (M68K_REGNAME(REGNO (op)), file);
2656 else if (GET_CODE (op) == MEM)
2658 output_address (XEXP (op, 0));
2659 if (letter == 'd' && ! TARGET_68020
2660 && CONSTANT_ADDRESS_P (XEXP (op, 0))
2661 && !(GET_CODE (XEXP (op, 0)) == CONST_INT
2662 && INTVAL (XEXP (op, 0)) < 0x8000
2663 && INTVAL (XEXP (op, 0)) >= -0x8000))
2664 fprintf (file, MOTOROLA ? ".l" : ":l");
2666 else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == SFmode)
2668 REAL_VALUE_TYPE r;
2669 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
2670 ASM_OUTPUT_FLOAT_OPERAND (letter, file, r);
2672 else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == XFmode)
2674 REAL_VALUE_TYPE r;
2675 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
2676 ASM_OUTPUT_LONG_DOUBLE_OPERAND (file, r);
2678 else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == DFmode)
2680 REAL_VALUE_TYPE r;
2681 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
2682 ASM_OUTPUT_DOUBLE_OPERAND (file, r);
2684 else
2686 /* Use `print_operand_address' instead of `output_addr_const'
2687 to ensure that we print relevant PIC stuff. */
2688 asm_fprintf (file, "%I");
2689 if (TARGET_PCREL
2690 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST))
2691 print_operand_address (file, op);
2692 else
2693 output_addr_const (file, op);
2698 /* A C compound statement to output to stdio stream STREAM the
2699 assembler syntax for an instruction operand that is a memory
2700 reference whose address is ADDR. ADDR is an RTL expression.
2702 Note that this contains a kludge that knows that the only reason
2703 we have an address (plus (label_ref...) (reg...)) when not generating
2704 PIC code is in the insn before a tablejump, and we know that m68k.md
2705 generates a label LInnn: on such an insn.
2707 It is possible for PIC to generate a (plus (label_ref...) (reg...))
2708 and we handle that just like we would a (plus (symbol_ref...) (reg...)).
2710 They also do not like things like "pea 1.w", so we simple leave off
2711 the .w on small constants.
2713 This routine is responsible for distinguishing between -fpic and -fPIC
2714 style relocations in an address. When generating -fpic code the
2715 offset is output in word mode (e.g. movel a5@(_foo:w), a0). When generating
2716 -fPIC code the offset is output in long mode (e.g. movel a5@(_foo:l), a0) */
2718 #if MOTOROLA
2719 # define ASM_OUTPUT_CASE_FETCH(file, labelno, regname)\
2720 asm_fprintf (file, "%LL%d(%Rpc,%s.", labelno, regname)
2721 #else /* !MOTOROLA */
2722 # define ASM_OUTPUT_CASE_FETCH(file, labelno, regname)\
2723 asm_fprintf (file, "%Rpc@(%LL%d,%s:", labelno, regname)
2724 #endif /* !MOTOROLA */
2726 void
2727 print_operand_address (FILE *file, rtx addr)
2729 register rtx reg1, reg2, breg, ireg;
2730 rtx offset;
2732 switch (GET_CODE (addr))
2734 case REG:
2735 fprintf (file, MOTOROLA ? "(%s)" : "%s@", M68K_REGNAME(REGNO (addr)));
2736 break;
2737 case PRE_DEC:
2738 fprintf (file, MOTOROLA ? "-(%s)" : "%s@-",
2739 M68K_REGNAME(REGNO (XEXP (addr, 0))));
2740 break;
2741 case POST_INC:
2742 fprintf (file, MOTOROLA ? "(%s)+" : "%s@+",
2743 M68K_REGNAME(REGNO (XEXP (addr, 0))));
2744 break;
2745 case PLUS:
2746 reg1 = reg2 = ireg = breg = offset = 0;
2747 if (CONSTANT_ADDRESS_P (XEXP (addr, 0)))
2749 offset = XEXP (addr, 0);
2750 addr = XEXP (addr, 1);
2752 else if (CONSTANT_ADDRESS_P (XEXP (addr, 1)))
2754 offset = XEXP (addr, 1);
2755 addr = XEXP (addr, 0);
2757 if (GET_CODE (addr) != PLUS)
2761 else if (GET_CODE (XEXP (addr, 0)) == SIGN_EXTEND)
2763 reg1 = XEXP (addr, 0);
2764 addr = XEXP (addr, 1);
2766 else if (GET_CODE (XEXP (addr, 1)) == SIGN_EXTEND)
2768 reg1 = XEXP (addr, 1);
2769 addr = XEXP (addr, 0);
2771 else if (GET_CODE (XEXP (addr, 0)) == MULT)
2773 reg1 = XEXP (addr, 0);
2774 addr = XEXP (addr, 1);
2776 else if (GET_CODE (XEXP (addr, 1)) == MULT)
2778 reg1 = XEXP (addr, 1);
2779 addr = XEXP (addr, 0);
2781 else if (GET_CODE (XEXP (addr, 0)) == REG)
2783 reg1 = XEXP (addr, 0);
2784 addr = XEXP (addr, 1);
2786 else if (GET_CODE (XEXP (addr, 1)) == REG)
2788 reg1 = XEXP (addr, 1);
2789 addr = XEXP (addr, 0);
2791 if (GET_CODE (addr) == REG || GET_CODE (addr) == MULT
2792 || GET_CODE (addr) == SIGN_EXTEND)
2794 if (reg1 == 0)
2796 reg1 = addr;
2798 else
2800 reg2 = addr;
2802 addr = 0;
2804 #if 0 /* for OLD_INDEXING */
2805 else if (GET_CODE (addr) == PLUS)
2807 if (GET_CODE (XEXP (addr, 0)) == REG)
2809 reg2 = XEXP (addr, 0);
2810 addr = XEXP (addr, 1);
2812 else if (GET_CODE (XEXP (addr, 1)) == REG)
2814 reg2 = XEXP (addr, 1);
2815 addr = XEXP (addr, 0);
2818 #endif
2819 if (offset != 0)
2821 gcc_assert (!addr);
2822 addr = offset;
2824 if ((reg1 && (GET_CODE (reg1) == SIGN_EXTEND
2825 || GET_CODE (reg1) == MULT))
2826 || (reg2 != 0 && REGNO_OK_FOR_BASE_P (REGNO (reg2))))
2828 breg = reg2;
2829 ireg = reg1;
2831 else if (reg1 != 0 && REGNO_OK_FOR_BASE_P (REGNO (reg1)))
2833 breg = reg1;
2834 ireg = reg2;
2836 if (ireg != 0 && breg == 0 && GET_CODE (addr) == LABEL_REF
2837 && ! (flag_pic && ireg == pic_offset_table_rtx))
2839 int scale = 1;
2840 if (GET_CODE (ireg) == MULT)
2842 scale = INTVAL (XEXP (ireg, 1));
2843 ireg = XEXP (ireg, 0);
2845 if (GET_CODE (ireg) == SIGN_EXTEND)
2847 ASM_OUTPUT_CASE_FETCH (file,
2848 CODE_LABEL_NUMBER (XEXP (addr, 0)),
2849 M68K_REGNAME(REGNO (XEXP (ireg, 0))));
2850 fprintf (file, "w");
2852 else
2854 ASM_OUTPUT_CASE_FETCH (file,
2855 CODE_LABEL_NUMBER (XEXP (addr, 0)),
2856 M68K_REGNAME(REGNO (ireg)));
2857 fprintf (file, "l");
2859 if (scale != 1)
2860 fprintf (file, MOTOROLA ? "*%d" : ":%d", scale);
2861 putc (')', file);
2862 break;
2864 if (breg != 0 && ireg == 0 && GET_CODE (addr) == LABEL_REF
2865 && ! (flag_pic && breg == pic_offset_table_rtx))
2867 ASM_OUTPUT_CASE_FETCH (file,
2868 CODE_LABEL_NUMBER (XEXP (addr, 0)),
2869 M68K_REGNAME(REGNO (breg)));
2870 fprintf (file, "l)");
2871 break;
2873 if (ireg != 0 || breg != 0)
2875 int scale = 1;
2877 gcc_assert (breg);
2878 gcc_assert (flag_pic || !addr || GET_CODE (addr) != LABEL_REF);
2880 if (MOTOROLA)
2882 if (addr != 0)
2884 output_addr_const (file, addr);
2885 if (flag_pic && (breg == pic_offset_table_rtx))
2887 fprintf (file, "@GOT");
2888 if (flag_pic == 1)
2889 fprintf (file, ".w");
2892 fprintf (file, "(%s", M68K_REGNAME(REGNO (breg)));
2893 if (ireg != 0)
2894 putc (',', file);
2896 else /* !MOTOROLA */
2898 fprintf (file, "%s@(", M68K_REGNAME(REGNO (breg)));
2899 if (addr != 0)
2901 output_addr_const (file, addr);
2902 if (breg == pic_offset_table_rtx)
2903 switch (flag_pic)
2905 case 1:
2906 fprintf (file, ":w"); break;
2907 case 2:
2908 fprintf (file, ":l"); break;
2909 default:
2910 break;
2912 if (ireg != 0)
2913 putc (',', file);
2915 } /* !MOTOROLA */
2916 if (ireg != 0 && GET_CODE (ireg) == MULT)
2918 scale = INTVAL (XEXP (ireg, 1));
2919 ireg = XEXP (ireg, 0);
2921 if (ireg != 0 && GET_CODE (ireg) == SIGN_EXTEND)
2922 fprintf (file, MOTOROLA ? "%s.w" : "%s:w",
2923 M68K_REGNAME(REGNO (XEXP (ireg, 0))));
2924 else if (ireg != 0)
2925 fprintf (file, MOTOROLA ? "%s.l" : "%s:l",
2926 M68K_REGNAME(REGNO (ireg)));
2927 if (scale != 1)
2928 fprintf (file, MOTOROLA ? "*%d" : ":%d", scale);
2929 putc (')', file);
2930 break;
2932 else if (reg1 != 0 && GET_CODE (addr) == LABEL_REF
2933 && ! (flag_pic && reg1 == pic_offset_table_rtx))
2935 ASM_OUTPUT_CASE_FETCH (file,
2936 CODE_LABEL_NUMBER (XEXP (addr, 0)),
2937 M68K_REGNAME(REGNO (reg1)));
2938 fprintf (file, "l)");
2939 break;
2941 /* FALL-THROUGH (is this really what we want?) */
2942 default:
2943 if (GET_CODE (addr) == CONST_INT
2944 && INTVAL (addr) < 0x8000
2945 && INTVAL (addr) >= -0x8000)
2947 fprintf (file, MOTOROLA ? "%d.w" : "%d:w", (int) INTVAL (addr));
2949 else if (GET_CODE (addr) == CONST_INT)
2951 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (addr));
2953 else if (TARGET_PCREL)
2955 fputc ('(', file);
2956 output_addr_const (file, addr);
2957 if (flag_pic == 1)
2958 asm_fprintf (file, ":w,%Rpc)");
2959 else
2960 asm_fprintf (file, ":l,%Rpc)");
2962 else
2964 /* Special case for SYMBOL_REF if the symbol name ends in
2965 `.<letter>', this can be mistaken as a size suffix. Put
2966 the name in parentheses. */
2967 if (GET_CODE (addr) == SYMBOL_REF
2968 && strlen (XSTR (addr, 0)) > 2
2969 && XSTR (addr, 0)[strlen (XSTR (addr, 0)) - 2] == '.')
2971 putc ('(', file);
2972 output_addr_const (file, addr);
2973 putc (')', file);
2975 else
2976 output_addr_const (file, addr);
2978 break;
2982 /* Check for cases where a clr insns can be omitted from code using
2983 strict_low_part sets. For example, the second clrl here is not needed:
2984 clrl d0; movw a0@+,d0; use d0; clrl d0; movw a0@+; use d0; ...
2986 MODE is the mode of this STRICT_LOW_PART set. FIRST_INSN is the clear
2987 insn we are checking for redundancy. TARGET is the register set by the
2988 clear insn. */
2990 bool
2991 strict_low_part_peephole_ok (enum machine_mode mode, rtx first_insn,
2992 rtx target)
2994 rtx p;
2996 p = prev_nonnote_insn (first_insn);
2998 while (p)
3000 /* If it isn't an insn, then give up. */
3001 if (GET_CODE (p) != INSN)
3002 return false;
3004 if (reg_set_p (target, p))
3006 rtx set = single_set (p);
3007 rtx dest;
3009 /* If it isn't an easy to recognize insn, then give up. */
3010 if (! set)
3011 return false;
3013 dest = SET_DEST (set);
3015 /* If this sets the entire target register to zero, then our
3016 first_insn is redundant. */
3017 if (rtx_equal_p (dest, target)
3018 && SET_SRC (set) == const0_rtx)
3019 return true;
3020 else if (GET_CODE (dest) == STRICT_LOW_PART
3021 && GET_CODE (XEXP (dest, 0)) == REG
3022 && REGNO (XEXP (dest, 0)) == REGNO (target)
3023 && (GET_MODE_SIZE (GET_MODE (XEXP (dest, 0)))
3024 <= GET_MODE_SIZE (mode)))
3025 /* This is a strict low part set which modifies less than
3026 we are using, so it is safe. */
3028 else
3029 return false;
3032 p = prev_nonnote_insn (p);
3035 return false;
3038 /* Operand predicates for implementing asymmetric pc-relative addressing
3039 on m68k. The m68k supports pc-relative addressing (mode 7, register 2)
3040 when used as a source operand, but not as a destination operand.
3042 We model this by restricting the meaning of the basic predicates
3043 (general_operand, memory_operand, etc) to forbid the use of this
3044 addressing mode, and then define the following predicates that permit
3045 this addressing mode. These predicates can then be used for the
3046 source operands of the appropriate instructions.
3048 n.b. While it is theoretically possible to change all machine patterns
3049 to use this addressing more where permitted by the architecture,
3050 it has only been implemented for "common" cases: SImode, HImode, and
3051 QImode operands, and only for the principle operations that would
3052 require this addressing mode: data movement and simple integer operations.
3054 In parallel with these new predicates, two new constraint letters
3055 were defined: 'S' and 'T'. 'S' is the -mpcrel analog of 'm'.
3056 'T' replaces 's' in the non-pcrel case. It is a no-op in the pcrel case.
3057 In the pcrel case 's' is only valid in combination with 'a' registers.
3058 See addsi3, subsi3, cmpsi, and movsi patterns for a better understanding
3059 of how these constraints are used.
3061 The use of these predicates is strictly optional, though patterns that
3062 don't will cause an extra reload register to be allocated where one
3063 was not necessary:
3065 lea (abc:w,%pc),%a0 ; need to reload address
3066 moveq &1,%d1 ; since write to pc-relative space
3067 movel %d1,%a0@ ; is not allowed
3069 lea (abc:w,%pc),%a1 ; no need to reload address here
3070 movel %a1@,%d0 ; since "movel (abc:w,%pc),%d0" is ok
3072 For more info, consult tiemann@cygnus.com.
3075 All of the ugliness with predicates and constraints is due to the
3076 simple fact that the m68k does not allow a pc-relative addressing
3077 mode as a destination. gcc does not distinguish between source and
3078 destination addresses. Hence, if we claim that pc-relative address
3079 modes are valid, e.g. GO_IF_LEGITIMATE_ADDRESS accepts them, then we
3080 end up with invalid code. To get around this problem, we left
3081 pc-relative modes as invalid addresses, and then added special
3082 predicates and constraints to accept them.
3084 A cleaner way to handle this is to modify gcc to distinguish
3085 between source and destination addresses. We can then say that
3086 pc-relative is a valid source address but not a valid destination
3087 address, and hopefully avoid a lot of the predicate and constraint
3088 hackery. Unfortunately, this would be a pretty big change. It would
3089 be a useful change for a number of ports, but there aren't any current
3090 plans to undertake this.
3092 ***************************************************************************/
3095 const char *
3096 output_andsi3 (rtx *operands)
3098 int logval;
3099 if (GET_CODE (operands[2]) == CONST_INT
3100 && (INTVAL (operands[2]) | 0xffff) == -1
3101 && (DATA_REG_P (operands[0])
3102 || offsettable_memref_p (operands[0]))
3103 && !TARGET_COLDFIRE)
3105 if (GET_CODE (operands[0]) != REG)
3106 operands[0] = adjust_address (operands[0], HImode, 2);
3107 operands[2] = GEN_INT (INTVAL (operands[2]) & 0xffff);
3108 /* Do not delete a following tstl %0 insn; that would be incorrect. */
3109 CC_STATUS_INIT;
3110 if (operands[2] == const0_rtx)
3111 return "clr%.w %0";
3112 return "and%.w %2,%0";
3114 if (GET_CODE (operands[2]) == CONST_INT
3115 && (logval = exact_log2 (~ INTVAL (operands[2]))) >= 0
3116 && (DATA_REG_P (operands[0])
3117 || offsettable_memref_p (operands[0])))
3119 if (DATA_REG_P (operands[0]))
3121 operands[1] = GEN_INT (logval);
3123 else
3125 operands[0] = adjust_address (operands[0], SImode, 3 - (logval / 8));
3126 operands[1] = GEN_INT (logval % 8);
3128 /* This does not set condition codes in a standard way. */
3129 CC_STATUS_INIT;
3130 return "bclr %1,%0";
3132 return "and%.l %2,%0";
3135 const char *
3136 output_iorsi3 (rtx *operands)
3138 register int logval;
3139 if (GET_CODE (operands[2]) == CONST_INT
3140 && INTVAL (operands[2]) >> 16 == 0
3141 && (DATA_REG_P (operands[0])
3142 || offsettable_memref_p (operands[0]))
3143 && !TARGET_COLDFIRE)
3145 if (GET_CODE (operands[0]) != REG)
3146 operands[0] = adjust_address (operands[0], HImode, 2);
3147 /* Do not delete a following tstl %0 insn; that would be incorrect. */
3148 CC_STATUS_INIT;
3149 if (INTVAL (operands[2]) == 0xffff)
3150 return "mov%.w %2,%0";
3151 return "or%.w %2,%0";
3153 if (GET_CODE (operands[2]) == CONST_INT
3154 && (logval = exact_log2 (INTVAL (operands[2]))) >= 0
3155 && (DATA_REG_P (operands[0])
3156 || offsettable_memref_p (operands[0])))
3158 if (DATA_REG_P (operands[0]))
3159 operands[1] = GEN_INT (logval);
3160 else
3162 operands[0] = adjust_address (operands[0], SImode, 3 - (logval / 8));
3163 operands[1] = GEN_INT (logval % 8);
3165 CC_STATUS_INIT;
3166 return "bset %1,%0";
3168 return "or%.l %2,%0";
3171 const char *
3172 output_xorsi3 (rtx *operands)
3174 register int logval;
3175 if (GET_CODE (operands[2]) == CONST_INT
3176 && INTVAL (operands[2]) >> 16 == 0
3177 && (offsettable_memref_p (operands[0]) || DATA_REG_P (operands[0]))
3178 && !TARGET_COLDFIRE)
3180 if (! DATA_REG_P (operands[0]))
3181 operands[0] = adjust_address (operands[0], HImode, 2);
3182 /* Do not delete a following tstl %0 insn; that would be incorrect. */
3183 CC_STATUS_INIT;
3184 if (INTVAL (operands[2]) == 0xffff)
3185 return "not%.w %0";
3186 return "eor%.w %2,%0";
3188 if (GET_CODE (operands[2]) == CONST_INT
3189 && (logval = exact_log2 (INTVAL (operands[2]))) >= 0
3190 && (DATA_REG_P (operands[0])
3191 || offsettable_memref_p (operands[0])))
3193 if (DATA_REG_P (operands[0]))
3194 operands[1] = GEN_INT (logval);
3195 else
3197 operands[0] = adjust_address (operands[0], SImode, 3 - (logval / 8));
3198 operands[1] = GEN_INT (logval % 8);
3200 CC_STATUS_INIT;
3201 return "bchg %1,%0";
3203 return "eor%.l %2,%0";
3206 #ifdef M68K_TARGET_COFF
3208 /* Output assembly to switch to section NAME with attribute FLAGS. */
3210 static void
3211 m68k_coff_asm_named_section (const char *name, unsigned int flags,
3212 tree decl ATTRIBUTE_UNUSED)
3214 char flagchar;
3216 if (flags & SECTION_WRITE)
3217 flagchar = 'd';
3218 else
3219 flagchar = 'x';
3221 fprintf (asm_out_file, "\t.section\t%s,\"%c\"\n", name, flagchar);
3224 #endif /* M68K_TARGET_COFF */
3226 static void
3227 m68k_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED,
3228 HOST_WIDE_INT delta,
3229 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
3230 tree function)
3232 rtx xops[1];
3233 const char *fmt;
3235 if (delta > 0 && delta <= 8)
3236 asm_fprintf (file, MOTOROLA ?
3237 "\taddq.l %I%d,4(%Rsp)\n" :
3238 "\taddql %I%d,%Rsp@(4)\n",
3239 (int) delta);
3240 else if (delta < 0 && delta >= -8)
3241 asm_fprintf (file, MOTOROLA ?
3242 "\tsubq.l %I%d,4(%Rsp)\n" :
3243 "\tsubql %I%d,%Rsp@(4)\n",
3244 (int) -delta);
3245 else if (TARGET_COLDFIRE)
3247 /* ColdFire can't add/sub a constant to memory unless it is in
3248 the range of addq/subq. So load the value into %d0 and
3249 then add it to 4(%sp). */
3250 if (delta >= -128 && delta <= 127)
3251 asm_fprintf (file, MOTOROLA ?
3252 "\tmoveq.l %I%wd,%Rd0\n" :
3253 "\tmoveql %I%wd,%Rd0\n", delta);
3254 else
3255 asm_fprintf (file, MOTOROLA ?
3256 "\tmove.l %I%wd,%Rd0\n" :
3257 "\tmovel %I%wd,%Rd0\n", delta);
3258 asm_fprintf (file, MOTOROLA ?
3259 "\tadd.l %Rd0,4(%Rsp)\n" :
3260 "\taddl %Rd0,%Rsp@(4)\n");
3262 else
3263 asm_fprintf (file, MOTOROLA ?
3264 "\tadd.l %I%wd,4(%Rsp)\n" :
3265 "\taddl %I%wd,%Rsp@(4)\n",
3266 delta);
3268 xops[0] = DECL_RTL (function);
3270 /* Logic taken from call patterns in m68k.md. */
3271 if (flag_pic)
3273 if (TARGET_PCREL)
3274 fmt = "bra.l %o0";
3275 else if ((flag_pic == 1) || TARGET_68020)
3277 if (MOTOROLA)
3278 #if defined(USE_GAS)
3279 fmt = "bra.l %0@PLTPC";
3280 #else
3281 fmt = "bra %0@PLTPC";
3282 #endif
3283 else /* !MOTOROLA */
3284 #ifdef USE_GAS
3285 fmt = "bra.l %0";
3286 #else
3287 fmt = "jra %0,a1";
3288 #endif
3290 else if (optimize_size || TARGET_ID_SHARED_LIBRARY)
3291 fmt = "move.l %0@GOT(%%a5), %%a1\n\tjmp (%%a1)";
3292 else
3293 fmt = "lea %0-.-8,%%a1\n\tjsr 0(%%pc,%%a1)";
3295 else
3297 #if MOTOROLA && !defined (USE_GAS)
3298 fmt = "jmp %0";
3299 #else
3300 fmt = "jra %0";
3301 #endif
3304 output_asm_insn (fmt, xops);
3307 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
3309 static rtx
3310 m68k_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
3311 int incoming ATTRIBUTE_UNUSED)
3313 return gen_rtx_REG (Pmode, M68K_STRUCT_VALUE_REGNUM);
3316 /* Return nonzero if register old_reg can be renamed to register new_reg. */
3318 m68k_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED,
3319 unsigned int new_reg)
3322 /* Interrupt functions can only use registers that have already been
3323 saved by the prologue, even if they would normally be
3324 call-clobbered. */
3326 if (m68k_interrupt_function_p (current_function_decl)
3327 && !regs_ever_live[new_reg])
3328 return 0;
3330 return 1;
3333 /* Value is true if hard register REGNO can hold a value of machine-mode MODE.
3334 On the 68000, the cpu registers can hold any mode except bytes in address
3335 registers, but the 68881 registers can hold only SFmode or DFmode. */
3336 bool
3337 m68k_regno_mode_ok (int regno, enum machine_mode mode)
3339 if (regno < 8)
3341 /* Data Registers, can hold aggregate if fits in. */
3342 if (regno + GET_MODE_SIZE (mode) / 4 <= 8)
3343 return true;
3345 else if (regno < 16)
3347 /* Address Registers, can't hold bytes, can hold aggregate if
3348 fits in. */
3349 if (GET_MODE_SIZE (mode) == 1)
3350 return false;
3351 if (regno + GET_MODE_SIZE (mode) / 4 <= 16)
3352 return true;
3354 else if (regno < 24)
3356 /* FPU registers, hold float or complex float of long double or
3357 smaller. */
3358 if ((GET_MODE_CLASS (mode) == MODE_FLOAT
3359 || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
3360 && GET_MODE_UNIT_SIZE (mode) <= 12)
3361 return true;
3363 return false;