1 /* Subroutines for gcc2 for pdp11.
2 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2004, 2005
3 Free Software Foundation, Inc.
4 Contributed by Michael K. Gschwind (mike@vlsivie.tuwien.ac.at).
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
25 #include "coretypes.h"
29 #include "hard-reg-set.h"
31 #include "insn-config.h"
32 #include "conditions.h"
35 #include "insn-attr.h"
43 #include "target-def.h"
46 #define FPU_REG_P(X) ((X)>=8 && (X)<14)
47 #define CPU_REG_P(X) ((X)>=0 && (X)<8)
50 /* this is the current value returned by the macro FIRST_PARM_OFFSET
52 int current_first_parm_offset
;
54 /* Routines to encode/decode pdp11 floats */
55 static void encode_pdp11_f (const struct real_format
*fmt
,
56 long *, const REAL_VALUE_TYPE
*);
57 static void decode_pdp11_f (const struct real_format
*,
58 REAL_VALUE_TYPE
*, const long *);
59 static void encode_pdp11_d (const struct real_format
*fmt
,
60 long *, const REAL_VALUE_TYPE
*);
61 static void decode_pdp11_d (const struct real_format
*,
62 REAL_VALUE_TYPE
*, const long *);
64 /* These two are taken from the corresponding vax descriptors
65 in real.c, changing only the encode/decode routine pointers. */
66 const struct real_format pdp11_f_format
=
84 const struct real_format pdp11_d_format
=
103 encode_pdp11_f (const struct real_format
*fmt ATTRIBUTE_UNUSED
, long *buf
,
104 const REAL_VALUE_TYPE
*r
)
106 (*vax_f_format
.encode
) (fmt
, buf
, r
);
107 buf
[0] = ((buf
[0] >> 16) & 0xffff) | ((buf
[0] & 0xffff) << 16);
111 decode_pdp11_f (const struct real_format
*fmt ATTRIBUTE_UNUSED
,
112 REAL_VALUE_TYPE
*r
, const long *buf
)
115 tbuf
= ((buf
[0] >> 16) & 0xffff) | ((buf
[0] & 0xffff) << 16);
116 (*vax_f_format
.decode
) (fmt
, r
, &tbuf
);
120 encode_pdp11_d (const struct real_format
*fmt ATTRIBUTE_UNUSED
, long *buf
,
121 const REAL_VALUE_TYPE
*r
)
123 (*vax_d_format
.encode
) (fmt
, buf
, r
);
124 buf
[0] = ((buf
[0] >> 16) & 0xffff) | ((buf
[0] & 0xffff) << 16);
125 buf
[1] = ((buf
[1] >> 16) & 0xffff) | ((buf
[1] & 0xffff) << 16);
129 decode_pdp11_d (const struct real_format
*fmt ATTRIBUTE_UNUSED
,
130 REAL_VALUE_TYPE
*r
, const long *buf
)
133 tbuf
[0] = ((buf
[0] >> 16) & 0xffff) | ((buf
[0] & 0xffff) << 16);
134 tbuf
[1] = ((buf
[1] >> 16) & 0xffff) | ((buf
[1] & 0xffff) << 16);
135 (*vax_d_format
.decode
) (fmt
, r
, tbuf
);
138 /* This is where the condition code register lives. */
139 /* rtx cc0_reg_rtx; - no longer needed? */
141 static bool pdp11_handle_option (size_t, const char *, int);
142 static rtx
find_addr_reg (rtx
);
143 static const char *singlemove_string (rtx
*);
144 static bool pdp11_assemble_integer (rtx
, unsigned int, int);
145 static void pdp11_output_function_prologue (FILE *, HOST_WIDE_INT
);
146 static void pdp11_output_function_epilogue (FILE *, HOST_WIDE_INT
);
147 static bool pdp11_rtx_costs (rtx
, int, int, int *);
148 static bool pdp11_return_in_memory (tree
, tree
);
150 /* Initialize the GCC target structure. */
151 #undef TARGET_ASM_BYTE_OP
152 #define TARGET_ASM_BYTE_OP NULL
153 #undef TARGET_ASM_ALIGNED_HI_OP
154 #define TARGET_ASM_ALIGNED_HI_OP NULL
155 #undef TARGET_ASM_ALIGNED_SI_OP
156 #define TARGET_ASM_ALIGNED_SI_OP NULL
157 #undef TARGET_ASM_INTEGER
158 #define TARGET_ASM_INTEGER pdp11_assemble_integer
160 #undef TARGET_ASM_FUNCTION_PROLOGUE
161 #define TARGET_ASM_FUNCTION_PROLOGUE pdp11_output_function_prologue
162 #undef TARGET_ASM_FUNCTION_EPILOGUE
163 #define TARGET_ASM_FUNCTION_EPILOGUE pdp11_output_function_epilogue
165 #undef TARGET_ASM_OPEN_PAREN
166 #define TARGET_ASM_OPEN_PAREN "["
167 #undef TARGET_ASM_CLOSE_PAREN
168 #define TARGET_ASM_CLOSE_PAREN "]"
170 #undef TARGET_DEFAULT_TARGET_FLAGS
171 #define TARGET_DEFAULT_TARGET_FLAGS \
172 (MASK_FPU | MASK_45 | MASK_ABSHI_BUILTIN | TARGET_UNIX_ASM_DEFAULT)
173 #undef TARGET_HANDLE_OPTION
174 #define TARGET_HANDLE_OPTION pdp11_handle_option
176 #undef TARGET_RTX_COSTS
177 #define TARGET_RTX_COSTS pdp11_rtx_costs
179 #undef TARGET_RETURN_IN_MEMORY
180 #define TARGET_RETURN_IN_MEMORY pdp11_return_in_memory
182 struct gcc_target targetm
= TARGET_INITIALIZER
;
184 /* Implement TARGET_HANDLE_OPTION. */
187 pdp11_handle_option (size_t code
, const char *arg ATTRIBUTE_UNUSED
,
188 int value ATTRIBUTE_UNUSED
)
193 target_flags
&= ~(MASK_40
| MASK_45
);
201 /* Nonzero if OP is a valid second operand for an arithmetic insn. */
204 arith_operand (rtx op
, enum machine_mode mode
)
206 return (register_operand (op
, mode
) || GET_CODE (op
) == CONST_INT
);
210 const_immediate_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
212 return (GET_CODE (op
) == CONST_INT
);
216 immediate15_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
218 return (GET_CODE (op
) == CONST_INT
&& ((INTVAL (op
) & 0x8000) == 0x0000));
222 expand_shift_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
224 return (GET_CODE (op
) == CONST_INT
225 && abs (INTVAL(op
)) > 1
226 && abs (INTVAL(op
)) <= 4);
230 stream is a stdio stream to output the code to.
231 size is an int: how many units of temporary storage to allocate.
232 Refer to the array `regs_ever_live' to determine which registers
233 to save; `regs_ever_live[I]' is nonzero if register number I
234 is ever used in the function. This macro is responsible for
235 knowing which registers should not be saved even if used.
241 pdp11_output_function_prologue (FILE *stream
, HOST_WIDE_INT size
)
243 fprintf (stream
, "\tjsr r5, csv\n");
246 fprintf (stream
, "\t/*abuse empty parameter slot for locals!*/\n");
248 asm_fprintf (stream
, "\tsub $%#wo, sp\n", size
- 2);
256 pdp11_output_function_prologue (FILE *stream
, HOST_WIDE_INT size
)
258 HOST_WIDE_INT fsize
= ((size
) + 1) & ~1;
263 "\n\t; /* function prologue %s*/\n",
264 current_function_name ());
266 /* if we are outputting code for main,
267 the switch FPU to right mode if TARGET_FPU */
268 if (MAIN_NAME_P (DECL_NAME (current_function_decl
)) && TARGET_FPU
)
271 "\t;/* switch cpu to double float, single integer */\n");
272 fprintf(stream
, "\tsetd\n");
273 fprintf(stream
, "\tseti\n\n");
276 if (frame_pointer_needed
)
278 fprintf(stream
, "\tmov r5, -(sp)\n");
279 fprintf(stream
, "\tmov sp, r5\n");
288 asm_fprintf (stream
, "\tsub $%#wo, sp\n", fsize
);
290 /* save CPU registers */
291 for (regno
= 0; regno
< 8; regno
++)
292 if (regs_ever_live
[regno
] && ! call_used_regs
[regno
])
293 if (! ((regno
== FRAME_POINTER_REGNUM
)
294 && frame_pointer_needed
))
295 fprintf (stream
, "\tmov %s, -(sp)\n", reg_names
[regno
]);
296 /* fpu regs saving */
298 /* via_ac specifies the ac to use for saving ac4, ac5 */
301 for (regno
= 8; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
304 if (LOAD_FPU_REG_P(regno
)
305 && regs_ever_live
[regno
]
306 && ! call_used_regs
[regno
])
308 fprintf (stream
, "\tstd %s, -(sp)\n", reg_names
[regno
]);
312 /* maybe make ac4, ac5 call used regs?? */
314 if (NO_LOAD_FPU_REG_P(regno
)
315 && regs_ever_live
[regno
]
316 && ! call_used_regs
[regno
])
318 gcc_assert (via_ac
!= -1);
319 fprintf (stream
, "\tldd %s, %s\n",
320 reg_names
[regno
], reg_names
[via_ac
]);
321 fprintf (stream
, "\tstd %s, -(sp)\n", reg_names
[via_ac
]);
325 fprintf (stream
, "\t;/* end of prologue */\n\n");
328 #endif /* !TWO_BSD */
331 The function epilogue should not depend on the current stack pointer!
332 It should use the frame pointer only. This is mandatory because
333 of alloca; we also take advantage of it to omit stack adjustments
336 /* maybe we can make leaf functions faster by switching to the
337 second register file - this way we don't have to save regs!
338 leaf functions are ~ 50% of all functions (dynamically!)
340 set/clear bit 11 (dec. 2048) of status word for switching register files -
341 but how can we do this? the pdp11/45 manual says bit may only
342 be set (p.24), but not cleared!
344 switching to kernel is probably more expensive, so we'll leave it
345 like this and not use the second set of registers...
347 maybe as option if you want to generate code for kernel mode? */
352 pdp11_output_function_epilogue (FILE *stream
,
353 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
355 fprintf (stream
, "\t/* SP ignored by cret? */\n");
356 fprintf (stream
, "\tjmp cret\n");
362 pdp11_output_function_epilogue (FILE *stream
, HOST_WIDE_INT size
)
364 HOST_WIDE_INT fsize
= ((size
) + 1) & ~1;
369 fprintf (stream
, "\n\t; /*function epilogue */\n");
371 if (frame_pointer_needed
)
373 /* hope this is safe - m68k does it also .... */
374 regs_ever_live
[FRAME_POINTER_REGNUM
] = 0;
376 for (i
=7, j
= 0 ; i
>= 0 ; i
--)
377 if (regs_ever_live
[i
] && ! call_used_regs
[i
])
380 /* remember # of pushed bytes for CPU regs */
383 /* change fp -> r5 due to the compile error on libgcc2.c */
384 for (i
=7 ; i
>= 0 ; i
--)
385 if (regs_ever_live
[i
] && ! call_used_regs
[i
])
386 fprintf(stream
, "\tmov %#o(r5), %s\n",(-fsize
-2*j
--)&0xffff, reg_names
[i
]);
389 via_ac
= FIRST_PSEUDO_REGISTER
-1;
391 for (i
= FIRST_PSEUDO_REGISTER
; i
> 7; i
--)
392 if (regs_ever_live
[i
] && ! call_used_regs
[i
])
398 for (i
= FIRST_PSEUDO_REGISTER
; i
> 7; i
--)
400 if (LOAD_FPU_REG_P(i
)
402 && ! call_used_regs
[i
])
404 fprintf(stream
, "\tldd %#o(r5), %s\n", (-fsize
-k
)&0xffff, reg_names
[i
]);
408 if (NO_LOAD_FPU_REG_P(i
)
410 && ! call_used_regs
[i
])
412 gcc_assert (LOAD_FPU_REG_P(via_ac
));
414 fprintf(stream
, "\tldd %#o(r5), %s\n", (-fsize
-k
)&0xffff, reg_names
[via_ac
]);
415 fprintf(stream
, "\tstd %s, %s\n", reg_names
[via_ac
], reg_names
[i
]);
420 fprintf(stream
, "\tmov r5, sp\n");
421 fprintf (stream
, "\tmov (sp)+, r5\n");
425 via_ac
= FIRST_PSEUDO_REGISTER
-1;
428 for (i
= FIRST_PSEUDO_REGISTER
; i
> 7; i
--)
429 if (regs_ever_live
[i
] && call_used_regs
[i
])
432 for (i
= FIRST_PSEUDO_REGISTER
; i
> 7; i
--)
434 if (LOAD_FPU_REG_P(i
)
436 && ! call_used_regs
[i
])
437 fprintf(stream
, "\tldd (sp)+, %s\n", reg_names
[i
]);
439 if (NO_LOAD_FPU_REG_P(i
)
441 && ! call_used_regs
[i
])
443 gcc_assert (LOAD_FPU_REG_P(via_ac
));
445 fprintf(stream
, "\tldd (sp)+, %s\n", reg_names
[via_ac
]);
446 fprintf(stream
, "\tstd %s, %s\n", reg_names
[via_ac
], reg_names
[i
]);
450 for (i
=7; i
>= 0; i
--)
451 if (regs_ever_live
[i
] && !call_used_regs
[i
])
452 fprintf(stream
, "\tmov (sp)+, %s\n", reg_names
[i
]);
455 fprintf((stream
), "\tadd $%#o, sp\n", (fsize
)&0xffff);
458 fprintf (stream
, "\trts pc\n");
459 fprintf (stream
, "\t;/* end of epilogue*/\n\n\n");
462 #endif /* !TWO_BSD */
464 /* Return the best assembler insn template
465 for moving operands[1] into operands[0] as a fullword. */
467 singlemove_string (rtx
*operands
)
469 if (operands
[1] != const0_rtx
)
476 /* Output assembler code to perform a doubleword move insn
477 with operands OPERANDS. */
480 output_move_double (rtx
*operands
)
482 enum { REGOP
, OFFSOP
, MEMOP
, PUSHOP
, POPOP
, CNSTOP
, RNDOP
} optype0
, optype1
;
484 rtx addreg0
= 0, addreg1
= 0;
486 /* First classify both operands. */
488 if (REG_P (operands
[0]))
490 else if (offsettable_memref_p (operands
[0]))
492 else if (GET_CODE (XEXP (operands
[0], 0)) == POST_INC
)
494 else if (GET_CODE (XEXP (operands
[0], 0)) == PRE_DEC
)
496 else if (GET_CODE (operands
[0]) == MEM
)
501 if (REG_P (operands
[1]))
503 else if (CONSTANT_P (operands
[1])
505 || GET_CODE (operands
[1]) == CONST_DOUBLE
509 else if (offsettable_memref_p (operands
[1]))
511 else if (GET_CODE (XEXP (operands
[1], 0)) == POST_INC
)
513 else if (GET_CODE (XEXP (operands
[1], 0)) == PRE_DEC
)
515 else if (GET_CODE (operands
[1]) == MEM
)
520 /* Check for the cases that the operand constraints are not
521 supposed to allow to happen. Abort if we get one,
522 because generating code for these cases is painful. */
524 gcc_assert (optype0
!= RNDOP
&& optype1
!= RNDOP
);
526 /* If one operand is decrementing and one is incrementing
527 decrement the former register explicitly
528 and change that operand into ordinary indexing. */
530 if (optype0
== PUSHOP
&& optype1
== POPOP
)
532 operands
[0] = XEXP (XEXP (operands
[0], 0), 0);
533 output_asm_insn ("sub $4,%0", operands
);
534 operands
[0] = gen_rtx_MEM (SImode
, operands
[0]);
537 if (optype0
== POPOP
&& optype1
== PUSHOP
)
539 operands
[1] = XEXP (XEXP (operands
[1], 0), 0);
540 output_asm_insn ("sub $4,%1", operands
);
541 operands
[1] = gen_rtx_MEM (SImode
, operands
[1]);
545 /* If an operand is an unoffsettable memory ref, find a register
546 we can increment temporarily to make it refer to the second word. */
548 if (optype0
== MEMOP
)
549 addreg0
= find_addr_reg (XEXP (operands
[0], 0));
551 if (optype1
== MEMOP
)
552 addreg1
= find_addr_reg (XEXP (operands
[1], 0));
554 /* Ok, we can do one word at a time.
555 Normally we do the low-numbered word first,
556 but if either operand is autodecrementing then we
557 do the high-numbered word first.
559 In either case, set up in LATEHALF the operands to use
560 for the high-numbered word and in some cases alter the
561 operands in OPERANDS to be suitable for the low-numbered word. */
563 if (optype0
== REGOP
)
564 latehalf
[0] = gen_rtx_REG (HImode
, REGNO (operands
[0]) + 1);
565 else if (optype0
== OFFSOP
)
566 latehalf
[0] = adjust_address (operands
[0], HImode
, 2);
568 latehalf
[0] = operands
[0];
570 if (optype1
== REGOP
)
571 latehalf
[1] = gen_rtx_REG (HImode
, REGNO (operands
[1]) + 1);
572 else if (optype1
== OFFSOP
)
573 latehalf
[1] = adjust_address (operands
[1], HImode
, 2);
574 else if (optype1
== CNSTOP
)
576 if (CONSTANT_P (operands
[1]))
578 /* now the mess begins, high word is in lower word???
580 that's what ashc makes me think, but I don't remember :-( */
581 latehalf
[1] = GEN_INT (INTVAL(operands
[1]) >> 16);
582 operands
[1] = GEN_INT (INTVAL(operands
[1]) & 0xff);
585 /* immediate 32 bit values not allowed */
586 gcc_assert (GET_CODE (operands
[1]) != CONST_DOUBLE
);
589 latehalf
[1] = operands
[1];
591 /* If insn is effectively movd N(sp),-(sp) then we will do the
592 high word first. We should use the adjusted operand 1 (which is N+4(sp))
593 for the low word as well, to compensate for the first decrement of sp. */
594 if (optype0
== PUSHOP
595 && REGNO (XEXP (XEXP (operands
[0], 0), 0)) == STACK_POINTER_REGNUM
596 && reg_overlap_mentioned_p (stack_pointer_rtx
, operands
[1]))
597 operands
[1] = latehalf
[1];
599 /* If one or both operands autodecrementing,
600 do the two words, high-numbered first. */
602 /* Likewise, the first move would clobber the source of the second one,
603 do them in the other order. This happens only for registers;
604 such overlap can't happen in memory unless the user explicitly
605 sets it up, and that is an undefined circumstance. */
607 if (optype0
== PUSHOP
|| optype1
== PUSHOP
608 || (optype0
== REGOP
&& optype1
== REGOP
609 && REGNO (operands
[0]) == REGNO (latehalf
[1])))
611 /* Make any unoffsettable addresses point at high-numbered word. */
613 output_asm_insn ("add $2,%0", &addreg0
);
615 output_asm_insn ("add $2,%0", &addreg1
);
618 output_asm_insn (singlemove_string (latehalf
), latehalf
);
620 /* Undo the adds we just did. */
622 output_asm_insn ("sub $2,%0", &addreg0
);
624 output_asm_insn ("sub $2,%0", &addreg1
);
626 /* Do low-numbered word. */
627 return singlemove_string (operands
);
630 /* Normal case: do the two words, low-numbered first. */
632 output_asm_insn (singlemove_string (operands
), operands
);
634 /* Make any unoffsettable addresses point at high-numbered word. */
636 output_asm_insn ("add $2,%0", &addreg0
);
638 output_asm_insn ("add $2,%0", &addreg1
);
641 output_asm_insn (singlemove_string (latehalf
), latehalf
);
643 /* Undo the adds we just did. */
645 output_asm_insn ("sub $2,%0", &addreg0
);
647 output_asm_insn ("sub $2,%0", &addreg1
);
651 /* Output assembler code to perform a quadword move insn
652 with operands OPERANDS. */
655 output_move_quad (rtx
*operands
)
657 enum { REGOP
, OFFSOP
, MEMOP
, PUSHOP
, POPOP
, CNSTOP
, RNDOP
} optype0
, optype1
;
659 rtx addreg0
= 0, addreg1
= 0;
661 output_asm_insn(";/* movdi/df: %1 -> %0 */", operands
);
663 if (REG_P (operands
[0]))
665 else if (offsettable_memref_p (operands
[0]))
667 else if (GET_CODE (XEXP (operands
[0], 0)) == POST_INC
)
669 else if (GET_CODE (XEXP (operands
[0], 0)) == PRE_DEC
)
671 else if (GET_CODE (operands
[0]) == MEM
)
676 if (REG_P (operands
[1]))
678 else if (CONSTANT_P (operands
[1])
679 || GET_CODE (operands
[1]) == CONST_DOUBLE
)
681 else if (offsettable_memref_p (operands
[1]))
683 else if (GET_CODE (XEXP (operands
[1], 0)) == POST_INC
)
685 else if (GET_CODE (XEXP (operands
[1], 0)) == PRE_DEC
)
687 else if (GET_CODE (operands
[1]) == MEM
)
692 /* Check for the cases that the operand constraints are not
693 supposed to allow to happen. Abort if we get one,
694 because generating code for these cases is painful. */
696 gcc_assert (optype0
!= RNDOP
&& optype1
!= RNDOP
);
698 /* check if we move a CPU reg to an FPU reg, or vice versa! */
699 if (optype0
== REGOP
&& optype1
== REGOP
)
700 /* bogus - 64 bit cannot reside in CPU! */
701 gcc_assert (!CPU_REG_P(REGNO(operands
[0]))
702 && !CPU_REG_P (REGNO(operands
[1])));
704 if (optype0
== REGOP
|| optype1
== REGOP
)
706 /* check for use of clrd????
707 if you ever allow ac4 and ac5 (now we require secondary load)
708 you must check whether
709 you want to load into them or store from them -
710 then dump ac0 into $help$ movce ac4/5 to ac0, do the
711 store from ac0, and restore ac0 - if you can find
712 an unused ac[0-3], use that and you save a store and a load!*/
714 if (FPU_REG_P(REGNO(operands
[0])))
716 if (GET_CODE(operands
[1]) == CONST_DOUBLE
)
719 REAL_VALUE_FROM_CONST_DOUBLE (r
, operands
[1]);
721 if (REAL_VALUES_EQUAL (r
, dconst0
))
722 return "{clrd|clrf} %0";
725 return "{ldd|movf} %1, %0";
728 if (FPU_REG_P(REGNO(operands
[1])))
729 return "{std|movf} %1, %0";
732 /* If one operand is decrementing and one is incrementing
733 decrement the former register explicitly
734 and change that operand into ordinary indexing. */
736 if (optype0
== PUSHOP
&& optype1
== POPOP
)
738 operands
[0] = XEXP (XEXP (operands
[0], 0), 0);
739 output_asm_insn ("sub $8,%0", operands
);
740 operands
[0] = gen_rtx_MEM (DImode
, operands
[0]);
743 if (optype0
== POPOP
&& optype1
== PUSHOP
)
745 operands
[1] = XEXP (XEXP (operands
[1], 0), 0);
746 output_asm_insn ("sub $8,%1", operands
);
747 operands
[1] = gen_rtx_MEM (SImode
, operands
[1]);
751 /* If an operand is an unoffsettable memory ref, find a register
752 we can increment temporarily to make it refer to the second word. */
754 if (optype0
== MEMOP
)
755 addreg0
= find_addr_reg (XEXP (operands
[0], 0));
757 if (optype1
== MEMOP
)
758 addreg1
= find_addr_reg (XEXP (operands
[1], 0));
760 /* Ok, we can do one word at a time.
761 Normally we do the low-numbered word first,
762 but if either operand is autodecrementing then we
763 do the high-numbered word first.
765 In either case, set up in LATEHALF the operands to use
766 for the high-numbered word and in some cases alter the
767 operands in OPERANDS to be suitable for the low-numbered word. */
769 if (optype0
== REGOP
)
770 latehalf
[0] = gen_rtx_REG (SImode
, REGNO (operands
[0]) + 2);
771 else if (optype0
== OFFSOP
)
772 latehalf
[0] = adjust_address (operands
[0], SImode
, 4);
774 latehalf
[0] = operands
[0];
776 if (optype1
== REGOP
)
777 latehalf
[1] = gen_rtx_REG (SImode
, REGNO (operands
[1]) + 2);
778 else if (optype1
== OFFSOP
)
779 latehalf
[1] = adjust_address (operands
[1], SImode
, 4);
780 else if (optype1
== CNSTOP
)
782 if (GET_CODE (operands
[1]) == CONST_DOUBLE
)
786 REAL_VALUE_FROM_CONST_DOUBLE (r
, operands
[1]);
787 REAL_VALUE_TO_TARGET_DOUBLE (r
, dval
);
788 latehalf
[1] = GEN_INT (dval
[1]);
789 operands
[1] = GEN_INT (dval
[0]);
791 else if (GET_CODE(operands
[1]) == CONST_INT
)
793 latehalf
[1] = const0_rtx
;
799 latehalf
[1] = operands
[1];
801 /* If insn is effectively movd N(sp),-(sp) then we will do the
802 high word first. We should use the adjusted operand 1 (which is N+4(sp))
803 for the low word as well, to compensate for the first decrement of sp. */
804 if (optype0
== PUSHOP
805 && REGNO (XEXP (XEXP (operands
[0], 0), 0)) == STACK_POINTER_REGNUM
806 && reg_overlap_mentioned_p (stack_pointer_rtx
, operands
[1]))
807 operands
[1] = latehalf
[1];
809 /* If one or both operands autodecrementing,
810 do the two words, high-numbered first. */
812 /* Likewise, the first move would clobber the source of the second one,
813 do them in the other order. This happens only for registers;
814 such overlap can't happen in memory unless the user explicitly
815 sets it up, and that is an undefined circumstance. */
817 if (optype0
== PUSHOP
|| optype1
== PUSHOP
818 || (optype0
== REGOP
&& optype1
== REGOP
819 && REGNO (operands
[0]) == REGNO (latehalf
[1])))
821 /* Make any unoffsettable addresses point at high-numbered word. */
823 output_asm_insn ("add $4,%0", &addreg0
);
825 output_asm_insn ("add $4,%0", &addreg1
);
828 output_asm_insn(output_move_double(latehalf
), latehalf
);
830 /* Undo the adds we just did. */
832 output_asm_insn ("sub $4,%0", &addreg0
);
834 output_asm_insn ("sub $4,%0", &addreg1
);
836 /* Do low-numbered word. */
837 return output_move_double (operands
);
840 /* Normal case: do the two words, low-numbered first. */
842 output_asm_insn (output_move_double (operands
), operands
);
844 /* Make any unoffsettable addresses point at high-numbered word. */
846 output_asm_insn ("add $4,%0", &addreg0
);
848 output_asm_insn ("add $4,%0", &addreg1
);
851 output_asm_insn (output_move_double (latehalf
), latehalf
);
853 /* Undo the adds we just did. */
855 output_asm_insn ("sub $4,%0", &addreg0
);
857 output_asm_insn ("sub $4,%0", &addreg1
);
863 /* Return a REG that occurs in ADDR with coefficient 1.
864 ADDR can be effectively incremented by incrementing REG. */
867 find_addr_reg (rtx addr
)
869 while (GET_CODE (addr
) == PLUS
)
871 if (GET_CODE (XEXP (addr
, 0)) == REG
)
872 addr
= XEXP (addr
, 0);
873 if (GET_CODE (XEXP (addr
, 1)) == REG
)
874 addr
= XEXP (addr
, 1);
875 if (CONSTANT_P (XEXP (addr
, 0)))
876 addr
= XEXP (addr
, 1);
877 if (CONSTANT_P (XEXP (addr
, 1)))
878 addr
= XEXP (addr
, 0);
880 if (GET_CODE (addr
) == REG
)
885 /* Output an ascii string. */
887 output_ascii (FILE *file
, const char *p
, int size
)
891 /* This used to output .byte "string", which doesn't work with the UNIX
892 assembler and I think not with DEC ones either. */
893 fprintf (file
, "\t.byte ");
895 for (i
= 0; i
< size
; i
++)
897 register int c
= p
[i
];
900 fprintf (file
, "%#o", c
);
908 /* --- stole from out-vax, needs changes */
911 print_operand_address (FILE *file
, register rtx addr
)
913 register rtx reg1
, reg2
, breg
, ireg
;
918 switch (GET_CODE (addr
))
925 addr
= XEXP (addr
, 0);
929 fprintf (file
, "(%s)", reg_names
[REGNO (addr
)]);
934 fprintf (file
, "-(%s)", reg_names
[REGNO (XEXP (addr
, 0))]);
939 fprintf (file
, "(%s)+", reg_names
[REGNO (XEXP (addr
, 0))]);
946 if (CONSTANT_ADDRESS_P (XEXP (addr
, 0))
947 || GET_CODE (XEXP (addr
, 0)) == MEM
)
949 offset
= XEXP (addr
, 0);
950 addr
= XEXP (addr
, 1);
952 else if (CONSTANT_ADDRESS_P (XEXP (addr
, 1))
953 || GET_CODE (XEXP (addr
, 1)) == MEM
)
955 offset
= XEXP (addr
, 1);
956 addr
= XEXP (addr
, 0);
958 if (GET_CODE (addr
) != PLUS
)
960 else if (GET_CODE (XEXP (addr
, 0)) == MULT
)
962 reg1
= XEXP (addr
, 0);
963 addr
= XEXP (addr
, 1);
965 else if (GET_CODE (XEXP (addr
, 1)) == MULT
)
967 reg1
= XEXP (addr
, 1);
968 addr
= XEXP (addr
, 0);
970 else if (GET_CODE (XEXP (addr
, 0)) == REG
)
972 reg1
= XEXP (addr
, 0);
973 addr
= XEXP (addr
, 1);
975 else if (GET_CODE (XEXP (addr
, 1)) == REG
)
977 reg1
= XEXP (addr
, 1);
978 addr
= XEXP (addr
, 0);
980 if (GET_CODE (addr
) == REG
|| GET_CODE (addr
) == MULT
)
990 gcc_assert (addr
== 0);
993 if (reg1
!= 0 && GET_CODE (reg1
) == MULT
)
998 else if (reg2
!= 0 && GET_CODE (reg2
) == MULT
)
1003 else if (reg2
!= 0 || GET_CODE (addr
) == MEM
)
1014 output_address (addr
);
1017 gcc_assert (GET_CODE (breg
) == REG
);
1018 fprintf (file
, "(%s)", reg_names
[REGNO (breg
)]);
1022 if (GET_CODE (ireg
) == MULT
)
1023 ireg
= XEXP (ireg
, 0);
1024 gcc_assert (GET_CODE (ireg
) == REG
);
1025 gcc_unreachable(); /* ??? */
1026 fprintf (file
, "[%s]", reg_names
[REGNO (ireg
)]);
1031 output_addr_const_pdp11 (file
, addr
);
1035 /* Target hook to assemble integer objects. We need to use the
1036 pdp-specific version of output_addr_const. */
1039 pdp11_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
1045 fprintf (asm_out_file
, "\t.byte\t");
1046 output_addr_const_pdp11 (asm_out_file
, x
);
1047 fprintf (asm_out_file
, " /* char */\n");
1051 fprintf (asm_out_file
, TARGET_UNIX_ASM
? "\t" : "\t.word\t");
1052 output_addr_const_pdp11 (asm_out_file
, x
);
1053 fprintf (asm_out_file
, " /* short */\n");
1056 return default_assemble_integer (x
, size
, aligned_p
);
1060 /* register move costs, indexed by regs */
1062 static const int move_costs
[N_REG_CLASSES
][N_REG_CLASSES
] =
1064 /* NO MUL GEN LFPU NLFPU FPU ALL */
1066 /* NO */ { 0, 0, 0, 0, 0, 0, 0},
1067 /* MUL */ { 0, 2, 2, 10, 22, 22, 22},
1068 /* GEN */ { 0, 2, 2, 10, 22, 22, 22},
1069 /* LFPU */ { 0, 10, 10, 2, 2, 2, 10},
1070 /* NLFPU */ { 0, 22, 22, 2, 2, 2, 22},
1071 /* FPU */ { 0, 22, 22, 2, 2, 2, 22},
1072 /* ALL */ { 0, 22, 22, 10, 22, 22, 22}
1076 /* -- note that some moves are tremendously expensive,
1077 because they require lots of tricks! do we have to
1078 charge the costs incurred by secondary reload class
1079 -- as we do here with 22 -- or not ? */
1082 register_move_cost(c1
, c2
)
1083 enum reg_class c1
, c2
;
1085 return move_costs
[(int)c1
][(int)c2
];
1089 pdp11_rtx_costs (rtx x
, int code
, int outer_code ATTRIBUTE_UNUSED
, int *total
)
1094 if (INTVAL (x
) == 0 || INTVAL (x
) == -1 || INTVAL (x
) == 1)
1104 /* Twice as expensive as REG. */
1109 /* Twice (or 4 times) as expensive as 16 bit. */
1114 /* ??? There is something wrong in MULT because MULT is not
1115 as cheap as total = 2 even if we can shift! */
1116 /* If optimizing for size make mult etc cheap, but not 1, so when
1117 in doubt the faster insn is chosen. */
1119 *total
= COSTS_N_INSNS (2);
1121 *total
= COSTS_N_INSNS (11);
1126 *total
= COSTS_N_INSNS (2);
1128 *total
= COSTS_N_INSNS (25);
1133 *total
= COSTS_N_INSNS (2);
1135 *total
= COSTS_N_INSNS (26);
1139 /* Equivalent to length, so same for optimize_size. */
1140 *total
= COSTS_N_INSNS (3);
1144 /* Only used for qi->hi. */
1145 *total
= COSTS_N_INSNS (1);
1149 if (GET_MODE (x
) == HImode
)
1150 *total
= COSTS_N_INSNS (1);
1151 else if (GET_MODE (x
) == SImode
)
1152 *total
= COSTS_N_INSNS (6);
1154 *total
= COSTS_N_INSNS (2);
1161 *total
= COSTS_N_INSNS (1);
1162 else if (GET_MODE (x
) == QImode
)
1164 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
1165 *total
= COSTS_N_INSNS (8); /* worst case */
1167 *total
= COSTS_N_INSNS (INTVAL (XEXP (x
, 1)));
1169 else if (GET_MODE (x
) == HImode
)
1171 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
1173 if (abs (INTVAL (XEXP (x
, 1))) == 1)
1174 *total
= COSTS_N_INSNS (1);
1176 *total
= COSTS_N_INSNS (2.5 + 0.5 * INTVAL (XEXP (x
, 1)));
1179 *total
= COSTS_N_INSNS (10); /* worst case */
1181 else if (GET_MODE (x
) == SImode
)
1183 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
1184 *total
= COSTS_N_INSNS (2.5 + 0.5 * INTVAL (XEXP (x
, 1)));
1185 else /* worst case */
1186 *total
= COSTS_N_INSNS (18);
1196 output_jump (const char *pos
, const char *neg
, int length
)
1200 static char buf
[1000];
1203 /* currently we don't need this, because the tstdf and cmpdf
1204 copy the condition code immediately, and other float operations are not
1205 yet recognized as changing the FCC - if so, then the length-cost of all
1206 jump insns increases by one, because we have to potentially copy the
1208 if (cc_status
.flags
& CC_IN_FPU
)
1209 output_asm_insn("cfcc", NULL
);
1217 strcat(buf
, " %l0");
1223 sprintf(buf
, "%s JMP_%d\n\tjmp %%l0\nJMP_%d:", neg
, x
, x
);
1237 notice_update_cc_on_set(rtx exp
, rtx insn ATTRIBUTE_UNUSED
)
1239 if (GET_CODE (SET_DEST (exp
)) == CC0
)
1241 cc_status
.flags
= 0;
1242 cc_status
.value1
= SET_DEST (exp
);
1243 cc_status
.value2
= SET_SRC (exp
);
1246 if (GET_MODE(SET_SRC(exp)) == DFmode)
1247 cc_status.flags |= CC_IN_FPU;
1250 else if ((GET_CODE (SET_DEST (exp
)) == REG
1251 || GET_CODE (SET_DEST (exp
)) == MEM
)
1252 && GET_CODE (SET_SRC (exp
)) != PC
1253 && (GET_MODE (SET_DEST(exp
)) == HImode
1254 || GET_MODE (SET_DEST(exp
)) == QImode
)
1255 && (GET_CODE (SET_SRC(exp
)) == PLUS
1256 || GET_CODE (SET_SRC(exp
)) == MINUS
1257 || GET_CODE (SET_SRC(exp
)) == AND
1258 || GET_CODE (SET_SRC(exp
)) == IOR
1259 || GET_CODE (SET_SRC(exp
)) == XOR
1260 || GET_CODE (SET_SRC(exp
)) == NOT
1261 || GET_CODE (SET_SRC(exp
)) == NEG
1262 || GET_CODE (SET_SRC(exp
)) == REG
1263 || GET_CODE (SET_SRC(exp
)) == MEM
))
1265 cc_status
.flags
= 0;
1266 cc_status
.value1
= SET_SRC (exp
);
1267 cc_status
.value2
= SET_DEST (exp
);
1269 if (cc_status
.value1
&& GET_CODE (cc_status
.value1
) == REG
1271 && reg_overlap_mentioned_p (cc_status
.value1
, cc_status
.value2
))
1272 cc_status
.value2
= 0;
1273 if (cc_status
.value1
&& GET_CODE (cc_status
.value1
) == MEM
1275 && GET_CODE (cc_status
.value2
) == MEM
)
1276 cc_status
.value2
= 0;
1278 else if (GET_CODE (SET_SRC (exp
)) == CALL
)
1282 else if (GET_CODE (SET_DEST (exp
)) == REG
)
1285 if ((cc_status
.value1
1286 && reg_overlap_mentioned_p (SET_DEST (exp
), cc_status
.value1
)))
1287 cc_status
.value1
= 0;
1288 if ((cc_status
.value2
1289 && reg_overlap_mentioned_p (SET_DEST (exp
), cc_status
.value2
)))
1290 cc_status
.value2
= 0;
1292 else if (SET_DEST(exp
) == pc_rtx
)
1296 else /* if (GET_CODE (SET_DEST (exp)) == MEM) */
1298 /* the last else is a bit paranoiac, but since nearly all instructions
1299 play with condition codes, it's reasonable! */
1301 CC_STATUS_INIT
; /* paranoia*/
1307 simple_memory_operand(rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1311 /* Eliminate non-memory operations */
1312 if (GET_CODE (op
) != MEM
)
1316 /* dword operations really put out 2 instructions, so eliminate them. */
1317 if (GET_MODE_SIZE (GET_MODE (op
)) > (HAVE_64BIT_P () ? 8 : 4))
1321 /* Decode the address now. */
1325 addr
= XEXP (op
, 0);
1327 switch (GET_CODE (addr
))
1330 /* (R0) - no extra cost */
1335 /* -(R0), (R0)+ - cheap! */
1339 /* cheap - is encoded in addressing mode info!
1341 -- except for @(R0), which has to be @0(R0) !!! */
1343 if (GET_CODE (XEXP (addr
, 0)) == REG
)
1353 /* @#address - extra cost */
1357 /* X(R0) - extra cost */
1369 * output a block move:
1371 * operands[0] ... to
1372 * operands[1] ... from
1373 * operands[2] ... length
1374 * operands[3] ... alignment
1375 * operands[4] ... scratch register
1380 output_block_move(rtx
*operands
)
1382 static int count
= 0;
1385 if (GET_CODE(operands
[2]) == CONST_INT
1388 if (INTVAL(operands
[2]) < 16
1389 && INTVAL(operands
[3]) == 1)
1393 for (i
= 1; i
<= INTVAL(operands
[2]); i
++)
1394 output_asm_insn("movb (%1)+, (%0)+", operands
);
1398 else if (INTVAL(operands
[2]) < 32)
1402 for (i
= 1; i
<= INTVAL(operands
[2])/2; i
++)
1403 output_asm_insn("mov (%1)+, (%0)+", operands
);
1405 /* may I assume that moved quantity is
1406 multiple of alignment ???
1415 /* can do other clever things, maybe... */
1418 if (CONSTANT_P(operands
[2]) )
1420 /* just move count to scratch */
1421 output_asm_insn("mov %2, %4", operands
);
1425 /* just clobber the register */
1426 operands
[4] = operands
[2];
1430 /* switch over alignment */
1431 switch (INTVAL(operands
[3]))
1447 sprintf(buf
, "\nmovestrhi%d:", count
);
1448 output_asm_insn(buf
, NULL
);
1450 output_asm_insn("movb (%1)+, (%0)+", operands
);
1454 sprintf(buf
, "sob %%4, movestrhi%d", count
);
1455 output_asm_insn(buf
, operands
);
1459 output_asm_insn("dec %4", operands
);
1461 sprintf(buf
, "bgt movestrhi%d", count
);
1462 output_asm_insn(buf
, NULL
);
1484 generate_compact_code
:
1486 output_asm_insn("asr %4", operands
);
1488 sprintf(buf
, "\nmovestrhi%d:", count
);
1489 output_asm_insn(buf
, NULL
);
1491 output_asm_insn("mov (%1)+, (%0)+", operands
);
1495 sprintf(buf
, "sob %%4, movestrhi%d", count
);
1496 output_asm_insn(buf
, operands
);
1500 output_asm_insn("dec %4", operands
);
1502 sprintf(buf
, "bgt movestrhi%d", count
);
1503 output_asm_insn(buf
, NULL
);
1529 goto generate_compact_code
;
1531 output_asm_insn("asr %4", operands
);
1532 output_asm_insn("asr %4", operands
);
1534 sprintf(buf
, "\nmovestrhi%d:", count
);
1535 output_asm_insn(buf
, NULL
);
1537 output_asm_insn("mov (%1)+, (%0)+", operands
);
1538 output_asm_insn("mov (%1)+, (%0)+", operands
);
1542 sprintf(buf
, "sob %%4, movestrhi%d", count
);
1543 output_asm_insn(buf
, operands
);
1547 output_asm_insn("dec %4", operands
);
1549 sprintf(buf
, "bgt movestrhi%d", count
);
1550 output_asm_insn(buf
, NULL
);
1580 goto generate_compact_code
;
1582 output_asm_insn("asr %4", operands
);
1583 output_asm_insn("asr %4", operands
);
1584 output_asm_insn("asr %4", operands
);
1586 sprintf(buf
, "\nmovestrhi%d:", count
);
1587 output_asm_insn(buf
, NULL
);
1589 output_asm_insn("mov (%1)+, (%0)+", operands
);
1590 output_asm_insn("mov (%1)+, (%0)+", operands
);
1591 output_asm_insn("mov (%1)+, (%0)+", operands
);
1592 output_asm_insn("mov (%1)+, (%0)+", operands
);
1596 sprintf(buf
, "sob %%4, movestrhi%d", count
);
1597 output_asm_insn(buf
, operands
);
1601 output_asm_insn("dec %4", operands
);
1603 sprintf(buf
, "bgt movestrhi%d", count
);
1604 output_asm_insn(buf
, NULL
);
1618 legitimate_address_p (enum machine_mode mode
, rtx address
)
1620 /* #define REG_OK_STRICT */
1621 GO_IF_LEGITIMATE_ADDRESS(mode
, address
, win
);
1628 /* #undef REG_OK_STRICT */
1631 /* This function checks whether a real value can be encoded as
1632 a literal, i.e., addressing mode 27. In that mode, real values
1633 are one word values, so the remaining 48 bits have to be zero. */
1635 legitimate_const_double_p (rtx address
)
1639 REAL_VALUE_FROM_CONST_DOUBLE (r
, address
);
1640 REAL_VALUE_TO_TARGET_DOUBLE (r
, sval
);
1641 if ((sval
[0] & 0xffff) == 0 && sval
[1] == 0)
1646 /* A copy of output_addr_const modified for pdp11 expression syntax.
1647 output_addr_const also gets called for %cDIGIT and %nDIGIT, which we don't
1648 use, and for debugging output, which we don't support with this port either.
1649 So this copy should get called whenever needed.
1652 output_addr_const_pdp11 (FILE *file
, rtx x
)
1657 switch (GET_CODE (x
))
1660 gcc_assert (flag_pic
);
1665 assemble_name (file
, XSTR (x
, 0));
1669 ASM_GENERATE_INTERNAL_LABEL (buf
, "L", CODE_LABEL_NUMBER (XEXP (x
, 0)));
1670 assemble_name (file
, buf
);
1674 ASM_GENERATE_INTERNAL_LABEL (buf
, "L", CODE_LABEL_NUMBER (x
));
1675 assemble_name (file
, buf
);
1679 /* Should we check for constants which are too big? Maybe cutting
1680 them off to 16 bits is OK? */
1681 fprintf (file
, "%#ho", (unsigned short) INTVAL (x
));
1685 /* This used to output parentheses around the expression,
1686 but that does not work on the 386 (either ATT or BSD assembler). */
1687 output_addr_const_pdp11 (file
, XEXP (x
, 0));
1691 if (GET_MODE (x
) == VOIDmode
)
1693 /* We can use %o if the number is one word and positive. */
1694 gcc_assert (!CONST_DOUBLE_HIGH (x
));
1695 fprintf (file
, "%#ho", (unsigned short) CONST_DOUBLE_LOW (x
));
1698 /* We can't handle floating point constants;
1699 PRINT_OPERAND must handle them. */
1700 output_operand_lossage ("floating constant misused");
1704 /* Some assemblers need integer constants to appear last (e.g. masm). */
1705 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
1707 output_addr_const_pdp11 (file
, XEXP (x
, 1));
1708 if (INTVAL (XEXP (x
, 0)) >= 0)
1709 fprintf (file
, "+");
1710 output_addr_const_pdp11 (file
, XEXP (x
, 0));
1714 output_addr_const_pdp11 (file
, XEXP (x
, 0));
1715 if (INTVAL (XEXP (x
, 1)) >= 0)
1716 fprintf (file
, "+");
1717 output_addr_const_pdp11 (file
, XEXP (x
, 1));
1722 /* Avoid outputting things like x-x or x+5-x,
1723 since some assemblers can't handle that. */
1724 x
= simplify_subtraction (x
);
1725 if (GET_CODE (x
) != MINUS
)
1728 output_addr_const_pdp11 (file
, XEXP (x
, 0));
1729 fprintf (file
, "-");
1730 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
1731 && INTVAL (XEXP (x
, 1)) < 0)
1733 fprintf (file
, targetm
.asm_out
.open_paren
);
1734 output_addr_const_pdp11 (file
, XEXP (x
, 1));
1735 fprintf (file
, targetm
.asm_out
.close_paren
);
1738 output_addr_const_pdp11 (file
, XEXP (x
, 1));
1743 output_addr_const_pdp11 (file
, XEXP (x
, 0));
1747 output_operand_lossage ("invalid expression as operand");
1751 /* Worker function for TARGET_RETURN_IN_MEMORY. */
1754 pdp11_return_in_memory (tree type
, tree fntype ATTRIBUTE_UNUSED
)
1756 /* Should probably return DImode and DFmode in memory, lest
1757 we fill up all regs!
1759 have to, else we crash - exception: maybe return result in
1760 ac0 if DFmode and FPU present - compatibility problem with
1761 libraries for non-floating point.... */
1762 return (TYPE_MODE (type
) == DImode
1763 || (TYPE_MODE (type
) == DFmode
&& ! TARGET_AC0
));