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