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