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