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