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