]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/pdp11/pdp11.c
Remove LIBGCC2_HAS_?F_MODE target macros.
[thirdparty/gcc.git] / gcc / config / pdp11 / pdp11.c
1 /* Subroutines for gcc2 for pdp11.
2 Copyright (C) 1994-2014 Free Software Foundation, Inc.
3 Contributed by Michael K. Gschwind (mike@vlsivie.tuwien.ac.at).
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "rtl.h"
26 #include "regs.h"
27 #include "hard-reg-set.h"
28 #include "insn-config.h"
29 #include "conditions.h"
30 #include "function.h"
31 #include "output.h"
32 #include "insn-attr.h"
33 #include "flags.h"
34 #include "recog.h"
35 #include "tree.h"
36 #include "stor-layout.h"
37 #include "varasm.h"
38 #include "calls.h"
39 #include "expr.h"
40 #include "diagnostic-core.h"
41 #include "tm_p.h"
42 #include "target.h"
43 #include "target-def.h"
44 #include "df.h"
45 #include "opts.h"
46 #include "dbxout.h"
47 #include "builtins.h"
48
49 /* this is the current value returned by the macro FIRST_PARM_OFFSET
50 defined in tm.h */
51 int current_first_parm_offset;
52
53 /* Routines to encode/decode pdp11 floats */
54 static void encode_pdp11_f (const struct real_format *fmt,
55 long *, const REAL_VALUE_TYPE *);
56 static void decode_pdp11_f (const struct real_format *,
57 REAL_VALUE_TYPE *, const long *);
58 static void encode_pdp11_d (const struct real_format *fmt,
59 long *, const REAL_VALUE_TYPE *);
60 static void decode_pdp11_d (const struct real_format *,
61 REAL_VALUE_TYPE *, const long *);
62
63 /* These two are taken from the corresponding vax descriptors
64 in real.c, changing only the encode/decode routine pointers. */
65 const struct real_format pdp11_f_format =
66 {
67 encode_pdp11_f,
68 decode_pdp11_f,
69 2,
70 24,
71 24,
72 -127,
73 127,
74 15,
75 15,
76 false,
77 false,
78 false,
79 false,
80 false,
81 false,
82 false,
83 false
84 };
85
86 const struct real_format pdp11_d_format =
87 {
88 encode_pdp11_d,
89 decode_pdp11_d,
90 2,
91 56,
92 56,
93 -127,
94 127,
95 15,
96 15,
97 false,
98 false,
99 false,
100 false,
101 false,
102 false,
103 false,
104 false
105 };
106
107 static void
108 encode_pdp11_f (const struct real_format *fmt ATTRIBUTE_UNUSED, long *buf,
109 const REAL_VALUE_TYPE *r)
110 {
111 (*vax_f_format.encode) (fmt, buf, r);
112 buf[0] = ((buf[0] >> 16) & 0xffff) | ((buf[0] & 0xffff) << 16);
113 }
114
115 static void
116 decode_pdp11_f (const struct real_format *fmt ATTRIBUTE_UNUSED,
117 REAL_VALUE_TYPE *r, const long *buf)
118 {
119 long tbuf;
120 tbuf = ((buf[0] >> 16) & 0xffff) | ((buf[0] & 0xffff) << 16);
121 (*vax_f_format.decode) (fmt, r, &tbuf);
122 }
123
124 static void
125 encode_pdp11_d (const struct real_format *fmt ATTRIBUTE_UNUSED, long *buf,
126 const REAL_VALUE_TYPE *r)
127 {
128 (*vax_d_format.encode) (fmt, buf, r);
129 buf[0] = ((buf[0] >> 16) & 0xffff) | ((buf[0] & 0xffff) << 16);
130 buf[1] = ((buf[1] >> 16) & 0xffff) | ((buf[1] & 0xffff) << 16);
131 }
132
133 static void
134 decode_pdp11_d (const struct real_format *fmt ATTRIBUTE_UNUSED,
135 REAL_VALUE_TYPE *r, const long *buf)
136 {
137 long tbuf[2];
138 tbuf[0] = ((buf[0] >> 16) & 0xffff) | ((buf[0] & 0xffff) << 16);
139 tbuf[1] = ((buf[1] >> 16) & 0xffff) | ((buf[1] & 0xffff) << 16);
140 (*vax_d_format.decode) (fmt, r, tbuf);
141 }
142
143 /* This is where the condition code register lives. */
144 /* rtx cc0_reg_rtx; - no longer needed? */
145
146 static const char *singlemove_string (rtx *);
147 static bool pdp11_assemble_integer (rtx, unsigned int, int);
148 static bool pdp11_rtx_costs (rtx, int, int, int, int *, bool);
149 static bool pdp11_return_in_memory (const_tree, const_tree);
150 static rtx pdp11_function_value (const_tree, const_tree, bool);
151 static rtx pdp11_libcall_value (enum machine_mode, const_rtx);
152 static bool pdp11_function_value_regno_p (const unsigned int);
153 static void pdp11_trampoline_init (rtx, tree, rtx);
154 static rtx pdp11_function_arg (cumulative_args_t, enum machine_mode,
155 const_tree, bool);
156 static void pdp11_function_arg_advance (cumulative_args_t,
157 enum machine_mode, const_tree, bool);
158 static void pdp11_conditional_register_usage (void);
159 static bool pdp11_legitimate_constant_p (enum machine_mode, rtx);
160
161 static bool pdp11_scalar_mode_supported_p (enum machine_mode);
162 \f
163 /* Initialize the GCC target structure. */
164 #undef TARGET_ASM_BYTE_OP
165 #define TARGET_ASM_BYTE_OP NULL
166 #undef TARGET_ASM_ALIGNED_HI_OP
167 #define TARGET_ASM_ALIGNED_HI_OP NULL
168 #undef TARGET_ASM_ALIGNED_SI_OP
169 #define TARGET_ASM_ALIGNED_SI_OP NULL
170 #undef TARGET_ASM_INTEGER
171 #define TARGET_ASM_INTEGER pdp11_assemble_integer
172
173 #undef TARGET_ASM_OPEN_PAREN
174 #define TARGET_ASM_OPEN_PAREN "["
175 #undef TARGET_ASM_CLOSE_PAREN
176 #define TARGET_ASM_CLOSE_PAREN "]"
177
178 #undef TARGET_RTX_COSTS
179 #define TARGET_RTX_COSTS pdp11_rtx_costs
180
181 #undef TARGET_FUNCTION_ARG
182 #define TARGET_FUNCTION_ARG pdp11_function_arg
183 #undef TARGET_FUNCTION_ARG_ADVANCE
184 #define TARGET_FUNCTION_ARG_ADVANCE pdp11_function_arg_advance
185
186 #undef TARGET_RETURN_IN_MEMORY
187 #define TARGET_RETURN_IN_MEMORY pdp11_return_in_memory
188
189 #undef TARGET_FUNCTION_VALUE
190 #define TARGET_FUNCTION_VALUE pdp11_function_value
191 #undef TARGET_LIBCALL_VALUE
192 #define TARGET_LIBCALL_VALUE pdp11_libcall_value
193 #undef TARGET_FUNCTION_VALUE_REGNO_P
194 #define TARGET_FUNCTION_VALUE_REGNO_P pdp11_function_value_regno_p
195
196 #undef TARGET_TRAMPOLINE_INIT
197 #define TARGET_TRAMPOLINE_INIT pdp11_trampoline_init
198
199 #undef TARGET_SECONDARY_RELOAD
200 #define TARGET_SECONDARY_RELOAD pdp11_secondary_reload
201
202 #undef TARGET_REGISTER_MOVE_COST
203 #define TARGET_REGISTER_MOVE_COST pdp11_register_move_cost
204
205 #undef TARGET_PREFERRED_RELOAD_CLASS
206 #define TARGET_PREFERRED_RELOAD_CLASS pdp11_preferred_reload_class
207
208 #undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
209 #define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS pdp11_preferred_output_reload_class
210
211 #undef TARGET_LEGITIMATE_ADDRESS_P
212 #define TARGET_LEGITIMATE_ADDRESS_P pdp11_legitimate_address_p
213
214 #undef TARGET_CONDITIONAL_REGISTER_USAGE
215 #define TARGET_CONDITIONAL_REGISTER_USAGE pdp11_conditional_register_usage
216
217 #undef TARGET_ASM_FUNCTION_SECTION
218 #define TARGET_ASM_FUNCTION_SECTION pdp11_function_section
219
220 #undef TARGET_PRINT_OPERAND
221 #define TARGET_PRINT_OPERAND pdp11_asm_print_operand
222
223 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
224 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P pdp11_asm_print_operand_punct_valid_p
225
226 #undef TARGET_LEGITIMATE_CONSTANT_P
227 #define TARGET_LEGITIMATE_CONSTANT_P pdp11_legitimate_constant_p
228
229 #undef TARGET_SCALAR_MODE_SUPPORTED_P
230 #define TARGET_SCALAR_MODE_SUPPORTED_P pdp11_scalar_mode_supported_p
231 \f
232 /* A helper function to determine if REGNO should be saved in the
233 current function's stack frame. */
234
235 static inline bool
236 pdp11_saved_regno (unsigned regno)
237 {
238 return !call_used_regs[regno] && df_regs_ever_live_p (regno);
239 }
240
241 /* Expand the function prologue. */
242
243 void
244 pdp11_expand_prologue (void)
245 {
246 HOST_WIDE_INT fsize = get_frame_size ();
247 unsigned regno;
248 rtx x, via_ac = NULL;
249
250 /* If we are outputting code for main, the switch FPU to the
251 right mode if TARGET_FPU. */
252 if (MAIN_NAME_P (DECL_NAME (current_function_decl)) && TARGET_FPU)
253 {
254 emit_insn (gen_setd ());
255 emit_insn (gen_seti ());
256 }
257
258 if (frame_pointer_needed)
259 {
260 x = gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx);
261 x = gen_frame_mem (Pmode, x);
262 emit_move_insn (x, hard_frame_pointer_rtx);
263
264 emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
265 }
266
267 /* Make frame. */
268 if (fsize)
269 {
270 emit_insn (gen_addhi3 (stack_pointer_rtx, stack_pointer_rtx,
271 GEN_INT (-fsize)));
272
273 /* Prevent frame references via the frame pointer from being
274 scheduled before the frame is allocated. */
275 if (frame_pointer_needed)
276 emit_insn (gen_blockage ());
277 }
278
279 /* Save CPU registers. */
280 for (regno = R0_REGNUM; regno <= PC_REGNUM; regno++)
281 if (pdp11_saved_regno (regno)
282 && (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed))
283 {
284 x = gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx);
285 x = gen_frame_mem (Pmode, x);
286 emit_move_insn (x, gen_rtx_REG (Pmode, regno));
287 }
288
289 /* Save FPU registers. */
290 for (regno = AC0_REGNUM; regno <= AC3_REGNUM; regno++)
291 if (pdp11_saved_regno (regno))
292 {
293 x = gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx);
294 x = gen_frame_mem (DFmode, x);
295 via_ac = gen_rtx_REG (DFmode, regno);
296 emit_move_insn (x, via_ac);
297 }
298
299 /* ??? Maybe make ac4, ac5 call used regs?? */
300 for (regno = AC4_REGNUM; regno <= AC5_REGNUM; regno++)
301 if (pdp11_saved_regno (regno))
302 {
303 gcc_assert (via_ac != NULL);
304 emit_move_insn (via_ac, gen_rtx_REG (DFmode, regno));
305
306 x = gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx);
307 x = gen_frame_mem (DFmode, x);
308 emit_move_insn (x, via_ac);
309 }
310 }
311
312 /* The function epilogue should not depend on the current stack pointer!
313 It should use the frame pointer only. This is mandatory because
314 of alloca; we also take advantage of it to omit stack adjustments
315 before returning. */
316
317 /* Maybe we can make leaf functions faster by switching to the
318 second register file - this way we don't have to save regs!
319 leaf functions are ~ 50% of all functions (dynamically!)
320
321 set/clear bit 11 (dec. 2048) of status word for switching register files -
322 but how can we do this? the pdp11/45 manual says bit may only
323 be set (p.24), but not cleared!
324
325 switching to kernel is probably more expensive, so we'll leave it
326 like this and not use the second set of registers...
327
328 maybe as option if you want to generate code for kernel mode? */
329
330 void
331 pdp11_expand_epilogue (void)
332 {
333 HOST_WIDE_INT fsize = get_frame_size ();
334 unsigned regno;
335 rtx x, reg, via_ac = NULL;
336
337 if (pdp11_saved_regno (AC4_REGNUM) || pdp11_saved_regno (AC5_REGNUM))
338 {
339 /* Find a temporary with which to restore AC4/5. */
340 for (regno = AC0_REGNUM; regno <= AC3_REGNUM; regno++)
341 if (pdp11_saved_regno (regno))
342 {
343 via_ac = gen_rtx_REG (DFmode, regno);
344 break;
345 }
346 }
347
348 /* If possible, restore registers via pops. */
349 if (!frame_pointer_needed || crtl->sp_is_unchanging)
350 {
351 /* Restore registers via pops. */
352
353 for (regno = AC5_REGNUM; regno >= AC0_REGNUM; regno--)
354 if (pdp11_saved_regno (regno))
355 {
356 x = gen_rtx_POST_INC (Pmode, stack_pointer_rtx);
357 x = gen_frame_mem (DFmode, x);
358 reg = gen_rtx_REG (DFmode, regno);
359
360 if (LOAD_FPU_REG_P (regno))
361 emit_move_insn (reg, x);
362 else
363 {
364 emit_move_insn (via_ac, x);
365 emit_move_insn (reg, via_ac);
366 }
367 }
368
369 for (regno = PC_REGNUM; regno >= R0_REGNUM + 2; regno--)
370 if (pdp11_saved_regno (regno)
371 && (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed))
372 {
373 x = gen_rtx_POST_INC (Pmode, stack_pointer_rtx);
374 x = gen_frame_mem (Pmode, x);
375 emit_move_insn (gen_rtx_REG (Pmode, regno), x);
376 }
377 }
378 else
379 {
380 /* Restore registers via moves. */
381 /* ??? If more than a few registers need to be restored, it's smaller
382 to generate a pointer through which we can emit pops. Consider
383 that moves cost 2*NREG words and pops cost NREG+3 words. This
384 means that the crossover is NREG=3.
385
386 Possible registers to use are:
387 (1) The first call-saved general register. This register will
388 be restored with the last pop.
389 (2) R1, if it's not used as a return register.
390 (3) FP itself. This option may result in +4 words, since we
391 may need two add imm,rn instructions instead of just one.
392 This also has the downside that we're not representing
393 the unwind info in any way, so during the epilogue the
394 debugger may get lost. */
395
396 HOST_WIDE_INT ofs = -pdp11_sp_frame_offset ();
397
398 for (regno = AC5_REGNUM; regno >= AC0_REGNUM; regno--)
399 if (pdp11_saved_regno (regno))
400 {
401 x = plus_constant (Pmode, hard_frame_pointer_rtx, ofs);
402 x = gen_frame_mem (DFmode, x);
403 reg = gen_rtx_REG (DFmode, regno);
404
405 if (LOAD_FPU_REG_P (regno))
406 emit_move_insn (reg, x);
407 else
408 {
409 emit_move_insn (via_ac, x);
410 emit_move_insn (reg, via_ac);
411 }
412 ofs += 8;
413 }
414
415 for (regno = PC_REGNUM; regno >= R0_REGNUM + 2; regno--)
416 if (pdp11_saved_regno (regno)
417 && (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed))
418 {
419 x = plus_constant (Pmode, hard_frame_pointer_rtx, ofs);
420 x = gen_frame_mem (Pmode, x);
421 emit_move_insn (gen_rtx_REG (Pmode, regno), x);
422 ofs += 2;
423 }
424 }
425
426 /* Deallocate the stack frame. */
427 if (fsize)
428 {
429 /* Prevent frame references via any pointer from being
430 scheduled after the frame is deallocated. */
431 emit_insn (gen_blockage ());
432
433 if (frame_pointer_needed)
434 {
435 /* We can deallocate the frame with a single move. */
436 emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx);
437 }
438 else
439 emit_insn (gen_addhi3 (stack_pointer_rtx, stack_pointer_rtx,
440 GEN_INT (fsize)));
441 }
442
443 if (frame_pointer_needed)
444 {
445 x = gen_rtx_POST_INC (Pmode, stack_pointer_rtx);
446 x = gen_frame_mem (Pmode, x);
447 emit_move_insn (hard_frame_pointer_rtx, x);
448 }
449
450 emit_jump_insn (gen_return ());
451 }
452
453 /* Return the best assembler insn template
454 for moving operands[1] into operands[0] as a fullword. */
455 static const char *
456 singlemove_string (rtx *operands)
457 {
458 if (operands[1] != const0_rtx)
459 return "mov %1,%0";
460
461 return "clr %0";
462 }
463
464 \f
465 /* Expand multi-word operands (SImode or DImode) into the 2 or 4
466 corresponding HImode operands. The number of operands is given
467 as the third argument, and the required order of the parts as
468 the fourth argument. */
469 bool
470 pdp11_expand_operands (rtx *operands, rtx exops[][2], int opcount,
471 pdp11_action *action, pdp11_partorder order)
472 {
473 int words, op, w, i, sh;
474 pdp11_partorder useorder;
475 bool sameoff = false;
476 enum { REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP } optype;
477 REAL_VALUE_TYPE r;
478 long sval[2];
479
480 words = GET_MODE_BITSIZE (GET_MODE (operands[0])) / 16;
481
482 /* If either piece order is accepted and one is pre-decrement
483 while the other is post-increment, set order to be high order
484 word first. That will force the pre-decrement to be turned
485 into a pointer adjust, then offset addressing.
486 Otherwise, if either operand uses pre-decrement, that means
487 the order is low order first.
488 Otherwise, if both operands are registers and destination is
489 higher than source and they overlap, do low order word (highest
490 register number) first. */
491 useorder = either;
492 if (opcount == 2)
493 {
494 if (!REG_P (operands[0]) && !REG_P (operands[1]) &&
495 !(CONSTANT_P (operands[1]) ||
496 GET_CODE (operands[1]) == CONST_DOUBLE) &&
497 ((GET_CODE (XEXP (operands[0], 0)) == POST_INC &&
498 GET_CODE (XEXP (operands[1], 0)) == PRE_DEC) ||
499 (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC &&
500 GET_CODE (XEXP (operands[1], 0)) == POST_INC)))
501 useorder = big;
502 else if ((!REG_P (operands[0]) &&
503 GET_CODE (XEXP (operands[0], 0)) == PRE_DEC) ||
504 (!REG_P (operands[1]) &&
505 !(CONSTANT_P (operands[1]) ||
506 GET_CODE (operands[1]) == CONST_DOUBLE) &&
507 GET_CODE (XEXP (operands[1], 0)) == PRE_DEC))
508 useorder = little;
509 else if (REG_P (operands[0]) && REG_P (operands[1]) &&
510 REGNO (operands[0]) > REGNO (operands[1]) &&
511 REGNO (operands[0]) < REGNO (operands[1]) + words)
512 useorder = little;
513
514 /* Check for source == offset from register and dest == push of
515 the same register. In that case, we have to use the same
516 offset (the one for the low order word) for all words, because
517 the push increases the offset to each source word.
518 In theory there are other cases like this, for example dest == pop,
519 but those don't occur in real life so ignore those. */
520 if (GET_CODE (operands[0]) == MEM
521 && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
522 && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM
523 && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
524 sameoff = true;
525 }
526
527 /* If the caller didn't specify order, use the one we computed,
528 or high word first if we don't care either. If the caller did
529 specify, verify we don't have a problem with that order.
530 (If it matters to the caller, constraints need to be used to
531 ensure this case doesn't occur). */
532 if (order == either)
533 order = (useorder == either) ? big : useorder;
534 else
535 gcc_assert (useorder == either || useorder == order);
536
537
538 for (op = 0; op < opcount; op++)
539 {
540 /* First classify the operand. */
541 if (REG_P (operands[op]))
542 optype = REGOP;
543 else if (CONSTANT_P (operands[op])
544 || GET_CODE (operands[op]) == CONST_DOUBLE)
545 optype = CNSTOP;
546 else if (GET_CODE (XEXP (operands[op], 0)) == POST_INC)
547 optype = POPOP;
548 else if (GET_CODE (XEXP (operands[op], 0)) == PRE_DEC)
549 optype = PUSHOP;
550 else if (!reload_in_progress || offsettable_memref_p (operands[op]))
551 optype = OFFSOP;
552 else if (GET_CODE (operands[op]) == MEM)
553 optype = MEMOP;
554 else
555 optype = RNDOP;
556
557 /* Check for the cases that the operand constraints are not
558 supposed to allow to happen. Return failure for such cases. */
559 if (optype == RNDOP)
560 return false;
561
562 if (action != NULL)
563 action[op] = no_action;
564
565 /* If the operand uses pre-decrement addressing but we
566 want to get the parts high order first,
567 decrement the former register explicitly
568 and change the operand into ordinary indexing. */
569 if (optype == PUSHOP && order == big)
570 {
571 gcc_assert (action != NULL);
572 action[op] = dec_before;
573 operands[op] = gen_rtx_MEM (GET_MODE (operands[op]),
574 XEXP (XEXP (operands[op], 0), 0));
575 optype = OFFSOP;
576 }
577 /* If the operand uses post-increment mode but we want
578 to get the parts low order first, change the operand
579 into ordinary indexing and remember to increment
580 the register explicitly when we're done. */
581 else if (optype == POPOP && order == little)
582 {
583 gcc_assert (action != NULL);
584 action[op] = inc_after;
585 operands[op] = gen_rtx_MEM (GET_MODE (operands[op]),
586 XEXP (XEXP (operands[op], 0), 0));
587 optype = OFFSOP;
588 }
589
590 if (GET_CODE (operands[op]) == CONST_DOUBLE)
591 {
592 REAL_VALUE_FROM_CONST_DOUBLE (r, operands[op]);
593 REAL_VALUE_TO_TARGET_DOUBLE (r, sval);
594 }
595
596 for (i = 0; i < words; i++)
597 {
598 if (order == big)
599 w = i;
600 else if (sameoff)
601 w = words - 1;
602 else
603 w = words - 1 - i;
604
605 /* Set the output operand to be word "w" of the input. */
606 if (optype == REGOP)
607 exops[i][op] = gen_rtx_REG (HImode, REGNO (operands[op]) + w);
608 else if (optype == OFFSOP)
609 exops[i][op] = adjust_address (operands[op], HImode, w * 2);
610 else if (optype == CNSTOP)
611 {
612 if (GET_CODE (operands[op]) == CONST_DOUBLE)
613 {
614 sh = 16 - (w & 1) * 16;
615 exops[i][op] = gen_rtx_CONST_INT (HImode, (sval[w / 2] >> sh) & 0xffff);
616 }
617 else
618 {
619 sh = ((words - 1 - w) * 16);
620 exops[i][op] = gen_rtx_CONST_INT (HImode, trunc_int_for_mode (INTVAL(operands[op]) >> sh, HImode));
621 }
622 }
623 else
624 exops[i][op] = operands[op];
625 }
626 }
627 return true;
628 }
629
630 /* Output assembler code to perform a multiple-word move insn
631 with operands OPERANDS. This moves 2 or 4 words depending
632 on the machine mode of the operands. */
633
634 const char *
635 output_move_multiple (rtx *operands)
636 {
637 rtx exops[4][2];
638 pdp11_action action[2];
639 int i, words;
640
641 words = GET_MODE_BITSIZE (GET_MODE (operands[0])) / 16;
642
643 pdp11_expand_operands (operands, exops, 2, action, either);
644
645 /* Check for explicit decrement before. */
646 if (action[0] == dec_before)
647 {
648 operands[0] = XEXP (operands[0], 0);
649 output_asm_insn ("sub $4,%0", operands);
650 }
651 if (action[1] == dec_before)
652 {
653 operands[1] = XEXP (operands[1], 0);
654 output_asm_insn ("sub $4,%1", operands);
655 }
656
657 /* Do the words. */
658 for (i = 0; i < words; i++)
659 output_asm_insn (singlemove_string (exops[i]), exops[i]);
660
661 /* Check for increment after. */
662 if (action[0] == inc_after)
663 {
664 operands[0] = XEXP (operands[0], 0);
665 output_asm_insn ("add $4,%0", operands);
666 }
667 if (action[1] == inc_after)
668 {
669 operands[1] = XEXP (operands[1], 0);
670 output_asm_insn ("add $4,%1", operands);
671 }
672
673 return "";
674 }
675 \f
676 /* Output an ascii string. */
677 void
678 output_ascii (FILE *file, const char *p, int size)
679 {
680 int i;
681
682 /* This used to output .byte "string", which doesn't work with the UNIX
683 assembler and I think not with DEC ones either. */
684 fprintf (file, "\t.byte ");
685
686 for (i = 0; i < size; i++)
687 {
688 register int c = p[i];
689 if (c < 0)
690 c += 256;
691 fprintf (file, "%#o", c);
692 if (i < size - 1)
693 putc (',', file);
694 }
695 putc ('\n', file);
696 }
697
698
699 void
700 pdp11_asm_output_var (FILE *file, const char *name, int size,
701 int align, bool global)
702 {
703 if (align > 8)
704 fprintf (file, "\n\t.even\n");
705 if (global)
706 {
707 fprintf (file, ".globl ");
708 assemble_name (file, name);
709 }
710 fprintf (file, "\n");
711 assemble_name (file, name);
712 fprintf (file, ": .=.+ %#ho\n", (unsigned short)size);
713 }
714
715 static void
716 pdp11_asm_print_operand (FILE *file, rtx x, int code)
717 {
718 REAL_VALUE_TYPE r;
719 long sval[2];
720
721 if (code == '#')
722 fprintf (file, "#");
723 else if (code == '@')
724 {
725 if (TARGET_UNIX_ASM)
726 fprintf (file, "*");
727 else
728 fprintf (file, "@");
729 }
730 else if (GET_CODE (x) == REG)
731 fprintf (file, "%s", reg_names[REGNO (x)]);
732 else if (GET_CODE (x) == MEM)
733 output_address (XEXP (x, 0));
734 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) != SImode)
735 {
736 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
737 REAL_VALUE_TO_TARGET_DOUBLE (r, sval);
738 fprintf (file, "$%#lo", sval[0] >> 16);
739 }
740 else
741 {
742 putc ('$', file);
743 output_addr_const_pdp11 (file, x);
744 }
745 }
746
747 static bool
748 pdp11_asm_print_operand_punct_valid_p (unsigned char c)
749 {
750 return (c == '#' || c == '@');
751 }
752
753 void
754 print_operand_address (FILE *file, register rtx addr)
755 {
756 register rtx breg;
757 rtx offset;
758 int again = 0;
759
760 retry:
761
762 switch (GET_CODE (addr))
763 {
764 case MEM:
765 if (TARGET_UNIX_ASM)
766 fprintf (file, "*");
767 else
768 fprintf (file, "@");
769 addr = XEXP (addr, 0);
770 again = 1;
771 goto retry;
772
773 case REG:
774 fprintf (file, "(%s)", reg_names[REGNO (addr)]);
775 break;
776
777 case PRE_MODIFY:
778 case PRE_DEC:
779 fprintf (file, "-(%s)", reg_names[REGNO (XEXP (addr, 0))]);
780 break;
781
782 case POST_MODIFY:
783 case POST_INC:
784 fprintf (file, "(%s)+", reg_names[REGNO (XEXP (addr, 0))]);
785 break;
786
787 case PLUS:
788 breg = 0;
789 offset = 0;
790 if (CONSTANT_ADDRESS_P (XEXP (addr, 0))
791 || GET_CODE (XEXP (addr, 0)) == MEM)
792 {
793 offset = XEXP (addr, 0);
794 addr = XEXP (addr, 1);
795 }
796 else if (CONSTANT_ADDRESS_P (XEXP (addr, 1))
797 || GET_CODE (XEXP (addr, 1)) == MEM)
798 {
799 offset = XEXP (addr, 1);
800 addr = XEXP (addr, 0);
801 }
802 if (GET_CODE (addr) != PLUS)
803 ;
804 else if (GET_CODE (XEXP (addr, 0)) == REG)
805 {
806 breg = XEXP (addr, 0);
807 addr = XEXP (addr, 1);
808 }
809 else if (GET_CODE (XEXP (addr, 1)) == REG)
810 {
811 breg = XEXP (addr, 1);
812 addr = XEXP (addr, 0);
813 }
814 if (GET_CODE (addr) == REG)
815 {
816 gcc_assert (breg == 0);
817 breg = addr;
818 addr = 0;
819 }
820 if (offset != 0)
821 {
822 gcc_assert (addr == 0);
823 addr = offset;
824 }
825 if (addr != 0)
826 output_addr_const_pdp11 (file, addr);
827 if (breg != 0)
828 {
829 gcc_assert (GET_CODE (breg) == REG);
830 fprintf (file, "(%s)", reg_names[REGNO (breg)]);
831 }
832 break;
833
834 default:
835 if (!again && GET_CODE (addr) == CONST_INT)
836 {
837 /* Absolute (integer number) address. */
838 if (!TARGET_UNIX_ASM)
839 fprintf (file, "@$");
840 }
841 output_addr_const_pdp11 (file, addr);
842 }
843 }
844
845 /* Target hook to assemble integer objects. We need to use the
846 pdp-specific version of output_addr_const. */
847
848 static bool
849 pdp11_assemble_integer (rtx x, unsigned int size, int aligned_p)
850 {
851 if (aligned_p)
852 switch (size)
853 {
854 case 1:
855 fprintf (asm_out_file, "\t.byte\t");
856 output_addr_const_pdp11 (asm_out_file, GEN_INT (INTVAL (x) & 0xff));
857 ;
858 fprintf (asm_out_file, " /* char */\n");
859 return true;
860
861 case 2:
862 fprintf (asm_out_file, TARGET_UNIX_ASM ? "\t" : "\t.word\t");
863 output_addr_const_pdp11 (asm_out_file, x);
864 fprintf (asm_out_file, " /* short */\n");
865 return true;
866 }
867 return default_assemble_integer (x, size, aligned_p);
868 }
869
870
871 /* register move costs, indexed by regs */
872
873 static const int move_costs[N_REG_CLASSES][N_REG_CLASSES] =
874 {
875 /* NO MUL GEN LFPU NLFPU FPU ALL */
876
877 /* NO */ { 0, 0, 0, 0, 0, 0, 0},
878 /* MUL */ { 0, 2, 2, 22, 22, 22, 22},
879 /* GEN */ { 0, 2, 2, 22, 22, 22, 22},
880 /* LFPU */ { 0, 22, 22, 2, 2, 2, 22},
881 /* NLFPU */ { 0, 22, 22, 2, 10, 10, 22},
882 /* FPU */ { 0, 22, 22, 2, 10, 10, 22},
883 /* ALL */ { 0, 22, 22, 22, 22, 22, 22}
884 } ;
885
886
887 /* -- note that some moves are tremendously expensive,
888 because they require lots of tricks! do we have to
889 charge the costs incurred by secondary reload class
890 -- as we do here with 10 -- or not ? */
891
892 static int
893 pdp11_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED,
894 reg_class_t c1, reg_class_t c2)
895 {
896 return move_costs[(int)c1][(int)c2];
897 }
898
899 static bool
900 pdp11_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED,
901 int opno ATTRIBUTE_UNUSED, int *total,
902 bool speed ATTRIBUTE_UNUSED)
903 {
904 switch (code)
905 {
906 case CONST_INT:
907 if (INTVAL (x) == 0 || INTVAL (x) == -1 || INTVAL (x) == 1)
908 {
909 *total = 0;
910 return true;
911 }
912 /* FALLTHRU */
913
914 case CONST:
915 case LABEL_REF:
916 case SYMBOL_REF:
917 /* Twice as expensive as REG. */
918 *total = 2;
919 return true;
920
921 case CONST_DOUBLE:
922 /* Twice (or 4 times) as expensive as 16 bit. */
923 *total = 4;
924 return true;
925
926 case MULT:
927 /* ??? There is something wrong in MULT because MULT is not
928 as cheap as total = 2 even if we can shift! */
929 /* If optimizing for size make mult etc cheap, but not 1, so when
930 in doubt the faster insn is chosen. */
931 if (optimize_size)
932 *total = COSTS_N_INSNS (2);
933 else
934 *total = COSTS_N_INSNS (11);
935 return false;
936
937 case DIV:
938 if (optimize_size)
939 *total = COSTS_N_INSNS (2);
940 else
941 *total = COSTS_N_INSNS (25);
942 return false;
943
944 case MOD:
945 if (optimize_size)
946 *total = COSTS_N_INSNS (2);
947 else
948 *total = COSTS_N_INSNS (26);
949 return false;
950
951 case ABS:
952 /* Equivalent to length, so same for optimize_size. */
953 *total = COSTS_N_INSNS (3);
954 return false;
955
956 case ZERO_EXTEND:
957 /* Only used for qi->hi. */
958 *total = COSTS_N_INSNS (1);
959 return false;
960
961 case SIGN_EXTEND:
962 if (GET_MODE (x) == HImode)
963 *total = COSTS_N_INSNS (1);
964 else if (GET_MODE (x) == SImode)
965 *total = COSTS_N_INSNS (6);
966 else
967 *total = COSTS_N_INSNS (2);
968 return false;
969
970 case ASHIFT:
971 case LSHIFTRT:
972 case ASHIFTRT:
973 if (optimize_size)
974 *total = COSTS_N_INSNS (1);
975 else if (GET_MODE (x) == QImode)
976 {
977 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
978 *total = COSTS_N_INSNS (8); /* worst case */
979 else
980 *total = COSTS_N_INSNS (INTVAL (XEXP (x, 1)));
981 }
982 else if (GET_MODE (x) == HImode)
983 {
984 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
985 {
986 if (abs (INTVAL (XEXP (x, 1))) == 1)
987 *total = COSTS_N_INSNS (1);
988 else
989 *total = COSTS_N_INSNS (2.5 + 0.5 * INTVAL (XEXP (x, 1)));
990 }
991 else
992 *total = COSTS_N_INSNS (10); /* worst case */
993 }
994 else if (GET_MODE (x) == SImode)
995 {
996 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
997 *total = COSTS_N_INSNS (2.5 + 0.5 * INTVAL (XEXP (x, 1)));
998 else /* worst case */
999 *total = COSTS_N_INSNS (18);
1000 }
1001 return false;
1002
1003 default:
1004 return false;
1005 }
1006 }
1007
1008 const char *
1009 output_jump (enum rtx_code code, int inv, int length)
1010 {
1011 static int x = 0;
1012
1013 static char buf[1000];
1014 const char *pos, *neg;
1015
1016 if (cc_prev_status.flags & CC_NO_OVERFLOW)
1017 {
1018 switch (code)
1019 {
1020 case GTU: code = GT; break;
1021 case LTU: code = LT; break;
1022 case GEU: code = GE; break;
1023 case LEU: code = LE; break;
1024 default: ;
1025 }
1026 }
1027 switch (code)
1028 {
1029 case EQ: pos = "beq", neg = "bne"; break;
1030 case NE: pos = "bne", neg = "beq"; break;
1031 case GT: pos = "bgt", neg = "ble"; break;
1032 case GTU: pos = "bhi", neg = "blos"; break;
1033 case LT: pos = "blt", neg = "bge"; break;
1034 case LTU: pos = "blo", neg = "bhis"; break;
1035 case GE: pos = "bge", neg = "blt"; break;
1036 case GEU: pos = "bhis", neg = "blo"; break;
1037 case LE: pos = "ble", neg = "bgt"; break;
1038 case LEU: pos = "blos", neg = "bhi"; break;
1039 default: gcc_unreachable ();
1040 }
1041
1042 #if 0
1043 /* currently we don't need this, because the tstdf and cmpdf
1044 copy the condition code immediately, and other float operations are not
1045 yet recognized as changing the FCC - if so, then the length-cost of all
1046 jump insns increases by one, because we have to potentially copy the
1047 FCC! */
1048 if (cc_status.flags & CC_IN_FPU)
1049 output_asm_insn("cfcc", NULL);
1050 #endif
1051
1052 switch (length)
1053 {
1054 case 2:
1055
1056 sprintf(buf, "%s %%l1", inv ? neg : pos);
1057
1058 return buf;
1059
1060 case 6:
1061
1062 sprintf(buf, "%s JMP_%d\n\tjmp %%l1\nJMP_%d:", inv ? pos : neg, x, x);
1063
1064 x++;
1065
1066 return buf;
1067
1068 default:
1069
1070 gcc_unreachable ();
1071 }
1072
1073 }
1074
1075 void
1076 notice_update_cc_on_set(rtx exp, rtx insn ATTRIBUTE_UNUSED)
1077 {
1078 if (GET_CODE (SET_DEST (exp)) == CC0)
1079 {
1080 cc_status.flags = 0;
1081 cc_status.value1 = SET_DEST (exp);
1082 cc_status.value2 = SET_SRC (exp);
1083 }
1084 else if (GET_CODE (SET_SRC (exp)) == CALL)
1085 {
1086 CC_STATUS_INIT;
1087 }
1088 else if (SET_DEST(exp) == pc_rtx)
1089 {
1090 /* jump */
1091 }
1092 else if (GET_MODE (SET_DEST(exp)) == HImode
1093 || GET_MODE (SET_DEST(exp)) == QImode)
1094 {
1095 cc_status.flags = GET_CODE (SET_SRC(exp)) == MINUS ? 0 : CC_NO_OVERFLOW;
1096 cc_status.value1 = SET_SRC (exp);
1097 cc_status.value2 = SET_DEST (exp);
1098
1099 if (cc_status.value1 && GET_CODE (cc_status.value1) == REG
1100 && cc_status.value2
1101 && reg_overlap_mentioned_p (cc_status.value1, cc_status.value2))
1102 cc_status.value2 = 0;
1103 if (cc_status.value1 && GET_CODE (cc_status.value1) == MEM
1104 && cc_status.value2
1105 && GET_CODE (cc_status.value2) == MEM)
1106 cc_status.value2 = 0;
1107 }
1108 else
1109 {
1110 CC_STATUS_INIT;
1111 }
1112 }
1113
1114
1115 int
1116 simple_memory_operand(rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1117 {
1118 rtx addr;
1119
1120 /* Eliminate non-memory operations */
1121 if (GET_CODE (op) != MEM)
1122 return FALSE;
1123
1124 #if 0
1125 /* dword operations really put out 2 instructions, so eliminate them. */
1126 if (GET_MODE_SIZE (GET_MODE (op)) > (HAVE_64BIT_P () ? 8 : 4))
1127 return FALSE;
1128 #endif
1129
1130 /* Decode the address now. */
1131
1132 indirection:
1133
1134 addr = XEXP (op, 0);
1135
1136 switch (GET_CODE (addr))
1137 {
1138 case REG:
1139 /* (R0) - no extra cost */
1140 return 1;
1141
1142 case PRE_DEC:
1143 case POST_INC:
1144 /* -(R0), (R0)+ - cheap! */
1145 return 0;
1146
1147 case MEM:
1148 /* cheap - is encoded in addressing mode info!
1149
1150 -- except for @(R0), which has to be @0(R0) !!! */
1151
1152 if (GET_CODE (XEXP (addr, 0)) == REG)
1153 return 0;
1154
1155 op=addr;
1156 goto indirection;
1157
1158 case CONST_INT:
1159 case LABEL_REF:
1160 case CONST:
1161 case SYMBOL_REF:
1162 /* @#address - extra cost */
1163 return 0;
1164
1165 case PLUS:
1166 /* X(R0) - extra cost */
1167 return 0;
1168
1169 default:
1170 break;
1171 }
1172
1173 return FALSE;
1174 }
1175
1176
1177 /*
1178 * output a block move:
1179 *
1180 * operands[0] ... to
1181 * operands[1] ... from
1182 * operands[2] ... length
1183 * operands[3] ... alignment
1184 * operands[4] ... scratch register
1185 */
1186
1187
1188 const char *
1189 output_block_move(rtx *operands)
1190 {
1191 static int count = 0;
1192 char buf[200];
1193 int unroll;
1194 int lastbyte = 0;
1195
1196 /* Move of zero bytes is a NOP. */
1197 if (operands[2] == const0_rtx)
1198 return "";
1199
1200 /* Look for moves by small constant byte counts, those we'll
1201 expand to straight line code. */
1202 if (CONSTANT_P (operands[2]))
1203 {
1204 if (INTVAL (operands[2]) < 16
1205 && (!optimize_size || INTVAL (operands[2]) < 5)
1206 && INTVAL (operands[3]) == 1)
1207 {
1208 register int i;
1209
1210 for (i = 1; i <= INTVAL (operands[2]); i++)
1211 output_asm_insn("movb (%1)+, (%0)+", operands);
1212
1213 return "";
1214 }
1215 else if (INTVAL(operands[2]) < 32
1216 && (!optimize_size || INTVAL (operands[2]) < 9)
1217 && INTVAL (operands[3]) >= 2)
1218 {
1219 register int i;
1220
1221 for (i = 1; i <= INTVAL (operands[2]) / 2; i++)
1222 output_asm_insn ("mov (%1)+, (%0)+", operands);
1223 if (INTVAL (operands[2]) & 1)
1224 output_asm_insn ("movb (%1), (%0)", operands);
1225
1226 return "";
1227 }
1228 }
1229
1230 /* Ideally we'd look for moves that are multiples of 4 or 8
1231 bytes and handle those by unrolling the move loop. That
1232 makes for a lot of code if done at run time, but it's ok
1233 for constant counts. Also, for variable counts we have
1234 to worry about odd byte count with even aligned pointers.
1235 On 11/40 and up we handle that case; on older machines
1236 we don't and just use byte-wise moves all the time. */
1237
1238 if (CONSTANT_P (operands[2]) )
1239 {
1240 if (INTVAL (operands[3]) < 2)
1241 unroll = 0;
1242 else
1243 {
1244 lastbyte = INTVAL (operands[2]) & 1;
1245
1246 if (optimize_size || INTVAL (operands[2]) & 2)
1247 unroll = 1;
1248 else if (INTVAL (operands[2]) & 4)
1249 unroll = 2;
1250 else
1251 unroll = 3;
1252 }
1253
1254 /* Loop count is byte count scaled by unroll. */
1255 operands[2] = GEN_INT (INTVAL (operands[2]) >> unroll);
1256 output_asm_insn ("mov %2, %4", operands);
1257 }
1258 else
1259 {
1260 /* Variable byte count; use the input register
1261 as the scratch. */
1262 operands[4] = operands[2];
1263
1264 /* Decide whether to move by words, and check
1265 the byte count for zero. */
1266 if (TARGET_40_PLUS && INTVAL (operands[3]) > 1)
1267 {
1268 unroll = 1;
1269 output_asm_insn ("asr %4", operands);
1270 }
1271 else
1272 {
1273 unroll = 0;
1274 output_asm_insn ("tst %4", operands);
1275 }
1276 sprintf (buf, "beq movestrhi%d", count + 1);
1277 output_asm_insn (buf, NULL);
1278 }
1279
1280 /* Output the loop label. */
1281 sprintf (buf, "\nmovestrhi%d:", count);
1282 output_asm_insn (buf, NULL);
1283
1284 /* Output the appropriate move instructions. */
1285 switch (unroll)
1286 {
1287 case 0:
1288 output_asm_insn ("movb (%1)+, (%0)+", operands);
1289 break;
1290
1291 case 1:
1292 output_asm_insn ("mov (%1)+, (%0)+", operands);
1293 break;
1294
1295 case 2:
1296 output_asm_insn ("mov (%1)+, (%0)+", operands);
1297 output_asm_insn ("mov (%1)+, (%0)+", operands);
1298 break;
1299
1300 default:
1301 output_asm_insn ("mov (%1)+, (%0)+", operands);
1302 output_asm_insn ("mov (%1)+, (%0)+", operands);
1303 output_asm_insn ("mov (%1)+, (%0)+", operands);
1304 output_asm_insn ("mov (%1)+, (%0)+", operands);
1305 break;
1306 }
1307
1308 /* Output the decrement and test. */
1309 if (TARGET_40_PLUS)
1310 {
1311 sprintf (buf, "sob %%4, movestrhi%d", count);
1312 output_asm_insn (buf, operands);
1313 }
1314 else
1315 {
1316 output_asm_insn ("dec %4", operands);
1317 sprintf (buf, "bgt movestrhi%d", count);
1318 output_asm_insn (buf, NULL);
1319 }
1320 count ++;
1321
1322 /* If constant odd byte count, move the last byte. */
1323 if (lastbyte)
1324 output_asm_insn ("movb (%1), (%0)", operands);
1325 else if (!CONSTANT_P (operands[2]))
1326 {
1327 /* Output the destination label for the zero byte count check. */
1328 sprintf (buf, "\nmovestrhi%d:", count);
1329 output_asm_insn (buf, NULL);
1330 count++;
1331
1332 /* If we did word moves, check for trailing last byte. */
1333 if (unroll)
1334 {
1335 sprintf (buf, "bcc movestrhi%d", count);
1336 output_asm_insn (buf, NULL);
1337 output_asm_insn ("movb (%1), (%0)", operands);
1338 sprintf (buf, "\nmovestrhi%d:", count);
1339 output_asm_insn (buf, NULL);
1340 count++;
1341 }
1342 }
1343
1344 return "";
1345 }
1346
1347 /* This function checks whether a real value can be encoded as
1348 a literal, i.e., addressing mode 27. In that mode, real values
1349 are one word values, so the remaining 48 bits have to be zero. */
1350 int
1351 legitimate_const_double_p (rtx address)
1352 {
1353 REAL_VALUE_TYPE r;
1354 long sval[2];
1355 REAL_VALUE_FROM_CONST_DOUBLE (r, address);
1356 REAL_VALUE_TO_TARGET_DOUBLE (r, sval);
1357 if ((sval[0] & 0xffff) == 0 && sval[1] == 0)
1358 return 1;
1359 return 0;
1360 }
1361
1362 /* Implement CANNOT_CHANGE_MODE_CLASS. */
1363 bool
1364 pdp11_cannot_change_mode_class (enum machine_mode from,
1365 enum machine_mode to,
1366 enum reg_class rclass)
1367 {
1368 /* Also, FPU registers contain a whole float value and the parts of
1369 it are not separately accessible.
1370
1371 So we disallow all mode changes involving FPRs. */
1372 if (FLOAT_MODE_P (from) != FLOAT_MODE_P (to))
1373 return true;
1374
1375 return reg_classes_intersect_p (FPU_REGS, rclass);
1376 }
1377
1378 /* TARGET_PREFERRED_RELOAD_CLASS
1379
1380 Given an rtx X being reloaded into a reg required to be
1381 in class CLASS, return the class of reg to actually use.
1382 In general this is just CLASS; but on some machines
1383 in some cases it is preferable to use a more restrictive class.
1384
1385 loading is easier into LOAD_FPU_REGS than FPU_REGS! */
1386
1387 static reg_class_t
1388 pdp11_preferred_reload_class (rtx x, reg_class_t rclass)
1389 {
1390 if (rclass == FPU_REGS)
1391 return LOAD_FPU_REGS;
1392 if (rclass == ALL_REGS)
1393 {
1394 if (FLOAT_MODE_P (GET_MODE (x)))
1395 return LOAD_FPU_REGS;
1396 else
1397 return GENERAL_REGS;
1398 }
1399 return rclass;
1400 }
1401
1402 /* TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
1403
1404 Given an rtx X being reloaded into a reg required to be
1405 in class CLASS, return the class of reg to actually use.
1406 In general this is just CLASS; but on some machines
1407 in some cases it is preferable to use a more restrictive class.
1408
1409 loading is easier into LOAD_FPU_REGS than FPU_REGS! */
1410
1411 static reg_class_t
1412 pdp11_preferred_output_reload_class (rtx x, reg_class_t rclass)
1413 {
1414 if (rclass == FPU_REGS)
1415 return LOAD_FPU_REGS;
1416 if (rclass == ALL_REGS)
1417 {
1418 if (FLOAT_MODE_P (GET_MODE (x)))
1419 return LOAD_FPU_REGS;
1420 else
1421 return GENERAL_REGS;
1422 }
1423 return rclass;
1424 }
1425
1426
1427 /* TARGET_SECONDARY_RELOAD.
1428
1429 FPU registers AC4 and AC5 (class NO_LOAD_FPU_REGS) require an
1430 intermediate register (AC0-AC3: LOAD_FPU_REGS). Everything else
1431 can be loade/stored directly. */
1432 static reg_class_t
1433 pdp11_secondary_reload (bool in_p ATTRIBUTE_UNUSED,
1434 rtx x,
1435 reg_class_t reload_class,
1436 enum machine_mode reload_mode ATTRIBUTE_UNUSED,
1437 secondary_reload_info *sri ATTRIBUTE_UNUSED)
1438 {
1439 if (reload_class != NO_LOAD_FPU_REGS || GET_CODE (x) != REG ||
1440 REGNO_REG_CLASS (REGNO (x)) == LOAD_FPU_REGS)
1441 return NO_REGS;
1442
1443 return LOAD_FPU_REGS;
1444 }
1445
1446 /* Target routine to check if register to register move requires memory.
1447
1448 The answer is yes if we're going between general register and FPU
1449 registers. The mode doesn't matter in making this check.
1450 */
1451 bool
1452 pdp11_secondary_memory_needed (reg_class_t c1, reg_class_t c2,
1453 enum machine_mode mode ATTRIBUTE_UNUSED)
1454 {
1455 int fromfloat = (c1 == LOAD_FPU_REGS || c1 == NO_LOAD_FPU_REGS ||
1456 c1 == FPU_REGS);
1457 int tofloat = (c2 == LOAD_FPU_REGS || c2 == NO_LOAD_FPU_REGS ||
1458 c2 == FPU_REGS);
1459
1460 return (fromfloat != tofloat);
1461 }
1462
1463 /* TARGET_LEGITIMATE_ADDRESS_P recognizes an RTL expression
1464 that is a valid memory address for an instruction.
1465 The MODE argument is the machine mode for the MEM expression
1466 that wants to use this address.
1467
1468 */
1469
1470 static bool
1471 pdp11_legitimate_address_p (enum machine_mode mode,
1472 rtx operand, bool strict)
1473 {
1474 rtx xfoob;
1475
1476 /* accept @#address */
1477 if (CONSTANT_ADDRESS_P (operand))
1478 return true;
1479
1480 switch (GET_CODE (operand))
1481 {
1482 case REG:
1483 /* accept (R0) */
1484 return !strict || REGNO_OK_FOR_BASE_P (REGNO (operand));
1485
1486 case PLUS:
1487 /* accept X(R0) */
1488 return GET_CODE (XEXP (operand, 0)) == REG
1489 && (!strict || REGNO_OK_FOR_BASE_P (REGNO (XEXP (operand, 0))))
1490 && CONSTANT_ADDRESS_P (XEXP (operand, 1));
1491
1492 case PRE_DEC:
1493 /* accept -(R0) */
1494 return GET_CODE (XEXP (operand, 0)) == REG
1495 && (!strict || REGNO_OK_FOR_BASE_P (REGNO (XEXP (operand, 0))));
1496
1497 case POST_INC:
1498 /* accept (R0)+ */
1499 return GET_CODE (XEXP (operand, 0)) == REG
1500 && (!strict || REGNO_OK_FOR_BASE_P (REGNO (XEXP (operand, 0))));
1501
1502 case PRE_MODIFY:
1503 /* accept -(SP) -- which uses PRE_MODIFY for byte mode */
1504 return GET_CODE (XEXP (operand, 0)) == REG
1505 && REGNO (XEXP (operand, 0)) == STACK_POINTER_REGNUM
1506 && GET_CODE ((xfoob = XEXP (operand, 1))) == PLUS
1507 && GET_CODE (XEXP (xfoob, 0)) == REG
1508 && REGNO (XEXP (xfoob, 0)) == STACK_POINTER_REGNUM
1509 && CONSTANT_P (XEXP (xfoob, 1))
1510 && INTVAL (XEXP (xfoob,1)) == -2;
1511
1512 case POST_MODIFY:
1513 /* accept (SP)+ -- which uses POST_MODIFY for byte mode */
1514 return GET_CODE (XEXP (operand, 0)) == REG
1515 && REGNO (XEXP (operand, 0)) == STACK_POINTER_REGNUM
1516 && GET_CODE ((xfoob = XEXP (operand, 1))) == PLUS
1517 && GET_CODE (XEXP (xfoob, 0)) == REG
1518 && REGNO (XEXP (xfoob, 0)) == STACK_POINTER_REGNUM
1519 && CONSTANT_P (XEXP (xfoob, 1))
1520 && INTVAL (XEXP (xfoob,1)) == 2;
1521
1522 case MEM:
1523 /* handle another level of indirection ! */
1524 xfoob = XEXP (operand, 0);
1525
1526 /* (MEM:xx (MEM:xx ())) is not valid for SI, DI and currently
1527 also forbidden for float, because we have to handle this
1528 in output_move_double and/or output_move_quad() - we could
1529 do it, but currently it's not worth it!!!
1530 now that DFmode cannot go into CPU register file,
1531 maybe I should allow float ...
1532 but then I have to handle memory-to-memory moves in movdf ?? */
1533 if (GET_MODE_BITSIZE(mode) > 16)
1534 return false;
1535
1536 /* accept @address */
1537 if (CONSTANT_ADDRESS_P (xfoob))
1538 return true;
1539
1540 switch (GET_CODE (xfoob))
1541 {
1542 case REG:
1543 /* accept @(R0) - which is @0(R0) */
1544 return !strict || REGNO_OK_FOR_BASE_P(REGNO (xfoob));
1545
1546 case PLUS:
1547 /* accept @X(R0) */
1548 return GET_CODE (XEXP (xfoob, 0)) == REG
1549 && (!strict || REGNO_OK_FOR_BASE_P (REGNO (XEXP (xfoob, 0))))
1550 && CONSTANT_ADDRESS_P (XEXP (xfoob, 1));
1551
1552 case PRE_DEC:
1553 /* accept @-(R0) */
1554 return GET_CODE (XEXP (xfoob, 0)) == REG
1555 && (!strict || REGNO_OK_FOR_BASE_P (REGNO (XEXP (xfoob, 0))));
1556
1557 case POST_INC:
1558 /* accept @(R0)+ */
1559 return GET_CODE (XEXP (xfoob, 0)) == REG
1560 && (!strict || REGNO_OK_FOR_BASE_P (REGNO (XEXP (xfoob, 0))));
1561
1562 default:
1563 /* anything else is invalid */
1564 return false;
1565 }
1566
1567 default:
1568 /* anything else is invalid */
1569 return false;
1570 }
1571 }
1572
1573 /* Return the class number of the smallest class containing
1574 reg number REGNO. */
1575 enum reg_class
1576 pdp11_regno_reg_class (int regno)
1577 {
1578 if (regno == FRAME_POINTER_REGNUM || regno == ARG_POINTER_REGNUM)
1579 return GENERAL_REGS;
1580 else if (regno > AC3_REGNUM)
1581 return NO_LOAD_FPU_REGS;
1582 else if (regno >= AC0_REGNUM)
1583 return LOAD_FPU_REGS;
1584 else if (regno & 1)
1585 return MUL_REGS;
1586 else
1587 return GENERAL_REGS;
1588 }
1589
1590
1591 int
1592 pdp11_sp_frame_offset (void)
1593 {
1594 int offset = 0, regno;
1595 offset = get_frame_size();
1596 for (regno = 0; regno <= PC_REGNUM; regno++)
1597 if (pdp11_saved_regno (regno))
1598 offset += 2;
1599 for (regno = AC0_REGNUM; regno <= AC5_REGNUM; regno++)
1600 if (pdp11_saved_regno (regno))
1601 offset += 8;
1602
1603 return offset;
1604 }
1605
1606 /* Return the offset between two registers, one to be eliminated, and the other
1607 its replacement, at the start of a routine. */
1608
1609 int
1610 pdp11_initial_elimination_offset (int from, int to)
1611 {
1612 int spoff;
1613
1614 if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
1615 return 4;
1616 else if (from == FRAME_POINTER_REGNUM
1617 && to == HARD_FRAME_POINTER_REGNUM)
1618 return 0;
1619 else
1620 {
1621 gcc_assert (to == STACK_POINTER_REGNUM);
1622
1623 /* Get the size of the register save area. */
1624 spoff = pdp11_sp_frame_offset ();
1625 if (from == FRAME_POINTER_REGNUM)
1626 return spoff;
1627
1628 gcc_assert (from == ARG_POINTER_REGNUM);
1629
1630 /* If there is a frame pointer, that is saved too. */
1631 if (frame_pointer_needed)
1632 spoff += 2;
1633
1634 /* Account for the saved PC in the function call. */
1635 return spoff + 2;
1636 }
1637 }
1638
1639 /* A copy of output_addr_const modified for pdp11 expression syntax.
1640 output_addr_const also gets called for %cDIGIT and %nDIGIT, which we don't
1641 use, and for debugging output, which we don't support with this port either.
1642 So this copy should get called whenever needed.
1643 */
1644 void
1645 output_addr_const_pdp11 (FILE *file, rtx x)
1646 {
1647 char buf[256];
1648 int i;
1649
1650 restart:
1651 switch (GET_CODE (x))
1652 {
1653 case PC:
1654 gcc_assert (flag_pic);
1655 putc ('.', file);
1656 break;
1657
1658 case SYMBOL_REF:
1659 assemble_name (file, XSTR (x, 0));
1660 break;
1661
1662 case LABEL_REF:
1663 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
1664 assemble_name (file, buf);
1665 break;
1666
1667 case CODE_LABEL:
1668 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
1669 assemble_name (file, buf);
1670 break;
1671
1672 case CONST_INT:
1673 i = INTVAL (x);
1674 if (i < 0)
1675 {
1676 i = -i;
1677 fprintf (file, "-");
1678 }
1679 fprintf (file, "%#o", i & 0xffff);
1680 break;
1681
1682 case CONST:
1683 /* This used to output parentheses around the expression,
1684 but that does not work on the 386 (either ATT or BSD assembler). */
1685 output_addr_const_pdp11 (file, XEXP (x, 0));
1686 break;
1687
1688 case CONST_DOUBLE:
1689 if (GET_MODE (x) == VOIDmode)
1690 {
1691 /* We can use %o if the number is one word and positive. */
1692 gcc_assert (!CONST_DOUBLE_HIGH (x));
1693 fprintf (file, "%#ho", (unsigned short) CONST_DOUBLE_LOW (x));
1694 }
1695 else
1696 /* We can't handle floating point constants;
1697 PRINT_OPERAND must handle them. */
1698 output_operand_lossage ("floating constant misused");
1699 break;
1700
1701 case PLUS:
1702 /* Some assemblers need integer constants to appear last (e.g. masm). */
1703 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
1704 {
1705 output_addr_const_pdp11 (file, XEXP (x, 1));
1706 if (INTVAL (XEXP (x, 0)) >= 0)
1707 fprintf (file, "+");
1708 output_addr_const_pdp11 (file, XEXP (x, 0));
1709 }
1710 else
1711 {
1712 output_addr_const_pdp11 (file, XEXP (x, 0));
1713 if (INTVAL (XEXP (x, 1)) >= 0)
1714 fprintf (file, "+");
1715 output_addr_const_pdp11 (file, XEXP (x, 1));
1716 }
1717 break;
1718
1719 case MINUS:
1720 /* Avoid outputting things like x-x or x+5-x,
1721 since some assemblers can't handle that. */
1722 x = simplify_subtraction (x);
1723 if (GET_CODE (x) != MINUS)
1724 goto restart;
1725
1726 output_addr_const_pdp11 (file, XEXP (x, 0));
1727 if (GET_CODE (XEXP (x, 1)) != CONST_INT
1728 || INTVAL (XEXP (x, 1)) >= 0)
1729 fprintf (file, "-");
1730 output_addr_const_pdp11 (file, XEXP (x, 1));
1731 break;
1732
1733 case ZERO_EXTEND:
1734 case SIGN_EXTEND:
1735 output_addr_const_pdp11 (file, XEXP (x, 0));
1736 break;
1737
1738 default:
1739 output_operand_lossage ("invalid expression as operand");
1740 }
1741 }
1742
1743 /* Worker function for TARGET_RETURN_IN_MEMORY. */
1744
1745 static bool
1746 pdp11_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
1747 {
1748 /* Integers 32 bits and under, and scalar floats (if FPU), are returned
1749 in registers. The rest go into memory. */
1750 return (TYPE_MODE (type) == DImode
1751 || (FLOAT_MODE_P (TYPE_MODE (type)) && ! TARGET_AC0)
1752 || TREE_CODE (type) == VECTOR_TYPE
1753 || COMPLEX_MODE_P (TYPE_MODE (type)));
1754 }
1755
1756 /* Worker function for TARGET_FUNCTION_VALUE.
1757
1758 On the pdp11 the value is found in R0 (or ac0??? not without FPU!!!! ) */
1759
1760 static rtx
1761 pdp11_function_value (const_tree valtype,
1762 const_tree fntype_or_decl ATTRIBUTE_UNUSED,
1763 bool outgoing ATTRIBUTE_UNUSED)
1764 {
1765 return gen_rtx_REG (TYPE_MODE (valtype),
1766 BASE_RETURN_VALUE_REG(TYPE_MODE(valtype)));
1767 }
1768
1769 /* Worker function for TARGET_LIBCALL_VALUE. */
1770
1771 static rtx
1772 pdp11_libcall_value (enum machine_mode mode,
1773 const_rtx fun ATTRIBUTE_UNUSED)
1774 {
1775 return gen_rtx_REG (mode, BASE_RETURN_VALUE_REG(mode));
1776 }
1777
1778 /* Worker function for TARGET_FUNCTION_VALUE_REGNO_P.
1779
1780 On the pdp, the first "output" reg is the only register thus used.
1781
1782 maybe ac0 ? - as option someday! */
1783
1784 static bool
1785 pdp11_function_value_regno_p (const unsigned int regno)
1786 {
1787 return (regno == RETVAL_REGNUM) || (TARGET_AC0 && (regno == AC0_REGNUM));
1788 }
1789
1790 /* Worker function for TARGET_TRAMPOLINE_INIT.
1791
1792 trampoline - how should i do it in separate i+d ?
1793 have some allocate_trampoline magic???
1794
1795 the following should work for shared I/D:
1796
1797 MOV #STATIC, $4 01270Y 0x0000 <- STATIC; Y = STATIC_CHAIN_REGNUM
1798 JMP @#FUNCTION 000137 0x0000 <- FUNCTION
1799 */
1800
1801 static void
1802 pdp11_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
1803 {
1804 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
1805 rtx mem;
1806
1807 gcc_assert (!TARGET_SPLIT);
1808
1809 mem = adjust_address (m_tramp, HImode, 0);
1810 emit_move_insn (mem, GEN_INT (012700+STATIC_CHAIN_REGNUM));
1811 mem = adjust_address (m_tramp, HImode, 2);
1812 emit_move_insn (mem, chain_value);
1813 mem = adjust_address (m_tramp, HImode, 4);
1814 emit_move_insn (mem, GEN_INT (000137));
1815 emit_move_insn (mem, fnaddr);
1816 }
1817
1818 /* Worker function for TARGET_FUNCTION_ARG.
1819
1820 Determine where to put an argument to a function.
1821 Value is zero to push the argument on the stack,
1822 or a hard register in which to store the argument.
1823
1824 MODE is the argument's machine mode.
1825 TYPE is the data type of the argument (as a tree).
1826 This is null for libcalls where that information may
1827 not be available.
1828 CUM is a variable of type CUMULATIVE_ARGS which gives info about
1829 the preceding args and about the function being called.
1830 NAMED is nonzero if this argument is a named parameter
1831 (otherwise it is an extra parameter matching an ellipsis). */
1832
1833 static rtx
1834 pdp11_function_arg (cumulative_args_t cum ATTRIBUTE_UNUSED,
1835 enum machine_mode mode ATTRIBUTE_UNUSED,
1836 const_tree type ATTRIBUTE_UNUSED,
1837 bool named ATTRIBUTE_UNUSED)
1838 {
1839 return NULL_RTX;
1840 }
1841
1842 /* Worker function for TARGET_FUNCTION_ARG_ADVANCE.
1843
1844 Update the data in CUM to advance over an argument of mode MODE and
1845 data type TYPE. (TYPE is null for libcalls where that information
1846 may not be available.) */
1847
1848 static void
1849 pdp11_function_arg_advance (cumulative_args_t cum_v, enum machine_mode mode,
1850 const_tree type, bool named ATTRIBUTE_UNUSED)
1851 {
1852 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
1853
1854 *cum += (mode != BLKmode
1855 ? GET_MODE_SIZE (mode)
1856 : int_size_in_bytes (type));
1857 }
1858
1859 /* Make sure everything's fine if we *don't* have an FPU.
1860 This assumes that putting a register in fixed_regs will keep the
1861 compiler's mitts completely off it. We don't bother to zero it out
1862 of register classes. Also fix incompatible register naming with
1863 the UNIX assembler. */
1864
1865 static void
1866 pdp11_conditional_register_usage (void)
1867 {
1868 int i;
1869 HARD_REG_SET x;
1870 if (!TARGET_FPU)
1871 {
1872 COPY_HARD_REG_SET (x, reg_class_contents[(int)FPU_REGS]);
1873 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++ )
1874 if (TEST_HARD_REG_BIT (x, i))
1875 fixed_regs[i] = call_used_regs[i] = 1;
1876 }
1877
1878 if (TARGET_AC0)
1879 call_used_regs[AC0_REGNUM] = 1;
1880 if (TARGET_UNIX_ASM)
1881 {
1882 /* Change names of FPU registers for the UNIX assembler. */
1883 reg_names[8] = "fr0";
1884 reg_names[9] = "fr1";
1885 reg_names[10] = "fr2";
1886 reg_names[11] = "fr3";
1887 reg_names[12] = "fr4";
1888 reg_names[13] = "fr5";
1889 }
1890 }
1891
1892 static section *
1893 pdp11_function_section (tree decl ATTRIBUTE_UNUSED,
1894 enum node_frequency freq ATTRIBUTE_UNUSED,
1895 bool startup ATTRIBUTE_UNUSED,
1896 bool exit ATTRIBUTE_UNUSED)
1897 {
1898 return NULL;
1899 }
1900
1901 /* Implement TARGET_LEGITIMATE_CONSTANT_P. */
1902
1903 static bool
1904 pdp11_legitimate_constant_p (enum machine_mode mode ATTRIBUTE_UNUSED, rtx x)
1905 {
1906 return GET_CODE (x) != CONST_DOUBLE || legitimate_const_double_p (x);
1907 }
1908
1909 /* Implement TARGET_SCALAR_MODE_SUPPORTED_P. */
1910
1911 static bool
1912 pdp11_scalar_mode_supported_p (enum machine_mode mode)
1913 {
1914 /* Support SFmode even with -mfloat64. */
1915 if (mode == SFmode)
1916 return true;
1917 return default_scalar_mode_supported_p (mode);
1918 }
1919
1920 struct gcc_target targetm = TARGET_INITIALIZER;