OSDN Git Service

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