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