1 /* Subroutines for gcc2 for pdp11.
2 Copyright (C) 1994-2017 Free Software Foundation, Inc.
3 Contributed by Michael K. Gschwind (mike@vlsivie.tuwien.ac.at).
5 This file is part of GCC.
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)
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.
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/>. */
23 #include "coretypes.h"
28 #include "stringpool.h"
33 #include "insn-config.h"
37 #include "conditions.h"
39 #include "stor-layout.h"
46 /* This file should be included last. */
47 #include "target-def.h"
49 /* this is the current value returned by the macro FIRST_PARM_OFFSET
51 int current_first_parm_offset
;
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 *);
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
=
88 const struct real_format pdp11_d_format
=
112 encode_pdp11_f (const struct real_format
*fmt ATTRIBUTE_UNUSED
, long *buf
,
113 const REAL_VALUE_TYPE
*r
)
115 (*vax_f_format
.encode
) (fmt
, buf
, r
);
116 buf
[0] = ((buf
[0] >> 16) & 0xffff) | ((buf
[0] & 0xffff) << 16);
120 decode_pdp11_f (const struct real_format
*fmt ATTRIBUTE_UNUSED
,
121 REAL_VALUE_TYPE
*r
, const long *buf
)
124 tbuf
= ((buf
[0] >> 16) & 0xffff) | ((buf
[0] & 0xffff) << 16);
125 (*vax_f_format
.decode
) (fmt
, r
, &tbuf
);
129 encode_pdp11_d (const struct real_format
*fmt ATTRIBUTE_UNUSED
, long *buf
,
130 const REAL_VALUE_TYPE
*r
)
132 (*vax_d_format
.encode
) (fmt
, buf
, r
);
133 buf
[0] = ((buf
[0] >> 16) & 0xffff) | ((buf
[0] & 0xffff) << 16);
134 buf
[1] = ((buf
[1] >> 16) & 0xffff) | ((buf
[1] & 0xffff) << 16);
138 decode_pdp11_d (const struct real_format
*fmt ATTRIBUTE_UNUSED
,
139 REAL_VALUE_TYPE
*r
, const long *buf
)
142 tbuf
[0] = ((buf
[0] >> 16) & 0xffff) | ((buf
[0] & 0xffff) << 16);
143 tbuf
[1] = ((buf
[1] >> 16) & 0xffff) | ((buf
[1] & 0xffff) << 16);
144 (*vax_d_format
.decode
) (fmt
, r
, tbuf
);
147 /* This is where the condition code register lives. */
148 /* rtx cc0_reg_rtx; - no longer needed? */
150 static const char *singlemove_string (rtx
*);
151 static bool pdp11_assemble_integer (rtx
, unsigned int, int);
152 static bool pdp11_rtx_costs (rtx
, machine_mode
, int, int, int *, bool);
153 static bool pdp11_return_in_memory (const_tree
, const_tree
);
154 static rtx
pdp11_function_value (const_tree
, const_tree
, bool);
155 static rtx
pdp11_libcall_value (machine_mode
, const_rtx
);
156 static bool pdp11_function_value_regno_p (const unsigned int);
157 static void pdp11_trampoline_init (rtx
, tree
, rtx
);
158 static rtx
pdp11_function_arg (cumulative_args_t
, machine_mode
,
160 static void pdp11_function_arg_advance (cumulative_args_t
,
161 machine_mode
, const_tree
, bool);
162 static void pdp11_conditional_register_usage (void);
163 static bool pdp11_legitimate_constant_p (machine_mode
, rtx
);
165 static bool pdp11_scalar_mode_supported_p (scalar_mode
);
167 /* Initialize the GCC target structure. */
168 #undef TARGET_ASM_BYTE_OP
169 #define TARGET_ASM_BYTE_OP NULL
170 #undef TARGET_ASM_ALIGNED_HI_OP
171 #define TARGET_ASM_ALIGNED_HI_OP NULL
172 #undef TARGET_ASM_ALIGNED_SI_OP
173 #define TARGET_ASM_ALIGNED_SI_OP NULL
174 #undef TARGET_ASM_INTEGER
175 #define TARGET_ASM_INTEGER pdp11_assemble_integer
177 #undef TARGET_ASM_OPEN_PAREN
178 #define TARGET_ASM_OPEN_PAREN "["
179 #undef TARGET_ASM_CLOSE_PAREN
180 #define TARGET_ASM_CLOSE_PAREN "]"
182 #undef TARGET_RTX_COSTS
183 #define TARGET_RTX_COSTS pdp11_rtx_costs
185 #undef TARGET_FUNCTION_ARG
186 #define TARGET_FUNCTION_ARG pdp11_function_arg
187 #undef TARGET_FUNCTION_ARG_ADVANCE
188 #define TARGET_FUNCTION_ARG_ADVANCE pdp11_function_arg_advance
190 #undef TARGET_RETURN_IN_MEMORY
191 #define TARGET_RETURN_IN_MEMORY pdp11_return_in_memory
193 #undef TARGET_FUNCTION_VALUE
194 #define TARGET_FUNCTION_VALUE pdp11_function_value
195 #undef TARGET_LIBCALL_VALUE
196 #define TARGET_LIBCALL_VALUE pdp11_libcall_value
197 #undef TARGET_FUNCTION_VALUE_REGNO_P
198 #define TARGET_FUNCTION_VALUE_REGNO_P pdp11_function_value_regno_p
200 #undef TARGET_TRAMPOLINE_INIT
201 #define TARGET_TRAMPOLINE_INIT pdp11_trampoline_init
203 #undef TARGET_SECONDARY_RELOAD
204 #define TARGET_SECONDARY_RELOAD pdp11_secondary_reload
206 #undef TARGET_REGISTER_MOVE_COST
207 #define TARGET_REGISTER_MOVE_COST pdp11_register_move_cost
209 #undef TARGET_PREFERRED_RELOAD_CLASS
210 #define TARGET_PREFERRED_RELOAD_CLASS pdp11_preferred_reload_class
212 #undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
213 #define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS pdp11_preferred_output_reload_class
216 #define TARGET_LRA_P hook_bool_void_false
218 #undef TARGET_LEGITIMATE_ADDRESS_P
219 #define TARGET_LEGITIMATE_ADDRESS_P pdp11_legitimate_address_p
221 #undef TARGET_CONDITIONAL_REGISTER_USAGE
222 #define TARGET_CONDITIONAL_REGISTER_USAGE pdp11_conditional_register_usage
224 #undef TARGET_ASM_FUNCTION_SECTION
225 #define TARGET_ASM_FUNCTION_SECTION pdp11_function_section
227 #undef TARGET_PRINT_OPERAND
228 #define TARGET_PRINT_OPERAND pdp11_asm_print_operand
230 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
231 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P pdp11_asm_print_operand_punct_valid_p
233 #undef TARGET_LEGITIMATE_CONSTANT_P
234 #define TARGET_LEGITIMATE_CONSTANT_P pdp11_legitimate_constant_p
236 #undef TARGET_SCALAR_MODE_SUPPORTED_P
237 #define TARGET_SCALAR_MODE_SUPPORTED_P pdp11_scalar_mode_supported_p
239 #undef TARGET_HARD_REGNO_NREGS
240 #define TARGET_HARD_REGNO_NREGS pdp11_hard_regno_nregs
241 #undef TARGET_HARD_REGNO_MODE_OK
242 #define TARGET_HARD_REGNO_MODE_OK pdp11_hard_regno_mode_ok
244 #undef TARGET_MODES_TIEABLE_P
245 #define TARGET_MODES_TIEABLE_P pdp11_modes_tieable_p
247 #undef TARGET_SECONDARY_MEMORY_NEEDED
248 #define TARGET_SECONDARY_MEMORY_NEEDED pdp11_secondary_memory_needed
250 /* A helper function to determine if REGNO should be saved in the
251 current function's stack frame. */
254 pdp11_saved_regno (unsigned regno
)
256 return !call_used_regs
[regno
] && df_regs_ever_live_p (regno
);
259 /* Expand the function prologue. */
262 pdp11_expand_prologue (void)
264 HOST_WIDE_INT fsize
= get_frame_size ();
266 rtx x
, via_ac
= NULL
;
268 /* If we are outputting code for main, the switch FPU to the
269 right mode if TARGET_FPU. */
270 if (MAIN_NAME_P (DECL_NAME (current_function_decl
)) && TARGET_FPU
)
272 emit_insn (gen_setd ());
273 emit_insn (gen_seti ());
276 if (frame_pointer_needed
)
278 x
= gen_rtx_PRE_DEC (Pmode
, stack_pointer_rtx
);
279 x
= gen_frame_mem (Pmode
, x
);
280 emit_move_insn (x
, hard_frame_pointer_rtx
);
282 emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
288 emit_insn (gen_addhi3 (stack_pointer_rtx
, stack_pointer_rtx
,
291 /* Prevent frame references via the frame pointer from being
292 scheduled before the frame is allocated. */
293 if (frame_pointer_needed
)
294 emit_insn (gen_blockage ());
297 /* Save CPU registers. */
298 for (regno
= R0_REGNUM
; regno
<= PC_REGNUM
; regno
++)
299 if (pdp11_saved_regno (regno
)
300 && (regno
!= HARD_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
))
302 x
= gen_rtx_PRE_DEC (Pmode
, stack_pointer_rtx
);
303 x
= gen_frame_mem (Pmode
, x
);
304 emit_move_insn (x
, gen_rtx_REG (Pmode
, regno
));
307 /* Save FPU registers. */
308 for (regno
= AC0_REGNUM
; regno
<= AC3_REGNUM
; regno
++)
309 if (pdp11_saved_regno (regno
))
311 x
= gen_rtx_PRE_DEC (Pmode
, stack_pointer_rtx
);
312 x
= gen_frame_mem (DFmode
, x
);
313 via_ac
= gen_rtx_REG (DFmode
, regno
);
314 emit_move_insn (x
, via_ac
);
317 /* ??? Maybe make ac4, ac5 call used regs?? */
318 for (regno
= AC4_REGNUM
; regno
<= AC5_REGNUM
; regno
++)
319 if (pdp11_saved_regno (regno
))
321 gcc_assert (via_ac
!= NULL
);
322 emit_move_insn (via_ac
, gen_rtx_REG (DFmode
, regno
));
324 x
= gen_rtx_PRE_DEC (Pmode
, stack_pointer_rtx
);
325 x
= gen_frame_mem (DFmode
, x
);
326 emit_move_insn (x
, via_ac
);
330 /* The function epilogue should not depend on the current stack pointer!
331 It should use the frame pointer only. This is mandatory because
332 of alloca; we also take advantage of it to omit stack adjustments
335 /* Maybe we can make leaf functions faster by switching to the
336 second register file - this way we don't have to save regs!
337 leaf functions are ~ 50% of all functions (dynamically!)
339 set/clear bit 11 (dec. 2048) of status word for switching register files -
340 but how can we do this? the pdp11/45 manual says bit may only
341 be set (p.24), but not cleared!
343 switching to kernel is probably more expensive, so we'll leave it
344 like this and not use the second set of registers...
346 maybe as option if you want to generate code for kernel mode? */
349 pdp11_expand_epilogue (void)
351 HOST_WIDE_INT fsize
= get_frame_size ();
353 rtx x
, reg
, via_ac
= NULL
;
355 if (pdp11_saved_regno (AC4_REGNUM
) || pdp11_saved_regno (AC5_REGNUM
))
357 /* Find a temporary with which to restore AC4/5. */
358 for (regno
= AC0_REGNUM
; regno
<= AC3_REGNUM
; regno
++)
359 if (pdp11_saved_regno (regno
))
361 via_ac
= gen_rtx_REG (DFmode
, regno
);
366 /* If possible, restore registers via pops. */
367 if (!frame_pointer_needed
|| crtl
->sp_is_unchanging
)
369 /* Restore registers via pops. */
371 for (regno
= AC5_REGNUM
; regno
>= AC0_REGNUM
; regno
--)
372 if (pdp11_saved_regno (regno
))
374 x
= gen_rtx_POST_INC (Pmode
, stack_pointer_rtx
);
375 x
= gen_frame_mem (DFmode
, x
);
376 reg
= gen_rtx_REG (DFmode
, regno
);
378 if (LOAD_FPU_REG_P (regno
))
379 emit_move_insn (reg
, x
);
382 emit_move_insn (via_ac
, x
);
383 emit_move_insn (reg
, via_ac
);
387 for (regno
= PC_REGNUM
; regno
>= R0_REGNUM
+ 2; regno
--)
388 if (pdp11_saved_regno (regno
)
389 && (regno
!= HARD_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
))
391 x
= gen_rtx_POST_INC (Pmode
, stack_pointer_rtx
);
392 x
= gen_frame_mem (Pmode
, x
);
393 emit_move_insn (gen_rtx_REG (Pmode
, regno
), x
);
398 /* Restore registers via moves. */
399 /* ??? If more than a few registers need to be restored, it's smaller
400 to generate a pointer through which we can emit pops. Consider
401 that moves cost 2*NREG words and pops cost NREG+3 words. This
402 means that the crossover is NREG=3.
404 Possible registers to use are:
405 (1) The first call-saved general register. This register will
406 be restored with the last pop.
407 (2) R1, if it's not used as a return register.
408 (3) FP itself. This option may result in +4 words, since we
409 may need two add imm,rn instructions instead of just one.
410 This also has the downside that we're not representing
411 the unwind info in any way, so during the epilogue the
412 debugger may get lost. */
414 HOST_WIDE_INT ofs
= -pdp11_sp_frame_offset ();
416 for (regno
= AC5_REGNUM
; regno
>= AC0_REGNUM
; regno
--)
417 if (pdp11_saved_regno (regno
))
419 x
= plus_constant (Pmode
, hard_frame_pointer_rtx
, ofs
);
420 x
= gen_frame_mem (DFmode
, x
);
421 reg
= gen_rtx_REG (DFmode
, regno
);
423 if (LOAD_FPU_REG_P (regno
))
424 emit_move_insn (reg
, x
);
427 emit_move_insn (via_ac
, x
);
428 emit_move_insn (reg
, via_ac
);
433 for (regno
= PC_REGNUM
; regno
>= R0_REGNUM
+ 2; regno
--)
434 if (pdp11_saved_regno (regno
)
435 && (regno
!= HARD_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
))
437 x
= plus_constant (Pmode
, hard_frame_pointer_rtx
, ofs
);
438 x
= gen_frame_mem (Pmode
, x
);
439 emit_move_insn (gen_rtx_REG (Pmode
, regno
), x
);
444 /* Deallocate the stack frame. */
447 /* Prevent frame references via any pointer from being
448 scheduled after the frame is deallocated. */
449 emit_insn (gen_blockage ());
451 if (frame_pointer_needed
)
453 /* We can deallocate the frame with a single move. */
454 emit_move_insn (stack_pointer_rtx
, hard_frame_pointer_rtx
);
457 emit_insn (gen_addhi3 (stack_pointer_rtx
, stack_pointer_rtx
,
461 if (frame_pointer_needed
)
463 x
= gen_rtx_POST_INC (Pmode
, stack_pointer_rtx
);
464 x
= gen_frame_mem (Pmode
, x
);
465 emit_move_insn (hard_frame_pointer_rtx
, x
);
468 emit_jump_insn (gen_return ());
471 /* Return the best assembler insn template
472 for moving operands[1] into operands[0] as a fullword. */
474 singlemove_string (rtx
*operands
)
476 if (operands
[1] != const0_rtx
)
483 /* Expand multi-word operands (SImode or DImode) into the 2 or 4
484 corresponding HImode operands. The number of operands is given
485 as the third argument, and the required order of the parts as
486 the fourth argument. */
488 pdp11_expand_operands (rtx
*operands
, rtx exops
[][2], int opcount
,
489 pdp11_action
*action
, pdp11_partorder order
)
491 int words
, op
, w
, i
, sh
;
492 pdp11_partorder useorder
;
493 bool sameoff
= false;
494 enum { REGOP
, OFFSOP
, MEMOP
, PUSHOP
, POPOP
, CNSTOP
, RNDOP
} optype
;
497 words
= GET_MODE_BITSIZE (GET_MODE (operands
[0])) / 16;
499 /* If either piece order is accepted and one is pre-decrement
500 while the other is post-increment, set order to be high order
501 word first. That will force the pre-decrement to be turned
502 into a pointer adjust, then offset addressing.
503 Otherwise, if either operand uses pre-decrement, that means
504 the order is low order first.
505 Otherwise, if both operands are registers and destination is
506 higher than source and they overlap, do low order word (highest
507 register number) first. */
511 if (!REG_P (operands
[0]) && !REG_P (operands
[1]) &&
512 !(CONSTANT_P (operands
[1]) ||
513 GET_CODE (operands
[1]) == CONST_DOUBLE
) &&
514 ((GET_CODE (XEXP (operands
[0], 0)) == POST_INC
&&
515 GET_CODE (XEXP (operands
[1], 0)) == PRE_DEC
) ||
516 (GET_CODE (XEXP (operands
[0], 0)) == PRE_DEC
&&
517 GET_CODE (XEXP (operands
[1], 0)) == POST_INC
)))
519 else if ((!REG_P (operands
[0]) &&
520 GET_CODE (XEXP (operands
[0], 0)) == PRE_DEC
) ||
521 (!REG_P (operands
[1]) &&
522 !(CONSTANT_P (operands
[1]) ||
523 GET_CODE (operands
[1]) == CONST_DOUBLE
) &&
524 GET_CODE (XEXP (operands
[1], 0)) == PRE_DEC
))
526 else if (REG_P (operands
[0]) && REG_P (operands
[1]) &&
527 REGNO (operands
[0]) > REGNO (operands
[1]) &&
528 REGNO (operands
[0]) < REGNO (operands
[1]) + words
)
531 /* Check for source == offset from register and dest == push of
532 the same register. In that case, we have to use the same
533 offset (the one for the low order word) for all words, because
534 the push increases the offset to each source word.
535 In theory there are other cases like this, for example dest == pop,
536 but those don't occur in real life so ignore those. */
537 if (GET_CODE (operands
[0]) == MEM
538 && GET_CODE (XEXP (operands
[0], 0)) == PRE_DEC
539 && REGNO (XEXP (XEXP (operands
[0], 0), 0)) == STACK_POINTER_REGNUM
540 && reg_overlap_mentioned_p (stack_pointer_rtx
, operands
[1]))
544 /* If the caller didn't specify order, use the one we computed,
545 or high word first if we don't care either. If the caller did
546 specify, verify we don't have a problem with that order.
547 (If it matters to the caller, constraints need to be used to
548 ensure this case doesn't occur). */
550 order
= (useorder
== either
) ? big
: useorder
;
552 gcc_assert (useorder
== either
|| useorder
== order
);
555 for (op
= 0; op
< opcount
; op
++)
557 /* First classify the operand. */
558 if (REG_P (operands
[op
]))
560 else if (CONSTANT_P (operands
[op
])
561 || GET_CODE (operands
[op
]) == CONST_DOUBLE
)
563 else if (GET_CODE (XEXP (operands
[op
], 0)) == POST_INC
)
565 else if (GET_CODE (XEXP (operands
[op
], 0)) == PRE_DEC
)
567 else if (!reload_in_progress
|| offsettable_memref_p (operands
[op
]))
569 else if (GET_CODE (operands
[op
]) == MEM
)
574 /* Check for the cases that the operand constraints are not
575 supposed to allow to happen. Return failure for such cases. */
580 action
[op
] = no_action
;
582 /* If the operand uses pre-decrement addressing but we
583 want to get the parts high order first,
584 decrement the former register explicitly
585 and change the operand into ordinary indexing. */
586 if (optype
== PUSHOP
&& order
== big
)
588 gcc_assert (action
!= NULL
);
589 action
[op
] = dec_before
;
590 operands
[op
] = gen_rtx_MEM (GET_MODE (operands
[op
]),
591 XEXP (XEXP (operands
[op
], 0), 0));
594 /* If the operand uses post-increment mode but we want
595 to get the parts low order first, change the operand
596 into ordinary indexing and remember to increment
597 the register explicitly when we're done. */
598 else if (optype
== POPOP
&& order
== little
)
600 gcc_assert (action
!= NULL
);
601 action
[op
] = inc_after
;
602 operands
[op
] = gen_rtx_MEM (GET_MODE (operands
[op
]),
603 XEXP (XEXP (operands
[op
], 0), 0));
607 if (GET_CODE (operands
[op
]) == CONST_DOUBLE
)
608 REAL_VALUE_TO_TARGET_DOUBLE
609 (*CONST_DOUBLE_REAL_VALUE (operands
[op
]), sval
);
611 for (i
= 0; i
< words
; i
++)
620 /* Set the output operand to be word "w" of the input. */
622 exops
[i
][op
] = gen_rtx_REG (HImode
, REGNO (operands
[op
]) + w
);
623 else if (optype
== OFFSOP
)
624 exops
[i
][op
] = adjust_address (operands
[op
], HImode
, w
* 2);
625 else if (optype
== CNSTOP
)
627 if (GET_CODE (operands
[op
]) == CONST_DOUBLE
)
629 sh
= 16 - (w
& 1) * 16;
630 exops
[i
][op
] = gen_rtx_CONST_INT (HImode
, (sval
[w
/ 2] >> sh
) & 0xffff);
634 sh
= ((words
- 1 - w
) * 16);
635 exops
[i
][op
] = gen_rtx_CONST_INT (HImode
, trunc_int_for_mode (INTVAL(operands
[op
]) >> sh
, HImode
));
639 exops
[i
][op
] = operands
[op
];
645 /* Output assembler code to perform a multiple-word move insn
646 with operands OPERANDS. This moves 2 or 4 words depending
647 on the machine mode of the operands. */
650 output_move_multiple (rtx
*operands
)
653 pdp11_action action
[2];
656 words
= GET_MODE_BITSIZE (GET_MODE (operands
[0])) / 16;
658 pdp11_expand_operands (operands
, exops
, 2, action
, either
);
660 /* Check for explicit decrement before. */
661 if (action
[0] == dec_before
)
663 operands
[0] = XEXP (operands
[0], 0);
664 output_asm_insn ("sub $4,%0", operands
);
666 if (action
[1] == dec_before
)
668 operands
[1] = XEXP (operands
[1], 0);
669 output_asm_insn ("sub $4,%1", operands
);
673 for (i
= 0; i
< words
; i
++)
674 output_asm_insn (singlemove_string (exops
[i
]), exops
[i
]);
676 /* Check for increment after. */
677 if (action
[0] == inc_after
)
679 operands
[0] = XEXP (operands
[0], 0);
680 output_asm_insn ("add $4,%0", operands
);
682 if (action
[1] == inc_after
)
684 operands
[1] = XEXP (operands
[1], 0);
685 output_asm_insn ("add $4,%1", operands
);
691 /* Output an ascii string. */
693 output_ascii (FILE *file
, const char *p
, int size
)
697 /* This used to output .byte "string", which doesn't work with the UNIX
698 assembler and I think not with DEC ones either. */
699 fprintf (file
, "\t.byte ");
701 for (i
= 0; i
< size
; i
++)
703 register int c
= p
[i
];
706 fprintf (file
, "%#o", c
);
715 pdp11_asm_output_var (FILE *file
, const char *name
, int size
,
716 int align
, bool global
)
719 fprintf (file
, "\n\t.even\n");
722 fprintf (file
, ".globl ");
723 assemble_name (file
, name
);
725 fprintf (file
, "\n");
726 assemble_name (file
, name
);
727 fprintf (file
, ": .=.+ %#ho\n", (unsigned short)size
);
731 pdp11_asm_print_operand (FILE *file
, rtx x
, int code
)
737 else if (code
== '@')
744 else if (GET_CODE (x
) == REG
)
745 fprintf (file
, "%s", reg_names
[REGNO (x
)]);
746 else if (GET_CODE (x
) == MEM
)
747 output_address (GET_MODE (x
), XEXP (x
, 0));
748 else if (GET_CODE (x
) == CONST_DOUBLE
&& GET_MODE (x
) != SImode
)
750 REAL_VALUE_TO_TARGET_DOUBLE (*CONST_DOUBLE_REAL_VALUE (x
), sval
);
751 fprintf (file
, "$%#lo", sval
[0] >> 16);
756 output_addr_const_pdp11 (file
, x
);
761 pdp11_asm_print_operand_punct_valid_p (unsigned char c
)
763 return (c
== '#' || c
== '@');
767 print_operand_address (FILE *file
, register rtx addr
)
775 switch (GET_CODE (addr
))
782 addr
= XEXP (addr
, 0);
787 fprintf (file
, "(%s)", reg_names
[REGNO (addr
)]);
792 fprintf (file
, "-(%s)", reg_names
[REGNO (XEXP (addr
, 0))]);
797 fprintf (file
, "(%s)+", reg_names
[REGNO (XEXP (addr
, 0))]);
803 if (CONSTANT_ADDRESS_P (XEXP (addr
, 0))
804 || GET_CODE (XEXP (addr
, 0)) == MEM
)
806 offset
= XEXP (addr
, 0);
807 addr
= XEXP (addr
, 1);
809 else if (CONSTANT_ADDRESS_P (XEXP (addr
, 1))
810 || GET_CODE (XEXP (addr
, 1)) == MEM
)
812 offset
= XEXP (addr
, 1);
813 addr
= XEXP (addr
, 0);
815 if (GET_CODE (addr
) != PLUS
)
817 else if (GET_CODE (XEXP (addr
, 0)) == REG
)
819 breg
= XEXP (addr
, 0);
820 addr
= XEXP (addr
, 1);
822 else if (GET_CODE (XEXP (addr
, 1)) == REG
)
824 breg
= XEXP (addr
, 1);
825 addr
= XEXP (addr
, 0);
827 if (GET_CODE (addr
) == REG
)
829 gcc_assert (breg
== 0);
835 gcc_assert (addr
== 0);
839 output_addr_const_pdp11 (file
, addr
);
842 gcc_assert (GET_CODE (breg
) == REG
);
843 fprintf (file
, "(%s)", reg_names
[REGNO (breg
)]);
848 if (!again
&& GET_CODE (addr
) == CONST_INT
)
850 /* Absolute (integer number) address. */
851 if (!TARGET_UNIX_ASM
)
852 fprintf (file
, "@$");
854 output_addr_const_pdp11 (file
, addr
);
858 /* Target hook to assemble integer objects. We need to use the
859 pdp-specific version of output_addr_const. */
862 pdp11_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
868 fprintf (asm_out_file
, "\t.byte\t");
869 output_addr_const_pdp11 (asm_out_file
, GEN_INT (INTVAL (x
) & 0xff));
871 fprintf (asm_out_file
, " /* char */\n");
875 fprintf (asm_out_file
, TARGET_UNIX_ASM
? "\t" : "\t.word\t");
876 output_addr_const_pdp11 (asm_out_file
, x
);
877 fprintf (asm_out_file
, " /* short */\n");
880 return default_assemble_integer (x
, size
, aligned_p
);
884 /* register move costs, indexed by regs */
886 static const int move_costs
[N_REG_CLASSES
][N_REG_CLASSES
] =
888 /* NO MUL GEN LFPU NLFPU FPU ALL */
890 /* NO */ { 0, 0, 0, 0, 0, 0, 0},
891 /* MUL */ { 0, 2, 2, 22, 22, 22, 22},
892 /* GEN */ { 0, 2, 2, 22, 22, 22, 22},
893 /* LFPU */ { 0, 22, 22, 2, 2, 2, 22},
894 /* NLFPU */ { 0, 22, 22, 2, 10, 10, 22},
895 /* FPU */ { 0, 22, 22, 2, 10, 10, 22},
896 /* ALL */ { 0, 22, 22, 22, 22, 22, 22}
900 /* -- note that some moves are tremendously expensive,
901 because they require lots of tricks! do we have to
902 charge the costs incurred by secondary reload class
903 -- as we do here with 10 -- or not ? */
906 pdp11_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED
,
907 reg_class_t c1
, reg_class_t c2
)
909 return move_costs
[(int)c1
][(int)c2
];
913 pdp11_rtx_costs (rtx x
, machine_mode mode
, int outer_code ATTRIBUTE_UNUSED
,
914 int opno ATTRIBUTE_UNUSED
, int *total
,
915 bool speed ATTRIBUTE_UNUSED
)
917 int code
= GET_CODE (x
);
922 if (INTVAL (x
) == 0 || INTVAL (x
) == -1 || INTVAL (x
) == 1)
932 /* Twice as expensive as REG. */
937 /* Twice (or 4 times) as expensive as 16 bit. */
942 /* ??? There is something wrong in MULT because MULT is not
943 as cheap as total = 2 even if we can shift! */
944 /* If optimizing for size make mult etc cheap, but not 1, so when
945 in doubt the faster insn is chosen. */
947 *total
= COSTS_N_INSNS (2);
949 *total
= COSTS_N_INSNS (11);
954 *total
= COSTS_N_INSNS (2);
956 *total
= COSTS_N_INSNS (25);
961 *total
= COSTS_N_INSNS (2);
963 *total
= COSTS_N_INSNS (26);
967 /* Equivalent to length, so same for optimize_size. */
968 *total
= COSTS_N_INSNS (3);
972 /* Only used for qi->hi. */
973 *total
= COSTS_N_INSNS (1);
978 *total
= COSTS_N_INSNS (1);
979 else if (mode
== SImode
)
980 *total
= COSTS_N_INSNS (6);
982 *total
= COSTS_N_INSNS (2);
989 *total
= COSTS_N_INSNS (1);
990 else if (mode
== QImode
)
992 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
993 *total
= COSTS_N_INSNS (8); /* worst case */
995 *total
= COSTS_N_INSNS (INTVAL (XEXP (x
, 1)));
997 else if (mode
== HImode
)
999 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
1001 if (abs (INTVAL (XEXP (x
, 1))) == 1)
1002 *total
= COSTS_N_INSNS (1);
1004 *total
= COSTS_N_INSNS (2.5 + 0.5 * INTVAL (XEXP (x
, 1)));
1007 *total
= COSTS_N_INSNS (10); /* worst case */
1009 else if (mode
== SImode
)
1011 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
1012 *total
= COSTS_N_INSNS (2.5 + 0.5 * INTVAL (XEXP (x
, 1)));
1013 else /* worst case */
1014 *total
= COSTS_N_INSNS (18);
1024 output_jump (enum rtx_code code
, int inv
, int length
)
1028 static char buf
[1000];
1029 const char *pos
, *neg
;
1031 if (cc_prev_status
.flags
& CC_NO_OVERFLOW
)
1035 case GTU
: code
= GT
; break;
1036 case LTU
: code
= LT
; break;
1037 case GEU
: code
= GE
; break;
1038 case LEU
: code
= LE
; break;
1044 case EQ
: pos
= "beq", neg
= "bne"; break;
1045 case NE
: pos
= "bne", neg
= "beq"; break;
1046 case GT
: pos
= "bgt", neg
= "ble"; break;
1047 case GTU
: pos
= "bhi", neg
= "blos"; break;
1048 case LT
: pos
= "blt", neg
= "bge"; break;
1049 case LTU
: pos
= "blo", neg
= "bhis"; break;
1050 case GE
: pos
= "bge", neg
= "blt"; break;
1051 case GEU
: pos
= "bhis", neg
= "blo"; break;
1052 case LE
: pos
= "ble", neg
= "bgt"; break;
1053 case LEU
: pos
= "blos", neg
= "bhi"; break;
1054 default: gcc_unreachable ();
1058 /* currently we don't need this, because the tstdf and cmpdf
1059 copy the condition code immediately, and other float operations are not
1060 yet recognized as changing the FCC - if so, then the length-cost of all
1061 jump insns increases by one, because we have to potentially copy the
1063 if (cc_status
.flags
& CC_IN_FPU
)
1064 output_asm_insn("cfcc", NULL
);
1071 sprintf(buf
, "%s %%l1", inv
? neg
: pos
);
1077 sprintf(buf
, "%s JMP_%d\n\tjmp %%l1\nJMP_%d:", inv
? pos
: neg
, x
, x
);
1091 notice_update_cc_on_set(rtx exp
, rtx insn ATTRIBUTE_UNUSED
)
1093 if (GET_CODE (SET_DEST (exp
)) == CC0
)
1095 cc_status
.flags
= 0;
1096 cc_status
.value1
= SET_DEST (exp
);
1097 cc_status
.value2
= SET_SRC (exp
);
1099 else if (GET_CODE (SET_SRC (exp
)) == CALL
)
1103 else if (SET_DEST(exp
) == pc_rtx
)
1107 else if (GET_MODE (SET_DEST(exp
)) == HImode
1108 || GET_MODE (SET_DEST(exp
)) == QImode
)
1110 cc_status
.flags
= GET_CODE (SET_SRC(exp
)) == MINUS
? 0 : CC_NO_OVERFLOW
;
1111 cc_status
.value1
= SET_SRC (exp
);
1112 cc_status
.value2
= SET_DEST (exp
);
1114 if (cc_status
.value1
&& GET_CODE (cc_status
.value1
) == REG
1116 && reg_overlap_mentioned_p (cc_status
.value1
, cc_status
.value2
))
1117 cc_status
.value2
= 0;
1118 if (cc_status
.value1
&& GET_CODE (cc_status
.value1
) == MEM
1120 && GET_CODE (cc_status
.value2
) == MEM
)
1121 cc_status
.value2
= 0;
1131 simple_memory_operand(rtx op
, machine_mode mode ATTRIBUTE_UNUSED
)
1135 /* Eliminate non-memory operations */
1136 if (GET_CODE (op
) != MEM
)
1140 /* dword operations really put out 2 instructions, so eliminate them. */
1141 if (GET_MODE_SIZE (GET_MODE (op
)) > (HAVE_64BIT_P () ? 8 : 4))
1145 /* Decode the address now. */
1149 addr
= XEXP (op
, 0);
1151 switch (GET_CODE (addr
))
1154 /* (R0) - no extra cost */
1159 /* -(R0), (R0)+ - cheap! */
1163 /* cheap - is encoded in addressing mode info!
1165 -- except for @(R0), which has to be @0(R0) !!! */
1167 if (GET_CODE (XEXP (addr
, 0)) == REG
)
1177 /* @#address - extra cost */
1181 /* X(R0) - extra cost */
1193 * output a block move:
1195 * operands[0] ... to
1196 * operands[1] ... from
1197 * operands[2] ... length
1198 * operands[3] ... alignment
1199 * operands[4] ... scratch register
1204 output_block_move(rtx
*operands
)
1206 static int count
= 0;
1211 /* Move of zero bytes is a NOP. */
1212 if (operands
[2] == const0_rtx
)
1215 /* Look for moves by small constant byte counts, those we'll
1216 expand to straight line code. */
1217 if (CONSTANT_P (operands
[2]))
1219 if (INTVAL (operands
[2]) < 16
1220 && (!optimize_size
|| INTVAL (operands
[2]) < 5)
1221 && INTVAL (operands
[3]) == 1)
1225 for (i
= 1; i
<= INTVAL (operands
[2]); i
++)
1226 output_asm_insn("movb (%1)+, (%0)+", operands
);
1230 else if (INTVAL(operands
[2]) < 32
1231 && (!optimize_size
|| INTVAL (operands
[2]) < 9)
1232 && INTVAL (operands
[3]) >= 2)
1236 for (i
= 1; i
<= INTVAL (operands
[2]) / 2; i
++)
1237 output_asm_insn ("mov (%1)+, (%0)+", operands
);
1238 if (INTVAL (operands
[2]) & 1)
1239 output_asm_insn ("movb (%1), (%0)", operands
);
1245 /* Ideally we'd look for moves that are multiples of 4 or 8
1246 bytes and handle those by unrolling the move loop. That
1247 makes for a lot of code if done at run time, but it's ok
1248 for constant counts. Also, for variable counts we have
1249 to worry about odd byte count with even aligned pointers.
1250 On 11/40 and up we handle that case; on older machines
1251 we don't and just use byte-wise moves all the time. */
1253 if (CONSTANT_P (operands
[2]) )
1255 if (INTVAL (operands
[3]) < 2)
1259 lastbyte
= INTVAL (operands
[2]) & 1;
1261 if (optimize_size
|| INTVAL (operands
[2]) & 2)
1263 else if (INTVAL (operands
[2]) & 4)
1269 /* Loop count is byte count scaled by unroll. */
1270 operands
[2] = GEN_INT (INTVAL (operands
[2]) >> unroll
);
1271 output_asm_insn ("mov %2, %4", operands
);
1275 /* Variable byte count; use the input register
1277 operands
[4] = operands
[2];
1279 /* Decide whether to move by words, and check
1280 the byte count for zero. */
1281 if (TARGET_40_PLUS
&& INTVAL (operands
[3]) > 1)
1284 output_asm_insn ("asr %4", operands
);
1289 output_asm_insn ("tst %4", operands
);
1291 sprintf (buf
, "beq movestrhi%d", count
+ 1);
1292 output_asm_insn (buf
, NULL
);
1295 /* Output the loop label. */
1296 sprintf (buf
, "\nmovestrhi%d:", count
);
1297 output_asm_insn (buf
, NULL
);
1299 /* Output the appropriate move instructions. */
1303 output_asm_insn ("movb (%1)+, (%0)+", operands
);
1307 output_asm_insn ("mov (%1)+, (%0)+", operands
);
1311 output_asm_insn ("mov (%1)+, (%0)+", operands
);
1312 output_asm_insn ("mov (%1)+, (%0)+", operands
);
1316 output_asm_insn ("mov (%1)+, (%0)+", operands
);
1317 output_asm_insn ("mov (%1)+, (%0)+", operands
);
1318 output_asm_insn ("mov (%1)+, (%0)+", operands
);
1319 output_asm_insn ("mov (%1)+, (%0)+", operands
);
1323 /* Output the decrement and test. */
1326 sprintf (buf
, "sob %%4, movestrhi%d", count
);
1327 output_asm_insn (buf
, operands
);
1331 output_asm_insn ("dec %4", operands
);
1332 sprintf (buf
, "bgt movestrhi%d", count
);
1333 output_asm_insn (buf
, NULL
);
1337 /* If constant odd byte count, move the last byte. */
1339 output_asm_insn ("movb (%1), (%0)", operands
);
1340 else if (!CONSTANT_P (operands
[2]))
1342 /* Output the destination label for the zero byte count check. */
1343 sprintf (buf
, "\nmovestrhi%d:", count
);
1344 output_asm_insn (buf
, NULL
);
1347 /* If we did word moves, check for trailing last byte. */
1350 sprintf (buf
, "bcc movestrhi%d", count
);
1351 output_asm_insn (buf
, NULL
);
1352 output_asm_insn ("movb (%1), (%0)", operands
);
1353 sprintf (buf
, "\nmovestrhi%d:", count
);
1354 output_asm_insn (buf
, NULL
);
1362 /* This function checks whether a real value can be encoded as
1363 a literal, i.e., addressing mode 27. In that mode, real values
1364 are one word values, so the remaining 48 bits have to be zero. */
1366 legitimate_const_double_p (rtx address
)
1369 REAL_VALUE_TO_TARGET_DOUBLE (*CONST_DOUBLE_REAL_VALUE (address
), sval
);
1370 if ((sval
[0] & 0xffff) == 0 && sval
[1] == 0)
1375 /* Implement CANNOT_CHANGE_MODE_CLASS. */
1377 pdp11_cannot_change_mode_class (machine_mode from
,
1379 enum reg_class rclass
)
1381 /* Also, FPU registers contain a whole float value and the parts of
1382 it are not separately accessible.
1384 So we disallow all mode changes involving FPRs. */
1385 if (FLOAT_MODE_P (from
) != FLOAT_MODE_P (to
))
1388 return reg_classes_intersect_p (FPU_REGS
, rclass
);
1391 /* TARGET_PREFERRED_RELOAD_CLASS
1393 Given an rtx X being reloaded into a reg required to be
1394 in class CLASS, return the class of reg to actually use.
1395 In general this is just CLASS; but on some machines
1396 in some cases it is preferable to use a more restrictive class.
1398 loading is easier into LOAD_FPU_REGS than FPU_REGS! */
1401 pdp11_preferred_reload_class (rtx x
, reg_class_t rclass
)
1403 if (rclass
== FPU_REGS
)
1404 return LOAD_FPU_REGS
;
1405 if (rclass
== ALL_REGS
)
1407 if (FLOAT_MODE_P (GET_MODE (x
)))
1408 return LOAD_FPU_REGS
;
1410 return GENERAL_REGS
;
1415 /* TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
1417 Given an rtx X being reloaded into a reg required to be
1418 in class CLASS, return the class of reg to actually use.
1419 In general this is just CLASS; but on some machines
1420 in some cases it is preferable to use a more restrictive class.
1422 loading is easier into LOAD_FPU_REGS than FPU_REGS! */
1425 pdp11_preferred_output_reload_class (rtx x
, reg_class_t rclass
)
1427 if (rclass
== FPU_REGS
)
1428 return LOAD_FPU_REGS
;
1429 if (rclass
== ALL_REGS
)
1431 if (FLOAT_MODE_P (GET_MODE (x
)))
1432 return LOAD_FPU_REGS
;
1434 return GENERAL_REGS
;
1440 /* TARGET_SECONDARY_RELOAD.
1442 FPU registers AC4 and AC5 (class NO_LOAD_FPU_REGS) require an
1443 intermediate register (AC0-AC3: LOAD_FPU_REGS). Everything else
1444 can be loade/stored directly. */
1446 pdp11_secondary_reload (bool in_p ATTRIBUTE_UNUSED
,
1448 reg_class_t reload_class
,
1449 machine_mode reload_mode ATTRIBUTE_UNUSED
,
1450 secondary_reload_info
*sri ATTRIBUTE_UNUSED
)
1452 if (reload_class
!= NO_LOAD_FPU_REGS
|| GET_CODE (x
) != REG
||
1453 REGNO_REG_CLASS (REGNO (x
)) == LOAD_FPU_REGS
)
1456 return LOAD_FPU_REGS
;
1459 /* Implement TARGET_SECONDARY_MEMORY_NEEDED.
1461 The answer is yes if we're going between general register and FPU
1462 registers. The mode doesn't matter in making this check.
1465 pdp11_secondary_memory_needed (machine_mode
, reg_class_t c1
, reg_class_t c2
)
1467 int fromfloat
= (c1
== LOAD_FPU_REGS
|| c1
== NO_LOAD_FPU_REGS
||
1469 int tofloat
= (c2
== LOAD_FPU_REGS
|| c2
== NO_LOAD_FPU_REGS
||
1472 return (fromfloat
!= tofloat
);
1475 /* TARGET_LEGITIMATE_ADDRESS_P recognizes an RTL expression
1476 that is a valid memory address for an instruction.
1477 The MODE argument is the machine mode for the MEM expression
1478 that wants to use this address.
1483 pdp11_legitimate_address_p (machine_mode mode
,
1484 rtx operand
, bool strict
)
1488 /* accept @#address */
1489 if (CONSTANT_ADDRESS_P (operand
))
1492 switch (GET_CODE (operand
))
1496 return !strict
|| REGNO_OK_FOR_BASE_P (REGNO (operand
));
1500 return GET_CODE (XEXP (operand
, 0)) == REG
1501 && (!strict
|| REGNO_OK_FOR_BASE_P (REGNO (XEXP (operand
, 0))))
1502 && CONSTANT_ADDRESS_P (XEXP (operand
, 1));
1506 return GET_CODE (XEXP (operand
, 0)) == REG
1507 && (!strict
|| REGNO_OK_FOR_BASE_P (REGNO (XEXP (operand
, 0))));
1511 return GET_CODE (XEXP (operand
, 0)) == REG
1512 && (!strict
|| REGNO_OK_FOR_BASE_P (REGNO (XEXP (operand
, 0))));
1515 /* accept -(SP) -- which uses PRE_MODIFY for byte mode */
1516 return GET_CODE (XEXP (operand
, 0)) == REG
1517 && REGNO (XEXP (operand
, 0)) == STACK_POINTER_REGNUM
1518 && GET_CODE ((xfoob
= XEXP (operand
, 1))) == PLUS
1519 && GET_CODE (XEXP (xfoob
, 0)) == REG
1520 && REGNO (XEXP (xfoob
, 0)) == STACK_POINTER_REGNUM
1521 && CONSTANT_P (XEXP (xfoob
, 1))
1522 && INTVAL (XEXP (xfoob
,1)) == -2;
1525 /* accept (SP)+ -- which uses POST_MODIFY for byte mode */
1526 return GET_CODE (XEXP (operand
, 0)) == REG
1527 && REGNO (XEXP (operand
, 0)) == STACK_POINTER_REGNUM
1528 && GET_CODE ((xfoob
= XEXP (operand
, 1))) == PLUS
1529 && GET_CODE (XEXP (xfoob
, 0)) == REG
1530 && REGNO (XEXP (xfoob
, 0)) == STACK_POINTER_REGNUM
1531 && CONSTANT_P (XEXP (xfoob
, 1))
1532 && INTVAL (XEXP (xfoob
,1)) == 2;
1535 /* handle another level of indirection ! */
1536 xfoob
= XEXP (operand
, 0);
1538 /* (MEM:xx (MEM:xx ())) is not valid for SI, DI and currently
1539 also forbidden for float, because we have to handle this
1540 in output_move_double and/or output_move_quad() - we could
1541 do it, but currently it's not worth it!!!
1542 now that DFmode cannot go into CPU register file,
1543 maybe I should allow float ...
1544 but then I have to handle memory-to-memory moves in movdf ?? */
1545 if (GET_MODE_BITSIZE(mode
) > 16)
1548 /* accept @address */
1549 if (CONSTANT_ADDRESS_P (xfoob
))
1552 switch (GET_CODE (xfoob
))
1555 /* accept @(R0) - which is @0(R0) */
1556 return !strict
|| REGNO_OK_FOR_BASE_P(REGNO (xfoob
));
1560 return GET_CODE (XEXP (xfoob
, 0)) == REG
1561 && (!strict
|| REGNO_OK_FOR_BASE_P (REGNO (XEXP (xfoob
, 0))))
1562 && CONSTANT_ADDRESS_P (XEXP (xfoob
, 1));
1566 return GET_CODE (XEXP (xfoob
, 0)) == REG
1567 && (!strict
|| REGNO_OK_FOR_BASE_P (REGNO (XEXP (xfoob
, 0))));
1571 return GET_CODE (XEXP (xfoob
, 0)) == REG
1572 && (!strict
|| REGNO_OK_FOR_BASE_P (REGNO (XEXP (xfoob
, 0))));
1575 /* anything else is invalid */
1580 /* anything else is invalid */
1585 /* Return the class number of the smallest class containing
1586 reg number REGNO. */
1588 pdp11_regno_reg_class (int regno
)
1590 if (regno
== FRAME_POINTER_REGNUM
|| regno
== ARG_POINTER_REGNUM
)
1591 return GENERAL_REGS
;
1592 else if (regno
> AC3_REGNUM
)
1593 return NO_LOAD_FPU_REGS
;
1594 else if (regno
>= AC0_REGNUM
)
1595 return LOAD_FPU_REGS
;
1599 return GENERAL_REGS
;
1604 pdp11_sp_frame_offset (void)
1606 int offset
= 0, regno
;
1607 offset
= get_frame_size();
1608 for (regno
= 0; regno
<= PC_REGNUM
; regno
++)
1609 if (pdp11_saved_regno (regno
))
1611 for (regno
= AC0_REGNUM
; regno
<= AC5_REGNUM
; regno
++)
1612 if (pdp11_saved_regno (regno
))
1618 /* Return the offset between two registers, one to be eliminated, and the other
1619 its replacement, at the start of a routine. */
1622 pdp11_initial_elimination_offset (int from
, int to
)
1626 if (from
== ARG_POINTER_REGNUM
&& to
== HARD_FRAME_POINTER_REGNUM
)
1628 else if (from
== FRAME_POINTER_REGNUM
1629 && to
== HARD_FRAME_POINTER_REGNUM
)
1633 gcc_assert (to
== STACK_POINTER_REGNUM
);
1635 /* Get the size of the register save area. */
1636 spoff
= pdp11_sp_frame_offset ();
1637 if (from
== FRAME_POINTER_REGNUM
)
1640 gcc_assert (from
== ARG_POINTER_REGNUM
);
1642 /* If there is a frame pointer, that is saved too. */
1643 if (frame_pointer_needed
)
1646 /* Account for the saved PC in the function call. */
1651 /* A copy of output_addr_const modified for pdp11 expression syntax.
1652 output_addr_const also gets called for %cDIGIT and %nDIGIT, which we don't
1653 use, and for debugging output, which we don't support with this port either.
1654 So this copy should get called whenever needed.
1657 output_addr_const_pdp11 (FILE *file
, rtx x
)
1663 switch (GET_CODE (x
))
1666 gcc_assert (flag_pic
);
1671 assemble_name (file
, XSTR (x
, 0));
1675 ASM_GENERATE_INTERNAL_LABEL (buf
, "L", CODE_LABEL_NUMBER (XEXP (x
, 0)));
1676 assemble_name (file
, buf
);
1680 ASM_GENERATE_INTERNAL_LABEL (buf
, "L", CODE_LABEL_NUMBER (x
));
1681 assemble_name (file
, buf
);
1689 fprintf (file
, "-");
1691 fprintf (file
, "%#o", i
& 0xffff);
1695 /* This used to output parentheses around the expression,
1696 but that does not work on the 386 (either ATT or BSD assembler). */
1697 output_addr_const_pdp11 (file
, XEXP (x
, 0));
1701 if (GET_MODE (x
) == VOIDmode
)
1703 /* We can use %o if the number is one word and positive. */
1704 gcc_assert (!CONST_DOUBLE_HIGH (x
));
1705 fprintf (file
, "%#ho", (unsigned short) CONST_DOUBLE_LOW (x
));
1708 /* We can't handle floating point constants;
1709 PRINT_OPERAND must handle them. */
1710 output_operand_lossage ("floating constant misused");
1714 /* Some assemblers need integer constants to appear last (e.g. masm). */
1715 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
1717 output_addr_const_pdp11 (file
, XEXP (x
, 1));
1718 if (INTVAL (XEXP (x
, 0)) >= 0)
1719 fprintf (file
, "+");
1720 output_addr_const_pdp11 (file
, XEXP (x
, 0));
1724 output_addr_const_pdp11 (file
, XEXP (x
, 0));
1725 if (INTVAL (XEXP (x
, 1)) >= 0)
1726 fprintf (file
, "+");
1727 output_addr_const_pdp11 (file
, XEXP (x
, 1));
1732 /* Avoid outputting things like x-x or x+5-x,
1733 since some assemblers can't handle that. */
1734 x
= simplify_subtraction (x
);
1735 if (GET_CODE (x
) != MINUS
)
1738 output_addr_const_pdp11 (file
, XEXP (x
, 0));
1739 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
1740 || INTVAL (XEXP (x
, 1)) >= 0)
1741 fprintf (file
, "-");
1742 output_addr_const_pdp11 (file
, XEXP (x
, 1));
1747 output_addr_const_pdp11 (file
, XEXP (x
, 0));
1751 output_operand_lossage ("invalid expression as operand");
1755 /* Worker function for TARGET_RETURN_IN_MEMORY. */
1758 pdp11_return_in_memory (const_tree type
, const_tree fntype ATTRIBUTE_UNUSED
)
1760 /* Integers 32 bits and under, and scalar floats (if FPU), are returned
1761 in registers. The rest go into memory. */
1762 return (TYPE_MODE (type
) == DImode
1763 || (FLOAT_MODE_P (TYPE_MODE (type
)) && ! TARGET_AC0
)
1764 || TREE_CODE (type
) == VECTOR_TYPE
1765 || COMPLEX_MODE_P (TYPE_MODE (type
)));
1768 /* Worker function for TARGET_FUNCTION_VALUE.
1770 On the pdp11 the value is found in R0 (or ac0??? not without FPU!!!! ) */
1773 pdp11_function_value (const_tree valtype
,
1774 const_tree fntype_or_decl ATTRIBUTE_UNUSED
,
1775 bool outgoing ATTRIBUTE_UNUSED
)
1777 return gen_rtx_REG (TYPE_MODE (valtype
),
1778 BASE_RETURN_VALUE_REG(TYPE_MODE(valtype
)));
1781 /* Worker function for TARGET_LIBCALL_VALUE. */
1784 pdp11_libcall_value (machine_mode mode
,
1785 const_rtx fun ATTRIBUTE_UNUSED
)
1787 return gen_rtx_REG (mode
, BASE_RETURN_VALUE_REG(mode
));
1790 /* Worker function for TARGET_FUNCTION_VALUE_REGNO_P.
1792 On the pdp, the first "output" reg is the only register thus used.
1794 maybe ac0 ? - as option someday! */
1797 pdp11_function_value_regno_p (const unsigned int regno
)
1799 return (regno
== RETVAL_REGNUM
) || (TARGET_AC0
&& (regno
== AC0_REGNUM
));
1802 /* Worker function for TARGET_TRAMPOLINE_INIT.
1804 trampoline - how should i do it in separate i+d ?
1805 have some allocate_trampoline magic???
1807 the following should work for shared I/D:
1809 MOV #STATIC, $4 01270Y 0x0000 <- STATIC; Y = STATIC_CHAIN_REGNUM
1810 JMP @#FUNCTION 000137 0x0000 <- FUNCTION
1814 pdp11_trampoline_init (rtx m_tramp
, tree fndecl
, rtx chain_value
)
1816 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
1819 gcc_assert (!TARGET_SPLIT
);
1821 mem
= adjust_address (m_tramp
, HImode
, 0);
1822 emit_move_insn (mem
, GEN_INT (012700+STATIC_CHAIN_REGNUM
));
1823 mem
= adjust_address (m_tramp
, HImode
, 2);
1824 emit_move_insn (mem
, chain_value
);
1825 mem
= adjust_address (m_tramp
, HImode
, 4);
1826 emit_move_insn (mem
, GEN_INT (000137));
1827 emit_move_insn (mem
, fnaddr
);
1830 /* Worker function for TARGET_FUNCTION_ARG.
1832 Determine where to put an argument to a function.
1833 Value is zero to push the argument on the stack,
1834 or a hard register in which to store the argument.
1836 MODE is the argument's machine mode.
1837 TYPE is the data type of the argument (as a tree).
1838 This is null for libcalls where that information may
1840 CUM is a variable of type CUMULATIVE_ARGS which gives info about
1841 the preceding args and about the function being called.
1842 NAMED is nonzero if this argument is a named parameter
1843 (otherwise it is an extra parameter matching an ellipsis). */
1846 pdp11_function_arg (cumulative_args_t cum ATTRIBUTE_UNUSED
,
1847 machine_mode mode ATTRIBUTE_UNUSED
,
1848 const_tree type ATTRIBUTE_UNUSED
,
1849 bool named ATTRIBUTE_UNUSED
)
1854 /* Worker function for TARGET_FUNCTION_ARG_ADVANCE.
1856 Update the data in CUM to advance over an argument of mode MODE and
1857 data type TYPE. (TYPE is null for libcalls where that information
1858 may not be available.) */
1861 pdp11_function_arg_advance (cumulative_args_t cum_v
, machine_mode mode
,
1862 const_tree type
, bool named ATTRIBUTE_UNUSED
)
1864 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
1866 *cum
+= (mode
!= BLKmode
1867 ? GET_MODE_SIZE (mode
)
1868 : int_size_in_bytes (type
));
1871 /* Make sure everything's fine if we *don't* have an FPU.
1872 This assumes that putting a register in fixed_regs will keep the
1873 compiler's mitts completely off it. We don't bother to zero it out
1874 of register classes. Also fix incompatible register naming with
1875 the UNIX assembler. */
1878 pdp11_conditional_register_usage (void)
1884 COPY_HARD_REG_SET (x
, reg_class_contents
[(int)FPU_REGS
]);
1885 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++ )
1886 if (TEST_HARD_REG_BIT (x
, i
))
1887 fixed_regs
[i
] = call_used_regs
[i
] = 1;
1891 call_used_regs
[AC0_REGNUM
] = 1;
1892 if (TARGET_UNIX_ASM
)
1894 /* Change names of FPU registers for the UNIX assembler. */
1895 reg_names
[8] = "fr0";
1896 reg_names
[9] = "fr1";
1897 reg_names
[10] = "fr2";
1898 reg_names
[11] = "fr3";
1899 reg_names
[12] = "fr4";
1900 reg_names
[13] = "fr5";
1905 pdp11_function_section (tree decl ATTRIBUTE_UNUSED
,
1906 enum node_frequency freq ATTRIBUTE_UNUSED
,
1907 bool startup ATTRIBUTE_UNUSED
,
1908 bool exit ATTRIBUTE_UNUSED
)
1913 /* Implement TARGET_LEGITIMATE_CONSTANT_P. */
1916 pdp11_legitimate_constant_p (machine_mode mode ATTRIBUTE_UNUSED
, rtx x
)
1918 return GET_CODE (x
) != CONST_DOUBLE
|| legitimate_const_double_p (x
);
1921 /* Implement TARGET_SCALAR_MODE_SUPPORTED_P. */
1924 pdp11_scalar_mode_supported_p (scalar_mode mode
)
1926 /* Support SFmode even with -mfloat64. */
1929 return default_scalar_mode_supported_p (mode
);
1933 pdp11_branch_cost ()
1935 return (TARGET_BRANCH_CHEAP
? 0 : 1);
1938 /* Implement TARGET_HARD_REGNO_NREGS. */
1941 pdp11_hard_regno_nregs (unsigned int regno
, machine_mode mode
)
1943 if (regno
<= PC_REGNUM
)
1944 return CEIL (GET_MODE_SIZE (mode
), UNITS_PER_WORD
);
1948 /* Implement TARGET_HARD_REGNO_MODE_OK. On the pdp, the cpu registers
1949 can hold any mode other than float (because otherwise we may end up
1950 being asked to move from CPU to FPU register, which isn't a valid
1951 operation on the PDP11). For CPU registers, check alignment.
1953 FPU accepts SF and DF but actually holds a DF - simplifies life! */
1956 pdp11_hard_regno_mode_ok (unsigned int regno
, machine_mode mode
)
1958 if (regno
<= PC_REGNUM
)
1959 return (GET_MODE_BITSIZE (mode
) <= 16
1960 || (GET_MODE_BITSIZE (mode
) >= 32
1962 && !FLOAT_MODE_P (mode
)));
1964 return FLOAT_MODE_P (mode
);
1967 /* Implement TARGET_MODES_TIEABLE_P. */
1970 pdp11_modes_tieable_p (machine_mode
, machine_mode
)
1975 struct gcc_target targetm
= TARGET_INITIALIZER
;