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