Debian Codegraph @

gcc/config/vax/vax.cc

raw
1 /* Subroutines for insn-output.cc for VAX.
2 Copyright (C) 1987-2025 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
19
20 #define IN_TARGET_CODE 1
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "backend.h"
26 #include "target.h"
27 #include "rtl.h"
28 #include "tree.h"
29 #include "stringpool.h"
30 #include "attribs.h"
31 #include "df.h"
32 #include "memmodel.h"
33 #include "tm_p.h"
34 #include "optabs.h"
35 #include "regs.h"
36 #include "emit-rtl.h"
37 #include "calls.h"
38 #include "varasm.h"
39 #include "conditions.h"
40 #include "output.h"
41 #include "expr.h"
42 #include "reload.h"
43 #include "builtins.h"
44
45 /* This file should be included last. */
46 #include "target-def.h"
47
48 static void vax_option_override (void);
49 static bool vax_legitimate_address_p (machine_mode, rtx, bool,
50 code_helper = ERROR_MARK);
51 static void vax_file_start (void);
52 static void vax_init_libfuncs (void);
53 static void vax_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
54 HOST_WIDE_INT, tree);
55 static int vax_address_cost_1 (rtx);
56 static int vax_address_cost (rtx, machine_mode, addr_space_t, bool);
57 static bool vax_rtx_costs (rtx, machine_mode, int, int, int *, bool);
58 static machine_mode vax_cc_modes_compatible (machine_mode, machine_mode);
59 static rtx_insn *vax_md_asm_adjust (vec<rtx> &, vec<rtx> &,
60 vec<machine_mode> &, vec<const char *> &,
61 vec<rtx> &, vec<rtx> &, HARD_REG_SET &,
62 location_t);
63 static rtx vax_function_arg (cumulative_args_t, const function_arg_info &);
64 static void vax_function_arg_advance (cumulative_args_t,
65 const function_arg_info &);
66 static rtx vax_struct_value_rtx (tree, int);
67 static bool vax_lra_p (void);
68 static void vax_asm_trampoline_template (FILE *);
69 static void vax_trampoline_init (rtx, tree, rtx);
70 static poly_int64 vax_return_pops_args (tree, tree, poly_int64);
71 static bool vax_mode_dependent_address_p (const_rtx, addr_space_t);
72 static HOST_WIDE_INT vax_starting_frame_offset (void);
73
74 /* Initialize the GCC target structure. */
75 #undef TARGET_ASM_ALIGNED_HI_OP
76 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
77
78 #undef TARGET_ASM_FILE_START
79 #define TARGET_ASM_FILE_START vax_file_start
80 #undef TARGET_ASM_FILE_START_APP_OFF
81 #define TARGET_ASM_FILE_START_APP_OFF true
82
83 #undef TARGET_INIT_LIBFUNCS
84 #define TARGET_INIT_LIBFUNCS vax_init_libfuncs
85
86 #undef TARGET_ASM_OUTPUT_MI_THUNK
87 #define TARGET_ASM_OUTPUT_MI_THUNK vax_output_mi_thunk
88 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
89 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
90
91 /* Enable compare elimination pass. */
92 #undef TARGET_FLAGS_REGNUM
93 #define TARGET_FLAGS_REGNUM VAX_PSL_REGNUM
94
95 #undef TARGET_RTX_COSTS
96 #define TARGET_RTX_COSTS vax_rtx_costs
97 #undef TARGET_ADDRESS_COST
98 #define TARGET_ADDRESS_COST vax_address_cost
99
100 /* Return the narrowest CC mode that spans both modes offered. */
101 #undef TARGET_CC_MODES_COMPATIBLE
102 #define TARGET_CC_MODES_COMPATIBLE vax_cc_modes_compatible
103
104 /* Mark PSL as clobbered for compatibility with the CC0 representation. */
105 #undef TARGET_MD_ASM_ADJUST
106 #define TARGET_MD_ASM_ADJUST vax_md_asm_adjust
107
108 #undef TARGET_PROMOTE_PROTOTYPES
109 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
110
111 #undef TARGET_FUNCTION_ARG
112 #define TARGET_FUNCTION_ARG vax_function_arg
113 #undef TARGET_FUNCTION_ARG_ADVANCE
114 #define TARGET_FUNCTION_ARG_ADVANCE vax_function_arg_advance
115
116 #undef TARGET_STRUCT_VALUE_RTX
117 #define TARGET_STRUCT_VALUE_RTX vax_struct_value_rtx
118
119 #undef TARGET_LRA_P
120 #define TARGET_LRA_P vax_lra_p
121
122 #undef TARGET_LEGITIMATE_ADDRESS_P
123 #define TARGET_LEGITIMATE_ADDRESS_P vax_legitimate_address_p
124 #undef TARGET_MODE_DEPENDENT_ADDRESS_P
125 #define TARGET_MODE_DEPENDENT_ADDRESS_P vax_mode_dependent_address_p
126
127 #undef TARGET_FRAME_POINTER_REQUIRED
128 #define TARGET_FRAME_POINTER_REQUIRED hook_bool_void_true
129
130 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
131 #define TARGET_ASM_TRAMPOLINE_TEMPLATE vax_asm_trampoline_template
132 #undef TARGET_TRAMPOLINE_INIT
133 #define TARGET_TRAMPOLINE_INIT vax_trampoline_init
134 #undef TARGET_RETURN_POPS_ARGS
135 #define TARGET_RETURN_POPS_ARGS vax_return_pops_args
136
137 #undef TARGET_OPTION_OVERRIDE
138 #define TARGET_OPTION_OVERRIDE vax_option_override
139
140 #undef TARGET_STARTING_FRAME_OFFSET
141 #define TARGET_STARTING_FRAME_OFFSET vax_starting_frame_offset
142
143 #undef TARGET_HAVE_SPECULATION_SAFE_VALUE
144 #define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed
145
146 struct gcc_target targetm = TARGET_INITIALIZER;
147
148 /* Set global variables as needed for the options enabled. */
149
150 static void
151 vax_option_override (void)
152 {
153 /* We're VAX floating point, not IEEE floating point. */
154 if (TARGET_G_FLOAT)
155 REAL_MODE_FORMAT (DFmode) = &vax_g_format;
156
157 #ifdef SUBTARGET_OVERRIDE_OPTIONS
158 SUBTARGET_OVERRIDE_OPTIONS;
159 #endif
160 }
161
162 static void
163 vax_add_reg_cfa_offset (rtx insn, int offset, rtx src)
164 {
165 rtx x;
166
167 x = plus_constant (Pmode, frame_pointer_rtx, offset);
168 x = gen_rtx_MEM (SImode, x);
169 x = gen_rtx_SET (x, src);
170 add_reg_note (insn, REG_CFA_OFFSET, x);
171 }
172
173 /* Generate the assembly code for function entry. FILE is a stdio
174 stream to output the code to. SIZE is an int: how many units of
175 temporary storage to allocate.
176
177 Refer to the array `regs_ever_live' to determine which registers to
178 save; `regs_ever_live[I]' is nonzero if register number I is ever
179 used in the function. This function is responsible for knowing
180 which registers should not be saved even if used. */
181
182 void
183 vax_expand_prologue (void)
184 {
185 int regno, offset;
186 int mask = 0;
187 HOST_WIDE_INT size;
188 rtx insn;
189
190 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
191 if (df_regs_ever_live_p (regno) && !call_used_or_fixed_reg_p (regno))
192 mask |= 1 << regno;
193
194 insn = emit_insn (gen_procedure_entry_mask (GEN_INT (mask)));
195 RTX_FRAME_RELATED_P (insn) = 1;
196
197 /* The layout of the CALLG/S stack frame is follows:
198
199 <- CFA, AP
200 r11
201 r10
202 ... Registers saved as specified by MASK
203 r3
204 r2
205 return-addr
206 old fp
207 old ap
208 old psw
209 zero
210 <- FP, SP
211
212 The rest of the prologue will adjust the SP for the local frame. */
213
214 vax_add_reg_cfa_offset (insn, 4, arg_pointer_rtx);
215 vax_add_reg_cfa_offset (insn, 8, frame_pointer_rtx);
216 vax_add_reg_cfa_offset (insn, 12, pc_rtx);
217
218 offset = 16;
219 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
220 if (mask & (1 << regno))
221 {
222 vax_add_reg_cfa_offset (insn, offset, gen_rtx_REG (SImode, regno));
223 offset += 4;
224 }
225
226 /* Because add_reg_note pushes the notes, adding this last means that
227 it will be processed first. This is required to allow the other
228 notes be interpreted properly. */
229 add_reg_note (insn, REG_CFA_DEF_CFA,
230 plus_constant (Pmode, frame_pointer_rtx, offset));
231
232 /* Allocate the local stack frame. */
233 size = get_frame_size ();
234 size -= vax_starting_frame_offset ();
235 emit_insn (gen_addsi3 (stack_pointer_rtx,
236 stack_pointer_rtx, GEN_INT (-size)));
237
238 /* Do not allow instructions referencing local stack memory to be
239 scheduled before the frame is allocated. This is more pedantic
240 than anything else, given that VAX does not currently have a
241 scheduling description. */
242 emit_insn (gen_blockage ());
243 }
244
245 /* When debugging with stabs, we want to output an extra dummy label
246 so that gas can distinguish between D_float and G_float prior to
247 processing the .stabs directive identifying type double. */
248 static void
249 vax_file_start (void)
250 {
251 default_file_start ();
252 }
253
254 /* We can use the BSD C library routines for the libgcc calls that are
255 still generated, since that's what they boil down to anyways. When
256 ELF, avoid the user's namespace. */
257
258 static void
259 vax_init_libfuncs (void)
260 {
261 if (TARGET_BSD_DIVMOD)
262 {
263 set_optab_libfunc (udiv_optab, SImode, TARGET_ELF ? "*__udiv" : "*udiv");
264 set_optab_libfunc (umod_optab, SImode, TARGET_ELF ? "*__urem" : "*urem");
265 }
266 }
267
268 /* This is like nonimmediate_operand with a restriction on the type of MEM. */
269
270 static void
271 split_quadword_operands (rtx insn, enum rtx_code code, rtx * operands,
272 rtx * low, int n)
273 {
274 int i;
275
276 for (i = 0; i < n; i++)
277 low[i] = 0;
278
279 for (i = 0; i < n; i++)
280 {
281 if (MEM_P (operands[i])
282 && (GET_CODE (XEXP (operands[i], 0)) == PRE_DEC
283 || GET_CODE (XEXP (operands[i], 0)) == POST_INC))
284 {
285 rtx addr = XEXP (operands[i], 0);
286 operands[i] = low[i] = gen_rtx_MEM (SImode, addr);
287 }
288 else if (optimize_size && MEM_P (operands[i])
289 && REG_P (XEXP (operands[i], 0))
290 && (code != MINUS || operands[1] != const0_rtx)
291 && find_regno_note (insn, REG_DEAD,
292 REGNO (XEXP (operands[i], 0))))
293 {
294 low[i] = gen_rtx_MEM (SImode,
295 gen_rtx_POST_INC (Pmode,
296 XEXP (operands[i], 0)));
297 operands[i] = gen_rtx_MEM (SImode, XEXP (operands[i], 0));
298 }
299 else
300 {
301 low[i] = operand_subword (operands[i], 0, 0, DImode);
302 operands[i] = operand_subword (operands[i], 1, 0, DImode);
303 }
304 }
305 }
306
307 void
308 print_operand_address (FILE * file, rtx addr)
309 {
310 rtx orig = addr;
311 rtx reg1, breg, ireg;
312 rtx offset;
313
314 retry:
315 switch (GET_CODE (addr))
316 {
317 case MEM:
318 fprintf (file, "*");
319 addr = XEXP (addr, 0);
320 goto retry;
321
322 case REG:
323 fprintf (file, "(%s)", reg_names[REGNO (addr)]);
324 break;
325
326 case PRE_DEC:
327 fprintf (file, "-(%s)", reg_names[REGNO (XEXP (addr, 0))]);
328 break;
329
330 case POST_INC:
331 fprintf (file, "(%s)+", reg_names[REGNO (XEXP (addr, 0))]);
332 break;
333
334 case PLUS:
335 /* There can be either two or three things added here. One must be a
336 REG. One can be either a REG or a MULT/ASHIFT of a REG and an
337 appropriate constant, and the third can only be a constant or a MEM.
338
339 We get these two or three things and put the constant or MEM in
340 OFFSET, the MULT/ASHIFT or REG in IREG, and the REG in BREG. If we
341 have a register and can't tell yet if it is a base or index register,
342 put it into REG1. */
343
344 reg1 = 0; ireg = 0; breg = 0; offset = 0;
345
346 if (CONSTANT_ADDRESS_P (XEXP (addr, 0))
347 || MEM_P (XEXP (addr, 0)))
348 {
349 offset = XEXP (addr, 0);
350 addr = XEXP (addr, 1);
351 }
352 else if (CONSTANT_ADDRESS_P (XEXP (addr, 1))
353 || MEM_P (XEXP (addr, 1)))
354 {
355 offset = XEXP (addr, 1);
356 addr = XEXP (addr, 0);
357 }
358 else if (GET_CODE (XEXP (addr, 1)) == MULT
359 || GET_CODE (XEXP (addr, 1)) == ASHIFT)
360 {
361 ireg = XEXP (addr, 1);
362 addr = XEXP (addr, 0);
363 }
364 else if (GET_CODE (XEXP (addr, 0)) == MULT
365 || GET_CODE (XEXP (addr, 0)) == ASHIFT)
366 {
367 ireg = XEXP (addr, 0);
368 addr = XEXP (addr, 1);
369 }
370 else if (REG_P (XEXP (addr, 1)))
371 {
372 reg1 = XEXP (addr, 1);
373 addr = XEXP (addr, 0);
374 }
375 else if (REG_P (XEXP (addr, 0)))
376 {
377 reg1 = XEXP (addr, 0);
378 addr = XEXP (addr, 1);
379 }
380 else
381 gcc_unreachable ();
382
383 if (REG_P (addr))
384 {
385 if (reg1)
386 ireg = addr;
387 else
388 reg1 = addr;
389 }
390 else if (GET_CODE (addr) == MULT || GET_CODE (addr) == ASHIFT)
391 ireg = addr;
392 else
393 {
394 gcc_assert (GET_CODE (addr) == PLUS);
395 if (CONSTANT_ADDRESS_P (XEXP (addr, 0))
396 || MEM_P (XEXP (addr, 0)))
397 {
398 if (offset)
399 {
400 if (CONST_INT_P (offset))
401 offset = plus_constant (Pmode, XEXP (addr, 0),
402 INTVAL (offset));
403 else
404 {
405 gcc_assert (CONST_INT_P (XEXP (addr, 0)));
406 offset = plus_constant (Pmode, offset,
407 INTVAL (XEXP (addr, 0)));
408 }
409 }
410 offset = XEXP (addr, 0);
411 }
412 else if (REG_P (XEXP (addr, 0)))
413 {
414 if (reg1)
415 ireg = reg1, breg = XEXP (addr, 0), reg1 = 0;
416 else
417 reg1 = XEXP (addr, 0);
418 }
419 else
420 {
421 gcc_assert (GET_CODE (XEXP (addr, 0)) == MULT
422 || GET_CODE (XEXP (addr, 0)) == ASHIFT);
423 gcc_assert (!ireg);
424 ireg = XEXP (addr, 0);
425 }
426
427 if (CONSTANT_ADDRESS_P (XEXP (addr, 1))
428 || MEM_P (XEXP (addr, 1)))
429 {
430 if (offset)
431 {
432 if (CONST_INT_P (offset))
433 offset = plus_constant (Pmode, XEXP (addr, 1),
434 INTVAL (offset));
435 else
436 {
437 gcc_assert (CONST_INT_P (XEXP (addr, 1)));
438 offset = plus_constant (Pmode, offset,
439 INTVAL (XEXP (addr, 1)));
440 }
441 }
442 offset = XEXP (addr, 1);
443 }
444 else if (REG_P (XEXP (addr, 1)))
445 {
446 if (reg1)
447 ireg = reg1, breg = XEXP (addr, 1), reg1 = 0;
448 else
449 reg1 = XEXP (addr, 1);
450 }
451 else
452 {
453 gcc_assert (GET_CODE (XEXP (addr, 1)) == MULT
454 || GET_CODE (XEXP (addr, 1)) == ASHIFT);
455 gcc_assert (!ireg);
456 ireg = XEXP (addr, 1);
457 }
458 }
459
460 /* If REG1 is nonzero, figure out if it is a base or index register. */
461 if (reg1)
462 {
463 if (breg
464 || (flag_pic && GET_CODE (addr) == SYMBOL_REF)
465 || (offset
466 && (MEM_P (offset)
467 || (flag_pic && symbolic_operand (offset, SImode)))))
468 {
469 gcc_assert (!ireg);
470 ireg = reg1;
471 }
472 else
473 breg = reg1;
474 }
475
476 if (offset != 0)
477 {
478 if (flag_pic && symbolic_operand (offset, SImode))
479 {
480 if (breg && ireg)
481 {
482 debug_rtx (orig);
483 output_operand_lossage ("symbol used with both base and indexed registers");
484 }
485
486 #ifdef NO_EXTERNAL_INDIRECT_ADDRESS
487 if (flag_pic > 1 && GET_CODE (offset) == CONST
488 && GET_CODE (XEXP (XEXP (offset, 0), 0)) == SYMBOL_REF
489 && !SYMBOL_REF_LOCAL_P (XEXP (XEXP (offset, 0), 0)))
490 {
491 debug_rtx (orig);
492 output_operand_lossage ("symbol with offset used in PIC mode");
493 }
494 #endif
495
496 /* symbol(reg) isn't PIC, but symbol[reg] is. */
497 if (breg)
498 {
499 ireg = breg;
500 breg = 0;
501 }
502
503 }
504
505 output_address (VOIDmode, offset);
506 }
507
508 if (breg != 0)
509 fprintf (file, "(%s)", reg_names[REGNO (breg)]);
510
511 if (ireg != 0)
512 {
513 if (GET_CODE (ireg) == MULT || GET_CODE (ireg) == ASHIFT)
514 ireg = XEXP (ireg, 0);
515 gcc_assert (REG_P (ireg));
516 fprintf (file, "[%s]", reg_names[REGNO (ireg)]);
517 }
518 break;
519
520 default:
521 output_addr_const (file, addr);
522 }
523 }
524
525 void
526 print_operand (FILE *file, rtx x, int code)
527 {
528 if (code == '#')
529 fputc (ASM_DOUBLE_CHAR, file);
530 else if (code == '|')
531 fputs (REGISTER_PREFIX, file);
532 else if (code == 'k')
533 fputs (cond_name (x), file);
534 else if (code == 'K')
535 fputs (rev_cond_name (x), file);
536 else if (code == 'D' && CONST_INT_P (x) && INTVAL (x) < 0)
537 fprintf (file, "$" NEG_HWI_PRINT_HEX16, INTVAL (x));
538 else if (code == 'P' && CONST_INT_P (x))
539 fprintf (file, "$" HOST_WIDE_INT_PRINT_DEC, INTVAL (x) + 1);
540 else if (code == 'N' && CONST_INT_P (x))
541 fprintf (file, "$" HOST_WIDE_INT_PRINT_DEC, ~ INTVAL (x));
542 /* rotl instruction cannot deal with negative arguments. */
543 else if (code == 'R' && CONST_INT_P (x))
544 fprintf (file, "$" HOST_WIDE_INT_PRINT_DEC, 32 - INTVAL (x));
545 else if (code == 'H' && CONST_INT_P (x))
546 fprintf (file, "$%d", (int) (0xffff & ~ INTVAL (x)));
547 else if (code == 'h' && CONST_INT_P (x))
548 fprintf (file, "$%d", (short) - INTVAL (x));
549 else if (code == 'B' && CONST_INT_P (x))
550 fprintf (file, "$%d", (int) (0xff & ~ INTVAL (x)));
551 else if (code == 'b' && CONST_INT_P (x))
552 fprintf (file, "$%d", (int) (0xff & - INTVAL (x)));
553 else if (code == 'M' && CONST_INT_P (x))
554 fprintf (file, "$%d", ~((1 << INTVAL (x)) - 1));
555 else if (code == 'x' && CONST_INT_P (x))
556 fprintf (file, HOST_WIDE_INT_PRINT_HEX, INTVAL (x));
557 else if (REG_P (x))
558 fprintf (file, "%s", reg_names[REGNO (x)]);
559 else if (MEM_P (x))
560 output_address (GET_MODE (x), XEXP (x, 0));
561 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
562 {
563 char dstr[30];
564 real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x),
565 sizeof (dstr), 0, 1);
566 fprintf (file, "$0f%s", dstr);
567 }
568 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
569 {
570 char dstr[30];
571 real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x),
572 sizeof (dstr), 0, 1);
573 fprintf (file, "$0%c%s", ASM_DOUBLE_CHAR, dstr);
574 }
575 else
576 {
577 if (flag_pic > 1 && symbolic_operand (x, SImode))
578 {
579 debug_rtx (x);
580 output_operand_lossage ("symbol used as immediate operand");
581 }
582 putc ('$', file);
583 output_addr_const (file, x);
584 }
585 }
586
587 const char *
588 cond_name (rtx op)
589 {
590 switch (GET_CODE (op))
591 {
592 case NE:
593 return "neq";
594 case EQ:
595 return "eql";
596 case GE:
597 return "geq";
598 case GT:
599 return "gtr";
600 case LE:
601 return "leq";
602 case LT:
603 return "lss";
604 case GEU:
605 return "gequ";
606 case GTU:
607 return "gtru";
608 case LEU:
609 return "lequ";
610 case LTU:
611 return "lssu";
612
613 default:
614 gcc_unreachable ();
615 }
616 }
617
618 const char *
619 rev_cond_name (rtx op)
620 {
621 switch (GET_CODE (op))
622 {
623 case EQ:
624 return "neq";
625 case NE:
626 return "eql";
627 case LT:
628 return "geq";
629 case LE:
630 return "gtr";
631 case GT:
632 return "leq";
633 case GE:
634 return "lss";
635 case LTU:
636 return "gequ";
637 case LEU:
638 return "gtru";
639 case GTU:
640 return "lequ";
641 case GEU:
642 return "lssu";
643
644 default:
645 gcc_unreachable ();
646 }
647 }
648
649 static bool
650 vax_float_literal (rtx c)
651 {
652 machine_mode mode;
653 const REAL_VALUE_TYPE *r;
654 REAL_VALUE_TYPE s;
655 int i;
656
657 if (GET_CODE (c) != CONST_DOUBLE)
658 return false;
659
660 mode = GET_MODE (c);
661
662 if (c == const_tiny_rtx[(int) mode][0]
663 || c == const_tiny_rtx[(int) mode][1]
664 || c == const_tiny_rtx[(int) mode][2])
665 return true;
666
667 r = CONST_DOUBLE_REAL_VALUE (c);
668
669 for (i = 0; i < 7; i++)
670 {
671 int x = 1 << i;
672 bool ok;
673 real_from_integer (&s, mode, x, SIGNED);
674
675 if (real_equal (r, &s))
676 return true;
677 ok = exact_real_inverse (mode, &s);
678 gcc_assert (ok);
679 if (real_equal (r, &s))
680 return true;
681 }
682 return false;
683 }
684
685
686 /* Return the cost in cycles of a memory address, relative to register
687 indirect.
688
689 Each of the following adds the indicated number of cycles:
690
691 1 - symbolic address
692 1 - pre-decrement
693 1 - indexing and/or offset(register)
694 2 - indirect */
695
696
697 static int
698 vax_address_cost_1 (rtx addr)
699 {
700 int reg = 0, indexed = 0, indir = 0, offset = 0, predec = 0;
701 rtx plus_op0 = 0, plus_op1 = 0;
702 restart:
703 switch (GET_CODE (addr))
704 {
705 case PRE_DEC:
706 predec = 1;
707 /* FALLTHRU */
708 case REG:
709 case SUBREG:
710 case POST_INC:
711 reg = 1;
712 break;
713 case MULT:
714 case ASHIFT:
715 indexed = 1; /* 2 on VAX 2 */
716 break;
717 case CONST_INT:
718 /* byte offsets cost nothing (on a VAX 2, they cost 1 cycle) */
719 if (offset == 0)
720 offset = (unsigned HOST_WIDE_INT)(INTVAL(addr)+128) > 256;
721 break;
722 case CONST:
723 case SYMBOL_REF:
724 offset = 1; /* 2 on VAX 2 */
725 break;
726 case LABEL_REF: /* this is probably a byte offset from the pc */
727 if (offset == 0)
728 offset = 1;
729 break;
730 case PLUS:
731 if (plus_op0)
732 plus_op1 = XEXP (addr, 0);
733 else
734 plus_op0 = XEXP (addr, 0);
735 addr = XEXP (addr, 1);
736 goto restart;
737 case MEM:
738 indir = 2; /* 3 on VAX 2 */
739 addr = XEXP (addr, 0);
740 goto restart;
741 default:
742 break;
743 }
744
745 /* Up to 3 things can be added in an address. They are stored in
746 plus_op0, plus_op1, and addr. */
747
748 if (plus_op0)
749 {
750 addr = plus_op0;
751 plus_op0 = 0;
752 goto restart;
753 }
754 if (plus_op1)
755 {
756 addr = plus_op1;
757 plus_op1 = 0;
758 goto restart;
759 }
760 /* Indexing and register+offset can both be used (except on a VAX 2)
761 without increasing execution time over either one alone. */
762 if (reg && indexed && offset)
763 return reg + indir + offset + predec;
764 return reg + indexed + indir + offset + predec;
765 }
766
767 static int
768 vax_address_cost (rtx x, machine_mode mode ATTRIBUTE_UNUSED,
769 addr_space_t as ATTRIBUTE_UNUSED,
770 bool speed ATTRIBUTE_UNUSED)
771 {
772 return COSTS_N_INSNS (1 + (REG_P (x) ? 0 : vax_address_cost_1 (x)));
773 }
774
775 /* Cost of an expression on a VAX. This version has costs tuned for the
776 CVAX chip (found in the VAX 3 series) with comments for variations on
777 other models.
778
779 FIXME: The costs need review, particularly for TRUNCATE, FLOAT_EXTEND
780 and FLOAT_TRUNCATE. We need a -mcpu option to allow provision of
781 costs on a per cpu basis. */
782
783 static bool
784 vax_rtx_costs (rtx x, machine_mode mode, int outer_code,
785 int opno ATTRIBUTE_UNUSED,
786 int *total, bool speed ATTRIBUTE_UNUSED)
787 {
788 enum rtx_code code = GET_CODE (x);
789 int i = 0; /* may be modified in switch */
790 const char *fmt = GET_RTX_FORMAT (code); /* may be modified in switch */
791
792 switch (code)
793 {
794 /* On a VAX, constants from 0..63 are cheap because they can use the
795 1 byte literal constant format. Compare to -1 should be made cheap
796 so that decrement-and-branch insns can be formed more easily (if
797 the value -1 is copied to a register some decrement-and-branch
798 patterns will not match). */
799 case CONST_INT:
800 if (INTVAL (x) == 0)
801 {
802 *total = COSTS_N_INSNS (1) / 2;
803 return true;
804 }
805 if (outer_code == AND)
806 {
807 *total = ((unsigned HOST_WIDE_INT) ~INTVAL (x) <= 077
808 ? COSTS_N_INSNS (1) : COSTS_N_INSNS (2));
809 return true;
810 }
811 if ((unsigned HOST_WIDE_INT) INTVAL (x) <= 077
812 || (outer_code == COMPARE
813 && INTVAL (x) == -1)
814 || ((outer_code == PLUS || outer_code == MINUS)
815 && (unsigned HOST_WIDE_INT) -INTVAL (x) <= 077))
816 {
817 *total = COSTS_N_INSNS (1);
818 return true;
819 }
820 /* FALLTHRU */
821
822 case CONST:
823 case LABEL_REF:
824 case SYMBOL_REF:
825 *total = COSTS_N_INSNS (3);
826 return true;
827
828 case CONST_DOUBLE:
829 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
830 *total = vax_float_literal (x) ? COSTS_N_INSNS (5) : COSTS_N_INSNS (8);
831 else
832 *total = ((CONST_DOUBLE_HIGH (x) == 0
833 && (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x) < 64)
834 || (outer_code == PLUS
835 && CONST_DOUBLE_HIGH (x) == -1
836 && (unsigned HOST_WIDE_INT)-CONST_DOUBLE_LOW (x) < 64)
837 ? COSTS_N_INSNS (2) : COSTS_N_INSNS (5));
838 return true;
839
840 case POST_INC:
841 *total = COSTS_N_INSNS (2);
842 return true; /* Implies register operand. */
843
844 case PRE_DEC:
845 *total = COSTS_N_INSNS (3);
846 return true; /* Implies register operand. */
847
848 case MULT:
849 switch (mode)
850 {
851 case E_DFmode:
852 *total = COSTS_N_INSNS (16); /* 4 on VAX 9000 */
853 break;
854 case E_SFmode:
855 *total = COSTS_N_INSNS (9); /* 4 on VAX 9000, 12 on VAX 2 */
856 break;
857 case E_DImode:
858 *total = COSTS_N_INSNS (16); /* 6 on VAX 9000, 28 on VAX 2 */
859 break;
860 case E_SImode:
861 case E_HImode:
862 case E_QImode:
863 *total = COSTS_N_INSNS (10); /* 3-4 on VAX 9000, 20-28 on VAX 2 */
864 break;
865 default:
866 *total = MAX_COST; /* Mode is not supported. */
867 return true;
868 }
869 break;
870
871 case UDIV:
872 if (mode != SImode)
873 {
874 *total = MAX_COST; /* Mode is not supported. */
875 return true;
876 }
877 *total = COSTS_N_INSNS (17);
878 break;
879
880 case DIV:
881 if (mode == DImode)
882 *total = COSTS_N_INSNS (30); /* Highly variable. */
883 else if (mode == DFmode)
884 /* divide takes 28 cycles if the result is not zero, 13 otherwise */
885 *total = COSTS_N_INSNS (24);
886 else
887 *total = COSTS_N_INSNS (11); /* 25 on VAX 2 */
888 break;
889
890 case MOD:
891 *total = COSTS_N_INSNS (23);
892 break;
893
894 case UMOD:
895 if (mode != SImode)
896 {
897 *total = MAX_COST; /* Mode is not supported. */
898 return true;
899 }
900 *total = COSTS_N_INSNS (29);
901 break;
902
903 case FLOAT:
904 *total = COSTS_N_INSNS (6 /* 4 on VAX 9000 */
905 + (mode == DFmode)
906 + (GET_MODE (XEXP (x, 0)) != SImode));
907 break;
908
909 case FIX:
910 *total = COSTS_N_INSNS (7); /* 17 on VAX 2 */
911 break;
912
913 case ASHIFT:
914 case LSHIFTRT:
915 case ASHIFTRT:
916 if (mode == DImode)
917 *total = COSTS_N_INSNS (12);
918 else
919 *total = COSTS_N_INSNS (10); /* 6 on VAX 9000 */
920 break;
921
922 case ROTATE:
923 case ROTATERT:
924 *total = COSTS_N_INSNS (6); /* 5 on VAX 2, 4 on VAX 9000 */
925 if (CONST_INT_P (XEXP (x, 1)))
926 fmt = "e"; /* all constant rotate counts are short */
927 break;
928
929 case PLUS:
930 case MINUS:
931 *total = (mode == DFmode /* 6/8 on VAX 9000, 16/15 on VAX 2 */
932 ? COSTS_N_INSNS (13) : COSTS_N_INSNS (8));
933 /* Small integer operands can use subl2 and addl2. */
934 if ((CONST_INT_P (XEXP (x, 1)))
935 && (unsigned HOST_WIDE_INT)(INTVAL (XEXP (x, 1)) + 63) < 127)
936 fmt = "e";
937 break;
938
939 case IOR:
940 case XOR:
941 *total = COSTS_N_INSNS (3);
942 break;
943
944 case AND:
945 /* AND is special because the first operand is complemented. */
946 *total = COSTS_N_INSNS (3);
947 if (CONST_INT_P (XEXP (x, 0)))
948 {
949 if ((unsigned HOST_WIDE_INT)~INTVAL (XEXP (x, 0)) > 63)
950 *total = COSTS_N_INSNS (4);
951 fmt = "e";
952 i = 1;
953 }
954 break;
955
956 case NEG:
957 if (mode == DFmode)
958 *total = COSTS_N_INSNS (9);
959 else if (mode == SFmode)
960 *total = COSTS_N_INSNS (6);
961 else if (mode == DImode)
962 *total = COSTS_N_INSNS (4);
963 else
964 *total = COSTS_N_INSNS (2);
965 break;
966
967 case NOT:
968 *total = COSTS_N_INSNS (2);
969 break;
970
971 case ZERO_EXTRACT:
972 case SIGN_EXTRACT:
973 *total = COSTS_N_INSNS (15);
974 break;
975
976 case MEM:
977 if (mode == DImode || mode == DFmode)
978 *total = COSTS_N_INSNS (5); /* 7 on VAX 2 */
979 else
980 *total = COSTS_N_INSNS (3); /* 4 on VAX 2 */
981 x = XEXP (x, 0);
982 if (!REG_P (x) && GET_CODE (x) != POST_INC)
983 *total += COSTS_N_INSNS (vax_address_cost_1 (x));
984 return true;
985
986 case FLOAT_EXTEND:
987 case FLOAT_TRUNCATE:
988 case TRUNCATE:
989 *total = COSTS_N_INSNS (3); /* FIXME: Costs need to be checked */
990 break;
991
992 default:
993 return false;
994 }
995
996 /* Now look inside the expression. Operands which are not registers or
997 short constants add to the cost.
998
999 FMT and I may have been adjusted in the switch above for instructions
1000 which require special handling. */
1001
1002 while (*fmt++ == 'e')
1003 {
1004 rtx op = XEXP (x, i);
1005
1006 i += 1;
1007 code = GET_CODE (op);
1008
1009 /* A NOT is likely to be found as the first operand of an AND
1010 (in which case the relevant cost is of the operand inside
1011 the not) and not likely to be found anywhere else. */
1012 if (code == NOT)
1013 op = XEXP (op, 0), code = GET_CODE (op);
1014
1015 switch (code)
1016 {
1017 case CONST_INT:
1018 if ((unsigned HOST_WIDE_INT)INTVAL (op) > 63
1019 && mode != QImode)
1020 *total += COSTS_N_INSNS (1); /* 2 on VAX 2 */
1021 break;
1022 case CONST:
1023 case LABEL_REF:
1024 case SYMBOL_REF:
1025 *total += COSTS_N_INSNS (1); /* 2 on VAX 2 */
1026 break;
1027 case CONST_DOUBLE:
1028 if (GET_MODE_CLASS (GET_MODE (op)) == MODE_FLOAT)
1029 {
1030 /* Registers are faster than floating point constants -- even
1031 those constants which can be encoded in a single byte. */
1032 if (vax_float_literal (op))
1033 *total += COSTS_N_INSNS (1);
1034 else
1035 *total += (GET_MODE (x) == DFmode
1036 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (2));
1037 }
1038 else
1039 {
1040 if (CONST_DOUBLE_HIGH (op) != 0
1041 || (unsigned HOST_WIDE_INT)CONST_DOUBLE_LOW (op) > 63)
1042 *total += COSTS_N_INSNS (2);
1043 }
1044 break;
1045 case MEM:
1046 *total += COSTS_N_INSNS (1); /* 2 on VAX 2 */
1047 if (!REG_P (XEXP (op, 0)))
1048 *total += COSTS_N_INSNS (vax_address_cost_1 (XEXP (op, 0)));
1049 break;
1050 case REG:
1051 case SUBREG:
1052 break;
1053 default:
1054 *total += COSTS_N_INSNS (1);
1055 break;
1056 }
1057 }
1058 return true;
1059 }
1060
1061 /* With ELF we do not support GOT entries for external `symbol+offset'
1062 references, so do not accept external symbol references if an offset
1063 is to be added. Do not accept external symbol references at all if
1064 LOCAL_P is set. This is for cases where making a reference indirect
1065 would make it invalid. Do not accept any kind of symbols if SYMBOL_P
1066 is clear. This is for situations where the a reference is used as an
1067 immediate value for operations other than address loads (MOVA/PUSHA),
1068 as those operations do not support PC-relative immediates. */
1069
1070 bool
1071 vax_acceptable_pic_operand_p (rtx x ATTRIBUTE_UNUSED,
1072 bool local_p ATTRIBUTE_UNUSED,
1073 bool symbol_p ATTRIBUTE_UNUSED)
1074 {
1075 #ifdef NO_EXTERNAL_INDIRECT_ADDRESS
1076 if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS)
1077 {
1078 x = XEXP (XEXP (x, 0), 0);
1079 local_p = true;
1080 }
1081 switch (GET_CODE (x))
1082 {
1083 case SYMBOL_REF:
1084 return symbol_p && !(local_p && !SYMBOL_REF_LOCAL_P (x));
1085 case LABEL_REF:
1086 return symbol_p && !(local_p && LABEL_REF_NONLOCAL_P (x));
1087 default:
1088 break;
1089 }
1090 #endif
1091 return true;
1092 }
1093
1094 /* Given a comparison code (NE, EQ, etc.) and the operands of a COMPARE,
1095 return the mode to be used for the comparison. As we have the same
1096 interpretation of condition codes across all the instructions we just
1097 return the narrowest mode suitable for the comparison code requested. */
1098
1099 extern machine_mode
1100 vax_select_cc_mode (enum rtx_code op,
1101 rtx x ATTRIBUTE_UNUSED, rtx y ATTRIBUTE_UNUSED)
1102 {
1103 switch (op)
1104 {
1105 default:
1106 gcc_unreachable ();
1107 case NE:
1108 case EQ:
1109 return CCZmode;
1110 case GE:
1111 case LT:
1112 return CCNmode;
1113 case GT:
1114 case LE:
1115 return CCNZmode;
1116 case GEU:
1117 case GTU:
1118 case LEU:
1119 case LTU:
1120 return CCmode;
1121 }
1122 }
1123
1124 /* Return the narrowest CC mode that spans both modes offered. If they
1125 intersect, this will be the wider of the two, and if they do not then
1126 find one that is a superset of both (i.e. CCNZmode for a pair
1127 consisting of CCNmode and CCZmode). A wider CC writer will satisfy
1128 a narrower CC reader, e.g. a comparison operator that uses CCZmode
1129 can use a CCNZmode output of a previous instruction. */
1130
1131 static machine_mode
1132 vax_cc_modes_compatible (machine_mode m1, machine_mode m2)
1133 {
1134 switch (m1)
1135 {
1136 default:
1137 gcc_unreachable ();
1138 case E_CCmode:
1139 switch (m2)
1140 {
1141 default:
1142 gcc_unreachable ();
1143 case E_CCmode:
1144 case E_CCNZmode:
1145 case E_CCNmode:
1146 case E_CCZmode:
1147 return m1;
1148 }
1149 case E_CCNZmode:
1150 switch (m2)
1151 {
1152 default:
1153 gcc_unreachable ();
1154 case E_CCmode:
1155 return m2;
1156 case E_CCNmode:
1157 case E_CCNZmode:
1158 case E_CCZmode:
1159 return m1;
1160 }
1161 case E_CCNmode:
1162 case E_CCZmode:
1163 switch (m2)
1164 {
1165 default:
1166 gcc_unreachable ();
1167 case E_CCmode:
1168 case E_CCNZmode:
1169 return m2;
1170 case E_CCNmode:
1171 case E_CCZmode:
1172 return m1 == m2 ? m1 : E_CCNZmode;
1173 }
1174 }
1175 }
1176
1177 /* Mark PSL as clobbered for compatibility with the CC0 representation. */
1178
1179 static rtx_insn *
1180 vax_md_asm_adjust (vec<rtx> &outputs ATTRIBUTE_UNUSED,
1181 vec<rtx> &inputs ATTRIBUTE_UNUSED,
1182 vec<machine_mode> &input_modes ATTRIBUTE_UNUSED,
1183 vec<const char *> &constraints ATTRIBUTE_UNUSED,
1184 vec<rtx> &/*uses*/,
1185 vec<rtx> &clobbers, HARD_REG_SET &clobbered_regs,
1186 location_t /*loc*/)
1187 {
1188 clobbers.safe_push (gen_rtx_REG (CCmode, VAX_PSL_REGNUM));
1189 SET_HARD_REG_BIT (clobbered_regs, VAX_PSL_REGNUM);
1190 return NULL;
1191 }
1192
1193 /* Output code to add DELTA to the first argument, and then jump to FUNCTION.
1194 Used for C++ multiple inheritance.
1195 .mask ^m<r2,r3,r4,r5,r6,r7,r8,r9,r10,r11> #conservative entry mask
1196 addl2 $DELTA, 4(ap) #adjust first argument
1197 jmp FUNCTION+2 #jump beyond FUNCTION's entry mask
1198 */
1199
1200 static void
1201 vax_output_mi_thunk (FILE * file,
1202 tree thunk ATTRIBUTE_UNUSED,
1203 HOST_WIDE_INT delta,
1204 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
1205 tree function)
1206 {
1207 const char *fnname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunk));
1208
1209 assemble_start_function (thunk, fnname);
1210 fprintf (file, "\t.word 0x0ffc\n\taddl2 $" HOST_WIDE_INT_PRINT_DEC, delta);
1211 asm_fprintf (file, ",4(%Rap)\n");
1212 fprintf (file, "\tjmp ");
1213 assemble_name (file, XSTR (XEXP (DECL_RTL (function), 0), 0));
1214 fprintf (file, "+2\n");
1215 assemble_end_function (thunk, fnname);
1216 }
1217
1218 static rtx
1219 vax_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
1220 int incoming ATTRIBUTE_UNUSED)
1221 {
1222 return gen_rtx_REG (Pmode, VAX_STRUCT_VALUE_REGNUM);
1223 }
1224
1225 /* Return true if we use LRA instead of reload pass. */
1226
1227 static bool
1228 vax_lra_p (void)
1229 {
1230 return TARGET_LRA;
1231 }
1232
1233 /* Output integer move instructions. */
1234
1235 bool
1236 vax_maybe_split_dimode_move (rtx *operands)
1237 {
1238 return (TARGET_QMATH
1239 && (!MEM_P (operands[0])
1240 || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
1241 || GET_CODE (XEXP (operands[0], 0)) == POST_INC
1242 || !illegal_addsub_di_memory_operand (operands[0], DImode))
1243 && ((CONST_INT_P (operands[1])
1244 && (unsigned HOST_WIDE_INT) INTVAL (operands[1]) >= 64)
1245 || GET_CODE (operands[1]) == CONST_DOUBLE));
1246 }
1247
1248 const char *
1249 vax_output_int_move (rtx insn ATTRIBUTE_UNUSED, rtx *operands,
1250 machine_mode mode)
1251 {
1252 rtx hi[3], lo[3];
1253 const char *pattern_hi, *pattern_lo;
1254 bool push_p;
1255
1256 switch (mode)
1257 {
1258 case E_DImode:
1259 if (operands[1] == const0_rtx)
1260 return "clrq %0";
1261 if (TARGET_QMATH && optimize_size
1262 && (CONST_INT_P (operands[1])
1263 || GET_CODE (operands[1]) == CONST_DOUBLE))
1264 {
1265 unsigned HOST_WIDE_INT hval, lval;
1266 int n;
1267
1268 if (GET_CODE (operands[1]) == CONST_DOUBLE)
1269 {
1270 gcc_assert (HOST_BITS_PER_WIDE_INT != 64);
1271
1272 /* Make sure only the low 32 bits are valid. */
1273 lval = CONST_DOUBLE_LOW (operands[1]) & 0xffffffff;
1274 hval = CONST_DOUBLE_HIGH (operands[1]) & 0xffffffff;
1275 }
1276 else
1277 {
1278 lval = INTVAL (operands[1]);
1279 hval = 0;
1280 }
1281
1282 /* Here we see if we are trying to see if the 64bit value is really
1283 a 6bit shifted some arbitrary amount. If so, we can use ashq to
1284 shift it to the correct value saving 7 bytes (1 addr-mode-byte +
1285 8 bytes - 1 shift byte - 1 short literal byte. */
1286 if (lval != 0
1287 && (n = exact_log2 (lval & (- lval))) != -1
1288 && (lval >> n) < 64)
1289 {
1290 lval >>= n;
1291
1292 /* On 32bit platforms, if the 6bits didn't overflow into the
1293 upper 32bit value that value better be 0. If we have
1294 overflowed, make sure it wasn't too much. */
1295 if (HOST_BITS_PER_WIDE_INT == 32 && hval != 0)
1296 {
1297 if (n <= 26 || hval >= ((unsigned)1 << (n - 26)))
1298 n = 0; /* failure */
1299 else
1300 lval |= hval << (32 - n);
1301 }
1302 /* If n is 0, then ashq is not the best way to emit this. */
1303 if (n > 0)
1304 {
1305 operands[1] = GEN_INT (lval);
1306 operands[2] = GEN_INT (n);
1307 return "ashq %2,%D1,%0";
1308 }
1309 #if HOST_BITS_PER_WIDE_INT == 32
1310 }
1311 /* On 32bit platforms, if the low 32bit value is 0, checkout the
1312 upper 32bit value. */
1313 else if (hval != 0
1314 && (n = exact_log2 (hval & (- hval)) - 1) != -1
1315 && (hval >> n) < 64)
1316 {
1317 operands[1] = GEN_INT (hval >> n);
1318 operands[2] = GEN_INT (n + 32);
1319 return "ashq %2,%D1,%0";
1320 #endif
1321 }
1322 }
1323
1324 if (vax_maybe_split_dimode_move (operands))
1325 {
1326 hi[0] = operands[0];
1327 hi[1] = operands[1];
1328
1329 split_quadword_operands (insn, SET, hi, lo, 2);
1330
1331 pattern_lo = vax_output_int_move (NULL, lo, SImode);
1332 pattern_hi = vax_output_int_move (NULL, hi, SImode);
1333
1334 /* The patterns are just movl/movl or pushl/pushl then a movq will
1335 be shorter (1 opcode byte + 1 addrmode byte + 8 immediate value
1336 bytes .vs. 2 opcode bytes + 2 addrmode bytes + 8 immediate value
1337 value bytes. */
1338 if ((startswith (pattern_lo, "movl")
1339 && startswith (pattern_hi, "movl"))
1340 || (startswith (pattern_lo, "pushl")
1341 && startswith (pattern_hi, "pushl")))
1342 return "movq %1,%0";
1343
1344 if (MEM_P (operands[0])
1345 && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
1346 {
1347 output_asm_insn (pattern_hi, hi);
1348 operands[0] = lo[0];
1349 operands[1] = lo[1];
1350 operands[2] = lo[2];
1351 return pattern_lo;
1352 }
1353 else
1354 {
1355 output_asm_insn (pattern_lo, lo);
1356 operands[0] = hi[0];
1357 operands[1] = hi[1];
1358 operands[2] = hi[2];
1359 return pattern_hi;
1360 }
1361 }
1362 return "movq %1,%0";
1363
1364 case E_SImode:
1365 push_p = push_operand (operands[0], SImode);
1366
1367 if (symbolic_operand (operands[1], SImode))
1368 return push_p ? "pushab %a1" : "movab %a1,%0";
1369
1370 if (operands[1] == const0_rtx)
1371 return push_p ? "pushl %1" : "clrl %0";
1372
1373 if (CONST_INT_P (operands[1])
1374 && (unsigned HOST_WIDE_INT) INTVAL (operands[1]) >= 64)
1375 {
1376 HOST_WIDE_INT i = INTVAL (operands[1]);
1377 int n;
1378 if ((unsigned HOST_WIDE_INT)(~i) < 64)
1379 return "mcoml %N1,%0";
1380 if ((unsigned HOST_WIDE_INT)i < 0x100)
1381 return "movzbl %1,%0";
1382 if (i >= -0x80 && i < 0)
1383 return "cvtbl %1,%0";
1384 if (optimize_size
1385 && (n = exact_log2 (i & (-i))) != -1
1386 && ((unsigned HOST_WIDE_INT)i >> n) < 64)
1387 {
1388 operands[1] = GEN_INT ((unsigned HOST_WIDE_INT)i >> n);
1389 operands[2] = GEN_INT (n);
1390 return "ashl %2,%1,%0";
1391 }
1392 if ((unsigned HOST_WIDE_INT)i < 0x10000)
1393 return "movzwl %1,%0";
1394 if (i >= -0x8000 && i < 0)
1395 return "cvtwl %1,%0";
1396 }
1397 return push_p ? "pushl %1" : "movl %1,%0";
1398
1399 case E_HImode:
1400 if (CONST_INT_P (operands[1]))
1401 {
1402 HOST_WIDE_INT i = INTVAL (operands[1]);
1403 if (i == 0)
1404 return "clrw %0";
1405 else if ((unsigned HOST_WIDE_INT)i < 64)
1406 return "movw %1,%0";
1407 else if ((unsigned HOST_WIDE_INT)~i < 64)
1408 return "mcomw %H1,%0";
1409 else if ((unsigned HOST_WIDE_INT)i < 256)
1410 return "movzbw %1,%0";
1411 else if (i >= -0x80 && i < 0)
1412 return "cvtbw %1,%0";
1413 }
1414 return "movw %1,%0";
1415
1416 case E_QImode:
1417 if (CONST_INT_P (operands[1]))
1418 {
1419 HOST_WIDE_INT i = INTVAL (operands[1]);
1420 if (i == 0)
1421 return "clrb %0";
1422 else if ((unsigned HOST_WIDE_INT)~i < 64)
1423 return "mcomb %B1,%0";
1424 }
1425 return "movb %1,%0";
1426
1427 default:
1428 gcc_unreachable ();
1429 }
1430 }
1431
1432 /* Output integer add instructions.
1433
1434 The space-time-opcode tradeoffs for addition vary by model of VAX.
1435
1436 On a VAX 3 "movab (r1)[r2],r3" is faster than "addl3 r1,r2,r3",
1437 but it not faster on other models.
1438
1439 "movab #(r1),r2" is usually shorter than "addl3 #,r1,r2", and is
1440 faster on a VAX 3, but some VAXen (e.g. VAX 9000) will stall if
1441 a register is used in an address too soon after it is set.
1442 Compromise by using movab only when it is shorter than the add
1443 or the base register in the address is one of sp, ap, and fp,
1444 which are not modified very often. */
1445
1446 const char *
1447 vax_output_int_add (rtx_insn *insn, rtx *operands, machine_mode mode)
1448 {
1449 switch (mode)
1450 {
1451 case E_DImode:
1452 {
1453 rtx low[3];
1454 const char *pattern;
1455 int carry = 1;
1456 bool sub;
1457
1458 if (TARGET_QMATH && 0)
1459 debug_rtx (insn);
1460
1461 split_quadword_operands (insn, PLUS, operands, low, 3);
1462
1463 if (TARGET_QMATH)
1464 {
1465 gcc_assert (rtx_equal_p (operands[0], operands[1]));
1466 #ifdef NO_EXTERNAL_INDIRECT_ADDRESS
1467 gcc_assert (!flag_pic
1468 || !non_pic_external_memory_operand (low[2], SImode));
1469 gcc_assert (!flag_pic
1470 || !non_pic_external_memory_operand (low[0], SImode));
1471 #endif
1472
1473 /* No reason to add a 0 to the low part and thus no carry, so just
1474 emit the appropriate add/sub instruction. */
1475 if (low[2] == const0_rtx)
1476 return vax_output_int_add (NULL, operands, SImode);
1477
1478 /* Are we doing addition or subtraction? */
1479 sub = CONST_INT_P (operands[2]) && INTVAL (operands[2]) < 0;
1480
1481 /* We can't use vax_output_int_add since some the patterns don't
1482 modify the carry bit. */
1483 if (sub)
1484 {
1485 if (low[2] == constm1_rtx)
1486 pattern = "decl %0";
1487 else
1488 pattern = "subl2 $%n2,%0";
1489 }
1490 else
1491 {
1492 if (low[2] == const1_rtx)
1493 pattern = "incl %0";
1494 else
1495 pattern = "addl2 %2,%0";
1496 }
1497 output_asm_insn (pattern, low);
1498
1499 /* In 2's complement, -n = ~n + 1. Since we are dealing with
1500 two 32bit parts, we complement each and then add one to
1501 low part. We know that the low part can't overflow since
1502 it's value can never be 0. */
1503 if (sub)
1504 return "sbwc %N2,%0";
1505 return "adwc %2,%0";
1506 }
1507
1508 /* Add low parts. */
1509 if (rtx_equal_p (operands[0], operands[1]))
1510 {
1511 if (low[2] == const0_rtx)
1512 /* Should examine operand, punt if not POST_INC. */
1513 pattern = "tstl %0", carry = 0;
1514 else if (low[2] == const1_rtx)
1515 pattern = "incl %0";
1516 else
1517 pattern = "addl2 %2,%0";
1518 }
1519 else
1520 {
1521 if (low[2] == const0_rtx)
1522 pattern = "movl %1,%0", carry = 0;
1523 else
1524 pattern = "addl3 %2,%1,%0";
1525 }
1526 if (pattern)
1527 output_asm_insn (pattern, low);
1528 if (!carry)
1529 /* If CARRY is 0, we don't have any carry value to worry about. */
1530 return get_insn_template (CODE_FOR_addsi3, insn);
1531 /* %0 = C + %1 + %2 */
1532 if (!rtx_equal_p (operands[0], operands[1]))
1533 output_asm_insn ((operands[1] == const0_rtx
1534 ? "clrl %0"
1535 : "movl %1,%0"), operands);
1536 return "adwc %2,%0";
1537 }
1538
1539 case E_SImode:
1540 if (rtx_equal_p (operands[0], operands[1]))
1541 {
1542 if (operands[2] == const1_rtx)
1543 return "incl %0";
1544 if (operands[2] == constm1_rtx)
1545 return "decl %0";
1546 if (CONST_INT_P (operands[2])
1547 && (unsigned HOST_WIDE_INT) (- INTVAL (operands[2])) < 64)
1548 return "subl2 $%n2,%0";
1549 if (CONST_INT_P (operands[2])
1550 && (unsigned HOST_WIDE_INT) INTVAL (operands[2]) >= 64
1551 && REG_P (operands[1])
1552 && ((INTVAL (operands[2]) < 32767 && INTVAL (operands[2]) > -32768)
1553 || REGNO (operands[1]) > 11))
1554 return "movab %c2(%1),%0";
1555 if (REG_P (operands[0]) && symbolic_operand (operands[2], SImode))
1556 return "movab %a2[%0],%0";
1557 return "addl2 %2,%0";
1558 }
1559
1560 if (rtx_equal_p (operands[0], operands[2]))
1561 {
1562 if (REG_P (operands[0]) && symbolic_operand (operands[1], SImode))
1563 return "movab %a1[%0],%0";
1564 return "addl2 %1,%0";
1565 }
1566
1567 if (CONST_INT_P (operands[2])
1568 && INTVAL (operands[2]) < 32767
1569 && INTVAL (operands[2]) > -32768
1570 && REG_P (operands[1])
1571 && push_operand (operands[0], SImode))
1572 return "pushab %c2(%1)";
1573
1574 if (CONST_INT_P (operands[2])
1575 && (unsigned HOST_WIDE_INT) (- INTVAL (operands[2])) < 64)
1576 return "subl3 $%n2,%1,%0";
1577
1578 if (CONST_INT_P (operands[2])
1579 && (unsigned HOST_WIDE_INT) INTVAL (operands[2]) >= 64
1580 && REG_P (operands[1])
1581 && ((INTVAL (operands[2]) < 32767 && INTVAL (operands[2]) > -32768)
1582 || REGNO (operands[1]) > 11))
1583 return "movab %c2(%1),%0";
1584
1585 /* Add this if using gcc on a VAX 3xxx:
1586 if (REG_P (operands[1]) && REG_P (operands[2]))
1587 return "movab (%1)[%2],%0";
1588 */
1589
1590 if (REG_P (operands[1]) && symbolic_operand (operands[2], SImode))
1591 {
1592 if (push_operand (operands[0], SImode))
1593 return "pushab %a2[%1]";
1594 return "movab %a2[%1],%0";
1595 }
1596
1597 if (REG_P (operands[2]) && symbolic_operand (operands[1], SImode))
1598 {
1599 if (push_operand (operands[0], SImode))
1600 return "pushab %a1[%2]";
1601 return "movab %a1[%2],%0";
1602 }
1603
1604 if (flag_pic && REG_P (operands[0])
1605 && symbolic_operand (operands[2], SImode))
1606 return "movab %a2,%0;addl2 %1,%0";
1607
1608 if (flag_pic
1609 && (symbolic_operand (operands[1], SImode)
1610 || symbolic_operand (operands[2], SImode)))
1611 debug_rtx (insn);
1612
1613 return "addl3 %1,%2,%0";
1614
1615 case E_HImode:
1616 if (rtx_equal_p (operands[0], operands[1]))
1617 {
1618 if (operands[2] == const1_rtx)
1619 return "incw %0";
1620 if (operands[2] == constm1_rtx)
1621 return "decw %0";
1622 if (CONST_INT_P (operands[2])
1623 && (unsigned HOST_WIDE_INT) (- INTVAL (operands[2])) < 64)
1624 return "subw2 $%n2,%0";
1625 return "addw2 %2,%0";
1626 }
1627 if (rtx_equal_p (operands[0], operands[2]))
1628 return "addw2 %1,%0";
1629 if (CONST_INT_P (operands[2])
1630 && (unsigned HOST_WIDE_INT) (- INTVAL (operands[2])) < 64)
1631 return "subw3 $%n2,%1,%0";
1632 return "addw3 %1,%2,%0";
1633
1634 case E_QImode:
1635 if (rtx_equal_p (operands[0], operands[1]))
1636 {
1637 if (operands[2] == const1_rtx)
1638 return "incb %0";
1639 if (operands[2] == constm1_rtx)
1640 return "decb %0";
1641 if (CONST_INT_P (operands[2])
1642 && (unsigned HOST_WIDE_INT) (- INTVAL (operands[2])) < 64)
1643 return "subb2 $%n2,%0";
1644 return "addb2 %2,%0";
1645 }
1646 if (rtx_equal_p (operands[0], operands[2]))
1647 return "addb2 %1,%0";
1648 if (CONST_INT_P (operands[2])
1649 && (unsigned HOST_WIDE_INT) (- INTVAL (operands[2])) < 64)
1650 return "subb3 $%n2,%1,%0";
1651 return "addb3 %1,%2,%0";
1652
1653 default:
1654 gcc_unreachable ();
1655 }
1656 }
1657
1658 const char *
1659 vax_output_int_subtract (rtx_insn *insn, rtx *operands, machine_mode mode)
1660 {
1661 switch (mode)
1662 {
1663 case E_DImode:
1664 {
1665 rtx low[3];
1666 const char *pattern;
1667 int carry = 1;
1668
1669 if (TARGET_QMATH && 0)
1670 debug_rtx (insn);
1671
1672 split_quadword_operands (insn, MINUS, operands, low, 3);
1673
1674 if (TARGET_QMATH)
1675 {
1676 if (operands[1] == const0_rtx && low[1] == const0_rtx)
1677 {
1678 /* Negation is tricky. It's basically complement and increment.
1679 Negate hi, then lo, and subtract the carry back. */
1680 if ((MEM_P (low[0]) && GET_CODE (XEXP (low[0], 0)) == POST_INC)
1681 || (MEM_P (operands[0])
1682 && GET_CODE (XEXP (operands[0], 0)) == POST_INC))
1683 fatal_insn ("illegal operand detected", insn);
1684 output_asm_insn ("mnegl %2,%0", operands);
1685 output_asm_insn ("mnegl %2,%0", low);
1686 return "sbwc $0,%0";
1687 }
1688 gcc_assert (rtx_equal_p (operands[0], operands[1]));
1689 gcc_assert (rtx_equal_p (low[0], low[1]));
1690 if (low[2] == const1_rtx)
1691 output_asm_insn ("decl %0", low);
1692 else
1693 output_asm_insn ("subl2 %2,%0", low);
1694 return "sbwc %2,%0";
1695 }
1696
1697 /* Subtract low parts. */
1698 if (rtx_equal_p (operands[0], operands[1]))
1699 {
1700 if (low[2] == const0_rtx)
1701 pattern = 0, carry = 0;
1702 else if (low[2] == constm1_rtx)
1703 pattern = "decl %0";
1704 else
1705 pattern = "subl2 %2,%0";
1706 }
1707 else
1708 {
1709 if (low[2] == constm1_rtx)
1710 pattern = "decl %0";
1711 else if (low[2] == const0_rtx)
1712 pattern = get_insn_template (CODE_FOR_movsi, insn), carry = 0;
1713 else
1714 pattern = "subl3 %2,%1,%0";
1715 }
1716 if (pattern)
1717 output_asm_insn (pattern, low);
1718 if (carry)
1719 {
1720 if (!rtx_equal_p (operands[0], operands[1]))
1721 return "movl %1,%0;sbwc %2,%0";
1722 return "sbwc %2,%0";
1723 /* %0 = %2 - %1 - C */
1724 }
1725 return get_insn_template (CODE_FOR_subsi3, insn);
1726 }
1727
1728 default:
1729 gcc_unreachable ();
1730 }
1731 }
1732
1733 /* True if X is an rtx for a constant that is a valid address. */
1734
1735 bool
1736 legitimate_constant_address_p (rtx x)
1737 {
1738 if (GET_CODE (x) == LABEL_REF || GET_CODE (x) == SYMBOL_REF
1739 || CONST_INT_P (x) || GET_CODE (x) == HIGH)
1740 return true;
1741 if (GET_CODE (x) != CONST)
1742 return false;
1743 #ifdef NO_EXTERNAL_INDIRECT_ADDRESS
1744 if (flag_pic
1745 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1746 && !SYMBOL_REF_LOCAL_P (XEXP (XEXP (x, 0), 0)))
1747 return false;
1748 #endif
1749 return true;
1750 }
1751
1752 /* The other macros defined here are used only in legitimate_address_p (). */
1753
1754 /* Nonzero if X is a hard reg that can be used as an index
1755 or, if not strict, if it is a pseudo reg. */
1756 #define INDEX_REGISTER_P(X, STRICT) \
1757 (REG_P (X) && (!(STRICT) || REGNO_OK_FOR_INDEX_P (REGNO (X))))
1758
1759 /* Nonzero if X is a hard reg that can be used as a base reg
1760 or, if not strict, if it is a pseudo reg. */
1761 #define BASE_REGISTER_P(X, STRICT) \
1762 (REG_P (X) && (!(STRICT) || REGNO_OK_FOR_BASE_P (REGNO (X))))
1763
1764 #ifdef NO_EXTERNAL_INDIRECT_ADDRESS
1765
1766 /* Re-definition of CONSTANT_ADDRESS_P, which is true only when there
1767 are no SYMBOL_REFs for external symbols present. */
1768
1769 static bool
1770 indirectable_constant_address_p (rtx x, bool indirect)
1771 {
1772 if (GET_CODE (x) == SYMBOL_REF)
1773 return !flag_pic || SYMBOL_REF_LOCAL_P (x) || !indirect;
1774
1775 if (GET_CODE (x) == CONST)
1776 return !flag_pic
1777 || GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
1778 || SYMBOL_REF_LOCAL_P (XEXP (XEXP (x, 0), 0));
1779
1780 return CONSTANT_ADDRESS_P (x);
1781 }
1782
1783 #else /* not NO_EXTERNAL_INDIRECT_ADDRESS */
1784
1785 static bool
1786 indirectable_constant_address_p (rtx x, bool indirect ATTRIBUTE_UNUSED)
1787 {
1788 return CONSTANT_ADDRESS_P (x);
1789 }
1790
1791 #endif /* not NO_EXTERNAL_INDIRECT_ADDRESS */
1792
1793 /* True if X is an address which can be indirected. External symbols
1794 could be in a sharable image library, so we disallow those. */
1795
1796 static bool
1797 indirectable_address_p (rtx x, bool strict, bool indirect)
1798 {
1799 if (indirectable_constant_address_p (x, indirect)
1800 || BASE_REGISTER_P (x, strict))
1801 return true;
1802 if (GET_CODE (x) != PLUS
1803 || !BASE_REGISTER_P (XEXP (x, 0), strict)
1804 || (flag_pic && !CONST_INT_P (XEXP (x, 1))))
1805 return false;
1806 return indirectable_constant_address_p (XEXP (x, 1), indirect);
1807 }
1808
1809 /* Return true if x is a valid address not using indexing.
1810 (This much is the easy part.) */
1811 static bool
1812 nonindexed_address_p (rtx x, bool strict)
1813 {
1814 rtx xfoo0;
1815 if (REG_P (x))
1816 {
1817 if (! reload_in_progress
1818 || reg_equiv_mem (REGNO (x)) == 0
1819 || indirectable_address_p (reg_equiv_mem (REGNO (x)), strict, false))
1820 return true;
1821 }
1822 if (indirectable_constant_address_p (x, false))
1823 return true;
1824 if (indirectable_address_p (x, strict, false))
1825 return true;
1826 xfoo0 = XEXP (x, 0);
1827 if (MEM_P (x) && indirectable_address_p (xfoo0, strict, true))
1828 return true;
1829 if ((GET_CODE (x) == PRE_DEC || GET_CODE (x) == POST_INC)
1830 && BASE_REGISTER_P (xfoo0, strict))
1831 return true;
1832 return false;
1833 }
1834
1835 /* True if PROD is either a reg times size of mode MODE and MODE is less
1836 than or equal 8 bytes, or just a reg if MODE is one byte. For a MULT
1837 RTX we accept its operands in either order, however ASHIFT is not
1838 commutative, so in that case reg has to be the left operand. */
1839
1840 static bool
1841 index_term_p (rtx prod, machine_mode mode, bool strict)
1842 {
1843 rtx xfoo0, xfoo1;
1844 bool log_p;
1845
1846 if (GET_MODE_SIZE (mode) == 1)
1847 return BASE_REGISTER_P (prod, strict);
1848
1849 if ((GET_CODE (prod) != MULT && GET_CODE (prod) != ASHIFT)
1850 || GET_MODE_SIZE (mode) > 8)
1851 return false;
1852
1853 log_p = GET_CODE (prod) == ASHIFT;
1854 xfoo0 = XEXP (prod, 0);
1855 xfoo1 = XEXP (prod, 1);
1856
1857 if (!log_p
1858 && CONST_INT_P (xfoo0)
1859 && GET_MODE_SIZE (mode) == INTVAL (xfoo0)
1860 && INDEX_REGISTER_P (xfoo1, strict))
1861 return true;
1862
1863 if (CONST_INT_P (xfoo1)
1864 && GET_MODE_SIZE (mode) == (log_p ? 1 << INTVAL (xfoo1) : INTVAL (xfoo1))
1865 && INDEX_REGISTER_P (xfoo0, strict))
1866 return true;
1867
1868 return false;
1869 }
1870
1871 /* Return true if X is the sum of a register
1872 and a valid index term for mode MODE. */
1873 static bool
1874 reg_plus_index_p (rtx x, machine_mode mode, bool strict)
1875 {
1876 rtx xfoo0, xfoo1;
1877
1878 if (GET_CODE (x) != PLUS)
1879 return false;
1880
1881 xfoo0 = XEXP (x, 0);
1882 xfoo1 = XEXP (x, 1);
1883
1884 if (BASE_REGISTER_P (xfoo0, strict) && index_term_p (xfoo1, mode, strict))
1885 return true;
1886
1887 if (BASE_REGISTER_P (xfoo1, strict) && index_term_p (xfoo0, mode, strict))
1888 return true;
1889
1890 return false;
1891 }
1892
1893 /* Return true if xfoo0 and xfoo1 constitute a valid indexed address. */
1894 static bool
1895 indexable_address_p (rtx xfoo0, rtx xfoo1, machine_mode mode, bool strict)
1896 {
1897 if (!CONSTANT_ADDRESS_P (xfoo0))
1898 return false;
1899 if (BASE_REGISTER_P (xfoo1, strict))
1900 return !flag_pic || mode == QImode;
1901 if (flag_pic && symbolic_operand (xfoo0, SImode))
1902 return false;
1903 return reg_plus_index_p (xfoo1, mode, strict);
1904 }
1905
1906 /* legitimate_address_p returns true if it recognizes an RTL expression "x"
1907 that is a valid memory address for an instruction.
1908 The MODE argument is the machine mode for the MEM expression
1909 that wants to use this address. */
1910 bool
1911 vax_legitimate_address_p (machine_mode mode, rtx x, bool strict, code_helper)
1912 {
1913 rtx xfoo0, xfoo1;
1914
1915 if (nonindexed_address_p (x, strict))
1916 return true;
1917
1918 if (GET_CODE (x) != PLUS)
1919 return false;
1920
1921 /* Handle <address>[index] represented with index-sum outermost */
1922
1923 xfoo0 = XEXP (x, 0);
1924 xfoo1 = XEXP (x, 1);
1925
1926 if (index_term_p (xfoo0, mode, strict)
1927 && nonindexed_address_p (xfoo1, strict))
1928 return true;
1929
1930 if (index_term_p (xfoo1, mode, strict)
1931 && nonindexed_address_p (xfoo0, strict))
1932 return true;
1933
1934 /* Handle offset(reg)[index] with offset added outermost */
1935
1936 if (indexable_address_p (xfoo0, xfoo1, mode, strict)
1937 || indexable_address_p (xfoo1, xfoo0, mode, strict))
1938 return true;
1939
1940 return false;
1941 }
1942
1943 /* Return true if x (a legitimate address expression) has an effect that
1944 depends on the machine mode it is used for. On the VAX, the predecrement
1945 and postincrement address depend thus (the amount of decrement or
1946 increment being the length of the operand) and all indexed address depend
1947 thus (because the index scale factor is the length of the operand). */
1948
1949 static bool
1950 vax_mode_dependent_address_p (const_rtx x, addr_space_t as ATTRIBUTE_UNUSED)
1951 {
1952 rtx xfoo0, xfoo1;
1953
1954 /* Auto-increment cases are now dealt with generically in recog.cc. */
1955 if (GET_CODE (x) != PLUS)
1956 return false;
1957
1958 xfoo0 = XEXP (x, 0);
1959 xfoo1 = XEXP (x, 1);
1960
1961 if (CONST_INT_P (xfoo0) && REG_P (xfoo1))
1962 return false;
1963 if (CONST_INT_P (xfoo1) && REG_P (xfoo0))
1964 return false;
1965 if (!flag_pic && CONSTANT_ADDRESS_P (xfoo0) && REG_P (xfoo1))
1966 return false;
1967 if (!flag_pic && CONSTANT_ADDRESS_P (xfoo1) && REG_P (xfoo0))
1968 return false;
1969
1970 return true;
1971 }
1972
1973 static rtx
1974 fixup_mathdi_operand (rtx x, machine_mode mode)
1975 {
1976 if (illegal_addsub_di_memory_operand (x, mode))
1977 {
1978 rtx addr = XEXP (x, 0);
1979 rtx temp = gen_reg_rtx (Pmode);
1980 rtx offset = 0;
1981 #ifdef NO_EXTERNAL_INDIRECT_ADDRESS
1982 if (GET_CODE (addr) == CONST && flag_pic)
1983 {
1984 offset = XEXP (XEXP (addr, 0), 1);
1985 addr = XEXP (XEXP (addr, 0), 0);
1986 }
1987 #endif
1988 emit_move_insn (temp, addr);
1989 if (offset)
1990 temp = gen_rtx_PLUS (Pmode, temp, offset);
1991 x = gen_rtx_MEM (DImode, temp);
1992 }
1993 return x;
1994 }
1995
1996 void
1997 vax_expand_addsub_di_operands (rtx * operands, enum rtx_code code)
1998 {
1999 int hi_only = operand_subword (operands[2], 0, 0, DImode) == const0_rtx;
2000 rtx temp;
2001
2002 rtx (*gen_old_insn)(rtx, rtx, rtx);
2003 rtx (*gen_si_insn)(rtx, rtx, rtx);
2004 rtx (*gen_insn)(rtx, rtx, rtx);
2005
2006 if (code == PLUS)
2007 {
2008 gen_old_insn = gen_adddi3_old;
2009 gen_si_insn = gen_addsi3;
2010 gen_insn = gen_adcdi3;
2011 }
2012 else if (code == MINUS)
2013 {
2014 gen_old_insn = gen_subdi3_old;
2015 gen_si_insn = gen_subsi3;
2016 gen_insn = gen_sbcdi3;
2017 }
2018 else
2019 gcc_unreachable ();
2020
2021 /* If this is addition (thus operands are commutative) and if there is one
2022 addend that duplicates the desination, we want that addend to be the
2023 first addend. */
2024 if (code == PLUS
2025 && rtx_equal_p (operands[0], operands[2])
2026 && !rtx_equal_p (operands[1], operands[2]))
2027 {
2028 temp = operands[2];
2029 operands[2] = operands[1];
2030 operands[1] = temp;
2031 }
2032
2033 if (!TARGET_QMATH)
2034 {
2035 emit_insn ((*gen_old_insn) (operands[0], operands[1], operands[2]));
2036 }
2037 else if (hi_only)
2038 {
2039 if (!rtx_equal_p (operands[0], operands[1])
2040 && (REG_P (operands[0]) && MEM_P (operands[1])))
2041 {
2042 emit_move_insn (operands[0], operands[1]);
2043 operands[1] = operands[0];
2044 }
2045
2046 operands[0] = fixup_mathdi_operand (operands[0], DImode);
2047 operands[1] = fixup_mathdi_operand (operands[1], DImode);
2048 operands[2] = fixup_mathdi_operand (operands[2], DImode);
2049
2050 if (!rtx_equal_p (operands[0], operands[1]))
2051 emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
2052 operand_subword (operands[1], 0, 0, DImode));
2053
2054 emit_insn ((*gen_si_insn) (operand_subword (operands[0], 1, 0, DImode),
2055 operand_subword (operands[1], 1, 0, DImode),
2056 operand_subword (operands[2], 1, 0, DImode)));
2057 }
2058 else
2059 {
2060 /* If we are adding a value to itself, that's really a multiply by 2,
2061 and that's just a left shift by 1. If subtracting, it's just 0. */
2062 if (rtx_equal_p (operands[1], operands[2]))
2063 {
2064 if (code == PLUS)
2065 emit_insn (gen_ashldi3 (operands[0], operands[1], const1_rtx));
2066 else
2067 emit_move_insn (operands[0], const0_rtx);
2068 return;
2069 }
2070
2071 operands[0] = fixup_mathdi_operand (operands[0], DImode);
2072
2073 /* If an operand is the same as operand[0], use the operand[0] rtx
2074 because fixup will an equivalent rtx but not an equal one. */
2075
2076 if (rtx_equal_p (operands[0], operands[1]))
2077 operands[1] = operands[0];
2078 else
2079 operands[1] = fixup_mathdi_operand (operands[1], DImode);
2080
2081 if (rtx_equal_p (operands[0], operands[2]))
2082 operands[2] = operands[0];
2083 else
2084 operands[2] = fixup_mathdi_operand (operands[2], DImode);
2085
2086 /* If we are adding or subtracting 0, then this is a move. */
2087 if (code == PLUS && operands[1] == const0_rtx)
2088 {
2089 temp = operands[2];
2090 operands[2] = operands[1];
2091 operands[1] = temp;
2092 }
2093 if (operands[2] == const0_rtx)
2094 {
2095 emit_move_insn (operands[0], operands[1]);
2096 return;
2097 }
2098
2099 /* If we are subtracting not from ourselves [d = a - b], and because the
2100 carry ops are two operand only, we would need to do a move prior to
2101 the subtract. And if d == b, we would need a temp otherwise
2102 [d = a, d -= d] and we end up with 0. Instead we rewrite d = a - b
2103 into d = -b, d += a. Since -b can never overflow, even if b == d,
2104 no temp is needed.
2105
2106 If we are doing addition, since the carry ops are two operand, if
2107 we aren't adding to ourselves, move the first addend to the
2108 destination first. */
2109
2110 gcc_assert (operands[1] != const0_rtx || code == MINUS);
2111 if (!rtx_equal_p (operands[0], operands[1]) && operands[1] != const0_rtx)
2112 {
2113 if (code == MINUS && CONSTANT_P (operands[1]))
2114 {
2115 emit_insn (gen_sbcdi3 (operands[0], const0_rtx, operands[2]));
2116 code = PLUS;
2117 gen_insn = gen_adcdi3;
2118 operands[2] = operands[1];
2119 operands[1] = operands[0];
2120 }
2121 else
2122 emit_move_insn (operands[0], operands[1]);
2123 }
2124
2125 /* Subtracting a constant will have been rewritten to an addition of the
2126 negative of that constant before we get here. */
2127 gcc_assert (!CONSTANT_P (operands[2]) || code == PLUS);
2128 emit_insn ((*gen_insn) (operands[0], operands[1], operands[2]));
2129 }
2130 }
2131
2132 /* Output assembler code for a block containing the constant parts
2133 of a trampoline, leaving space for the variable parts. */
2134
2135 /* On the VAX, the trampoline contains an entry mask and two instructions:
2136 .word NN
2137 movl $STATIC,r0 (store the functions static chain)
2138 jmp *$FUNCTION (jump to function code at address FUNCTION) */
2139
2140 static void
2141 vax_asm_trampoline_template (FILE *f ATTRIBUTE_UNUSED)
2142 {
2143 assemble_aligned_integer (2, const0_rtx);
2144 assemble_aligned_integer (2, GEN_INT (0x8fd0));
2145 assemble_aligned_integer (4, const0_rtx);
2146 assemble_aligned_integer (1, GEN_INT (0x50 + STATIC_CHAIN_REGNUM));
2147 assemble_aligned_integer (2, GEN_INT (0x9f17));
2148 assemble_aligned_integer (4, const0_rtx);
2149 }
2150
2151 /* We copy the register-mask from the function's pure code
2152 to the start of the trampoline. */
2153
2154 static void
2155 vax_trampoline_init (rtx m_tramp, tree fndecl, rtx cxt)
2156 {
2157 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
2158 rtx mem;
2159
2160 emit_block_move (m_tramp, assemble_trampoline_template (),
2161 GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
2162
2163 mem = adjust_address (m_tramp, HImode, 0);
2164 emit_move_insn (mem, gen_const_mem (HImode, fnaddr));
2165
2166 mem = adjust_address (m_tramp, SImode, 4);
2167 emit_move_insn (mem, cxt);
2168 mem = adjust_address (m_tramp, SImode, 11);
2169 emit_move_insn (mem, plus_constant (Pmode, fnaddr, 2));
2170 emit_insn (gen_sync_istream ());
2171 }
2172
2173 /* Value is the number of bytes of arguments automatically
2174 popped when returning from a subroutine call.
2175 FUNDECL is the declaration node of the function (as a tree),
2176 FUNTYPE is the data type of the function (as a tree),
2177 or for a library call it is an identifier node for the subroutine name.
2178 SIZE is the number of bytes of arguments passed on the stack.
2179
2180 On the VAX, the RET insn pops a maximum of 255 args for any function. */
2181
2182 static poly_int64
2183 vax_return_pops_args (tree fundecl ATTRIBUTE_UNUSED,
2184 tree funtype ATTRIBUTE_UNUSED, poly_int64 size)
2185 {
2186 return size > 255 * 4 ? 0 : (HOST_WIDE_INT) size;
2187 }
2188
2189 /* Implement TARGET_FUNCTION_ARG. On the VAX all args are pushed. */
2190
2191 static rtx
2192 vax_function_arg (cumulative_args_t, const function_arg_info &)
2193 {
2194 return NULL_RTX;
2195 }
2196
2197 /* Update the data in CUM to advance over argument ARG. */
2198
2199 static void
2200 vax_function_arg_advance (cumulative_args_t cum_v,
2201 const function_arg_info &arg)
2202 {
2203 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
2204
2205 *cum += (arg.promoted_size_in_bytes () + 3) & ~3;
2206 }
2207
2208 static HOST_WIDE_INT
2209 vax_starting_frame_offset (void)
2210 {
2211 /* On ELF targets, reserve the top of the stack for exception handler
2212 stackadj value. */
2213 return TARGET_ELF ? -4 : 0;
2214 }
2215