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