m68k.c (m68k_output_pic_call): Don't use bsr.l for !TARGET_68020.
[gcc.git] / gcc / config / m68k / m68k.c
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.
5
6 This file is part of GCC.
7
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.
12
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.
17
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. */
22
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"
46
47 enum reg_class regno_reg_class[] =
48 {
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
56 };
57
58
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
71
72
73 /* Structure describing stack frame layout. */
74 struct m68k_frame
75 {
76 /* Stack pointer to frame pointer offset. */
77 HOST_WIDE_INT offset;
78
79 /* Offset of FPU registers. */
80 HOST_WIDE_INT foffset;
81
82 /* Frame size in bytes (rounded up). */
83 HOST_WIDE_INT size;
84
85 /* Data and address register. */
86 int reg_no;
87 unsigned int reg_mask;
88 unsigned int reg_rev_mask;
89
90 /* FPU registers. */
91 int fpu_no;
92 unsigned int fpu_mask;
93 unsigned int fpu_rev_mask;
94
95 /* Offsets relative to ARG_POINTER. */
96 HOST_WIDE_INT frame_pointer_offset;
97 HOST_WIDE_INT stack_pointer_offset;
98
99 /* Function which the above information refers to. */
100 int funcdef_no;
101 };
102
103 /* Current frame information calculated by m68k_compute_frame_layout(). */
104 static struct m68k_frame current_frame;
105
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 *);
125 \f
126
127 /* Specify the identification number of the library being built */
128 const char *m68k_library_id_string = "_current_shared_library_a5_offset_";
129
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;
134 \f
135 /* Initialize the GCC target structure. */
136
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
141
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
150
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
159
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
164
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
169
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
174
175 #undef TARGET_ASM_FILE_START_APP_OFF
176 #define TARGET_ASM_FILE_START_APP_OFF true
177
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
182
183 #undef TARGET_RTX_COSTS
184 #define TARGET_RTX_COSTS m68k_rtx_costs
185
186 #undef TARGET_ATTRIBUTE_TABLE
187 #define TARGET_ATTRIBUTE_TABLE m68k_attribute_table
188
189 #undef TARGET_PROMOTE_PROTOTYPES
190 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
191
192 #undef TARGET_STRUCT_VALUE_RTX
193 #define TARGET_STRUCT_VALUE_RTX m68k_struct_value_rtx
194
195 static const struct attribute_spec m68k_attribute_table[] =
196 {
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 }
200 };
201
202 struct gcc_target targetm = TARGET_INITIALIZER;
203 \f
204 /* These bits are controlled by all CPU selection options. Many options
205 also control MASK_68881, but some (notably -m68020) leave it alone. */
206
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)
210
211 /* Implement TARGET_HANDLE_OPTION. */
212
213 static bool
214 m68k_handle_option (size_t code, const char *arg, int value)
215 {
216 switch (code)
217 {
218 case OPT_m5200:
219 target_flags &= ~(MASK_ALL_CPU_BITS | MASK_68881);
220 target_flags |= MASK_5200;
221 return true;
222
223 case OPT_m5206e:
224 target_flags &= ~(MASK_ALL_CPU_BITS | MASK_68881);
225 target_flags |= MASK_5200 | MASK_CF_HWDIV;
226 return true;
227
228 case OPT_m528x:
229 target_flags &= ~(MASK_ALL_CPU_BITS | MASK_68881);
230 target_flags |= MASK_528x | MASK_CF_HWDIV;
231 return true;
232
233 case OPT_m5307:
234 target_flags &= ~(MASK_ALL_CPU_BITS | MASK_68881);
235 target_flags |= MASK_CFV3 | MASK_CF_HWDIV;
236 return true;
237
238 case OPT_m5407:
239 target_flags &= ~(MASK_ALL_CPU_BITS | MASK_68881);
240 target_flags |= MASK_CFV4 | MASK_CF_HWDIV;
241 return true;
242
243 case OPT_m68000:
244 case OPT_mc68000:
245 target_flags &= ~(MASK_ALL_CPU_BITS | MASK_68881);
246 return true;
247
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;
253
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;
258
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;
264
265 case OPT_m68030:
266 target_flags &= ~MASK_ALL_CPU_BITS;
267 target_flags |= MASK_68020 | MASK_68030 | MASK_BITFIELD;
268 return true;
269
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;
275
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;
281
282 case OPT_m68302:
283 target_flags &= ~(MASK_ALL_CPU_BITS | MASK_68881);
284 return true;
285
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;
291
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;
299
300 default:
301 return true;
302 }
303 }
304
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.
310
311 Don't use this macro to turn on various extra optimizations for
312 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
313
314 void
315 override_options (void)
316 {
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.
319 */
320 if (TARGET_SEP_DATA && TARGET_ID_SHARED_LIBRARY)
321 error ("cannot specify both -msep-data and -mid-shared-library");
322
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.
326 */
327 if (TARGET_SEP_DATA || TARGET_ID_SHARED_LIBRARY)
328 flag_pic = 2;
329
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");
334
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;
340
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;
348
349 SUBTARGET_OVERRIDE_OPTIONS;
350 }
351 \f
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)
356 {
357 tree a;
358
359 if (TREE_CODE (func) != FUNCTION_DECL)
360 return false;
361
362 a = lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func));
363 return (a != NULL_TREE);
364 }
365
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)
373 {
374 if (TREE_CODE (*node) != FUNCTION_DECL)
375 {
376 warning (OPT_Wattributes, "%qs attribute only applies to functions",
377 IDENTIFIER_POINTER (name));
378 *no_add_attrs = true;
379 }
380
381 return NULL_TREE;
382 }
383
384 static void
385 m68k_compute_frame_layout (void)
386 {
387 int regno, saved;
388 unsigned int mask, rmask;
389 bool interrupt_handler = m68k_interrupt_function_p (current_function_decl);
390
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;
396
397 current_frame.size = (get_frame_size () + 3) & -4;
398
399 mask = rmask = saved = 0;
400 for (regno = 0; regno < 16; regno++)
401 if (m68k_save_reg (regno, interrupt_handler))
402 {
403 mask |= 1 << regno;
404 rmask |= 1 << (15 - regno);
405 saved++;
406 }
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;
411
412 current_frame.foffset = 0;
413 mask = rmask = saved = 0;
414 if (TARGET_68881 /* || TARGET_CFV4E */)
415 {
416 for (regno = 16; regno < 24; regno++)
417 if (m68k_save_reg (regno, interrupt_handler))
418 {
419 mask |= 1 << (regno - 16);
420 rmask |= 1 << (23 - regno);
421 saved++;
422 }
423 current_frame.foffset = saved * 12 /* (TARGET_CFV4E ? 8 : 12) */;
424 current_frame.offset += current_frame.foffset;
425 }
426 current_frame.fpu_no = saved;
427 current_frame.fpu_mask = mask;
428 current_frame.fpu_rev_mask = rmask;
429
430 /* Remember what function this frame refers to. */
431 current_frame.funcdef_no = current_function_funcdef_no;
432 }
433
434 HOST_WIDE_INT
435 m68k_initial_elimination_offset (int from, int to)
436 {
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;
442
443 m68k_compute_frame_layout ();
444
445 gcc_assert (to == STACK_POINTER_REGNUM);
446 switch (from)
447 {
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 ();
455 }
456 }
457
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. */
463
464 static bool
465 m68k_save_reg (unsigned int regno, bool interrupt_handler)
466 {
467 if (flag_pic && regno == PIC_OFFSET_TABLE_REGNUM)
468 {
469 if (current_function_uses_pic_offset_table)
470 return true;
471 if (!current_function_is_leaf && TARGET_ID_SHARED_LIBRARY)
472 return true;
473 }
474
475 if (current_function_calls_eh_return)
476 {
477 unsigned int i;
478 for (i = 0; ; i++)
479 {
480 unsigned int test = EH_RETURN_DATA_REGNO (i);
481 if (test == INVALID_REGNUM)
482 break;
483 if (test == regno)
484 return true;
485 }
486 }
487
488 /* Fixed regs we never touch. */
489 if (fixed_regs[regno])
490 return false;
491
492 /* The frame pointer (if it is such) is handled specially. */
493 if (regno == FRAME_POINTER_REGNUM && frame_pointer_needed)
494 return false;
495
496 /* Interrupt handlers must also save call_used_regs
497 if they are live or when calling nested functions. */
498 if (interrupt_handler)
499 {
500 if (regs_ever_live[regno])
501 return true;
502
503 if (!current_function_is_leaf && call_used_regs[regno])
504 return true;
505 }
506
507 /* Never need to save registers that aren't touched. */
508 if (!regs_ever_live[regno])
509 return false;
510
511 /* Otherwise save everything that isn't call-clobbered. */
512 return !call_used_regs[regno];
513 }
514
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. */
518
519 static void
520 m68k_output_function_prologue (FILE *stream,
521 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
522 {
523 HOST_WIDE_INT fsize_with_regs;
524 HOST_WIDE_INT cfa_offset = INCOMING_FRAME_SP_OFFSET;
525
526 m68k_compute_frame_layout();
527
528 /* If the stack limit is a symbol, we can check it here,
529 before actually allocating the space. */
530 if (current_function_limit_stack
531 && GET_CODE (stack_limit_rtx) == SYMBOL_REF)
532 asm_fprintf (stream, "\tcmp" ASM_DOT "l %I%s+%wd,%Rsp\n\ttrapcs\n",
533 XSTR (stack_limit_rtx, 0), current_frame.size + 4);
534
535 /* On ColdFire add register save into initial stack frame setup, if possible. */
536 fsize_with_regs = current_frame.size;
537 if (TARGET_COLDFIRE && current_frame.reg_no > 2)
538 fsize_with_regs += current_frame.reg_no * 4;
539
540 if (frame_pointer_needed)
541 {
542 if (current_frame.size == 0 && TARGET_68040)
543 /* on the 68040, pea + move is faster than link.w 0 */
544 fprintf (stream, (MOTOROLA
545 ? "\tpea (%s)\n\tmove.l %s,%s\n"
546 : "\tpea %s@\n\tmovel %s,%s\n"),
547 M68K_REGNAME (FRAME_POINTER_REGNUM),
548 M68K_REGNAME (STACK_POINTER_REGNUM),
549 M68K_REGNAME (FRAME_POINTER_REGNUM));
550 else if (fsize_with_regs < 0x8000)
551 asm_fprintf (stream, "\tlink" ASM_DOTW " %s,%I%wd\n",
552 M68K_REGNAME (FRAME_POINTER_REGNUM), -fsize_with_regs);
553 else if (TARGET_68020)
554 asm_fprintf (stream, "\tlink" ASM_DOTL " %s,%I%wd\n",
555 M68K_REGNAME (FRAME_POINTER_REGNUM), -fsize_with_regs);
556 else
557 /* Adding negative number is faster on the 68040. */
558 asm_fprintf (stream,
559 "\tlink" ASM_DOTW " %s,%I0\n"
560 "\tadd" ASM_DOT "l %I%wd,%Rsp\n",
561 M68K_REGNAME (FRAME_POINTER_REGNUM), -fsize_with_regs);
562 }
563 else if (fsize_with_regs) /* !frame_pointer_needed */
564 {
565 if (fsize_with_regs < 0x8000)
566 {
567 if (fsize_with_regs <= 8)
568 {
569 if (!TARGET_COLDFIRE)
570 asm_fprintf (stream, "\tsubq" ASM_DOT "w %I%wd,%Rsp\n",
571 fsize_with_regs);
572 else
573 asm_fprintf (stream, "\tsubq" ASM_DOT "l %I%wd,%Rsp\n",
574 fsize_with_regs);
575 }
576 else if (fsize_with_regs <= 16 && TARGET_CPU32)
577 /* On the CPU32 it is faster to use two subqw instructions to
578 subtract a small integer (8 < N <= 16) to a register. */
579 asm_fprintf (stream,
580 "\tsubq" ASM_DOT "w %I8,%Rsp\n"
581 "\tsubq" ASM_DOT "w %I%wd,%Rsp\n",
582 fsize_with_regs - 8);
583 else if (TARGET_68040)
584 /* Adding negative number is faster on the 68040. */
585 asm_fprintf (stream, "\tadd" ASM_DOT "w %I%wd,%Rsp\n",
586 -fsize_with_regs);
587 else
588 asm_fprintf (stream, (MOTOROLA
589 ? "\tlea (%wd,%Rsp),%Rsp\n"
590 : "\tlea %Rsp@(%wd),%Rsp\n"),
591 -fsize_with_regs);
592 }
593 else /* fsize_with_regs >= 0x8000 */
594 asm_fprintf (stream, "\tadd" ASM_DOT "l %I%wd,%Rsp\n",
595 -fsize_with_regs);
596 } /* !frame_pointer_needed */
597
598 if (dwarf2out_do_frame ())
599 {
600 if (frame_pointer_needed)
601 {
602 char *l;
603 l = (char *) dwarf2out_cfi_label ();
604 cfa_offset += 4;
605 dwarf2out_reg_save (l, FRAME_POINTER_REGNUM, -cfa_offset);
606 dwarf2out_def_cfa (l, FRAME_POINTER_REGNUM, cfa_offset);
607 cfa_offset += current_frame.size;
608 }
609 else
610 {
611 cfa_offset += current_frame.size;
612 dwarf2out_def_cfa ("", STACK_POINTER_REGNUM, cfa_offset);
613 }
614 }
615
616 if (current_frame.fpu_mask)
617 {
618 asm_fprintf (stream, (MOTOROLA
619 ? "\tfmovm %I0x%x,-(%Rsp)\n"
620 : "\tfmovem %I0x%x,%Rsp@-\n"),
621 current_frame.fpu_mask);
622
623 if (dwarf2out_do_frame ())
624 {
625 char *l = (char *) dwarf2out_cfi_label ();
626 int n_regs, regno;
627
628 cfa_offset += current_frame.fpu_no * 12;
629 if (! frame_pointer_needed)
630 dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, cfa_offset);
631 for (regno = 16, n_regs = 0; regno < 24; regno++)
632 if (current_frame.fpu_mask & (1 << (regno - 16)))
633 dwarf2out_reg_save (l, regno, -cfa_offset + n_regs++ * 12);
634 }
635 }
636
637 /* If the stack limit is not a symbol, check it here.
638 This has the disadvantage that it may be too late... */
639 if (current_function_limit_stack)
640 {
641 if (REG_P (stack_limit_rtx))
642 asm_fprintf (stream, "\tcmp" ASM_DOT "l %s,%Rsp\n\ttrapcs\n",
643 M68K_REGNAME (REGNO (stack_limit_rtx)));
644 else if (GET_CODE (stack_limit_rtx) != SYMBOL_REF)
645 warning (0, "stack limit expression is not supported");
646 }
647
648 if (current_frame.reg_no <= 2)
649 {
650 /* Store each separately in the same order moveml uses.
651 Using two movel instructions instead of a single moveml
652 is about 15% faster for the 68020 and 68030 at no expense
653 in code size. */
654
655 int i;
656
657 for (i = 0; i < 16; i++)
658 if (current_frame.reg_rev_mask & (1 << i))
659 {
660 asm_fprintf (stream, (MOTOROLA
661 ? "\t%Omove.l %s,-(%Rsp)\n"
662 : "\tmovel %s,%Rsp@-\n"),
663 M68K_REGNAME (15 - i));
664 if (dwarf2out_do_frame ())
665 {
666 char *l = (char *) dwarf2out_cfi_label ();
667
668 cfa_offset += 4;
669 if (! frame_pointer_needed)
670 dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, cfa_offset);
671 dwarf2out_reg_save (l, 15 - i, -cfa_offset);
672 }
673 }
674 }
675 else if (current_frame.reg_rev_mask)
676 {
677 if (TARGET_COLDFIRE)
678 /* The ColdFire does not support the predecrement form of the
679 MOVEM instruction, so we must adjust the stack pointer and
680 then use the plain address register indirect mode.
681 The required register save space was combined earlier with
682 the fsize_with_regs amount. */
683
684 asm_fprintf (stream, (MOTOROLA
685 ? "\tmovm.l %I0x%x,(%Rsp)\n"
686 : "\tmoveml %I0x%x,%Rsp@\n"),
687 current_frame.reg_mask);
688 else
689 asm_fprintf (stream, (MOTOROLA
690 ? "\tmovm.l %I0x%x,-(%Rsp)\n"
691 : "\tmoveml %I0x%x,%Rsp@-\n"),
692 current_frame.reg_rev_mask);
693 if (dwarf2out_do_frame ())
694 {
695 char *l = (char *) dwarf2out_cfi_label ();
696 int n_regs, regno;
697
698 cfa_offset += current_frame.reg_no * 4;
699 if (! frame_pointer_needed)
700 dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, cfa_offset);
701 for (regno = 0, n_regs = 0; regno < 16; regno++)
702 if (current_frame.reg_mask & (1 << regno))
703 dwarf2out_reg_save (l, regno, -cfa_offset + n_regs++ * 4);
704 }
705 }
706 if (!TARGET_SEP_DATA && flag_pic
707 && (current_function_uses_pic_offset_table
708 || (!current_function_is_leaf && TARGET_ID_SHARED_LIBRARY)))
709 {
710 if (TARGET_ID_SHARED_LIBRARY)
711 {
712 asm_fprintf (stream, "\tmovel %s@(%s), %s\n",
713 M68K_REGNAME (PIC_OFFSET_TABLE_REGNUM),
714 m68k_library_id_string,
715 M68K_REGNAME (PIC_OFFSET_TABLE_REGNUM));
716 }
717 else
718 {
719 if (MOTOROLA)
720 asm_fprintf (stream,
721 "\t%Olea (%Rpc, %U_GLOBAL_OFFSET_TABLE_@GOTPC), %s\n",
722 M68K_REGNAME (PIC_OFFSET_TABLE_REGNUM));
723 else
724 {
725 asm_fprintf (stream, "\tmovel %I%U_GLOBAL_OFFSET_TABLE_, %s\n",
726 M68K_REGNAME (PIC_OFFSET_TABLE_REGNUM));
727 asm_fprintf (stream, "\tlea %Rpc@(0,%s:l),%s\n",
728 M68K_REGNAME (PIC_OFFSET_TABLE_REGNUM),
729 M68K_REGNAME (PIC_OFFSET_TABLE_REGNUM));
730 }
731 }
732 }
733 }
734 \f
735 /* Return true if this function's epilogue can be output as RTL. */
736
737 bool
738 use_return_insn (void)
739 {
740 if (!reload_completed || frame_pointer_needed || get_frame_size () != 0)
741 return false;
742
743 /* We can output the epilogue as RTL only if no registers need to be
744 restored. */
745 m68k_compute_frame_layout ();
746 return current_frame.reg_no ? false : true;
747 }
748
749 /* This function generates the assembly code for function exit,
750 on machines that need it.
751
752 The function epilogue should not depend on the current stack pointer!
753 It should use the frame pointer only, if there is a frame pointer.
754 This is mandatory because of alloca; we also take advantage of it to
755 omit stack adjustments before returning. */
756
757 static void
758 m68k_output_function_epilogue (FILE *stream,
759 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
760 {
761 HOST_WIDE_INT fsize, fsize_with_regs;
762 bool big = false;
763 bool restore_from_sp = false;
764 rtx insn = get_last_insn ();
765
766 m68k_compute_frame_layout ();
767
768 /* If the last insn was a BARRIER, we don't have to write any code. */
769 if (GET_CODE (insn) == NOTE)
770 insn = prev_nonnote_insn (insn);
771 if (insn && GET_CODE (insn) == BARRIER)
772 {
773 /* Output just a no-op so that debuggers don't get confused
774 about which function the pc is in at this address. */
775 fprintf (stream, "\tnop\n");
776 return;
777 }
778
779 #ifdef FUNCTION_EXTRA_EPILOGUE
780 FUNCTION_EXTRA_EPILOGUE (stream, size);
781 #endif
782
783 fsize = current_frame.size;
784
785 /* FIXME: leaf_function_p below is too strong.
786 What we really need to know there is if there could be pending
787 stack adjustment needed at that point. */
788 restore_from_sp
789 = (! frame_pointer_needed
790 || (! current_function_calls_alloca && leaf_function_p ()));
791
792 /* fsize_with_regs is the size we need to adjust the sp when
793 popping the frame. */
794 fsize_with_regs = fsize;
795
796 /* Because the ColdFire doesn't support moveml with
797 complex address modes, we must adjust the stack manually
798 after restoring registers. When the frame pointer isn't used,
799 we can merge movem adjustment into frame unlinking
800 made immediately after it. */
801 if (TARGET_COLDFIRE && restore_from_sp && (current_frame.reg_no > 2))
802 fsize_with_regs += current_frame.reg_no * 4;
803
804 if (current_frame.offset + fsize >= 0x8000
805 && ! restore_from_sp
806 && (current_frame.reg_mask || current_frame.fpu_mask))
807 {
808 /* Because the ColdFire doesn't support moveml with
809 complex address modes we make an extra correction here. */
810 if (TARGET_COLDFIRE)
811 fsize += current_frame.offset;
812
813 asm_fprintf (stream, "\t%Omove" ASM_DOT "l %I%wd,%Ra1\n", -fsize);
814 fsize = 0, big = true;
815 }
816 if (current_frame.reg_no <= 2)
817 {
818 /* Restore each separately in the same order moveml does.
819 Using two movel instructions instead of a single moveml
820 is about 15% faster for the 68020 and 68030 at no expense
821 in code size. */
822
823 int i;
824 HOST_WIDE_INT offset = current_frame.offset + fsize;
825
826 for (i = 0; i < 16; i++)
827 if (current_frame.reg_mask & (1 << i))
828 {
829 if (big)
830 {
831 if (MOTOROLA)
832 asm_fprintf (stream, "\t%Omove.l -%wd(%s,%Ra1.l),%s\n",
833 offset,
834 M68K_REGNAME (FRAME_POINTER_REGNUM),
835 M68K_REGNAME (i));
836 else
837 asm_fprintf (stream, "\tmovel %s@(-%wd,%Ra1:l),%s\n",
838 M68K_REGNAME (FRAME_POINTER_REGNUM),
839 offset,
840 M68K_REGNAME (i));
841 }
842 else if (restore_from_sp)
843 asm_fprintf (stream, (MOTOROLA
844 ? "\t%Omove.l (%Rsp)+,%s\n"
845 : "\tmovel %Rsp@+,%s\n"),
846 M68K_REGNAME (i));
847 else
848 {
849 if (MOTOROLA)
850 asm_fprintf (stream, "\t%Omove.l -%wd(%s),%s\n",
851 offset,
852 M68K_REGNAME (FRAME_POINTER_REGNUM),
853 M68K_REGNAME (i));
854 else
855 asm_fprintf (stream, "\tmovel %s@(-%wd),%s\n",
856 M68K_REGNAME (FRAME_POINTER_REGNUM),
857 offset,
858 M68K_REGNAME (i));
859 }
860 offset -= 4;
861 }
862 }
863 else if (current_frame.reg_mask)
864 {
865 /* The ColdFire requires special handling due to its limited moveml
866 insn. */
867 if (TARGET_COLDFIRE)
868 {
869 if (big)
870 {
871 asm_fprintf (stream, "\tadd" ASM_DOT "l %s,%Ra1\n",
872 M68K_REGNAME (FRAME_POINTER_REGNUM));
873 asm_fprintf (stream, (MOTOROLA
874 ? "\tmovm.l (%Ra1),%I0x%x\n"
875 : "\tmoveml %Ra1@,%I0x%x\n"),
876 current_frame.reg_mask);
877 }
878 else if (restore_from_sp)
879 asm_fprintf (stream, (MOTOROLA
880 ? "\tmovm.l (%Rsp),%I0x%x\n"
881 : "\tmoveml %Rsp@,%I0x%x\n"),
882 current_frame.reg_mask);
883 else
884 {
885 if (MOTOROLA)
886 asm_fprintf (stream, "\tmovm.l -%wd(%s),%I0x%x\n",
887 current_frame.offset + fsize,
888 M68K_REGNAME (FRAME_POINTER_REGNUM),
889 current_frame.reg_mask);
890 else
891 asm_fprintf (stream, "\tmoveml %s@(-%wd),%I0x%x\n",
892 M68K_REGNAME (FRAME_POINTER_REGNUM),
893 current_frame.offset + fsize,
894 current_frame.reg_mask);
895 }
896 }
897 else /* !TARGET_COLDFIRE */
898 {
899 if (big)
900 {
901 if (MOTOROLA)
902 asm_fprintf (stream, "\tmovm.l -%wd(%s,%Ra1.l),%I0x%x\n",
903 current_frame.offset + fsize,
904 M68K_REGNAME (FRAME_POINTER_REGNUM),
905 current_frame.reg_mask);
906 else
907 asm_fprintf (stream, "\tmoveml %s@(-%wd,%Ra1:l),%I0x%x\n",
908 M68K_REGNAME (FRAME_POINTER_REGNUM),
909 current_frame.offset + fsize,
910 current_frame.reg_mask);
911 }
912 else if (restore_from_sp)
913 {
914 asm_fprintf (stream, (MOTOROLA
915 ? "\tmovm.l (%Rsp)+,%I0x%x\n"
916 : "\tmoveml %Rsp@+,%I0x%x\n"),
917 current_frame.reg_mask);
918 }
919 else
920 {
921 if (MOTOROLA)
922 asm_fprintf (stream, "\tmovm.l -%wd(%s),%I0x%x\n",
923 current_frame.offset + fsize,
924 M68K_REGNAME (FRAME_POINTER_REGNUM),
925 current_frame.reg_mask);
926 else
927 asm_fprintf (stream, "\tmoveml %s@(-%wd),%I0x%x\n",
928 M68K_REGNAME (FRAME_POINTER_REGNUM),
929 current_frame.offset + fsize,
930 current_frame.reg_mask);
931 }
932 }
933 }
934 if (current_frame.fpu_rev_mask)
935 {
936 if (big)
937 {
938 if (MOTOROLA)
939 asm_fprintf (stream, "\tfmovm -%wd(%s,%Ra1.l),%I0x%x\n",
940 current_frame.foffset + fsize,
941 M68K_REGNAME (FRAME_POINTER_REGNUM),
942 current_frame.fpu_rev_mask);
943 else
944 asm_fprintf (stream, "\tfmovem %s@(-%wd,%Ra1:l),%I0x%x\n",
945 M68K_REGNAME (FRAME_POINTER_REGNUM),
946 current_frame.foffset + fsize,
947 current_frame.fpu_rev_mask);
948 }
949 else if (restore_from_sp)
950 {
951 if (MOTOROLA)
952 asm_fprintf (stream, "\tfmovm (%Rsp)+,%I0x%x\n",
953 current_frame.fpu_rev_mask);
954 else
955 asm_fprintf (stream, "\tfmovem %Rsp@+,%I0x%x\n",
956 current_frame.fpu_rev_mask);
957 }
958 else
959 {
960 if (MOTOROLA)
961 asm_fprintf (stream, "\tfmovm -%wd(%s),%I0x%x\n",
962 current_frame.foffset + fsize,
963 M68K_REGNAME (FRAME_POINTER_REGNUM),
964 current_frame.fpu_rev_mask);
965 else
966 asm_fprintf (stream, "\tfmovem %s@(-%wd),%I0x%x\n",
967 M68K_REGNAME (FRAME_POINTER_REGNUM),
968 current_frame.foffset + fsize,
969 current_frame.fpu_rev_mask);
970 }
971 }
972 if (frame_pointer_needed)
973 fprintf (stream, "\tunlk %s\n", M68K_REGNAME (FRAME_POINTER_REGNUM));
974 else if (fsize_with_regs)
975 {
976 if (fsize_with_regs <= 8)
977 {
978 if (!TARGET_COLDFIRE)
979 asm_fprintf (stream, "\taddq" ASM_DOT "w %I%wd,%Rsp\n",
980 fsize_with_regs);
981 else
982 asm_fprintf (stream, "\taddq" ASM_DOT "l %I%wd,%Rsp\n",
983 fsize_with_regs);
984 }
985 else if (fsize_with_regs <= 16 && TARGET_CPU32)
986 {
987 /* On the CPU32 it is faster to use two addqw instructions to
988 add a small integer (8 < N <= 16) to a register. */
989 asm_fprintf (stream,
990 "\taddq" ASM_DOT "w %I8,%Rsp\n"
991 "\taddq" ASM_DOT "w %I%wd,%Rsp\n",
992 fsize_with_regs - 8);
993 }
994 else if (fsize_with_regs < 0x8000)
995 {
996 if (TARGET_68040)
997 asm_fprintf (stream, "\tadd" ASM_DOT "w %I%wd,%Rsp\n",
998 fsize_with_regs);
999 else
1000 asm_fprintf (stream, (MOTOROLA
1001 ? "\tlea (%wd,%Rsp),%Rsp\n"
1002 : "\tlea %Rsp@(%wd),%Rsp\n"),
1003 fsize_with_regs);
1004 }
1005 else
1006 asm_fprintf (stream, "\tadd" ASM_DOT "l %I%wd,%Rsp\n", fsize_with_regs);
1007 }
1008 if (current_function_calls_eh_return)
1009 asm_fprintf (stream, "\tadd" ASM_DOT "l %Ra0,%Rsp\n");
1010 if (m68k_interrupt_function_p (current_function_decl))
1011 fprintf (stream, "\trte\n");
1012 else if (current_function_pops_args)
1013 asm_fprintf (stream, "\trtd %I%d\n", current_function_pops_args);
1014 else
1015 fprintf (stream, "\trts\n");
1016 }
1017 \f
1018 /* Return true if X is a valid comparison operator for the dbcc
1019 instruction.
1020
1021 Note it rejects floating point comparison operators.
1022 (In the future we could use Fdbcc).
1023
1024 It also rejects some comparisons when CC_NO_OVERFLOW is set. */
1025
1026 int
1027 valid_dbcc_comparison_p_2 (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
1028 {
1029 switch (GET_CODE (x))
1030 {
1031 case EQ: case NE: case GTU: case LTU:
1032 case GEU: case LEU:
1033 return 1;
1034
1035 /* Reject some when CC_NO_OVERFLOW is set. This may be over
1036 conservative */
1037 case GT: case LT: case GE: case LE:
1038 return ! (cc_prev_status.flags & CC_NO_OVERFLOW);
1039 default:
1040 return 0;
1041 }
1042 }
1043
1044 /* Return nonzero if flags are currently in the 68881 flag register. */
1045 int
1046 flags_in_68881 (void)
1047 {
1048 /* We could add support for these in the future */
1049 return cc_status.flags & CC_IN_68881;
1050 }
1051
1052 /* Output a BSR instruction suitable for PIC code. */
1053 void
1054 m68k_output_pic_call (rtx dest)
1055 {
1056 const char *out;
1057
1058 if (!(GET_CODE (dest) == MEM && GET_CODE (XEXP (dest, 0)) == SYMBOL_REF))
1059 out = "jsr %0";
1060 /* We output a BSR instruction if we're building for a target that
1061 supports long branches. Otherwise we generate one of two sequences:
1062 a shorter one that uses a GOT entry or a longer one that doesn't.
1063 We'll use the -Os command-line flag to decide which to generate.
1064 Both sequences take the same time to execute on the ColdFire. */
1065 else if (TARGET_PCREL)
1066 out = "bsr.l %o0";
1067 else if (TARGET_68020)
1068 #if defined(USE_GAS)
1069 out = "bsr.l %0@PLTPC";
1070 #else
1071 out = "bsr %0@PLTPC";
1072 #endif
1073 else if (optimize_size || TARGET_ID_SHARED_LIBRARY)
1074 out = "move.l %0@GOT(%%a5), %%a1\n\tjsr (%%a1)";
1075 else
1076 out = "lea %0-.-8,%%a1\n\tjsr 0(%%pc,%%a1)";
1077
1078 output_asm_insn (out, &dest);
1079 }
1080
1081 /* Output a dbCC; jCC sequence. Note we do not handle the
1082 floating point version of this sequence (Fdbcc). We also
1083 do not handle alternative conditions when CC_NO_OVERFLOW is
1084 set. It is assumed that valid_dbcc_comparison_p and flags_in_68881 will
1085 kick those out before we get here. */
1086
1087 void
1088 output_dbcc_and_branch (rtx *operands)
1089 {
1090 switch (GET_CODE (operands[3]))
1091 {
1092 case EQ:
1093 output_asm_insn (MOTOROLA
1094 ? "dbeq %0,%l1\n\tjbeq %l2"
1095 : "dbeq %0,%l1\n\tjeq %l2",
1096 operands);
1097 break;
1098
1099 case NE:
1100 output_asm_insn (MOTOROLA
1101 ? "dbne %0,%l1\n\tjbne %l2"
1102 : "dbne %0,%l1\n\tjne %l2",
1103 operands);
1104 break;
1105
1106 case GT:
1107 output_asm_insn (MOTOROLA
1108 ? "dbgt %0,%l1\n\tjbgt %l2"
1109 : "dbgt %0,%l1\n\tjgt %l2",
1110 operands);
1111 break;
1112
1113 case GTU:
1114 output_asm_insn (MOTOROLA
1115 ? "dbhi %0,%l1\n\tjbhi %l2"
1116 : "dbhi %0,%l1\n\tjhi %l2",
1117 operands);
1118 break;
1119
1120 case LT:
1121 output_asm_insn (MOTOROLA
1122 ? "dblt %0,%l1\n\tjblt %l2"
1123 : "dblt %0,%l1\n\tjlt %l2",
1124 operands);
1125 break;
1126
1127 case LTU:
1128 output_asm_insn (MOTOROLA
1129 ? "dbcs %0,%l1\n\tjbcs %l2"
1130 : "dbcs %0,%l1\n\tjcs %l2",
1131 operands);
1132 break;
1133
1134 case GE:
1135 output_asm_insn (MOTOROLA
1136 ? "dbge %0,%l1\n\tjbge %l2"
1137 : "dbge %0,%l1\n\tjge %l2",
1138 operands);
1139 break;
1140
1141 case GEU:
1142 output_asm_insn (MOTOROLA
1143 ? "dbcc %0,%l1\n\tjbcc %l2"
1144 : "dbcc %0,%l1\n\tjcc %l2",
1145 operands);
1146 break;
1147
1148 case LE:
1149 output_asm_insn (MOTOROLA
1150 ? "dble %0,%l1\n\tjble %l2"
1151 : "dble %0,%l1\n\tjle %l2",
1152 operands);
1153 break;
1154
1155 case LEU:
1156 output_asm_insn (MOTOROLA
1157 ? "dbls %0,%l1\n\tjbls %l2"
1158 : "dbls %0,%l1\n\tjls %l2",
1159 operands);
1160 break;
1161
1162 default:
1163 gcc_unreachable ();
1164 }
1165
1166 /* If the decrement is to be done in SImode, then we have
1167 to compensate for the fact that dbcc decrements in HImode. */
1168 switch (GET_MODE (operands[0]))
1169 {
1170 case SImode:
1171 output_asm_insn (MOTOROLA
1172 ? "clr%.w %0\n\tsubq%.l #1,%0\n\tjbpl %l1"
1173 : "clr%.w %0\n\tsubq%.l #1,%0\n\tjpl %l1",
1174 operands);
1175 break;
1176
1177 case HImode:
1178 break;
1179
1180 default:
1181 gcc_unreachable ();
1182 }
1183 }
1184
1185 const char *
1186 output_scc_di (rtx op, rtx operand1, rtx operand2, rtx dest)
1187 {
1188 rtx loperands[7];
1189 enum rtx_code op_code = GET_CODE (op);
1190
1191 /* This does not produce a useful cc. */
1192 CC_STATUS_INIT;
1193
1194 /* The m68k cmp.l instruction requires operand1 to be a reg as used
1195 below. Swap the operands and change the op if these requirements
1196 are not fulfilled. */
1197 if (GET_CODE (operand2) == REG && GET_CODE (operand1) != REG)
1198 {
1199 rtx tmp = operand1;
1200
1201 operand1 = operand2;
1202 operand2 = tmp;
1203 op_code = swap_condition (op_code);
1204 }
1205 loperands[0] = operand1;
1206 if (GET_CODE (operand1) == REG)
1207 loperands[1] = gen_rtx_REG (SImode, REGNO (operand1) + 1);
1208 else
1209 loperands[1] = adjust_address (operand1, SImode, 4);
1210 if (operand2 != const0_rtx)
1211 {
1212 loperands[2] = operand2;
1213 if (GET_CODE (operand2) == REG)
1214 loperands[3] = gen_rtx_REG (SImode, REGNO (operand2) + 1);
1215 else
1216 loperands[3] = adjust_address (operand2, SImode, 4);
1217 }
1218 loperands[4] = gen_label_rtx ();
1219 if (operand2 != const0_rtx)
1220 {
1221 output_asm_insn (MOTOROLA
1222 ? "cmp%.l %2,%0\n\tjbne %l4\n\tcmp%.l %3,%1"
1223 : "cmp%.l %2,%0\n\tjne %l4\n\tcmp%.l %3,%1",
1224 loperands);
1225 }
1226 else
1227 {
1228 if (TARGET_68020 || TARGET_COLDFIRE || ! ADDRESS_REG_P (loperands[0]))
1229 output_asm_insn ("tst%.l %0", loperands);
1230 else
1231 output_asm_insn ("cmp%.w #0,%0", loperands);
1232
1233 output_asm_insn (MOTOROLA ? "jbne %l4" : "jne %l4", loperands);
1234
1235 if (TARGET_68020 || TARGET_COLDFIRE || ! ADDRESS_REG_P (loperands[1]))
1236 output_asm_insn ("tst%.l %1", loperands);
1237 else
1238 output_asm_insn ("cmp%.w #0,%1", loperands);
1239 }
1240
1241 loperands[5] = dest;
1242
1243 switch (op_code)
1244 {
1245 case EQ:
1246 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1247 CODE_LABEL_NUMBER (loperands[4]));
1248 output_asm_insn ("seq %5", loperands);
1249 break;
1250
1251 case NE:
1252 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1253 CODE_LABEL_NUMBER (loperands[4]));
1254 output_asm_insn ("sne %5", loperands);
1255 break;
1256
1257 case GT:
1258 loperands[6] = gen_label_rtx ();
1259 output_asm_insn (MOTOROLA ? "shi %5\n\tjbra %l6" : "shi %5\n\tjra %l6",
1260 loperands);
1261 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1262 CODE_LABEL_NUMBER (loperands[4]));
1263 output_asm_insn ("sgt %5", loperands);
1264 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1265 CODE_LABEL_NUMBER (loperands[6]));
1266 break;
1267
1268 case GTU:
1269 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1270 CODE_LABEL_NUMBER (loperands[4]));
1271 output_asm_insn ("shi %5", loperands);
1272 break;
1273
1274 case LT:
1275 loperands[6] = gen_label_rtx ();
1276 output_asm_insn (MOTOROLA ? "scs %5\n\tjbra %l6" : "scs %5\n\tjra %l6",
1277 loperands);
1278 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1279 CODE_LABEL_NUMBER (loperands[4]));
1280 output_asm_insn ("slt %5", loperands);
1281 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1282 CODE_LABEL_NUMBER (loperands[6]));
1283 break;
1284
1285 case LTU:
1286 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1287 CODE_LABEL_NUMBER (loperands[4]));
1288 output_asm_insn ("scs %5", loperands);
1289 break;
1290
1291 case GE:
1292 loperands[6] = gen_label_rtx ();
1293 output_asm_insn (MOTOROLA ? "scc %5\n\tjbra %l6" : "scc %5\n\tjra %l6",
1294 loperands);
1295 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1296 CODE_LABEL_NUMBER (loperands[4]));
1297 output_asm_insn ("sge %5", loperands);
1298 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1299 CODE_LABEL_NUMBER (loperands[6]));
1300 break;
1301
1302 case GEU:
1303 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1304 CODE_LABEL_NUMBER (loperands[4]));
1305 output_asm_insn ("scc %5", loperands);
1306 break;
1307
1308 case LE:
1309 loperands[6] = gen_label_rtx ();
1310 output_asm_insn (MOTOROLA ? "sls %5\n\tjbra %l6" : "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;
1318
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;
1324
1325 default:
1326 gcc_unreachable ();
1327 }
1328 return "";
1329 }
1330
1331 const char *
1332 output_btst (rtx *operands, rtx countop, rtx dataop, rtx insn, int signpos)
1333 {
1334 operands[0] = countop;
1335 operands[1] = dataop;
1336
1337 if (GET_CODE (countop) == CONST_INT)
1338 {
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)
1343 {
1344 int offset = (count & ~signpos) / 8;
1345 count = count & signpos;
1346 operands[1] = dataop = adjust_address (dataop, QImode, offset);
1347 }
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;
1352
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";
1364
1365 cc_status.flags = CC_NOT_NEGATIVE;
1366 }
1367 return "btst %0,%1";
1368 }
1369 \f
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.
1374
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.
1378
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.
1383
1384 The assembler is also responsible for translating a symbol name
1385 into a constant displacement from the start of the GOT.
1386
1387 A quick example may make things a little clearer:
1388
1389 When not generating PIC code to store the value 12345 into _foo
1390 we would generate the following code:
1391
1392 movel #12345, _foo
1393
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:
1396
1397 lea _foo, a0
1398 movel #12345, a0@
1399
1400 The code in movsi will intercept the lea instruction and call this
1401 routine which will transform the instructions into:
1402
1403 movel a5@(_foo:w), a0
1404 movel #12345, a0@
1405
1406
1407 That (in a nutshell) is how *all* symbol and label references are
1408 handled. */
1409
1410 rtx
1411 legitimize_pic_address (rtx orig, enum machine_mode mode ATTRIBUTE_UNUSED,
1412 rtx reg)
1413 {
1414 rtx pic_ref = orig;
1415
1416 /* First handle a simple SYMBOL_REF or LABEL_REF */
1417 if (GET_CODE (orig) == SYMBOL_REF || GET_CODE (orig) == LABEL_REF)
1418 {
1419 gcc_assert (reg);
1420
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;
1428 }
1429 else if (GET_CODE (orig) == CONST)
1430 {
1431 rtx base;
1432
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;
1437
1438 gcc_assert (reg);
1439
1440 /* legitimize both operands of the PLUS */
1441 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
1442
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);
1446
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? */
1451 }
1452 return pic_ref;
1453 }
1454
1455 \f
1456 typedef enum { MOVL, SWAP, NEGW, NOTW, NOTB, MOVQ, MVS, MVZ } CONST_METHOD;
1457
1458 static CONST_METHOD const_method (rtx);
1459
1460 #define USE_MOVQ(i) ((unsigned) ((i) + 128) <= 255)
1461
1462 static CONST_METHOD
1463 const_method (rtx constant)
1464 {
1465 int i;
1466 unsigned u;
1467
1468 i = INTVAL (constant);
1469 if (USE_MOVQ (i))
1470 return MOVQ;
1471
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)
1475 {
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;
1486 }
1487
1488 /* Try also with swap. */
1489 u = i;
1490 if (USE_MOVQ ((u >> 16) | (u << 16)))
1491 return SWAP;
1492
1493 if (TARGET_CFV4)
1494 {
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;
1500 }
1501
1502 /* Otherwise, use move.l */
1503 return MOVL;
1504 }
1505
1506 static int
1507 const_int_cost (rtx constant)
1508 {
1509 switch (const_method (constant))
1510 {
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 ();
1526 }
1527 }
1528
1529 static bool
1530 m68k_rtx_costs (rtx x, int code, int outer_code, int *total)
1531 {
1532 switch (code)
1533 {
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;
1541
1542 case CONST:
1543 case LABEL_REF:
1544 case SYMBOL_REF:
1545 *total = 3;
1546 return true;
1547
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;
1557
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
1564 terms. */
1565 #define MULL_COST (TARGET_68060 ? 2 : TARGET_68040 ? 5 \
1566 : (TARGET_COLDFIRE && !TARGET_5200) ? 3 \
1567 : TARGET_COLDFIRE ? 10 : 13)
1568 #define MULW_COST (TARGET_68060 ? 2 : TARGET_68040 ? 3 : TARGET_68020 ? 8 \
1569 : (TARGET_COLDFIRE && !TARGET_5200) ? 2 : 5)
1570 #define DIVW_COST (TARGET_68020 ? 27 : TARGET_CF_HWDIV ? 11 : 12)
1571
1572 case PLUS:
1573 /* An lea costs about three times as much as a simple add. */
1574 if (GET_MODE (x) == SImode
1575 && GET_CODE (XEXP (x, 1)) == REG
1576 && GET_CODE (XEXP (x, 0)) == MULT
1577 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
1578 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1579 && (INTVAL (XEXP (XEXP (x, 0), 1)) == 2
1580 || INTVAL (XEXP (XEXP (x, 0), 1)) == 4
1581 || INTVAL (XEXP (XEXP (x, 0), 1)) == 8))
1582 {
1583 /* lea an@(dx:l:i),am */
1584 *total = COSTS_N_INSNS (TARGET_COLDFIRE ? 2 : 3);
1585 return true;
1586 }
1587 return false;
1588
1589 case ASHIFT:
1590 case ASHIFTRT:
1591 case LSHIFTRT:
1592 if (TARGET_68060)
1593 {
1594 *total = COSTS_N_INSNS(1);
1595 return true;
1596 }
1597 if (! TARGET_68020 && ! TARGET_COLDFIRE)
1598 {
1599 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
1600 {
1601 if (INTVAL (XEXP (x, 1)) < 16)
1602 *total = COSTS_N_INSNS (2) + INTVAL (XEXP (x, 1)) / 2;
1603 else
1604 /* We're using clrw + swap for these cases. */
1605 *total = COSTS_N_INSNS (4) + (INTVAL (XEXP (x, 1)) - 16) / 2;
1606 }
1607 else
1608 *total = COSTS_N_INSNS (10); /* Worst case. */
1609 return true;
1610 }
1611 /* A shift by a big integer takes an extra instruction. */
1612 if (GET_CODE (XEXP (x, 1)) == CONST_INT
1613 && (INTVAL (XEXP (x, 1)) == 16))
1614 {
1615 *total = COSTS_N_INSNS (2); /* clrw;swap */
1616 return true;
1617 }
1618 if (GET_CODE (XEXP (x, 1)) == CONST_INT
1619 && !(INTVAL (XEXP (x, 1)) > 0
1620 && INTVAL (XEXP (x, 1)) <= 8))
1621 {
1622 *total = COSTS_N_INSNS (TARGET_COLDFIRE ? 1 : 3); /* lsr #i,dn */
1623 return true;
1624 }
1625 return false;
1626
1627 case MULT:
1628 if ((GET_CODE (XEXP (x, 0)) == ZERO_EXTEND
1629 || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)
1630 && GET_MODE (x) == SImode)
1631 *total = COSTS_N_INSNS (MULW_COST);
1632 else if (GET_MODE (x) == QImode || GET_MODE (x) == HImode)
1633 *total = COSTS_N_INSNS (MULW_COST);
1634 else
1635 *total = COSTS_N_INSNS (MULL_COST);
1636 return true;
1637
1638 case DIV:
1639 case UDIV:
1640 case MOD:
1641 case UMOD:
1642 if (GET_MODE (x) == QImode || GET_MODE (x) == HImode)
1643 *total = COSTS_N_INSNS (DIVW_COST); /* div.w */
1644 else if (TARGET_CF_HWDIV)
1645 *total = COSTS_N_INSNS (18);
1646 else
1647 *total = COSTS_N_INSNS (43); /* div.l */
1648 return true;
1649
1650 default:
1651 return false;
1652 }
1653 }
1654
1655 const char *
1656 output_move_const_into_data_reg (rtx *operands)
1657 {
1658 int i;
1659
1660 i = INTVAL (operands[1]);
1661 switch (const_method (operands[1]))
1662 {
1663 case MVZ:
1664 return "mvsw %1,%0";
1665 case MVS:
1666 return "mvzw %1,%0";
1667 case MOVQ:
1668 return "moveq %1,%0";
1669 case NOTB:
1670 CC_STATUS_INIT;
1671 operands[1] = GEN_INT (i ^ 0xff);
1672 return "moveq %1,%0\n\tnot%.b %0";
1673 case NOTW:
1674 CC_STATUS_INIT;
1675 operands[1] = GEN_INT (i ^ 0xffff);
1676 return "moveq %1,%0\n\tnot%.w %0";
1677 case NEGW:
1678 CC_STATUS_INIT;
1679 return "moveq #-128,%0\n\tneg%.w %0";
1680 case SWAP:
1681 {
1682 unsigned u = i;
1683
1684 operands[1] = GEN_INT ((u << 16) | (u >> 16));
1685 return "moveq %1,%0\n\tswap %0";
1686 }
1687 case MOVL:
1688 return "move%.l %1,%0";
1689 default:
1690 gcc_unreachable ();
1691 }
1692 }
1693
1694 /* Return 1 if 'constant' can be represented by
1695 mov3q on a ColdFire V4 core. */
1696 int
1697 valid_mov3q_const (rtx constant)
1698 {
1699 int i;
1700
1701 if (TARGET_CFV4 && GET_CODE (constant) == CONST_INT)
1702 {
1703 i = INTVAL (constant);
1704 if (i == -1 || (i >= 1 && i <= 7))
1705 return 1;
1706 }
1707 return 0;
1708 }
1709
1710
1711 const char *
1712 output_move_simode_const (rtx *operands)
1713 {
1714 if (operands[1] == const0_rtx
1715 && (DATA_REG_P (operands[0])
1716 || GET_CODE (operands[0]) == MEM)
1717 /* clr insns on 68000 read before writing.
1718 This isn't so on the 68010, but we have no TARGET_68010. */
1719 && ((TARGET_68020 || TARGET_COLDFIRE)
1720 || !(GET_CODE (operands[0]) == MEM
1721 && MEM_VOLATILE_P (operands[0]))))
1722 return "clr%.l %0";
1723 else if ((GET_MODE (operands[0]) == SImode)
1724 && valid_mov3q_const (operands[1]))
1725 return "mov3q%.l %1,%0";
1726 else if (operands[1] == const0_rtx
1727 && ADDRESS_REG_P (operands[0]))
1728 return "sub%.l %0,%0";
1729 else if (DATA_REG_P (operands[0]))
1730 return output_move_const_into_data_reg (operands);
1731 else if (ADDRESS_REG_P (operands[0])
1732 && INTVAL (operands[1]) < 0x8000
1733 && INTVAL (operands[1]) >= -0x8000)
1734 {
1735 if (valid_mov3q_const (operands[1]))
1736 return "mov3q%.l %1,%0";
1737 return "move%.w %1,%0";
1738 }
1739 else if (GET_CODE (operands[0]) == MEM
1740 && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
1741 && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM
1742 && INTVAL (operands[1]) < 0x8000
1743 && INTVAL (operands[1]) >= -0x8000)
1744 {
1745 if (valid_mov3q_const (operands[1]))
1746 return "mov3q%.l %1,%-";
1747 return "pea %a1";
1748 }
1749 return "move%.l %1,%0";
1750 }
1751
1752 const char *
1753 output_move_simode (rtx *operands)
1754 {
1755 if (GET_CODE (operands[1]) == CONST_INT)
1756 return output_move_simode_const (operands);
1757 else if ((GET_CODE (operands[1]) == SYMBOL_REF
1758 || GET_CODE (operands[1]) == CONST)
1759 && push_operand (operands[0], SImode))
1760 return "pea %a1";
1761 else if ((GET_CODE (operands[1]) == SYMBOL_REF
1762 || GET_CODE (operands[1]) == CONST)
1763 && ADDRESS_REG_P (operands[0]))
1764 return "lea %a1,%0";
1765 return "move%.l %1,%0";
1766 }
1767
1768 const char *
1769 output_move_himode (rtx *operands)
1770 {
1771 if (GET_CODE (operands[1]) == CONST_INT)
1772 {
1773 if (operands[1] == const0_rtx
1774 && (DATA_REG_P (operands[0])
1775 || GET_CODE (operands[0]) == MEM)
1776 /* clr insns on 68000 read before writing.
1777 This isn't so on the 68010, but we have no TARGET_68010. */
1778 && ((TARGET_68020 || TARGET_COLDFIRE)
1779 || !(GET_CODE (operands[0]) == MEM
1780 && MEM_VOLATILE_P (operands[0]))))
1781 return "clr%.w %0";
1782 else if (operands[1] == const0_rtx
1783 && ADDRESS_REG_P (operands[0]))
1784 return "sub%.l %0,%0";
1785 else if (DATA_REG_P (operands[0])
1786 && INTVAL (operands[1]) < 128
1787 && INTVAL (operands[1]) >= -128)
1788 return "moveq %1,%0";
1789 else if (INTVAL (operands[1]) < 0x8000
1790 && INTVAL (operands[1]) >= -0x8000)
1791 return "move%.w %1,%0";
1792 }
1793 else if (CONSTANT_P (operands[1]))
1794 return "move%.l %1,%0";
1795 /* Recognize the insn before a tablejump, one that refers
1796 to a table of offsets. Such an insn will need to refer
1797 to a label on the insn. So output one. Use the label-number
1798 of the table of offsets to generate this label. This code,
1799 and similar code below, assumes that there will be at most one
1800 reference to each table. */
1801 if (GET_CODE (operands[1]) == MEM
1802 && GET_CODE (XEXP (operands[1], 0)) == PLUS
1803 && GET_CODE (XEXP (XEXP (operands[1], 0), 1)) == LABEL_REF
1804 && GET_CODE (XEXP (XEXP (operands[1], 0), 0)) != PLUS)
1805 {
1806 rtx labelref = XEXP (XEXP (operands[1], 0), 1);
1807 if (MOTOROLA)
1808 asm_fprintf (asm_out_file, "\t.set %LLI%d,.+2\n",
1809 CODE_LABEL_NUMBER (XEXP (labelref, 0)));
1810 else
1811 (*targetm.asm_out.internal_label) (asm_out_file, "LI",
1812 CODE_LABEL_NUMBER (XEXP (labelref, 0)));
1813 }
1814 return "move%.w %1,%0";
1815 }
1816
1817 const char *
1818 output_move_qimode (rtx *operands)
1819 {
1820 /* 68k family always modifies the stack pointer by at least 2, even for
1821 byte pushes. The 5200 (ColdFire) does not do this. */
1822
1823 /* This case is generated by pushqi1 pattern now. */
1824 gcc_assert (!(GET_CODE (operands[0]) == MEM
1825 && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
1826 && XEXP (XEXP (operands[0], 0), 0) == stack_pointer_rtx
1827 && ! ADDRESS_REG_P (operands[1])
1828 && ! TARGET_COLDFIRE));
1829
1830 /* clr and st insns on 68000 read before writing.
1831 This isn't so on the 68010, but we have no TARGET_68010. */
1832 if (!ADDRESS_REG_P (operands[0])
1833 && ((TARGET_68020 || TARGET_COLDFIRE)
1834 || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))))
1835 {
1836 if (operands[1] == const0_rtx)
1837 return "clr%.b %0";
1838 if ((!TARGET_COLDFIRE || DATA_REG_P (operands[0]))
1839 && GET_CODE (operands[1]) == CONST_INT
1840 && (INTVAL (operands[1]) & 255) == 255)
1841 {
1842 CC_STATUS_INIT;
1843 return "st %0";
1844 }
1845 }
1846 if (GET_CODE (operands[1]) == CONST_INT
1847 && DATA_REG_P (operands[0])
1848 && INTVAL (operands[1]) < 128
1849 && INTVAL (operands[1]) >= -128)
1850 return "moveq %1,%0";
1851 if (operands[1] == const0_rtx && ADDRESS_REG_P (operands[0]))
1852 return "sub%.l %0,%0";
1853 if (GET_CODE (operands[1]) != CONST_INT && CONSTANT_P (operands[1]))
1854 return "move%.l %1,%0";
1855 /* 68k family (including the 5200 ColdFire) does not support byte moves to
1856 from address registers. */
1857 if (ADDRESS_REG_P (operands[0]) || ADDRESS_REG_P (operands[1]))
1858 return "move%.w %1,%0";
1859 return "move%.b %1,%0";
1860 }
1861
1862 const char *
1863 output_move_stricthi (rtx *operands)
1864 {
1865 if (operands[1] == const0_rtx
1866 /* clr insns on 68000 read before writing.
1867 This isn't so on the 68010, but we have no TARGET_68010. */
1868 && ((TARGET_68020 || TARGET_COLDFIRE)
1869 || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))))
1870 return "clr%.w %0";
1871 return "move%.w %1,%0";
1872 }
1873
1874 const char *
1875 output_move_strictqi (rtx *operands)
1876 {
1877 if (operands[1] == const0_rtx
1878 /* clr insns on 68000 read before writing.
1879 This isn't so on the 68010, but we have no TARGET_68010. */
1880 && ((TARGET_68020 || TARGET_COLDFIRE)
1881 || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))))
1882 return "clr%.b %0";
1883 return "move%.b %1,%0";
1884 }
1885
1886 /* Return the best assembler insn template
1887 for moving operands[1] into operands[0] as a fullword. */
1888
1889 static const char *
1890 singlemove_string (rtx *operands)
1891 {
1892 if (GET_CODE (operands[1]) == CONST_INT)
1893 return output_move_simode_const (operands);
1894 return "move%.l %1,%0";
1895 }
1896
1897
1898 /* Output assembler code to perform a doubleword move insn
1899 with operands OPERANDS. */
1900
1901 const char *
1902 output_move_double (rtx *operands)
1903 {
1904 enum
1905 {
1906 REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP
1907 } optype0, optype1;
1908 rtx latehalf[2];
1909 rtx middlehalf[2];
1910 rtx xops[2];
1911 rtx addreg0 = 0, addreg1 = 0;
1912 int dest_overlapped_low = 0;
1913 int size = GET_MODE_SIZE (GET_MODE (operands[0]));
1914
1915 middlehalf[0] = 0;
1916 middlehalf[1] = 0;
1917
1918 /* First classify both operands. */
1919
1920 if (REG_P (operands[0]))
1921 optype0 = REGOP;
1922 else if (offsettable_memref_p (operands[0]))
1923 optype0 = OFFSOP;
1924 else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
1925 optype0 = POPOP;
1926 else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
1927 optype0 = PUSHOP;
1928 else if (GET_CODE (operands[0]) == MEM)
1929 optype0 = MEMOP;
1930 else
1931 optype0 = RNDOP;
1932
1933 if (REG_P (operands[1]))
1934 optype1 = REGOP;
1935 else if (CONSTANT_P (operands[1]))
1936 optype1 = CNSTOP;
1937 else if (offsettable_memref_p (operands[1]))
1938 optype1 = OFFSOP;
1939 else if (GET_CODE (XEXP (operands[1], 0)) == POST_INC)
1940 optype1 = POPOP;
1941 else if (GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)
1942 optype1 = PUSHOP;
1943 else if (GET_CODE (operands[1]) == MEM)
1944 optype1 = MEMOP;
1945 else
1946 optype1 = RNDOP;
1947
1948 /* Check for the cases that the operand constraints are not supposed
1949 to allow to happen. Generating code for these cases is
1950 painful. */
1951 gcc_assert (optype0 != RNDOP && optype1 != RNDOP);
1952
1953 /* If one operand is decrementing and one is incrementing
1954 decrement the former register explicitly
1955 and change that operand into ordinary indexing. */
1956
1957 if (optype0 == PUSHOP && optype1 == POPOP)
1958 {
1959 operands[0] = XEXP (XEXP (operands[0], 0), 0);
1960 if (size == 12)
1961 output_asm_insn ("sub%.l #12,%0", operands);
1962 else
1963 output_asm_insn ("subq%.l #8,%0", operands);
1964 if (GET_MODE (operands[1]) == XFmode)
1965 operands[0] = gen_rtx_MEM (XFmode, operands[0]);
1966 else if (GET_MODE (operands[0]) == DFmode)
1967 operands[0] = gen_rtx_MEM (DFmode, operands[0]);
1968 else
1969 operands[0] = gen_rtx_MEM (DImode, operands[0]);
1970 optype0 = OFFSOP;
1971 }
1972 if (optype0 == POPOP && optype1 == PUSHOP)
1973 {
1974 operands[1] = XEXP (XEXP (operands[1], 0), 0);
1975 if (size == 12)
1976 output_asm_insn ("sub%.l #12,%1", operands);
1977 else
1978 output_asm_insn ("subq%.l #8,%1", operands);
1979 if (GET_MODE (operands[1]) == XFmode)
1980 operands[1] = gen_rtx_MEM (XFmode, operands[1]);
1981 else if (GET_MODE (operands[1]) == DFmode)
1982 operands[1] = gen_rtx_MEM (DFmode, operands[1]);
1983 else
1984 operands[1] = gen_rtx_MEM (DImode, operands[1]);
1985 optype1 = OFFSOP;
1986 }
1987
1988 /* If an operand is an unoffsettable memory ref, find a register
1989 we can increment temporarily to make it refer to the second word. */
1990
1991 if (optype0 == MEMOP)
1992 addreg0 = find_addr_reg (XEXP (operands[0], 0));
1993
1994 if (optype1 == MEMOP)
1995 addreg1 = find_addr_reg (XEXP (operands[1], 0));
1996
1997 /* Ok, we can do one word at a time.
1998 Normally we do the low-numbered word first,
1999 but if either operand is autodecrementing then we
2000 do the high-numbered word first.
2001
2002 In either case, set up in LATEHALF the operands to use
2003 for the high-numbered word and in some cases alter the
2004 operands in OPERANDS to be suitable for the low-numbered word. */
2005
2006 if (size == 12)
2007 {
2008 if (optype0 == REGOP)
2009 {
2010 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 2);
2011 middlehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2012 }
2013 else if (optype0 == OFFSOP)
2014 {
2015 middlehalf[0] = adjust_address (operands[0], SImode, 4);
2016 latehalf[0] = adjust_address (operands[0], SImode, size - 4);
2017 }
2018 else
2019 {
2020 middlehalf[0] = operands[0];
2021 latehalf[0] = operands[0];
2022 }
2023
2024 if (optype1 == REGOP)
2025 {
2026 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 2);
2027 middlehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2028 }
2029 else if (optype1 == OFFSOP)
2030 {
2031 middlehalf[1] = adjust_address (operands[1], SImode, 4);
2032 latehalf[1] = adjust_address (operands[1], SImode, size - 4);
2033 }
2034 else if (optype1 == CNSTOP)
2035 {
2036 if (GET_CODE (operands[1]) == CONST_DOUBLE)
2037 {
2038 REAL_VALUE_TYPE r;
2039 long l[3];
2040
2041 REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
2042 REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
2043 operands[1] = GEN_INT (l[0]);
2044 middlehalf[1] = GEN_INT (l[1]);
2045 latehalf[1] = GEN_INT (l[2]);
2046 }
2047 else
2048 {
2049 /* No non-CONST_DOUBLE constant should ever appear
2050 here. */
2051 gcc_assert (!CONSTANT_P (operands[1]));
2052 }
2053 }
2054 else
2055 {
2056 middlehalf[1] = operands[1];
2057 latehalf[1] = operands[1];
2058 }
2059 }
2060 else
2061 /* size is not 12: */
2062 {
2063 if (optype0 == REGOP)
2064 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2065 else if (optype0 == OFFSOP)
2066 latehalf[0] = adjust_address (operands[0], SImode, size - 4);
2067 else
2068 latehalf[0] = operands[0];
2069
2070 if (optype1 == REGOP)
2071 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2072 else if (optype1 == OFFSOP)
2073 latehalf[1] = adjust_address (operands[1], SImode, size - 4);
2074 else if (optype1 == CNSTOP)
2075 split_double (operands[1], &operands[1], &latehalf[1]);
2076 else
2077 latehalf[1] = operands[1];
2078 }
2079
2080 /* If insn is effectively movd N(sp),-(sp) then we will do the
2081 high word first. We should use the adjusted operand 1 (which is N+4(sp))
2082 for the low word as well, to compensate for the first decrement of sp. */
2083 if (optype0 == PUSHOP
2084 && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM
2085 && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
2086 operands[1] = middlehalf[1] = latehalf[1];
2087
2088 /* For (set (reg:DI N) (mem:DI ... (reg:SI N) ...)),
2089 if the upper part of reg N does not appear in the MEM, arrange to
2090 emit the move late-half first. Otherwise, compute the MEM address
2091 into the upper part of N and use that as a pointer to the memory
2092 operand. */
2093 if (optype0 == REGOP
2094 && (optype1 == OFFSOP || optype1 == MEMOP))
2095 {
2096 rtx testlow = gen_rtx_REG (SImode, REGNO (operands[0]));
2097
2098 if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0))
2099 && reg_overlap_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
2100 {
2101 /* If both halves of dest are used in the src memory address,
2102 compute the address into latehalf of dest.
2103 Note that this can't happen if the dest is two data regs. */
2104 compadr:
2105 xops[0] = latehalf[0];
2106 xops[1] = XEXP (operands[1], 0);
2107 output_asm_insn ("lea %a1,%0", xops);
2108 if (GET_MODE (operands[1]) == XFmode )
2109 {
2110 operands[1] = gen_rtx_MEM (XFmode, latehalf[0]);
2111 middlehalf[1] = adjust_address (operands[1], DImode, size - 8);
2112 latehalf[1] = adjust_address (operands[1], DImode, size - 4);
2113 }
2114 else
2115 {
2116 operands[1] = gen_rtx_MEM (DImode, latehalf[0]);
2117 latehalf[1] = adjust_address (operands[1], DImode, size - 4);
2118 }
2119 }
2120 else if (size == 12
2121 && reg_overlap_mentioned_p (middlehalf[0],
2122 XEXP (operands[1], 0)))
2123 {
2124 /* Check for two regs used by both source and dest.
2125 Note that this can't happen if the dest is all data regs.
2126 It can happen if the dest is d6, d7, a0.
2127 But in that case, latehalf is an addr reg, so
2128 the code at compadr does ok. */
2129
2130 if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0))
2131 || reg_overlap_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
2132 goto compadr;
2133
2134 /* JRV says this can't happen: */
2135 gcc_assert (!addreg0 && !addreg1);
2136
2137 /* Only the middle reg conflicts; simply put it last. */
2138 output_asm_insn (singlemove_string (operands), operands);
2139 output_asm_insn (singlemove_string (latehalf), latehalf);
2140 output_asm_insn (singlemove_string (middlehalf), middlehalf);
2141 return "";
2142 }
2143 else if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0)))
2144 /* If the low half of dest is mentioned in the source memory
2145 address, the arrange to emit the move late half first. */
2146 dest_overlapped_low = 1;
2147 }
2148
2149 /* If one or both operands autodecrementing,
2150 do the two words, high-numbered first. */
2151
2152 /* Likewise, the first move would clobber the source of the second one,
2153 do them in the other order. This happens only for registers;
2154 such overlap can't happen in memory unless the user explicitly
2155 sets it up, and that is an undefined circumstance. */
2156
2157 if (optype0 == PUSHOP || optype1 == PUSHOP
2158 || (optype0 == REGOP && optype1 == REGOP
2159 && ((middlehalf[1] && REGNO (operands[0]) == REGNO (middlehalf[1]))
2160 || REGNO (operands[0]) == REGNO (latehalf[1])))
2161 || dest_overlapped_low)
2162 {
2163 /* Make any unoffsettable addresses point at high-numbered word. */
2164 if (addreg0)
2165 {
2166 if (size == 12)
2167 output_asm_insn ("addq%.l #8,%0", &addreg0);
2168 else
2169 output_asm_insn ("addq%.l #4,%0", &addreg0);
2170 }
2171 if (addreg1)
2172 {
2173 if (size == 12)
2174 output_asm_insn ("addq%.l #8,%0", &addreg1);
2175 else
2176 output_asm_insn ("addq%.l #4,%0", &addreg1);
2177 }
2178
2179 /* Do that word. */
2180 output_asm_insn (singlemove_string (latehalf), latehalf);
2181
2182 /* Undo the adds we just did. */
2183 if (addreg0)
2184 output_asm_insn ("subq%.l #4,%0", &addreg0);
2185 if (addreg1)
2186 output_asm_insn ("subq%.l #4,%0", &addreg1);
2187
2188 if (size == 12)
2189 {
2190 output_asm_insn (singlemove_string (middlehalf), middlehalf);
2191 if (addreg0)
2192 output_asm_insn ("subq%.l #4,%0", &addreg0);
2193 if (addreg1)
2194 output_asm_insn ("subq%.l #4,%0", &addreg1);
2195 }
2196
2197 /* Do low-numbered word. */
2198 return singlemove_string (operands);
2199 }
2200
2201 /* Normal case: do the two words, low-numbered first. */
2202
2203 output_asm_insn (singlemove_string (operands), operands);
2204
2205 /* Do the middle one of the three words for long double */
2206 if (size == 12)
2207 {
2208 if (addreg0)
2209 output_asm_insn ("addq%.l #4,%0", &addreg0);
2210 if (addreg1)
2211 output_asm_insn ("addq%.l #4,%0", &addreg1);
2212
2213 output_asm_insn (singlemove_string (middlehalf), middlehalf);
2214 }
2215
2216 /* Make any unoffsettable addresses point at high-numbered word. */
2217 if (addreg0)
2218 output_asm_insn ("addq%.l #4,%0", &addreg0);
2219 if (addreg1)
2220 output_asm_insn ("addq%.l #4,%0", &addreg1);
2221
2222 /* Do that word. */
2223 output_asm_insn (singlemove_string (latehalf), latehalf);
2224
2225 /* Undo the adds we just did. */
2226 if (addreg0)
2227 {
2228 if (size == 12)
2229 output_asm_insn ("subq%.l #8,%0", &addreg0);
2230 else
2231 output_asm_insn ("subq%.l #4,%0", &addreg0);
2232 }
2233 if (addreg1)
2234 {
2235 if (size == 12)
2236 output_asm_insn ("subq%.l #8,%0", &addreg1);
2237 else
2238 output_asm_insn ("subq%.l #4,%0", &addreg1);
2239 }
2240
2241 return "";
2242 }
2243
2244 /* Return a REG that occurs in ADDR with coefficient 1.
2245 ADDR can be effectively incremented by incrementing REG. */
2246
2247 static rtx
2248 find_addr_reg (rtx addr)
2249 {
2250 while (GET_CODE (addr) == PLUS)
2251 {
2252 if (GET_CODE (XEXP (addr, 0)) == REG)
2253 addr = XEXP (addr, 0);
2254 else if (GET_CODE (XEXP (addr, 1)) == REG)
2255 addr = XEXP (addr, 1);
2256 else if (CONSTANT_P (XEXP (addr, 0)))
2257 addr = XEXP (addr, 1);
2258 else if (CONSTANT_P (XEXP (addr, 1)))
2259 addr = XEXP (addr, 0);
2260 else
2261 gcc_unreachable ();
2262 }
2263 gcc_assert (GET_CODE (addr) == REG);
2264 return addr;
2265 }
2266
2267 /* Output assembler code to perform a 32-bit 3-operand add. */
2268
2269 const char *
2270 output_addsi3 (rtx *operands)
2271 {
2272 if (! operands_match_p (operands[0], operands[1]))
2273 {
2274 if (!ADDRESS_REG_P (operands[1]))
2275 {
2276 rtx tmp = operands[1];
2277
2278 operands[1] = operands[2];
2279 operands[2] = tmp;
2280 }
2281
2282 /* These insns can result from reloads to access
2283 stack slots over 64k from the frame pointer. */
2284 if (GET_CODE (operands[2]) == CONST_INT
2285 && (INTVAL (operands[2]) < -32768 || INTVAL (operands[2]) > 32767))
2286 return "move%.l %2,%0\n\tadd%.l %1,%0";
2287 if (GET_CODE (operands[2]) == REG)
2288 return MOTOROLA ? "lea (%1,%2.l),%0" : "lea %1@(0,%2:l),%0";
2289 return MOTOROLA ? "lea (%c2,%1),%0" : "lea %1@(%c2),%0";
2290 }
2291 if (GET_CODE (operands[2]) == CONST_INT)
2292 {
2293 if (INTVAL (operands[2]) > 0
2294 && INTVAL (operands[2]) <= 8)
2295 return "addq%.l %2,%0";
2296 if (INTVAL (operands[2]) < 0
2297 && INTVAL (operands[2]) >= -8)
2298 {
2299 operands[2] = GEN_INT (- INTVAL (operands[2]));
2300 return "subq%.l %2,%0";
2301 }
2302 /* On the CPU32 it is faster to use two addql instructions to
2303 add a small integer (8 < N <= 16) to a register.
2304 Likewise for subql. */
2305 if (TARGET_CPU32 && REG_P (operands[0]))
2306 {
2307 if (INTVAL (operands[2]) > 8
2308 && INTVAL (operands[2]) <= 16)
2309 {
2310 operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
2311 return "addq%.l #8,%0\n\taddq%.l %2,%0";
2312 }
2313 if (INTVAL (operands[2]) < -8
2314 && INTVAL (operands[2]) >= -16)
2315 {
2316 operands[2] = GEN_INT (- INTVAL (operands[2]) - 8);
2317 return "subq%.l #8,%0\n\tsubq%.l %2,%0";
2318 }
2319 }
2320 if (ADDRESS_REG_P (operands[0])
2321 && INTVAL (operands[2]) >= -0x8000
2322 && INTVAL (operands[2]) < 0x8000)
2323 {
2324 if (TARGET_68040)
2325 return "add%.w %2,%0";
2326 else
2327 return MOTOROLA ? "lea (%c2,%0),%0" : "lea %0@(%c2),%0";
2328 }
2329 }
2330 return "add%.l %2,%0";
2331 }
2332 \f
2333 /* Store in cc_status the expressions that the condition codes will
2334 describe after execution of an instruction whose pattern is EXP.
2335 Do not alter them if the instruction would not alter the cc's. */
2336
2337 /* On the 68000, all the insns to store in an address register fail to
2338 set the cc's. However, in some cases these instructions can make it
2339 possibly invalid to use the saved cc's. In those cases we clear out
2340 some or all of the saved cc's so they won't be used. */
2341
2342 void
2343 notice_update_cc (rtx exp, rtx insn)
2344 {
2345 if (GET_CODE (exp) == SET)
2346 {
2347 if (GET_CODE (SET_SRC (exp)) == CALL)
2348 CC_STATUS_INIT;
2349 else if (ADDRESS_REG_P (SET_DEST (exp)))
2350 {
2351 if (cc_status.value1 && modified_in_p (cc_status.value1, insn))
2352 cc_status.value1 = 0;
2353 if (cc_status.value2 && modified_in_p (cc_status.value2, insn))
2354 cc_status.value2 = 0;
2355 }
2356 else if (!FP_REG_P (SET_DEST (exp))
2357 && SET_DEST (exp) != cc0_rtx
2358 && (FP_REG_P (SET_SRC (exp))
2359 || GET_CODE (SET_SRC (exp)) == FIX
2360 || GET_CODE (SET_SRC (exp)) == FLOAT_TRUNCATE
2361 || GET_CODE (SET_SRC (exp)) == FLOAT_EXTEND))
2362 CC_STATUS_INIT;
2363 /* A pair of move insns doesn't produce a useful overall cc. */
2364 else if (!FP_REG_P (SET_DEST (exp))
2365 && !FP_REG_P (SET_SRC (exp))
2366 && GET_MODE_SIZE (GET_MODE (SET_SRC (exp))) > 4
2367 && (GET_CODE (SET_SRC (exp)) == REG
2368 || GET_CODE (SET_SRC (exp)) == MEM
2369 || GET_CODE (SET_SRC (exp)) == CONST_DOUBLE))
2370 CC_STATUS_INIT;
2371 else if (SET_DEST (exp) != pc_rtx)
2372 {
2373 cc_status.flags = 0;
2374 cc_status.value1 = SET_DEST (exp);
2375 cc_status.value2 = SET_SRC (exp);
2376 }
2377 }
2378 else if (GET_CODE (exp) == PARALLEL
2379 && GET_CODE (XVECEXP (exp, 0, 0)) == SET)
2380 {
2381 rtx dest = SET_DEST (XVECEXP (exp, 0, 0));
2382 rtx src = SET_SRC (XVECEXP (exp, 0, 0));
2383
2384 if (ADDRESS_REG_P (dest))
2385 CC_STATUS_INIT;
2386 else if (dest != pc_rtx)
2387 {
2388 cc_status.flags = 0;
2389 cc_status.value1 = dest;
2390 cc_status.value2 = src;
2391 }
2392 }
2393 else
2394 CC_STATUS_INIT;
2395 if (cc_status.value2 != 0
2396 && ADDRESS_REG_P (cc_status.value2)
2397 && GET_MODE (cc_status.value2) == QImode)
2398 CC_STATUS_INIT;
2399 if (cc_status.value2 != 0)
2400 switch (GET_CODE (cc_status.value2))
2401 {
2402 case ASHIFT: case ASHIFTRT: case LSHIFTRT:
2403 case ROTATE: case ROTATERT:
2404 /* These instructions always clear the overflow bit, and set
2405 the carry to the bit shifted out. */
2406 /* ??? We don't currently have a way to signal carry not valid,
2407 nor do we check for it in the branch insns. */
2408 CC_STATUS_INIT;
2409 break;
2410
2411 case PLUS: case MINUS: case MULT:
2412 case DIV: case UDIV: case MOD: case UMOD: case NEG:
2413 if (GET_MODE (cc_status.value2) != VOIDmode)
2414 cc_status.flags |= CC_NO_OVERFLOW;
2415 break;
2416 case ZERO_EXTEND:
2417 /* (SET r1 (ZERO_EXTEND r2)) on this machine
2418 ends with a move insn moving r2 in r2's mode.
2419 Thus, the cc's are set for r2.
2420 This can set N bit spuriously. */
2421 cc_status.flags |= CC_NOT_NEGATIVE;
2422
2423 default:
2424 break;
2425 }
2426 if (cc_status.value1 && GET_CODE (cc_status.value1) == REG
2427 && cc_status.value2
2428 && reg_overlap_mentioned_p (cc_status.value1, cc_status.value2))
2429 cc_status.value2 = 0;
2430 if (((cc_status.value1 && FP_REG_P (cc_status.value1))
2431 || (cc_status.value2 && FP_REG_P (cc_status.value2))))
2432 cc_status.flags = CC_IN_68881;
2433 }
2434 \f
2435 const char *
2436 output_move_const_double (rtx *operands)
2437 {
2438 int code = standard_68881_constant_p (operands[1]);
2439
2440 if (code != 0)
2441 {
2442 static char buf[40];
2443
2444 sprintf (buf, "fmovecr #0x%x,%%0", code & 0xff);
2445 return buf;
2446 }
2447 return "fmove%.d %1,%0";
2448 }
2449
2450 const char *
2451 output_move_const_single (rtx *operands)
2452 {
2453 int code = standard_68881_constant_p (operands[1]);
2454
2455 if (code != 0)
2456 {
2457 static char buf[40];
2458
2459 sprintf (buf, "fmovecr #0x%x,%%0", code & 0xff);
2460 return buf;
2461 }
2462 return "fmove%.s %f1,%0";
2463 }
2464
2465 /* Return nonzero if X, a CONST_DOUBLE, has a value that we can get
2466 from the "fmovecr" instruction.
2467 The value, anded with 0xff, gives the code to use in fmovecr
2468 to get the desired constant. */
2469
2470 /* This code has been fixed for cross-compilation. */
2471
2472 static int inited_68881_table = 0;
2473
2474 static const char *const strings_68881[7] = {
2475 "0.0",
2476 "1.0",
2477 "10.0",
2478 "100.0",
2479 "10000.0",
2480 "1e8",
2481 "1e16"
2482 };
2483
2484 static const int codes_68881[7] = {
2485 0x0f,
2486 0x32,
2487 0x33,
2488 0x34,
2489 0x35,
2490 0x36,
2491 0x37
2492 };
2493
2494 REAL_VALUE_TYPE values_68881[7];
2495
2496 /* Set up values_68881 array by converting the decimal values
2497 strings_68881 to binary. */
2498
2499 void
2500 init_68881_table (void)
2501 {
2502 int i;
2503 REAL_VALUE_TYPE r;
2504 enum machine_mode mode;
2505
2506 mode = SFmode;
2507 for (i = 0; i < 7; i++)
2508 {
2509 if (i == 6)
2510 mode = DFmode;
2511 r = REAL_VALUE_ATOF (strings_68881[i], mode);
2512 values_68881[i] = r;
2513 }
2514 inited_68881_table = 1;
2515 }
2516
2517 int
2518 standard_68881_constant_p (rtx x)
2519 {
2520 REAL_VALUE_TYPE r;
2521 int i;
2522
2523 /* fmovecr must be emulated on the 68040 and 68060, so it shouldn't be
2524 used at all on those chips. */
2525 if (TARGET_68040 || TARGET_68060)
2526 return 0;
2527
2528 if (! inited_68881_table)
2529 init_68881_table ();
2530
2531 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
2532
2533 /* Use REAL_VALUES_IDENTICAL instead of REAL_VALUES_EQUAL so that -0.0
2534 is rejected. */
2535 for (i = 0; i < 6; i++)
2536 {
2537 if (REAL_VALUES_IDENTICAL (r, values_68881[i]))
2538 return (codes_68881[i]);
2539 }
2540
2541 if (GET_MODE (x) == SFmode)
2542 return 0;
2543
2544 if (REAL_VALUES_EQUAL (r, values_68881[6]))
2545 return (codes_68881[6]);
2546
2547 /* larger powers of ten in the constants ram are not used
2548 because they are not equal to a `double' C constant. */
2549 return 0;
2550 }
2551
2552 /* If X is a floating-point constant, return the logarithm of X base 2,
2553 or 0 if X is not a power of 2. */
2554
2555 int
2556 floating_exact_log2 (rtx x)
2557 {
2558 REAL_VALUE_TYPE r, r1;
2559 int exp;
2560
2561 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
2562
2563 if (REAL_VALUES_LESS (r, dconst1))
2564 return 0;
2565
2566 exp = real_exponent (&r);
2567 real_2expN (&r1, exp);
2568 if (REAL_VALUES_EQUAL (r1, r))
2569 return exp;
2570
2571 return 0;
2572 }
2573 \f
2574 /* A C compound statement to output to stdio stream STREAM the
2575 assembler syntax for an instruction operand X. X is an RTL
2576 expression.
2577
2578 CODE is a value that can be used to specify one of several ways
2579 of printing the operand. It is used when identical operands
2580 must be printed differently depending on the context. CODE
2581 comes from the `%' specification that was used to request
2582 printing of the operand. If the specification was just `%DIGIT'
2583 then CODE is 0; if the specification was `%LTR DIGIT' then CODE
2584 is the ASCII code for LTR.
2585
2586 If X is a register, this macro should print the register's name.
2587 The names can be found in an array `reg_names' whose type is
2588 `char *[]'. `reg_names' is initialized from `REGISTER_NAMES'.
2589
2590 When the machine description has a specification `%PUNCT' (a `%'
2591 followed by a punctuation character), this macro is called with
2592 a null pointer for X and the punctuation character for CODE.
2593
2594 The m68k specific codes are:
2595
2596 '.' for dot needed in Motorola-style opcode names.
2597 '-' for an operand pushing on the stack:
2598 sp@-, -(sp) or -(%sp) depending on the style of syntax.
2599 '+' for an operand pushing on the stack:
2600 sp@+, (sp)+ or (%sp)+ depending on the style of syntax.
2601 '@' for a reference to the top word on the stack:
2602 sp@, (sp) or (%sp) depending on the style of syntax.
2603 '#' for an immediate operand prefix (# in MIT and Motorola syntax
2604 but & in SGS syntax).
2605 '!' for the cc register (used in an `and to cc' insn).
2606 '$' for the letter `s' in an op code, but only on the 68040.
2607 '&' for the letter `d' in an op code, but only on the 68040.
2608 '/' for register prefix needed by longlong.h.
2609
2610 'b' for byte insn (no effect, on the Sun; this is for the ISI).
2611 'd' to force memory addressing to be absolute, not relative.
2612 'f' for float insn (print a CONST_DOUBLE as a float rather than in hex)
2613 'o' for operands to go directly to output_operand_address (bypassing
2614 print_operand_address--used only for SYMBOL_REFs under TARGET_PCREL)
2615 'x' for float insn (print a CONST_DOUBLE as a float rather than in hex),
2616 or print pair of registers as rx:ry.
2617
2618 */
2619
2620 void
2621 print_operand (FILE *file, rtx op, int letter)
2622 {
2623 if (letter == '.')
2624 {
2625 if (MOTOROLA)
2626 fprintf (file, ".");
2627 }
2628 else if (letter == '#')
2629 asm_fprintf (file, "%I");
2630 else if (letter == '-')
2631 asm_fprintf (file, MOTOROLA ? "-(%Rsp)" : "%Rsp@-");
2632 else if (letter == '+')
2633 asm_fprintf (file, MOTOROLA ? "(%Rsp)+" : "%Rsp@+");
2634 else if (letter == '@')
2635 asm_fprintf (file, MOTOROLA ? "(%Rsp)" : "%Rsp@");
2636 else if (letter == '!')
2637 asm_fprintf (file, "%Rfpcr");
2638 else if (letter == '$')
2639 {
2640 if (TARGET_68040_ONLY)
2641 fprintf (file, "s");
2642 }
2643 else if (letter == '&')
2644 {
2645 if (TARGET_68040_ONLY)
2646 fprintf (file, "d");
2647 }
2648 else if (letter == '/')
2649 asm_fprintf (file, "%R");
2650 else if (letter == 'o')
2651 {
2652 /* This is only for direct addresses with TARGET_PCREL */
2653 gcc_assert (GET_CODE (op) == MEM
2654 && GET_CODE (XEXP (op, 0)) == SYMBOL_REF
2655 && TARGET_PCREL);
2656 output_addr_const (file, XEXP (op, 0));
2657 }
2658 else if (GET_CODE (op) == REG)
2659 {
2660 if (letter == 'R')
2661 /* Print out the second register name of a register pair.
2662 I.e., R (6) => 7. */
2663 fputs (M68K_REGNAME(REGNO (op) + 1), file);
2664 else
2665 fputs (M68K_REGNAME(REGNO (op)), file);
2666 }
2667 else if (GET_CODE (op) == MEM)
2668 {
2669 output_address (XEXP (op, 0));
2670 if (letter == 'd' && ! TARGET_68020
2671 && CONSTANT_ADDRESS_P (XEXP (op, 0))
2672 && !(GET_CODE (XEXP (op, 0)) == CONST_INT
2673 && INTVAL (XEXP (op, 0)) < 0x8000
2674 && INTVAL (XEXP (op, 0)) >= -0x8000))
2675 fprintf (file, MOTOROLA ? ".l" : ":l");
2676 }
2677 else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == SFmode)
2678 {
2679 REAL_VALUE_TYPE r;
2680 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
2681 ASM_OUTPUT_FLOAT_OPERAND (letter, file, r);
2682 }
2683 else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == XFmode)
2684 {
2685 REAL_VALUE_TYPE r;
2686 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
2687 ASM_OUTPUT_LONG_DOUBLE_OPERAND (file, r);
2688 }
2689 else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == DFmode)
2690 {
2691 REAL_VALUE_TYPE r;
2692 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
2693 ASM_OUTPUT_DOUBLE_OPERAND (file, r);
2694 }
2695 else
2696 {
2697 /* Use `print_operand_address' instead of `output_addr_const'
2698 to ensure that we print relevant PIC stuff. */
2699 asm_fprintf (file, "%I");
2700 if (TARGET_PCREL
2701 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST))
2702 print_operand_address (file, op);
2703 else
2704 output_addr_const (file, op);
2705 }
2706 }
2707
2708 \f
2709 /* A C compound statement to output to stdio stream STREAM the
2710 assembler syntax for an instruction operand that is a memory
2711 reference whose address is ADDR. ADDR is an RTL expression.
2712
2713 Note that this contains a kludge that knows that the only reason
2714 we have an address (plus (label_ref...) (reg...)) when not generating
2715 PIC code is in the insn before a tablejump, and we know that m68k.md
2716 generates a label LInnn: on such an insn.
2717
2718 It is possible for PIC to generate a (plus (label_ref...) (reg...))
2719 and we handle that just like we would a (plus (symbol_ref...) (reg...)).
2720
2721 Some SGS assemblers have a bug such that "Lnnn-LInnn-2.b(pc,d0.l*2)"
2722 fails to assemble. Luckily "Lnnn(pc,d0.l*2)" produces the results
2723 we want. This difference can be accommodated by using an assembler
2724 define such "LDnnn" to be either "Lnnn-LInnn-2.b", "Lnnn", or any other
2725 string, as necessary. This is accomplished via the ASM_OUTPUT_CASE_END
2726 macro. See m68k/sgs.h for an example; for versions without the bug.
2727 Some assemblers refuse all the above solutions. The workaround is to
2728 emit "K(pc,d0.l*2)" with K being a small constant known to give the
2729 right behavior.
2730
2731 They also do not like things like "pea 1.w", so we simple leave off
2732 the .w on small constants.
2733
2734 This routine is responsible for distinguishing between -fpic and -fPIC
2735 style relocations in an address. When generating -fpic code the
2736 offset is output in word mode (e.g. movel a5@(_foo:w), a0). When generating
2737 -fPIC code the offset is output in long mode (e.g. movel a5@(_foo:l), a0) */
2738
2739 #if MOTOROLA
2740 # define ASM_OUTPUT_CASE_FETCH(file, labelno, regname) \
2741 asm_fprintf (file, "%LL%d-%LLI%d.b(%Rpc,%s.", labelno, labelno, regname)
2742 #else /* !MOTOROLA */
2743 # define ASM_OUTPUT_CASE_FETCH(file, labelno, regname) \
2744 asm_fprintf (file, "%Rpc@(%LL%d-%LLI%d-2:b,%s:", labelno, labelno, regname)
2745 #endif /* !MOTOROLA */
2746
2747 void
2748 print_operand_address (FILE *file, rtx addr)
2749 {
2750 register rtx reg1, reg2, breg, ireg;
2751 rtx offset;
2752
2753 switch (GET_CODE (addr))
2754 {
2755 case REG:
2756 fprintf (file, MOTOROLA ? "(%s)" : "%s@", M68K_REGNAME (REGNO (addr)));
2757 break;
2758 case PRE_DEC:
2759 fprintf (file, MOTOROLA ? "-(%s)" : "%s@-",
2760 M68K_REGNAME (REGNO (XEXP (addr, 0))));
2761 break;
2762 case POST_INC:
2763 fprintf (file, MOTOROLA ? "(%s)+" : "%s@+",
2764 M68K_REGNAME (REGNO (XEXP (addr, 0))));
2765 break;
2766 case PLUS:
2767 reg1 = reg2 = ireg = breg = offset = 0;
2768 if (CONSTANT_ADDRESS_P (XEXP (addr, 0)))
2769 {
2770 offset = XEXP (addr, 0);
2771 addr = XEXP (addr, 1);
2772 }
2773 else if (CONSTANT_ADDRESS_P (XEXP (addr, 1)))
2774 {
2775 offset = XEXP (addr, 1);
2776 addr = XEXP (addr, 0);
2777 }
2778 if (GET_CODE (addr) != PLUS)
2779 {
2780 ;
2781 }
2782 else if (GET_CODE (XEXP (addr, 0)) == SIGN_EXTEND)
2783 {
2784 reg1 = XEXP (addr, 0);
2785 addr = XEXP (addr, 1);
2786 }
2787 else if (GET_CODE (XEXP (addr, 1)) == SIGN_EXTEND)
2788 {
2789 reg1 = XEXP (addr, 1);
2790 addr = XEXP (addr, 0);
2791 }
2792 else if (GET_CODE (XEXP (addr, 0)) == MULT)
2793 {
2794 reg1 = XEXP (addr, 0);
2795 addr = XEXP (addr, 1);
2796 }
2797 else if (GET_CODE (XEXP (addr, 1)) == MULT)
2798 {
2799 reg1 = XEXP (addr, 1);
2800 addr = XEXP (addr, 0);
2801 }
2802 else if (GET_CODE (XEXP (addr, 0)) == REG)
2803 {
2804 reg1 = XEXP (addr, 0);
2805 addr = XEXP (addr, 1);
2806 }
2807 else if (GET_CODE (XEXP (addr, 1)) == REG)
2808 {
2809 reg1 = XEXP (addr, 1);
2810 addr = XEXP (addr, 0);
2811 }
2812 if (GET_CODE (addr) == REG || GET_CODE (addr) == MULT
2813 || GET_CODE (addr) == SIGN_EXTEND)
2814 {
2815 if (reg1 == 0)
2816 reg1 = addr;
2817 else
2818 reg2 = addr;
2819 addr = 0;
2820 }
2821 #if 0 /* for OLD_INDEXING */
2822 else if (GET_CODE (addr) == PLUS)
2823 {
2824 if (GET_CODE (XEXP (addr, 0)) == REG)
2825 {
2826 reg2 = XEXP (addr, 0);
2827 addr = XEXP (addr, 1);
2828 }
2829 else if (GET_CODE (XEXP (addr, 1)) == REG)
2830 {
2831 reg2 = XEXP (addr, 1);
2832 addr = XEXP (addr, 0);
2833 }
2834 }
2835 #endif
2836 if (offset != 0)
2837 {
2838 gcc_assert (!addr);
2839 addr = offset;
2840 }
2841 if ((reg1 && (GET_CODE (reg1) == SIGN_EXTEND
2842 || GET_CODE (reg1) == MULT))
2843 || (reg2 != 0 && REGNO_OK_FOR_BASE_P (REGNO (reg2))))
2844 {
2845 breg = reg2;
2846 ireg = reg1;
2847 }
2848 else if (reg1 != 0 && REGNO_OK_FOR_BASE_P (REGNO (reg1)))
2849 {
2850 breg = reg1;
2851 ireg = reg2;
2852 }
2853 if (ireg != 0 && breg == 0 && GET_CODE (addr) == LABEL_REF
2854 && ! (flag_pic && ireg == pic_offset_table_rtx))
2855 {
2856 int scale = 1;
2857 if (GET_CODE (ireg) == MULT)
2858 {
2859 scale = INTVAL (XEXP (ireg, 1));
2860 ireg = XEXP (ireg, 0);
2861 }
2862 if (GET_CODE (ireg) == SIGN_EXTEND)
2863 {
2864 ASM_OUTPUT_CASE_FETCH (file,
2865 CODE_LABEL_NUMBER (XEXP (addr, 0)),
2866 M68K_REGNAME (REGNO (XEXP (ireg, 0))));
2867 fprintf (file, "w");
2868 }
2869 else
2870 {
2871 ASM_OUTPUT_CASE_FETCH (file,
2872 CODE_LABEL_NUMBER (XEXP (addr, 0)),
2873 M68K_REGNAME (REGNO (ireg)));
2874 fprintf (file, "l");
2875 }
2876 if (scale != 1)
2877 fprintf (file, MOTOROLA ? "*%d" : ":%d", scale);
2878 putc (')', file);
2879 break;
2880 }
2881 if (breg != 0 && ireg == 0 && GET_CODE (addr) == LABEL_REF
2882 && ! (flag_pic && breg == pic_offset_table_rtx))
2883 {
2884 ASM_OUTPUT_CASE_FETCH (file,
2885 CODE_LABEL_NUMBER (XEXP (addr, 0)),
2886 M68K_REGNAME (REGNO (breg)));
2887 fprintf (file, "l)");
2888 break;
2889 }
2890 if (ireg != 0 || breg != 0)
2891 {
2892 int scale = 1;
2893
2894 gcc_assert (breg);
2895 gcc_assert (flag_pic || !addr || GET_CODE (addr) != LABEL_REF);
2896
2897 if (MOTOROLA)
2898 {
2899 if (addr != 0)
2900 {
2901 output_addr_const (file, addr);
2902 if (flag_pic && (breg == pic_offset_table_rtx))
2903 {
2904 fprintf (file, "@GOT");
2905 if (flag_pic == 1)
2906 fprintf (file, ".w");
2907 }
2908 }
2909 fprintf (file, "(%s", M68K_REGNAME (REGNO (breg)));
2910 if (ireg != 0)
2911 putc (',', file);
2912 }
2913 else /* !MOTOROLA */
2914 {
2915 fprintf (file, "%s@(", M68K_REGNAME (REGNO (breg)));
2916 if (addr != 0)
2917 {
2918 output_addr_const (file, addr);
2919 if (breg == pic_offset_table_rtx)
2920 switch (flag_pic)
2921 {
2922 case 1:
2923 fprintf (file, ":w");
2924 break;
2925 case 2:
2926 fprintf (file, ":l");
2927 break;
2928 default:
2929 break;
2930 }
2931 if (ireg != 0)
2932 putc (',', file);
2933 }
2934 } /* !MOTOROLA */
2935 if (ireg != 0 && GET_CODE (ireg) == MULT)
2936 {
2937 scale = INTVAL (XEXP (ireg, 1));
2938 ireg = XEXP (ireg, 0);
2939 }
2940 if (ireg != 0 && GET_CODE (ireg) == SIGN_EXTEND)
2941 fprintf (file, MOTOROLA ? "%s.w" : "%s:w",
2942 M68K_REGNAME (REGNO (XEXP (ireg, 0))));
2943 else if (ireg != 0)
2944 fprintf (file, MOTOROLA ? "%s.l" : "%s:l",
2945 M68K_REGNAME (REGNO (ireg)));
2946 if (scale != 1)
2947 fprintf (file, MOTOROLA ? "*%d" : ":%d", scale);
2948 putc (')', file);
2949 break;
2950 }
2951 else if (reg1 != 0 && GET_CODE (addr) == LABEL_REF
2952 && ! (flag_pic && reg1 == pic_offset_table_rtx))
2953 {
2954 ASM_OUTPUT_CASE_FETCH (file,
2955 CODE_LABEL_NUMBER (XEXP (addr, 0)),
2956 M68K_REGNAME (REGNO (reg1)));
2957 fprintf (file, "l)");
2958 break;
2959 }
2960 /* FALL-THROUGH (is this really what we want?) */
2961 default:
2962 if (GET_CODE (addr) == CONST_INT
2963 && INTVAL (addr) < 0x8000
2964 && INTVAL (addr) >= -0x8000)
2965 {
2966 fprintf (file, MOTOROLA ? "%d.w" : "%d:w", (int) INTVAL (addr));
2967 }
2968 else if (GET_CODE (addr) == CONST_INT)
2969 {
2970 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (addr));
2971 }
2972 else if (TARGET_PCREL)
2973 {
2974 fputc ('(', file);
2975 output_addr_const (file, addr);
2976 if (flag_pic == 1)
2977 asm_fprintf (file, ":w,%Rpc)");
2978 else
2979 asm_fprintf (file, ":l,%Rpc)");
2980 }
2981 else
2982 {
2983 /* Special case for SYMBOL_REF if the symbol name ends in
2984 `.<letter>', this can be mistaken as a size suffix. Put
2985 the name in parentheses. */
2986 if (GET_CODE (addr) == SYMBOL_REF
2987 && strlen (XSTR (addr, 0)) > 2
2988 && XSTR (addr, 0)[strlen (XSTR (addr, 0)) - 2] == '.')
2989 {
2990 putc ('(', file);
2991 output_addr_const (file, addr);
2992 putc (')', file);
2993 }
2994 else
2995 output_addr_const (file, addr);
2996 }
2997 break;
2998 }
2999 }
3000 \f
3001 /* Check for cases where a clr insns can be omitted from code using
3002 strict_low_part sets. For example, the second clrl here is not needed:
3003 clrl d0; movw a0@+,d0; use d0; clrl d0; movw a0@+; use d0; ...
3004
3005 MODE is the mode of this STRICT_LOW_PART set. FIRST_INSN is the clear
3006 insn we are checking for redundancy. TARGET is the register set by the
3007 clear insn. */
3008
3009 bool
3010 strict_low_part_peephole_ok (enum machine_mode mode, rtx first_insn,
3011 rtx target)
3012 {
3013 rtx p;
3014
3015 p = prev_nonnote_insn (first_insn);
3016
3017 while (p)
3018 {
3019 /* If it isn't an insn, then give up. */
3020 if (GET_CODE (p) != INSN)
3021 return false;
3022
3023 if (reg_set_p (target, p))
3024 {
3025 rtx set = single_set (p);
3026 rtx dest;
3027
3028 /* If it isn't an easy to recognize insn, then give up. */
3029 if (! set)
3030 return false;
3031
3032 dest = SET_DEST (set);
3033
3034 /* If this sets the entire target register to zero, then our
3035 first_insn is redundant. */
3036 if (rtx_equal_p (dest, target)
3037 && SET_SRC (set) == const0_rtx)
3038 return true;
3039 else if (GET_CODE (dest) == STRICT_LOW_PART
3040 && GET_CODE (XEXP (dest, 0)) == REG
3041 && REGNO (XEXP (dest, 0)) == REGNO (target)
3042 && (GET_MODE_SIZE (GET_MODE (XEXP (dest, 0)))
3043 <= GET_MODE_SIZE (mode)))
3044 /* This is a strict low part set which modifies less than
3045 we are using, so it is safe. */
3046 ;
3047 else
3048 return false;
3049 }
3050
3051 p = prev_nonnote_insn (p);
3052 }
3053
3054 return false;
3055 }
3056
3057 /* Operand predicates for implementing asymmetric pc-relative addressing
3058 on m68k. The m68k supports pc-relative addressing (mode 7, register 2)
3059 when used as a source operand, but not as a destination operand.
3060
3061 We model this by restricting the meaning of the basic predicates
3062 (general_operand, memory_operand, etc) to forbid the use of this
3063 addressing mode, and then define the following predicates that permit
3064 this addressing mode. These predicates can then be used for the
3065 source operands of the appropriate instructions.
3066
3067 n.b. While it is theoretically possible to change all machine patterns
3068 to use this addressing more where permitted by the architecture,
3069 it has only been implemented for "common" cases: SImode, HImode, and
3070 QImode operands, and only for the principle operations that would
3071 require this addressing mode: data movement and simple integer operations.
3072
3073 In parallel with these new predicates, two new constraint letters
3074 were defined: 'S' and 'T'. 'S' is the -mpcrel analog of 'm'.
3075 'T' replaces 's' in the non-pcrel case. It is a no-op in the pcrel case.
3076 In the pcrel case 's' is only valid in combination with 'a' registers.
3077 See addsi3, subsi3, cmpsi, and movsi patterns for a better understanding
3078 of how these constraints are used.
3079
3080 The use of these predicates is strictly optional, though patterns that
3081 don't will cause an extra reload register to be allocated where one
3082 was not necessary:
3083
3084 lea (abc:w,%pc),%a0 ; need to reload address
3085 moveq &1,%d1 ; since write to pc-relative space
3086 movel %d1,%a0@ ; is not allowed
3087 ...
3088 lea (abc:w,%pc),%a1 ; no need to reload address here
3089 movel %a1@,%d0 ; since "movel (abc:w,%pc),%d0" is ok
3090
3091 For more info, consult tiemann@cygnus.com.
3092
3093
3094 All of the ugliness with predicates and constraints is due to the
3095 simple fact that the m68k does not allow a pc-relative addressing
3096 mode as a destination. gcc does not distinguish between source and
3097 destination addresses. Hence, if we claim that pc-relative address
3098 modes are valid, e.g. GO_IF_LEGITIMATE_ADDRESS accepts them, then we
3099 end up with invalid code. To get around this problem, we left
3100 pc-relative modes as invalid addresses, and then added special
3101 predicates and constraints to accept them.
3102
3103 A cleaner way to handle this is to modify gcc to distinguish
3104 between source and destination addresses. We can then say that
3105 pc-relative is a valid source address but not a valid destination
3106 address, and hopefully avoid a lot of the predicate and constraint
3107 hackery. Unfortunately, this would be a pretty big change. It would
3108 be a useful change for a number of ports, but there aren't any current
3109 plans to undertake this.
3110
3111 ***************************************************************************/
3112
3113
3114 const char *
3115 output_andsi3 (rtx *operands)
3116 {
3117 int logval;
3118 if (GET_CODE (operands[2]) == CONST_INT
3119 && (INTVAL (operands[2]) | 0xffff) == -1
3120 && (DATA_REG_P (operands[0])
3121 || offsettable_memref_p (operands[0]))
3122 && !TARGET_COLDFIRE)
3123 {
3124 if (GET_CODE (operands[0]) != REG)
3125 operands[0] = adjust_address (operands[0], HImode, 2);
3126 operands[2] = GEN_INT (INTVAL (operands[2]) & 0xffff);
3127 /* Do not delete a following tstl %0 insn; that would be incorrect. */
3128 CC_STATUS_INIT;
3129 if (operands[2] == const0_rtx)
3130 return "clr%.w %0";
3131 return "and%.w %2,%0";
3132 }
3133 if (GET_CODE (operands[2]) == CONST_INT
3134 && (logval = exact_log2 (~ INTVAL (operands[2]))) >= 0
3135 && (DATA_REG_P (operands[0])
3136 || offsettable_memref_p (operands[0])))
3137 {
3138 if (DATA_REG_P (operands[0]))
3139 operands[1] = GEN_INT (logval);
3140 else
3141 {
3142 operands[0] = adjust_address (operands[0], SImode, 3 - (logval / 8));
3143 operands[1] = GEN_INT (logval % 8);
3144 }
3145 /* This does not set condition codes in a standard way. */
3146 CC_STATUS_INIT;
3147 return "bclr %1,%0";
3148 }
3149 return "and%.l %2,%0";
3150 }
3151
3152 const char *
3153 output_iorsi3 (rtx *operands)
3154 {
3155 register int logval;
3156 if (GET_CODE (operands[2]) == CONST_INT
3157 && INTVAL (operands[2]) >> 16 == 0
3158 && (DATA_REG_P (operands[0])
3159 || offsettable_memref_p (operands[0]))
3160 && !TARGET_COLDFIRE)
3161 {
3162 if (GET_CODE (operands[0]) != REG)
3163 operands[0] = adjust_address (operands[0], HImode, 2);
3164 /* Do not delete a following tstl %0 insn; that would be incorrect. */
3165 CC_STATUS_INIT;
3166 if (INTVAL (operands[2]) == 0xffff)
3167 return "mov%.w %2,%0";
3168 return "or%.w %2,%0";
3169 }
3170 if (GET_CODE (operands[2]) == CONST_INT
3171 && (logval = exact_log2 (INTVAL (operands[2]))) >= 0
3172 && (DATA_REG_P (operands[0])
3173 || offsettable_memref_p (operands[0])))
3174 {
3175 if (DATA_REG_P (operands[0]))
3176 operands[1] = GEN_INT (logval);
3177 else
3178 {
3179 operands[0] = adjust_address (operands[0], SImode, 3 - (logval / 8));
3180 operands[1] = GEN_INT (logval % 8);
3181 }
3182 CC_STATUS_INIT;
3183 return "bset %1,%0";
3184 }
3185 return "or%.l %2,%0";
3186 }
3187
3188 const char *
3189 output_xorsi3 (rtx *operands)
3190 {
3191 register int logval;
3192 if (GET_CODE (operands[2]) == CONST_INT
3193 && INTVAL (operands[2]) >> 16 == 0
3194 && (offsettable_memref_p (operands[0]) || DATA_REG_P (operands[0]))
3195 && !TARGET_COLDFIRE)
3196 {
3197 if (! DATA_REG_P (operands[0]))
3198 operands[0] = adjust_address (operands[0], HImode, 2);
3199 /* Do not delete a following tstl %0 insn; that would be incorrect. */
3200 CC_STATUS_INIT;
3201 if (INTVAL (operands[2]) == 0xffff)
3202 return "not%.w %0";
3203 return "eor%.w %2,%0";
3204 }
3205 if (GET_CODE (operands[2]) == CONST_INT
3206 && (logval = exact_log2 (INTVAL (operands[2]))) >= 0
3207 && (DATA_REG_P (operands[0])
3208 || offsettable_memref_p (operands[0])))
3209 {
3210 if (DATA_REG_P (operands[0]))
3211 operands[1] = GEN_INT (logval);
3212 else
3213 {
3214 operands[0] = adjust_address (operands[0], SImode, 3 - (logval / 8));
3215 operands[1] = GEN_INT (logval % 8);
3216 }
3217 CC_STATUS_INIT;
3218 return "bchg %1,%0";
3219 }
3220 return "eor%.l %2,%0";
3221 }
3222
3223 #ifdef M68K_TARGET_COFF
3224
3225 /* Output assembly to switch to section NAME with attribute FLAGS. */
3226
3227 static void
3228 m68k_coff_asm_named_section (const char *name, unsigned int flags,
3229 tree decl ATTRIBUTE_UNUSED)
3230 {
3231 char flagchar;
3232
3233 if (flags & SECTION_WRITE)
3234 flagchar = 'd';
3235 else
3236 flagchar = 'x';
3237
3238 fprintf (asm_out_file, "\t.section\t%s,\"%c\"\n", name, flagchar);
3239 }
3240
3241 #endif /* M68K_TARGET_COFF */
3242
3243 static void
3244 m68k_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED,
3245 HOST_WIDE_INT delta,
3246 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
3247 tree function)
3248 {
3249 rtx xops[1];
3250 const char *fmt;
3251
3252 if (delta > 0 && delta <= 8)
3253 asm_fprintf (file, (MOTOROLA
3254 ? "\taddq.l %I%d,4(%Rsp)\n"
3255 : "\taddql %I%d,%Rsp@(4)\n"),
3256 (int) delta);
3257 else if (delta < 0 && delta >= -8)
3258 asm_fprintf (file, (MOTOROLA
3259 ? "\tsubq.l %I%d,4(%Rsp)\n"
3260 : "\tsubql %I%d,%Rsp@(4)\n"),
3261 (int) -delta);
3262 else if (TARGET_COLDFIRE)
3263 {
3264 /* ColdFire can't add/sub a constant to memory unless it is in
3265 the range of addq/subq. So load the value into %d0 and
3266 then add it to 4(%sp). */
3267 if (delta >= -128 && delta <= 127)
3268 asm_fprintf (file, (MOTOROLA
3269 ? "\tmoveq.l %I%wd,%Rd0\n"
3270 : "\tmoveql %I%wd,%Rd0\n"),
3271 delta);
3272 else
3273 asm_fprintf (file, (MOTOROLA
3274 ? "\tmove.l %I%wd,%Rd0\n"
3275 : "\tmovel %I%wd,%Rd0\n"),
3276 delta);
3277 asm_fprintf (file, (MOTOROLA
3278 ? "\tadd.l %Rd0,4(%Rsp)\n"
3279 : "\taddl %Rd0,%Rsp@(4)\n"));
3280 }
3281 else
3282 asm_fprintf (file, (MOTOROLA
3283 ? "\tadd.l %I%wd,4(%Rsp)\n"
3284 : "\taddl %I%wd,%Rsp@(4)\n"),
3285 delta);
3286
3287 xops[0] = DECL_RTL (function);
3288
3289 /* Logic taken from call patterns in m68k.md. */
3290 if (flag_pic)
3291 {
3292 if (TARGET_PCREL)
3293 fmt = "bra.l %o0";
3294 else if (flag_pic == 1 || TARGET_68020)
3295 {
3296 if (MOTOROLA)
3297 {
3298 #if defined (USE_GAS)
3299 fmt = "bra.l %0@PLTPC";
3300 #else
3301 fmt = "bra %0@PLTPC";
3302 #endif
3303 }
3304 else /* !MOTOROLA */
3305 {
3306 #ifdef USE_GAS
3307 fmt = "bra.l %0";
3308 #else
3309 fmt = "jra %0,a1";
3310 #endif
3311 }
3312 }
3313 else if (optimize_size || TARGET_ID_SHARED_LIBRARY)
3314 fmt = "move.l %0@GOT(%%a5), %%a1\n\tjmp (%%a1)";
3315 else
3316 fmt = "lea %0-.-8,%%a1\n\tjsr 0(%%pc,%%a1)";
3317 }
3318 else
3319 {
3320 #if MOTOROLA && !defined (USE_GAS)
3321 fmt = "jmp %0";
3322 #else
3323 fmt = "jra %0";
3324 #endif
3325 }
3326
3327 output_asm_insn (fmt, xops);
3328 }
3329
3330 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
3331
3332 static rtx
3333 m68k_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
3334 int incoming ATTRIBUTE_UNUSED)
3335 {
3336 return gen_rtx_REG (Pmode, M68K_STRUCT_VALUE_REGNUM);
3337 }
3338
3339 /* Return nonzero if register old_reg can be renamed to register new_reg. */
3340 int
3341 m68k_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED,
3342 unsigned int new_reg)
3343 {
3344
3345 /* Interrupt functions can only use registers that have already been
3346 saved by the prologue, even if they would normally be
3347 call-clobbered. */
3348
3349 if (m68k_interrupt_function_p (current_function_decl)
3350 && !regs_ever_live[new_reg])
3351 return 0;
3352
3353 return 1;
3354 }
3355
3356 /* Value is true if hard register REGNO can hold a value of machine-mode MODE.
3357 On the 68000, the cpu registers can hold any mode except bytes in address
3358 registers, but the 68881 registers can hold only SFmode or DFmode. */
3359 bool
3360 m68k_regno_mode_ok (int regno, enum machine_mode mode)
3361 {
3362 if (regno < 8)
3363 {
3364 /* Data Registers, can hold aggregate if fits in. */
3365 if (regno + GET_MODE_SIZE (mode) / 4 <= 8)
3366 return true;
3367 }
3368 else if (regno < 16)
3369 {
3370 /* Address Registers, can't hold bytes, can hold aggregate if
3371 fits in. */
3372 if (GET_MODE_SIZE (mode) == 1)
3373 return false;
3374 if (regno + GET_MODE_SIZE (mode) / 4 <= 16)
3375 return true;
3376 }
3377 else if (regno < 24)
3378 {
3379 /* FPU registers, hold float or complex float of long double or
3380 smaller. */
3381 if ((GET_MODE_CLASS (mode) == MODE_FLOAT
3382 || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
3383 && GET_MODE_UNIT_SIZE (mode) <= 12)
3384 return true;
3385 }
3386 return false;
3387 }