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