(i960_output_ldconst): New code for XFmode.
[gcc.git] / gcc / config / i960 / i960.c
1 /* Subroutines used for code generation on intel 80960.
2 Copyright (C) 1992, 1995 Free Software Foundation, Inc.
3 Contributed by Steven McGeady, Intel Corp.
4 Additional Work by Glenn Colon-Bonet, Jonathan Shapiro, Andy Wilson
5 Converted to GCC 2.0 by Jim Wilson and Michael Tiemann, Cygnus Support.
6
7 This file is part of GNU CC.
8
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22
23 #include <stdio.h>
24
25 #include "config.h"
26 #include "rtl.h"
27 #include "regs.h"
28 #include "hard-reg-set.h"
29 #include "real.h"
30 #include "insn-config.h"
31 #include "conditions.h"
32 #include "insn-flags.h"
33 #include "output.h"
34 #include "insn-attr.h"
35 #include "flags.h"
36 #include "tree.h"
37 #include "insn-codes.h"
38 #include "assert.h"
39 #include "expr.h"
40 #include "function.h"
41 #include "recog.h"
42 #include <math.h>
43
44 /* Save the operands last given to a compare for use when we
45 generate a scc or bcc insn. */
46
47 rtx i960_compare_op0, i960_compare_op1;
48
49 /* Used to implement #pragma align/noalign. Initialized by OVERRIDE_OPTIONS
50 macro in i960.h. */
51
52 static int i960_maxbitalignment;
53 static int i960_last_maxbitalignment;
54
55 /* Used to implement switching between MEM and ALU insn types, for better
56 C series performance. */
57
58 enum insn_types i960_last_insn_type;
59
60 /* The leaf-procedure return register. Set only if this is a leaf routine. */
61
62 static int i960_leaf_ret_reg;
63
64 /* True if replacing tail calls with jumps is OK. */
65
66 static int tail_call_ok;
67
68 /* A string containing a list of insns to emit in the epilogue so as to
69 restore all registers saved by the prologue. Created by the prologue
70 code as it saves registers away. */
71
72 char epilogue_string[1000];
73
74 /* A unique number (per function) for return labels. */
75
76 static int ret_label = 0;
77
78 /* This is true if FNDECL is either a varargs or a stdarg function.
79 This is used to help identify functions that use an argument block. */
80
81 #define VARARGS_STDARG_FUNCTION(FNDECL) \
82 ((TYPE_ARG_TYPES (TREE_TYPE (FNDECL)) != 0 \
83 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (FNDECL)))) != void_type_node)) \
84 || current_function_varargs)
85
86 /* Handle pragmas for compatibility with Intel's compilers. */
87
88 /* ??? This is incomplete, since it does not handle all pragmas that the
89 intel compilers understand. */
90
91 void
92 process_pragma (finput)
93 FILE *finput;
94 {
95 int c;
96 int i;
97
98 c = getc (finput);
99 while (c == ' ' || c == '\t')
100 c = getc (finput);
101
102 if (c == 'a'
103 && getc (finput) == 'l'
104 && getc (finput) == 'i'
105 && getc (finput) == 'g'
106 && getc (finput) == 'n'
107 && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
108 {
109 char buf[20];
110 char *s = buf;
111 int align;
112
113 while (c == ' ' || c == '\t')
114 c = getc (finput);
115 if (c == '(')
116 c = getc (finput);
117 while (c >= '0' && c <= '9')
118 {
119 if (s < buf + sizeof buf - 1)
120 *s++ = c;
121 c = getc (finput);
122 }
123 *s = '\0';
124
125 align = atoi (buf);
126 switch (align)
127 {
128 case 0:
129 /* Return to last alignment. */
130 align = i960_last_maxbitalignment / 8;
131 /* Fall through. */
132 case 16:
133 case 8:
134 case 4:
135 case 2:
136 case 1:
137 i960_last_maxbitalignment = i960_maxbitalignment;
138 i960_maxbitalignment = align * 8;
139 break;
140
141 default:
142 /* Silently ignore bad values. */
143 break;
144 }
145
146 /* NOTE: ic960 R3.0 pragma align definition:
147
148 #pragma align [(size)] | (identifier=size[,...])
149 #pragma noalign [(identifier)[,...]]
150
151 (all parens are optional)
152
153 - size is [1,2,4,8,16]
154 - noalign means size==1
155 - applies only to component elements of a struct (and union?)
156 - identifier applies to structure tag (only)
157 - missing identifier means next struct
158
159 - alignment rules for bitfields need more investigation */
160 }
161
162 /* Should be pragma 'far' or equivalent for callx/balx here. */
163
164 ungetc (c, finput);
165 }
166
167 /* Initialize variables before compiling any files. */
168
169 void
170 i960_initialize ()
171 {
172 if (TARGET_IC_COMPAT2_0)
173 {
174 i960_maxbitalignment = 8;
175 i960_last_maxbitalignment = 128;
176 }
177 else
178 {
179 i960_maxbitalignment = 128;
180 i960_last_maxbitalignment = 8;
181 }
182 }
183 \f
184 /* Return true if OP can be used as the source of an fp move insn. */
185
186 int
187 fpmove_src_operand (op, mode)
188 rtx op;
189 enum machine_mode mode;
190 {
191 return (GET_CODE (op) == CONST_DOUBLE || general_operand (op, mode));
192 }
193
194 #if 0
195 /* Return true if OP is a register or zero. */
196
197 int
198 reg_or_zero_operand (op, mode)
199 rtx op;
200 enum machine_mode mode;
201 {
202 return register_operand (op, mode) || op == const0_rtx;
203 }
204 #endif
205
206 /* Return truth value of whether OP can be used as an operands in a three
207 address arithmetic insn (such as add %o1,7,%l2) of mode MODE. */
208
209 int
210 arith_operand (op, mode)
211 rtx op;
212 enum machine_mode mode;
213 {
214 return (register_operand (op, mode) || literal (op, mode));
215 }
216
217 /* Return true if OP is a register or a valid floating point literal. */
218
219 int
220 fp_arith_operand (op, mode)
221 rtx op;
222 enum machine_mode mode;
223 {
224 return (register_operand (op, mode) || fp_literal (op, mode));
225 }
226
227 /* Return true is OP is a register or a valid signed integer literal. */
228
229 int
230 signed_arith_operand (op, mode)
231 rtx op;
232 enum machine_mode mode;
233 {
234 return (register_operand (op, mode) || signed_literal (op, mode));
235 }
236
237 /* Return truth value of whether OP is a integer which fits the
238 range constraining immediate operands in three-address insns. */
239
240 int
241 literal (op, mode)
242 rtx op;
243 enum machine_mode mode;
244 {
245 return ((GET_CODE (op) == CONST_INT) && INTVAL(op) >= 0 && INTVAL(op) < 32);
246 }
247
248 /* Return true if OP is a float constant of 1. */
249
250 int
251 fp_literal_one (op, mode)
252 rtx op;
253 enum machine_mode mode;
254 {
255 return (TARGET_NUMERICS && mode == GET_MODE (op) && op == CONST1_RTX (mode));
256 }
257
258 /* Return true if OP is a float constant of 0. */
259
260 int
261 fp_literal_zero (op, mode)
262 rtx op;
263 enum machine_mode mode;
264 {
265 return (TARGET_NUMERICS && mode == GET_MODE (op) && op == CONST0_RTX (mode));
266 }
267
268 /* Return true if OP is a valid floating point literal. */
269
270 int
271 fp_literal(op, mode)
272 rtx op;
273 enum machine_mode mode;
274 {
275 return fp_literal_zero (op, mode) || fp_literal_one (op, mode);
276 }
277
278 /* Return true if OP is a valid signed immediate constant. */
279
280 int
281 signed_literal(op, mode)
282 rtx op;
283 enum machine_mode mode;
284 {
285 return ((GET_CODE (op) == CONST_INT) && INTVAL(op) > -32 && INTVAL(op) < 32);
286 }
287
288 /* Return truth value of statement that OP is a symbolic memory
289 operand of mode MODE. */
290
291 int
292 symbolic_memory_operand (op, mode)
293 rtx op;
294 enum machine_mode mode;
295 {
296 if (GET_CODE (op) == SUBREG)
297 op = SUBREG_REG (op);
298 if (GET_CODE (op) != MEM)
299 return 0;
300 op = XEXP (op, 0);
301 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
302 || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
303 }
304
305 /* Return truth value of whether OP is EQ or NE. */
306
307 int
308 eq_or_neq (op, mode)
309 rtx op;
310 enum machine_mode mode;
311 {
312 return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
313 }
314
315 /* OP is an integer register or a constant. */
316
317 int
318 arith32_operand (op, mode)
319 rtx op;
320 enum machine_mode mode;
321 {
322 if (register_operand (op, mode))
323 return 1;
324 return (CONSTANT_P (op));
325 }
326
327 /* Return true if OP is an integer constant which is a power of 2. */
328
329 int
330 power2_operand (op,mode)
331 rtx op;
332 enum machine_mode mode;
333 {
334 if (GET_CODE (op) != CONST_INT)
335 return 0;
336
337 return exact_log2 (INTVAL (op)) >= 0;
338 }
339
340 /* Return true if OP is an integer constant which is the complement of a
341 power of 2. */
342
343 int
344 cmplpower2_operand (op, mode)
345 rtx op;
346 enum machine_mode mode;
347 {
348 if (GET_CODE (op) != CONST_INT)
349 return 0;
350
351 return exact_log2 (~ INTVAL (op)) >= 0;
352 }
353
354 /* If VAL has only one bit set, return the index of that bit. Otherwise
355 return -1. */
356
357 int
358 bitpos (val)
359 unsigned int val;
360 {
361 register int i;
362
363 for (i = 0; val != 0; i++, val >>= 1)
364 {
365 if (val & 1)
366 {
367 if (val != 1)
368 return -1;
369 return i;
370 }
371 }
372 return -1;
373 }
374
375 /* Return non-zero if OP is a mask, i.e. all one bits are consecutive.
376 The return value indicates how many consecutive non-zero bits exist
377 if this is a mask. This is the same as the next function, except that
378 it does not indicate what the start and stop bit positions are. */
379
380 int
381 is_mask (val)
382 unsigned int val;
383 {
384 register int start, end, i;
385
386 start = -1;
387 for (i = 0; val != 0; val >>= 1, i++)
388 {
389 if (val & 1)
390 {
391 if (start < 0)
392 start = i;
393
394 end = i;
395 continue;
396 }
397 /* Still looking for the first bit. */
398 if (start < 0)
399 continue;
400
401 /* We've seen the start of a bit sequence, and now a zero. There
402 must be more one bits, otherwise we would have exited the loop.
403 Therefore, it is not a mask. */
404 if (val)
405 return 0;
406 }
407
408 /* The bit string has ones from START to END bit positions only. */
409 return end - start + 1;
410 }
411
412 /* If VAL is a mask, then return nonzero, with S set to the starting bit
413 position and E set to the ending bit position of the mask. The return
414 value indicates how many consecutive bits exist in the mask. This is
415 the same as the previous function, except that it also indicates the
416 start and end bit positions of the mask. */
417
418 int
419 bitstr (val, s, e)
420 unsigned int val;
421 int *s, *e;
422 {
423 register int start, end, i;
424
425 start = -1;
426 end = -1;
427 for (i = 0; val != 0; val >>= 1, i++)
428 {
429 if (val & 1)
430 {
431 if (start < 0)
432 start = i;
433
434 end = i;
435 continue;
436 }
437
438 /* Still looking for the first bit. */
439 if (start < 0)
440 continue;
441
442 /* We've seen the start of a bit sequence, and now a zero. There
443 must be more one bits, otherwise we would have exited the loop.
444 Therefor, it is not a mask. */
445 if (val)
446 {
447 start = -1;
448 end = -1;
449 break;
450 }
451 }
452
453 /* The bit string has ones from START to END bit positions only. */
454 *s = start;
455 *e = end;
456 return ((start < 0) ? 0 : end - start + 1);
457 }
458 \f
459 /* Return the machine mode to use for a comparison. */
460
461 enum machine_mode
462 select_cc_mode (op, x)
463 RTX_CODE op;
464 rtx x;
465 {
466 if (op == GTU || op == LTU || op == GEU || op == LEU)
467 return CC_UNSmode;
468 return CCmode;
469 }
470
471 /* X and Y are two things to compare using CODE. Emit the compare insn and
472 return the rtx for register 36 in the proper mode. */
473
474 rtx
475 gen_compare_reg (code, x, y)
476 enum rtx_code code;
477 rtx x, y;
478 {
479 rtx cc_reg;
480 enum machine_mode ccmode = SELECT_CC_MODE (code, x, y);
481 enum machine_mode mode
482 = GET_MODE (x) == VOIDmode ? GET_MODE (y) : GET_MODE (x);
483
484 if (mode == SImode)
485 {
486 if (! arith_operand (x, mode))
487 x = force_reg (SImode, x);
488 if (! arith_operand (y, mode))
489 y = force_reg (SImode, y);
490 }
491
492 cc_reg = gen_rtx (REG, ccmode, 36);
493 emit_insn (gen_rtx (SET, VOIDmode, cc_reg,
494 gen_rtx (COMPARE, ccmode, x, y)));
495
496 return cc_reg;
497 }
498
499 /* For the i960, REG is cost 1, REG+immed CONST is cost 2, REG+REG is cost 2,
500 REG+nonimmed CONST is cost 4. REG+SYMBOL_REF, SYMBOL_REF, and similar
501 are 4. Indexed addresses are cost 6. */
502
503 /* ??? Try using just RTX_COST, i.e. not defining ADDRESS_COST. */
504
505 int
506 i960_address_cost (x)
507 rtx x;
508 {
509 #if 0
510 /* Handled before calling here. */
511 if (GET_CODE (x) == REG)
512 return 1;
513 #endif
514 if (GET_CODE (x) == PLUS)
515 {
516 rtx base = XEXP (x, 0);
517 rtx offset = XEXP (x, 1);
518
519 if (GET_CODE (base) == SUBREG)
520 base = SUBREG_REG (base);
521 if (GET_CODE (offset) == SUBREG)
522 offset = SUBREG_REG (offset);
523
524 if (GET_CODE (base) == REG)
525 {
526 if (GET_CODE (offset) == REG)
527 return 2;
528 if (GET_CODE (offset) == CONST_INT)
529 {
530 if ((unsigned)INTVAL (offset) < 2047)
531 return 2;
532 return 4;
533 }
534 if (CONSTANT_P (offset))
535 return 4;
536 }
537 if (GET_CODE (base) == PLUS || GET_CODE (base) == MULT)
538 return 6;
539
540 /* This is an invalid address. The return value doesn't matter, but
541 for convenience we make this more expensive than anything else. */
542 return 12;
543 }
544 if (GET_CODE (x) == MULT)
545 return 6;
546
547 /* Symbol_refs and other unrecognized addresses are cost 4. */
548 return 4;
549 }
550 \f
551 /* Emit insns to move operands[1] into operands[0].
552
553 Return 1 if we have written out everything that needs to be done to
554 do the move. Otherwise, return 0 and the caller will emit the move
555 normally. */
556
557 int
558 emit_move_sequence (operands, mode)
559 rtx *operands;
560 enum machine_mode mode;
561 {
562 register rtx operand0 = operands[0];
563 register rtx operand1 = operands[1];
564
565 /* We can only store registers to memory. */
566
567 if (GET_CODE (operand0) == MEM && GET_CODE (operand1) != REG)
568 operands[1] = force_reg (mode, operand1);
569
570 return 0;
571 }
572 \f
573 /* Emit insns to load a constant to non-floating point registers.
574 Uses several strategies to try to use as few insns as possible. */
575
576 char *
577 i960_output_ldconst (dst, src)
578 register rtx dst, src;
579 {
580 register int rsrc1;
581 register unsigned rsrc2;
582 enum machine_mode mode = GET_MODE (dst);
583 rtx operands[4];
584
585 operands[0] = operands[2] = dst;
586 operands[1] = operands[3] = src;
587
588 /* Anything that isn't a compile time constant, such as a SYMBOL_REF,
589 must be a ldconst insn. */
590
591 if (GET_CODE (src) != CONST_INT && GET_CODE (src) != CONST_DOUBLE)
592 {
593 output_asm_insn ("ldconst %1,%0", operands);
594 return "";
595 }
596 else if (mode == XFmode)
597 {
598 REAL_VALUE_TYPE d;
599 long value_long[3];
600 int i;
601
602 if (fp_literal_zero (src, XFmode))
603 return "movt 0,%0";
604
605 REAL_VALUE_FROM_CONST_DOUBLE (d, src);
606 REAL_VALUE_TO_TARGET_LONG_DOUBLE (d, value_long);
607
608 output_asm_insn ("# ldconst %1,%0",operands);
609
610 for (i = 0; i < 3; i++)
611 {
612 operands[0] = gen_rtx (REG, SImode, REGNO (dst) + i);
613 operands[1] = GEN_INT (value_long[i]);
614 output_asm_insn (i960_output_ldconst (operands[0], operands[1]),
615 operands);
616 }
617
618 return "";
619 }
620 else if (mode == DFmode)
621 {
622 rtx first, second;
623
624 if (fp_literal_zero (src, DFmode))
625 return "movl 0,%0";
626
627 split_double (src, &first, &second);
628
629 output_asm_insn ("# ldconst %1,%0",operands);
630
631 operands[0] = gen_rtx (REG, SImode, REGNO (dst));
632 operands[1] = first;
633 output_asm_insn (i960_output_ldconst (operands[0], operands[1]),
634 operands);
635 operands[0] = gen_rtx (REG, SImode, REGNO (dst) + 1);
636 operands[1] = second;
637 output_asm_insn (i960_output_ldconst (operands[0], operands[1]),
638 operands);
639 return "";
640 }
641 else if (mode == SFmode)
642 {
643 REAL_VALUE_TYPE d;
644 long value;
645
646 REAL_VALUE_FROM_CONST_DOUBLE (d, src);
647 REAL_VALUE_TO_TARGET_SINGLE (d, value);
648
649 output_asm_insn ("# ldconst %1,%0",operands);
650 operands[0] = gen_rtx (REG, SImode, REGNO (dst));
651 operands[1] = gen_rtx (CONST_INT, VOIDmode, value);
652 output_asm_insn (i960_output_ldconst (operands[0], operands[1]),
653 operands);
654 return "";
655 }
656 else if (mode == TImode)
657 {
658 /* ??? This is currently not handled at all. */
659 abort ();
660
661 /* Note: lowest order word goes in lowest numbered reg. */
662 rsrc1 = INTVAL (src);
663 if (rsrc1 >= 0 && rsrc1 < 32)
664 return "movq %1,%0";
665 else
666 output_asm_insn ("movq\t0,%0\t# ldconstq %1,%0",operands);
667 /* Go pick up the low-order word. */
668 }
669 else if (mode == DImode)
670 {
671 rtx upperhalf, lowerhalf, xoperands[2];
672
673 if (GET_CODE (src) == CONST_DOUBLE || GET_CODE (src) == CONST_INT)
674 split_double (src, &lowerhalf, &upperhalf);
675
676 else
677 abort ();
678
679 /* Note: lowest order word goes in lowest numbered reg. */
680 /* Numbers from 0 to 31 can be handled with a single insn. */
681 rsrc1 = INTVAL (lowerhalf);
682 if (upperhalf == const0_rtx && rsrc1 >= 0 && rsrc1 < 32)
683 return "movl %1,%0";
684
685 /* Output the upper half with a recursive call. */
686 xoperands[0] = gen_rtx (REG, SImode, REGNO (dst) + 1);
687 xoperands[1] = upperhalf;
688 output_asm_insn (i960_output_ldconst (xoperands[0], xoperands[1]),
689 xoperands);
690 /* The lower word is emitted as normally. */
691 }
692 else
693 {
694 rsrc1 = INTVAL (src);
695 if (mode == QImode)
696 {
697 if (rsrc1 > 0xff)
698 rsrc1 &= 0xff;
699 }
700 else if (mode == HImode)
701 {
702 if (rsrc1 > 0xffff)
703 rsrc1 &= 0xffff;
704 }
705 }
706
707 if (rsrc1 >= 0)
708 {
709 /* ldconst 0..31,X -> mov 0..31,X */
710 if (rsrc1 < 32)
711 {
712 if (i960_last_insn_type == I_TYPE_REG && TARGET_C_SERIES)
713 return "lda %1,%0";
714 return "mov %1,%0";
715 }
716
717 /* ldconst 32..63,X -> add 31,nn,X */
718 if (rsrc1 < 63)
719 {
720 if (i960_last_insn_type == I_TYPE_REG && TARGET_C_SERIES)
721 return "lda %1,%0";
722 operands[1] = gen_rtx (CONST_INT, VOIDmode, rsrc1 - 31);
723 output_asm_insn ("addo\t31,%1,%0\t# ldconst %3,%0", operands);
724 return "";
725 }
726 }
727 else if (rsrc1 < 0)
728 {
729 /* ldconst -1..-31 -> sub 0,0..31,X */
730 if (rsrc1 >= -31)
731 {
732 /* return 'sub -(%1),0,%0' */
733 operands[1] = gen_rtx (CONST_INT, VOIDmode, - rsrc1);
734 output_asm_insn ("subo\t%1,0,%0\t# ldconst %3,%0", operands);
735 return "";
736 }
737
738 /* ldconst -32 -> not 31,X */
739 if (rsrc1 == -32)
740 {
741 operands[1] = gen_rtx (CONST_INT, VOIDmode, ~rsrc1);
742 output_asm_insn ("not\t%1,%0 # ldconst %3,%0", operands);
743 return "";
744 }
745 }
746
747 /* If const is a single bit. */
748 if (bitpos (rsrc1) >= 0)
749 {
750 operands[1] = gen_rtx (CONST_INT, VOIDmode, bitpos (rsrc1));
751 output_asm_insn ("setbit\t%1,0,%0\t# ldconst %3,%0", operands);
752 return "";
753 }
754
755 /* If const is a bit string of less than 6 bits (1..31 shifted). */
756 if (is_mask (rsrc1))
757 {
758 int s, e;
759
760 if (bitstr (rsrc1, &s, &e) < 6)
761 {
762 rsrc2 = ((unsigned int) rsrc1) >> s;
763 operands[1] = gen_rtx (CONST_INT, VOIDmode, rsrc2);
764 operands[2] = gen_rtx (CONST_INT, VOIDmode, s);
765 output_asm_insn ("shlo\t%2,%1,%0\t# ldconst %3,%0", operands);
766 return "";
767 }
768 }
769
770 /* Unimplemented cases:
771 const is in range 0..31 but rotated around end of word:
772 ror 31,3,g0 -> ldconst 0xe0000003,g0
773
774 and any 2 instruction cases that might be worthwhile */
775
776 output_asm_insn ("ldconst %1,%0", operands);
777 return "";
778 }
779
780 /* Determine if there is an opportunity for a bypass optimization.
781 Bypass succeeds on the 960K* if the destination of the previous
782 instruction is the second operand of the current instruction.
783 Bypass always succeeds on the C*.
784
785 Return 1 if the pattern should interchange the operands.
786
787 CMPBR_FLAG is true if this is for a compare-and-branch insn.
788 OP1 and OP2 are the two source operands of a 3 operand insn. */
789
790 int
791 i960_bypass (insn, op1, op2, cmpbr_flag)
792 register rtx insn, op1, op2;
793 int cmpbr_flag;
794 {
795 register rtx prev_insn, prev_dest;
796
797 if (TARGET_C_SERIES)
798 return 0;
799
800 /* Can't do this if op1 isn't a register. */
801 if (! REG_P (op1))
802 return 0;
803
804 /* Can't do this for a compare-and-branch if both ops aren't regs. */
805 if (cmpbr_flag && ! REG_P (op2))
806 return 0;
807
808 prev_insn = prev_real_insn (insn);
809
810 if (prev_insn && GET_CODE (prev_insn) == INSN
811 && GET_CODE (PATTERN (prev_insn)) == SET)
812 {
813 prev_dest = SET_DEST (PATTERN (prev_insn));
814 if ((GET_CODE (prev_dest) == REG && REGNO (prev_dest) == REGNO (op1))
815 || (GET_CODE (prev_dest) == SUBREG
816 && GET_CODE (SUBREG_REG (prev_dest)) == REG
817 && REGNO (SUBREG_REG (prev_dest)) == REGNO (op1)))
818 return 1;
819 }
820 return 0;
821 }
822 \f
823 /* Output the code which declares the function name. This also handles
824 leaf routines, which have special requirements, and initializes some
825 global variables. */
826
827 void
828 i960_function_name_declare (file, name, fndecl)
829 FILE *file;
830 char *name;
831 tree fndecl;
832 {
833 register int i, j;
834 int leaf_proc_ok;
835 rtx insn;
836
837 /* Increment global return label. */
838
839 ret_label++;
840
841 /* Compute whether tail calls and leaf routine optimizations can be performed
842 for this function. */
843
844 if (TARGET_TAILCALL)
845 tail_call_ok = 1;
846 else
847 tail_call_ok = 0;
848
849 if (TARGET_LEAFPROC)
850 leaf_proc_ok = 1;
851 else
852 leaf_proc_ok = 0;
853
854 /* Even if nobody uses extra parms, can't have leafproc or tail calls if
855 argblock, because argblock uses g14 implicitly. */
856
857 if (current_function_args_size != 0 || VARARGS_STDARG_FUNCTION (fndecl))
858 {
859 tail_call_ok = 0;
860 leaf_proc_ok = 0;
861 }
862
863 /* See if caller passes in an address to return value. */
864
865 if (aggregate_value_p (DECL_RESULT (fndecl)))
866 {
867 tail_call_ok = 0;
868 leaf_proc_ok = 0;
869 }
870
871 /* Can not use tail calls or make this a leaf routine if there is a non
872 zero frame size. */
873
874 if (get_frame_size () != 0)
875 leaf_proc_ok = 0;
876
877 /* I don't understand this condition, and do not think that it is correct.
878 Apparently this is just checking whether the frame pointer is used, and
879 we can't trust regs_ever_live[fp] since it is (almost?) always set. */
880
881 if (tail_call_ok)
882 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
883 if (GET_CODE (insn) == INSN
884 && reg_mentioned_p (frame_pointer_rtx, insn))
885 {
886 tail_call_ok = 0;
887 break;
888 }
889
890 /* Check for CALL insns. Can not be a leaf routine if there are any. */
891
892 if (leaf_proc_ok)
893 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
894 if (GET_CODE (insn) == CALL_INSN)
895 {
896 leaf_proc_ok = 0;
897 break;
898 }
899
900 /* Can not be a leaf routine if any non-call clobbered registers are
901 used in this function. */
902
903 if (leaf_proc_ok)
904 for (i = 0, j = 0; i < FIRST_PSEUDO_REGISTER; i++)
905 if (regs_ever_live[i]
906 && ((! call_used_regs[i]) || (i > 7 && i < 12)))
907 {
908 /* Global registers. */
909 if (i < 16 && i > 7 && i != 13)
910 leaf_proc_ok = 0;
911 /* Local registers. */
912 else if (i < 32)
913 leaf_proc_ok = 0;
914 }
915
916 /* Now choose a leaf return register, if we can find one, and if it is
917 OK for this to be a leaf routine. */
918
919 i960_leaf_ret_reg = -1;
920
921 if (optimize && leaf_proc_ok)
922 {
923 for (i960_leaf_ret_reg = -1, i = 0; i < 8; i++)
924 if (regs_ever_live[i] == 0)
925 {
926 i960_leaf_ret_reg = i;
927 regs_ever_live[i] = 1;
928 break;
929 }
930 }
931
932 /* Do this after choosing the leaf return register, so it will be listed
933 if one was chosen. */
934
935 fprintf (file, "\t# Function '%s'\n", (name[0] == '*' ? &name[1] : name));
936 fprintf (file, "\t# Registers used: ");
937
938 for (i = 0, j = 0; i < FIRST_PSEUDO_REGISTER; i++)
939 {
940 if (regs_ever_live[i])
941 {
942 fprintf (file, "%s%s ", reg_names[i], call_used_regs[i] ? "" : "*");
943
944 if (i > 15 && j == 0)
945 {
946 fprintf (file,"\n\t#\t\t ");
947 j++;
948 }
949 }
950 }
951
952 fprintf (file, "\n");
953
954 if (i960_leaf_ret_reg >= 0)
955 {
956 /* Make it a leaf procedure. */
957
958 if (TREE_PUBLIC (fndecl))
959 fprintf (file,"\t.globl\t%s.lf\n", (name[0] == '*' ? &name[1] : name));
960
961 fprintf (file, "\t.leafproc\t");
962 assemble_name (file, name);
963 fprintf (file, ",%s.lf\n", (name[0] == '*' ? &name[1] : name));
964 ASM_OUTPUT_LABEL (file, name);
965 fprintf (file, "\tlda LR%d,g14\n", ret_label);
966 fprintf (file, "%s.lf:\n", (name[0] == '*' ? &name[1] : name));
967 fprintf (file, "\tmov g14,g%d\n", i960_leaf_ret_reg);
968
969 if (TARGET_C_SERIES)
970 {
971 fprintf (file, "\tlda 0,g14\n");
972 i960_last_insn_type = I_TYPE_MEM;
973 }
974 else
975 {
976 fprintf (file, "\tmov 0,g14\n");
977 i960_last_insn_type = I_TYPE_REG;
978 }
979 }
980 else
981 {
982 ASM_OUTPUT_LABEL (file, name);
983 i960_last_insn_type = I_TYPE_CTRL;
984 }
985 }
986 \f
987 /* Compute and return the frame size. */
988
989 int
990 compute_frame_size (size)
991 int size;
992 {
993 int actual_fsize;
994 int outgoing_args_size = current_function_outgoing_args_size;
995
996 /* The STARTING_FRAME_OFFSET is totally hidden to us as far
997 as size is concerned. */
998 actual_fsize = (size + 15) & -16;
999 actual_fsize += (outgoing_args_size + 15) & -16;
1000
1001 return actual_fsize;
1002 }
1003
1004 /* Output code for the function prologue. */
1005
1006 void
1007 i960_function_prologue (file, size)
1008 FILE *file;
1009 unsigned int size;
1010 {
1011 register int i, j, nr;
1012 int n_iregs = 0;
1013 int rsize = 0;
1014 int actual_fsize, offset;
1015 char tmpstr[1000];
1016 /* -1 if reg must be saved on proc entry, 0 if available, 1 if saved
1017 somewhere. */
1018 int regs[FIRST_PSEUDO_REGISTER];
1019
1020 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1021 if (regs_ever_live[i]
1022 && ((! call_used_regs[i]) || (i > 7 && i < 12)))
1023 {
1024 regs[i] = -1;
1025 /* Count global registers that need saving. */
1026 if (i < 16)
1027 n_iregs++;
1028 }
1029 else
1030 regs[i] = 0;
1031
1032 epilogue_string[0] = '\0';
1033
1034 if (profile_flag || profile_block_flag)
1035 {
1036 /* When profiling, we may use registers 20 to 27 to save arguments, so
1037 they can't be used here for saving globals. J is the number of
1038 argument registers the mcount call will save. */
1039 for (j = 7; j >= 0 && ! regs_ever_live[j]; j--)
1040 ;
1041
1042 for (i = 20; i <= j + 20; i++)
1043 regs[i] = -1;
1044 }
1045
1046 /* First look for local registers to save globals in. */
1047 for (i = 0; i < 16; i++)
1048 {
1049 if (regs[i] == 0)
1050 continue;
1051
1052 /* Start at r4, not r3. */
1053 for (j = 20; j < 32; j++)
1054 {
1055 if (regs[j] != 0)
1056 continue;
1057
1058 regs[i] = 1;
1059 regs[j] = -1;
1060 regs_ever_live[j] = 1;
1061 nr = 1;
1062 if (i <= 14 && i % 2 == 0 && j <= 30 && j % 2 == 0
1063 && regs[i+1] != 0 && regs[j+1] == 0)
1064 {
1065 nr = 2;
1066 regs[i+1] = 1;
1067 regs[j+1] = -1;
1068 regs_ever_live[j+1] = 1;
1069 }
1070 if (nr == 2 && i <= 12 && i % 4 == 0 && j <= 28 && j % 4 == 0
1071 && regs[i+2] != 0 && regs[j+2] == 0)
1072 {
1073 nr = 3;
1074 regs[i+2] = 1;
1075 regs[j+2] = -1;
1076 regs_ever_live[j+2] = 1;
1077 }
1078 if (nr == 3 && regs[i+3] != 0 && regs[j+3] == 0)
1079 {
1080 nr = 4;
1081 regs[i+3] = 1;
1082 regs[j+3] = -1;
1083 regs_ever_live[j+3] = 1;
1084 }
1085
1086 fprintf (file, "\tmov%s %s,%s\n",
1087 ((nr == 4) ? "q" :
1088 (nr == 3) ? "t" :
1089 (nr == 2) ? "l" : ""),
1090 reg_names[i], reg_names[j]);
1091 sprintf (tmpstr, "\tmov%s %s,%s\n",
1092 ((nr == 4) ? "q" :
1093 (nr == 3) ? "t" :
1094 (nr == 2) ? "l" : ""),
1095 reg_names[j], reg_names[i]);
1096 strcat (epilogue_string, tmpstr);
1097
1098 n_iregs -= nr;
1099 i += nr-1;
1100 break;
1101 }
1102 }
1103
1104 /* N_iregs is now the number of global registers that haven't been saved
1105 yet. */
1106
1107 rsize = (n_iregs * 4);
1108 actual_fsize = compute_frame_size (size) + rsize;
1109 #if 0
1110 /* ??? The 1.2.1 compiler does this also. This is meant to round the frame
1111 size up to the nearest multiple of 16. I don't know whether this is
1112 necessary, or even desirable.
1113
1114 The frame pointer must be aligned, but the call instruction takes care of
1115 that. If we leave the stack pointer unaligned, we may save a little on
1116 dynamic stack allocation. And we don't lose, at least according to the
1117 i960CA manual. */
1118 actual_fsize = (actual_fsize + 15) & ~0xF;
1119 #endif
1120
1121 /* Allocate space for register save and locals. */
1122 if (actual_fsize > 0)
1123 {
1124 if (actual_fsize < 32)
1125 fprintf (file, "\taddo %d,sp,sp\n", actual_fsize);
1126 else
1127 fprintf (file, "\tlda\t%d(sp),sp\n", actual_fsize);
1128 }
1129
1130 /* Take hardware register save area created by the call instruction
1131 into account, but store them before the argument block area. */
1132 offset = 64 + actual_fsize - compute_frame_size (0) - rsize;
1133 /* Save registers on stack if needed. */
1134 for (i = 0, j = n_iregs; j > 0 && i < 16; i++)
1135 {
1136 if (regs[i] != -1)
1137 continue;
1138
1139 nr = 1;
1140
1141 if (i <= 14 && i % 2 == 0 && regs[i+1] == -1 && offset % 2 == 0)
1142 nr = 2;
1143
1144 if (nr == 2 && i <= 12 && i % 4 == 0 && regs[i+2] == -1
1145 && offset % 4 == 0)
1146 nr = 3;
1147
1148 if (nr == 3 && regs[i+3] == -1)
1149 nr = 4;
1150
1151 fprintf (file,"\tst%s %s,%d(fp)\n",
1152 ((nr == 4) ? "q" :
1153 (nr == 3) ? "t" :
1154 (nr == 2) ? "l" : ""),
1155 reg_names[i], offset);
1156 sprintf (tmpstr,"\tld%s %d(fp),%s\n",
1157 ((nr == 4) ? "q" :
1158 (nr == 3) ? "t" :
1159 (nr == 2) ? "l" : ""),
1160 offset, reg_names[i]);
1161 strcat (epilogue_string, tmpstr);
1162 i += nr-1;
1163 j -= nr;
1164 offset += nr * 4;
1165 }
1166
1167 if (actual_fsize == 0 && size == 0 && rsize == 0)
1168 return;
1169
1170 fprintf (file, "\t#Prologue stats:\n");
1171 fprintf (file, "\t# Total Frame Size: %d bytes\n", actual_fsize);
1172
1173 if (size)
1174 fprintf (file, "\t# Local Variable Size: %d bytes\n", size);
1175 if (rsize)
1176 fprintf (file, "\t# Register Save Size: %d regs, %d bytes\n",
1177 n_iregs, rsize);
1178 fprintf (file, "\t#End Prologue#\n");
1179 }
1180
1181 /* Output code for the function profiler. */
1182
1183 void
1184 output_function_profiler (file, labelno)
1185 FILE *file;
1186 int labelno;
1187 {
1188 /* The last used parameter register. */
1189 int last_parm_reg;
1190 int i, j, increment;
1191 int varargs_stdarg_function
1192 = VARARGS_STDARG_FUNCTION (current_function_decl);
1193
1194 /* Figure out the last used parameter register. The proper thing to do
1195 is to walk incoming args of the function. A function might have live
1196 parameter registers even if it has no incoming args. Note that we
1197 don't have to save parameter registers g8 to g11 because they are
1198 call preserved. */
1199
1200 /* See also output_function_prologue, which tries to use local registers
1201 for preserved call-saved global registers. */
1202
1203 for (last_parm_reg = 7;
1204 last_parm_reg >= 0 && ! regs_ever_live[last_parm_reg];
1205 last_parm_reg--)
1206 ;
1207
1208 /* Save parameter registers in regs r4 (20) to r11 (27). */
1209
1210 for (i = 0, j = 4; i <= last_parm_reg; i += increment, j += increment)
1211 {
1212 if (i % 4 == 0 && (last_parm_reg - i) >= 3)
1213 increment = 4;
1214 else if (i % 4 == 0 && (last_parm_reg - i) >= 2)
1215 increment = 3;
1216 else if (i % 2 == 0 && (last_parm_reg - i) >= 1)
1217 increment = 2;
1218 else
1219 increment = 1;
1220
1221 fprintf (file, "\tmov%s g%d,r%d\n",
1222 (increment == 4 ? "q" : increment == 3 ? "t"
1223 : increment == 2 ? "l": ""), i, j);
1224 }
1225
1226 /* If this function uses the arg pointer, then save it in r3 and then
1227 set it to zero. */
1228
1229 if (current_function_args_size != 0 || varargs_stdarg_function)
1230 fprintf (file, "\tmov g14,r3\n\tmov 0,g14\n");
1231
1232 /* Load location address into g0 and call mcount. */
1233
1234 fprintf (file, "\tlda\tLP%d,g0\n\tcallx\tmcount\n", labelno);
1235
1236 /* If this function uses the arg pointer, restore it. */
1237
1238 if (current_function_args_size != 0 || varargs_stdarg_function)
1239 fprintf (file, "\tmov r3,g14\n");
1240
1241 /* Restore parameter registers. */
1242
1243 for (i = 0, j = 4; i <= last_parm_reg; i += increment, j += increment)
1244 {
1245 if (i % 4 == 0 && (last_parm_reg - i) >= 3)
1246 increment = 4;
1247 else if (i % 4 == 0 && (last_parm_reg - i) >= 2)
1248 increment = 3;
1249 else if (i % 2 == 0 && (last_parm_reg - i) >= 1)
1250 increment = 2;
1251 else
1252 increment = 1;
1253
1254 fprintf (file, "\tmov%s r%d,g%d\n",
1255 (increment == 4 ? "q" : increment == 3 ? "t"
1256 : increment == 2 ? "l": ""), j, i);
1257 }
1258 }
1259
1260 /* Output code for the function epilogue. */
1261
1262 void
1263 i960_function_epilogue (file, size)
1264 FILE *file;
1265 unsigned int size;
1266 {
1267 if (i960_leaf_ret_reg >= 0)
1268 {
1269 fprintf (file, "LR%d: ret\n", ret_label);
1270 return;
1271 }
1272
1273 if (*epilogue_string == 0)
1274 {
1275 register rtx tmp;
1276
1277 /* Emit a return insn, but only if control can fall through to here. */
1278
1279 tmp = get_last_insn ();
1280 while (tmp)
1281 {
1282 if (GET_CODE (tmp) == BARRIER)
1283 return;
1284 if (GET_CODE (tmp) == CODE_LABEL)
1285 break;
1286 if (GET_CODE (tmp) == JUMP_INSN)
1287 {
1288 if (GET_CODE (PATTERN (tmp)) == RETURN)
1289 return;
1290 break;
1291 }
1292 if (GET_CODE (tmp) == NOTE)
1293 {
1294 tmp = PREV_INSN (tmp);
1295 continue;
1296 }
1297 break;
1298 }
1299 fprintf (file, "LR%d: ret\n", ret_label);
1300 return;
1301 }
1302
1303 fprintf (file, "LR%d:\n", ret_label);
1304
1305 fprintf (file, "\t#EPILOGUE#\n");
1306
1307 /* Output the string created by the prologue which will restore all
1308 registers saved by the prologue. */
1309
1310 if (epilogue_string[0] != '\0')
1311 fprintf (file, "%s", epilogue_string);
1312
1313 /* Must clear g14 on return. */
1314
1315 if (current_function_args_size != 0
1316 || VARARGS_STDARG_FUNCTION (current_function_decl))
1317 fprintf (file, "\tmov 0,g14\n");
1318
1319 fprintf (file, "\tret\n");
1320 fprintf (file, "\t#End Epilogue#\n");
1321 }
1322
1323 /* Output code for a call insn. */
1324
1325 char *
1326 i960_output_call_insn (target, argsize_rtx, arg_pointer, insn)
1327 register rtx target, argsize_rtx, arg_pointer, insn;
1328 {
1329 int argsize = INTVAL (argsize_rtx);
1330 rtx nexti = next_real_insn (insn);
1331 rtx operands[2];
1332 int varargs_stdarg_function
1333 = VARARGS_STDARG_FUNCTION (current_function_decl);
1334
1335 operands[0] = target;
1336 operands[1] = arg_pointer;
1337
1338 if (current_function_args_size != 0 || varargs_stdarg_function)
1339 output_asm_insn ("mov g14,r3", operands);
1340
1341 if (argsize > 48)
1342 output_asm_insn ("lda %a1,g14", operands);
1343 else if (current_function_args_size != 0 || varargs_stdarg_function)
1344 output_asm_insn ("mov 0,g14", operands);
1345
1346 /* The code used to assume that calls to SYMBOL_REFs could not be more
1347 than 24 bits away (b vs bx, callj vs callx). This is not true. This
1348 feature is now implemented by relaxing in the GNU linker. It can convert
1349 bx to b if in range, and callx to calls/call/balx/bal as appropriate. */
1350
1351 /* Nexti could be zero if the called routine is volatile. */
1352 if (optimize && (*epilogue_string == 0) && argsize == 0 && tail_call_ok
1353 && (nexti == 0 || GET_CODE (PATTERN (nexti)) == RETURN))
1354 {
1355 /* Delete following return insn. */
1356 if (nexti && no_labels_between_p (insn, nexti))
1357 delete_insn (nexti);
1358 output_asm_insn ("bx %0", operands);
1359 return "# notreached";
1360 }
1361
1362 output_asm_insn ("callx %0", operands);
1363
1364 if (current_function_args_size != 0 || varargs_stdarg_function)
1365 output_asm_insn ("mov r3,g14", operands);
1366
1367 return "";
1368 }
1369
1370 /* Output code for a return insn. */
1371
1372 char *
1373 i960_output_ret_insn (insn)
1374 register rtx insn;
1375 {
1376 static char lbuf[20];
1377
1378 if (*epilogue_string != 0)
1379 {
1380 if (! TARGET_CODE_ALIGN && next_real_insn (insn) == 0)
1381 return "";
1382
1383 sprintf (lbuf, "b LR%d", ret_label);
1384 return lbuf;
1385 }
1386
1387 if (current_function_args_size != 0
1388 || VARARGS_STDARG_FUNCTION (current_function_decl))
1389 output_asm_insn ("mov 0,g14", 0);
1390
1391 if (i960_leaf_ret_reg >= 0)
1392 {
1393 sprintf (lbuf, "bx (%s)", reg_names[i960_leaf_ret_reg]);
1394 return lbuf;
1395 }
1396 return "ret";
1397 }
1398 \f
1399 #if 0
1400 /* Return a character string representing the branch prediction
1401 opcode to be tacked on an instruction. This must at least
1402 return a null string. */
1403
1404 char *
1405 i960_br_predict_opcode (lab_ref, insn)
1406 rtx lab_ref, insn;
1407 {
1408 if (TARGET_BRANCH_PREDICT)
1409 {
1410 unsigned long label_uid;
1411
1412 if (GET_CODE (lab_ref) == CODE_LABEL)
1413 label_uid = INSN_UID (lab_ref);
1414 else if (GET_CODE (lab_ref) == LABEL_REF)
1415 label_uid = INSN_UID (XEXP (lab_ref, 0));
1416 else
1417 return ".f";
1418
1419 /* If not optimizing, then the insn_addresses array will not be
1420 valid. In this case, always return ".t" since most branches
1421 are taken. If optimizing, return .t for backward branches
1422 and .f for forward branches. */
1423 if (! optimize
1424 || insn_addresses[label_uid] < insn_addresses[INSN_UID (insn)])
1425 return ".t";
1426 return ".f";
1427 }
1428
1429 return "";
1430 }
1431 #endif
1432
1433 /* Print the operand represented by rtx X formatted by code CODE. */
1434
1435 void
1436 i960_print_operand (file, x, code)
1437 FILE *file;
1438 rtx x;
1439 char code;
1440 {
1441 enum rtx_code rtxcode = GET_CODE (x);
1442
1443 if (rtxcode == REG)
1444 {
1445 switch (code)
1446 {
1447 case 'D':
1448 /* Second reg of a double. */
1449 fprintf (file, "%s", reg_names[REGNO (x)+1]);
1450 break;
1451
1452 case 0:
1453 fprintf (file, "%s", reg_names[REGNO (x)]);
1454 break;
1455
1456 default:
1457 abort ();
1458 }
1459 return;
1460 }
1461 else if (rtxcode == MEM)
1462 {
1463 output_address (XEXP (x, 0));
1464 return;
1465 }
1466 else if (rtxcode == CONST_INT)
1467 {
1468 if (INTVAL (x) > 9999 || INTVAL (x) < -999)
1469 fprintf (file, "0x%x", INTVAL (x));
1470 else
1471 fprintf (file, "%d", INTVAL (x));
1472 return;
1473 }
1474 else if (rtxcode == CONST_DOUBLE)
1475 {
1476 REAL_VALUE_TYPE d;
1477 char dstr[30];
1478
1479 if (x == CONST0_RTX (GET_MODE (x)))
1480 {
1481 fprintf (file, "0f0.0");
1482 return;
1483 }
1484 else if (x == CONST1_RTX (GET_MODE (x)))
1485 {
1486 fprintf (file, "0f1.0");
1487 return;
1488 }
1489
1490 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
1491 REAL_VALUE_TO_DECIMAL (d, "%#g", dstr);
1492 fprintf (file, "0f%s", dstr);
1493 return;
1494 }
1495
1496 switch(code)
1497 {
1498 case 'B':
1499 /* Branch or jump, depending on assembler. */
1500 if (TARGET_ASM_COMPAT)
1501 fputs ("j", file);
1502 else
1503 fputs ("b", file);
1504 break;
1505
1506 case 'S':
1507 /* Sign of condition. */
1508 if ((rtxcode == EQ) || (rtxcode == NE) || (rtxcode == GTU)
1509 || (rtxcode == LTU) || (rtxcode == GEU) || (rtxcode == LEU))
1510 fputs ("o", file);
1511 else if ((rtxcode == GT) || (rtxcode == LT)
1512 || (rtxcode == GE) || (rtxcode == LE))
1513 fputs ("i", file);
1514 else
1515 abort();
1516 break;
1517
1518 case 'I':
1519 /* Inverted condition. */
1520 rtxcode = reverse_condition (rtxcode);
1521 goto normal;
1522
1523 case 'X':
1524 /* Inverted condition w/ reversed operands. */
1525 rtxcode = reverse_condition (rtxcode);
1526 /* Fallthrough. */
1527
1528 case 'R':
1529 /* Reversed operand condition. */
1530 rtxcode = swap_condition (rtxcode);
1531 /* Fallthrough. */
1532
1533 case 'C':
1534 /* Normal condition. */
1535 normal:
1536 if (rtxcode == EQ) { fputs ("e", file); return; }
1537 else if (rtxcode == NE) { fputs ("ne", file); return; }
1538 else if (rtxcode == GT) { fputs ("g", file); return; }
1539 else if (rtxcode == GTU) { fputs ("g", file); return; }
1540 else if (rtxcode == LT) { fputs ("l", file); return; }
1541 else if (rtxcode == LTU) { fputs ("l", file); return; }
1542 else if (rtxcode == GE) { fputs ("ge", file); return; }
1543 else if (rtxcode == GEU) { fputs ("ge", file); return; }
1544 else if (rtxcode == LE) { fputs ("le", file); return; }
1545 else if (rtxcode == LEU) { fputs ("le", file); return; }
1546 else abort ();
1547 break;
1548
1549 case 0:
1550 output_addr_const (file, x);
1551 break;
1552
1553 default:
1554 abort ();
1555 }
1556
1557 return;
1558 }
1559 \f
1560 /* Print a memory address as an operand to reference that memory location.
1561
1562 This is exactly the same as legitimate_address_p, except that it the prints
1563 addresses instead of recognizing them. */
1564
1565 void
1566 i960_print_operand_addr (file, addr)
1567 FILE *file;
1568 register rtx addr;
1569 {
1570 rtx breg, ireg;
1571 rtx scale, offset;
1572
1573 ireg = 0;
1574 breg = 0;
1575 offset = 0;
1576 scale = const1_rtx;
1577
1578 if (GET_CODE (addr) == REG)
1579 breg = addr;
1580 else if (CONSTANT_P (addr))
1581 offset = addr;
1582 else if (GET_CODE (addr) == PLUS)
1583 {
1584 rtx op0, op1;
1585
1586 op0 = XEXP (addr, 0);
1587 op1 = XEXP (addr, 1);
1588
1589 if (GET_CODE (op0) == REG)
1590 {
1591 breg = op0;
1592 if (GET_CODE (op1) == REG)
1593 ireg = op1;
1594 else if (CONSTANT_P (op1))
1595 offset = op1;
1596 else
1597 abort ();
1598 }
1599 else if (GET_CODE (op0) == PLUS)
1600 {
1601 if (GET_CODE (XEXP (op0, 0)) == MULT)
1602 {
1603 ireg = XEXP (XEXP (op0, 0), 0);
1604 scale = XEXP (XEXP (op0, 0), 1);
1605 if (GET_CODE (XEXP (op0, 1)) == REG)
1606 {
1607 breg = XEXP (op0, 1);
1608 offset = op1;
1609 }
1610 else
1611 abort ();
1612 }
1613 else if (GET_CODE (XEXP (op0, 0)) == REG)
1614 {
1615 breg = XEXP (op0, 0);
1616 if (GET_CODE (XEXP (op0, 1)) == REG)
1617 {
1618 ireg = XEXP (op0, 1);
1619 offset = op1;
1620 }
1621 else
1622 abort ();
1623 }
1624 else
1625 abort ();
1626 }
1627 else if (GET_CODE (op0) == MULT)
1628 {
1629 ireg = XEXP (op0, 0);
1630 scale = XEXP (op0, 1);
1631 if (GET_CODE (op1) == REG)
1632 breg = op1;
1633 else if (CONSTANT_P (op1))
1634 offset = op1;
1635 else
1636 abort ();
1637 }
1638 else
1639 abort ();
1640 }
1641 else if (GET_CODE (addr) == MULT)
1642 {
1643 ireg = XEXP (addr, 0);
1644 scale = XEXP (addr, 1);
1645 }
1646 else
1647 abort ();
1648
1649 if (offset)
1650 output_addr_const (file, offset);
1651 if (breg)
1652 fprintf (file, "(%s)", reg_names[REGNO (breg)]);
1653 if (ireg)
1654 fprintf (file, "[%s*%d]", reg_names[REGNO (ireg)], INTVAL (scale));
1655 }
1656 \f
1657 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
1658 that is a valid memory address for an instruction.
1659 The MODE argument is the machine mode for the MEM expression
1660 that wants to use this address.
1661
1662 On 80960, legitimate addresses are:
1663 base ld (g0),r0
1664 disp (12 or 32 bit) ld foo,r0
1665 base + index ld (g0)[g1*1],r0
1666 base + displ ld 0xf00(g0),r0
1667 base + index*scale + displ ld 0xf00(g0)[g1*4],r0
1668 index*scale + base ld (g0)[g1*4],r0
1669 index*scale + displ ld 0xf00[g1*4],r0
1670 index*scale ld [g1*4],r0
1671 index + base + displ ld 0xf00(g0)[g1*1],r0
1672
1673 In each case, scale can be 1, 2, 4, 8, or 16. */
1674
1675 /* This is exactly the same as i960_print_operand_addr, except that
1676 it recognizes addresses instead of printing them.
1677
1678 It only recognizes address in canonical form. LEGITIMIZE_ADDRESS should
1679 convert common non-canonical forms to canonical form so that they will
1680 be recognized. */
1681
1682 /* These two macros allow us to accept either a REG or a SUBREG anyplace
1683 where a register is valid. */
1684
1685 #define RTX_OK_FOR_BASE_P(X, STRICT) \
1686 ((GET_CODE (X) == REG \
1687 && (STRICT ? REG_OK_FOR_BASE_P_STRICT (X) : REG_OK_FOR_BASE_P (X))) \
1688 || (GET_CODE (X) == SUBREG \
1689 && GET_CODE (SUBREG_REG (X)) == REG \
1690 && (STRICT ? REG_OK_FOR_BASE_P_STRICT (SUBREG_REG (X)) \
1691 : REG_OK_FOR_BASE_P (SUBREG_REG (X)))))
1692
1693 #define RTX_OK_FOR_INDEX_P(X, STRICT) \
1694 ((GET_CODE (X) == REG \
1695 && (STRICT ? REG_OK_FOR_INDEX_P_STRICT (X) : REG_OK_FOR_INDEX_P (X)))\
1696 || (GET_CODE (X) == SUBREG \
1697 && GET_CODE (SUBREG_REG (X)) == REG \
1698 && (STRICT ? REG_OK_FOR_INDEX_P_STRICT (SUBREG_REG (X)) \
1699 : REG_OK_FOR_INDEX_P (SUBREG_REG (X)))))
1700
1701 int
1702 legitimate_address_p (mode, addr, strict)
1703 enum machine_mode mode;
1704 register rtx addr;
1705 int strict;
1706 {
1707 if (RTX_OK_FOR_BASE_P (addr, strict))
1708 return 1;
1709 else if (CONSTANT_P (addr))
1710 return 1;
1711 else if (GET_CODE (addr) == PLUS)
1712 {
1713 rtx op0, op1;
1714
1715 if (! TARGET_COMPLEX_ADDR && ! reload_completed)
1716 return 0;
1717
1718 op0 = XEXP (addr, 0);
1719 op1 = XEXP (addr, 1);
1720
1721 if (RTX_OK_FOR_BASE_P (op0, strict))
1722 {
1723 if (RTX_OK_FOR_INDEX_P (op1, strict))
1724 return 1;
1725 else if (CONSTANT_P (op1))
1726 return 1;
1727 else
1728 return 0;
1729 }
1730 else if (GET_CODE (op0) == PLUS)
1731 {
1732 if (GET_CODE (XEXP (op0, 0)) == MULT)
1733 {
1734 if (! (RTX_OK_FOR_INDEX_P (XEXP (XEXP (op0, 0), 0), strict)
1735 && SCALE_TERM_P (XEXP (XEXP (op0, 0), 1))))
1736 return 0;
1737
1738 if (RTX_OK_FOR_BASE_P (XEXP (op0, 1), strict)
1739 && CONSTANT_P (op1))
1740 return 1;
1741 else
1742 return 0;
1743 }
1744 else if (RTX_OK_FOR_BASE_P (XEXP (op0, 0), strict))
1745 {
1746 if (RTX_OK_FOR_INDEX_P (XEXP (op0, 1), strict)
1747 && CONSTANT_P (op1))
1748 return 1;
1749 else
1750 return 0;
1751 }
1752 else
1753 return 0;
1754 }
1755 else if (GET_CODE (op0) == MULT)
1756 {
1757 if (! (RTX_OK_FOR_INDEX_P (XEXP (op0, 0), strict)
1758 && SCALE_TERM_P (XEXP (op0, 1))))
1759 return 0;
1760
1761 if (RTX_OK_FOR_BASE_P (op1, strict))
1762 return 1;
1763 else if (CONSTANT_P (op1))
1764 return 1;
1765 else
1766 return 0;
1767 }
1768 else
1769 return 0;
1770 }
1771 else if (GET_CODE (addr) == MULT)
1772 {
1773 if (! TARGET_COMPLEX_ADDR && ! reload_completed)
1774 return 0;
1775
1776 return (RTX_OK_FOR_INDEX_P (XEXP (addr, 0), strict)
1777 && SCALE_TERM_P (XEXP (addr, 1)));
1778 }
1779 else
1780 return 0;
1781 }
1782
1783 /* Try machine-dependent ways of modifying an illegitimate address
1784 to be legitimate. If we find one, return the new, valid address.
1785 This macro is used in only one place: `memory_address' in explow.c.
1786
1787 This converts some non-canonical addresses to canonical form so they
1788 can be recognized. */
1789
1790 rtx
1791 legitimize_address (x, oldx, mode)
1792 register rtx x;
1793 register rtx oldx;
1794 enum machine_mode mode;
1795 {
1796 if (GET_CODE (x) == SYMBOL_REF)
1797 {
1798 abort ();
1799 x = copy_to_reg (x);
1800 }
1801
1802 if (! TARGET_COMPLEX_ADDR && ! reload_completed)
1803 return x;
1804
1805 /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
1806 into (plus (plus (mult (reg) (const)) (reg)) (const)). This can be
1807 created by virtual register instantiation, register elimination, and
1808 similar optimizations. */
1809 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT
1810 && GET_CODE (XEXP (x, 1)) == PLUS)
1811 x = gen_rtx (PLUS, Pmode,
1812 gen_rtx (PLUS, Pmode, XEXP (x, 0), XEXP (XEXP (x, 1), 0)),
1813 XEXP (XEXP (x, 1), 1));
1814
1815 /* Canonicalize (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
1816 into (plus (plus (mult (reg) (const)) (reg)) (const)). */
1817 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
1818 && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
1819 && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
1820 && CONSTANT_P (XEXP (x, 1)))
1821 {
1822 rtx constant, other;
1823
1824 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
1825 {
1826 constant = XEXP (x, 1);
1827 other = XEXP (XEXP (XEXP (x, 0), 1), 1);
1828 }
1829 else if (GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 1)) == CONST_INT)
1830 {
1831 constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
1832 other = XEXP (x, 1);
1833 }
1834 else
1835 constant = 0;
1836
1837 if (constant)
1838 x = gen_rtx (PLUS, Pmode,
1839 gen_rtx (PLUS, Pmode, XEXP (XEXP (x, 0), 0),
1840 XEXP (XEXP (XEXP (x, 0), 1), 0)),
1841 plus_constant (other, INTVAL (constant)));
1842 }
1843
1844 return x;
1845 }
1846 \f
1847 #if 0
1848 /* Return the most stringent alignment that we are willing to consider
1849 objects of size SIZE and known alignment ALIGN as having. */
1850
1851 int
1852 i960_alignment (size, align)
1853 int size;
1854 int align;
1855 {
1856 int i;
1857
1858 if (! TARGET_STRICT_ALIGN)
1859 if (TARGET_IC_COMPAT2_0 || align >= 4)
1860 {
1861 i = i960_object_bytes_bitalign (size) / BITS_PER_UNIT;
1862 if (i > align)
1863 align = i;
1864 }
1865
1866 return align;
1867 }
1868 #endif
1869 \f
1870 /* Modes for condition codes. */
1871 #define C_MODES \
1872 ((1 << (int) CCmode) | (1 << (int) CC_UNSmode) | (1<< (int) CC_CHKmode))
1873
1874 /* Modes for single-word (and smaller) quantities. */
1875 #define S_MODES \
1876 (~C_MODES \
1877 & ~ ((1 << (int) DImode) | (1 << (int) TImode) \
1878 | (1 << (int) DFmode) | (1 << (int) XFmode)))
1879
1880 /* Modes for double-word (and smaller) quantities. */
1881 #define D_MODES \
1882 (~C_MODES \
1883 & ~ ((1 << (int) TImode) | (1 << (int) XFmode)))
1884
1885 /* Modes for quad-word quantities. */
1886 #define T_MODES (~C_MODES)
1887
1888 /* Modes for single-float quantities. */
1889 #define SF_MODES ((1 << (int) SFmode))
1890
1891 /* Modes for double-float quantities. */
1892 #define DF_MODES (SF_MODES | (1 << (int) DFmode) | (1 << (int) SCmode))
1893
1894 /* Modes for quad-float quantities. */
1895 #define XF_MODES (DF_MODES | (1 << (int) XFmode) | (1 << (int) DCmode))
1896
1897 unsigned int hard_regno_mode_ok[FIRST_PSEUDO_REGISTER] = {
1898 T_MODES, S_MODES, D_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
1899 T_MODES, S_MODES, D_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
1900 T_MODES, S_MODES, D_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
1901 T_MODES, S_MODES, D_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
1902
1903 XF_MODES, XF_MODES, XF_MODES, XF_MODES, C_MODES};
1904
1905 \f
1906 /* Return the minimum alignment of an expression rtx X in bytes. This takes
1907 advantage of machine specific facts, such as knowing that the frame pointer
1908 is always 16 byte aligned. */
1909
1910 int
1911 i960_expr_alignment (x, size)
1912 rtx x;
1913 int size;
1914 {
1915 int align = 1;
1916
1917 if (x == 0)
1918 return 1;
1919
1920 switch (GET_CODE(x))
1921 {
1922 case CONST_INT:
1923 align = INTVAL(x);
1924
1925 if ((align & 0xf) == 0)
1926 align = 16;
1927 else if ((align & 0x7) == 0)
1928 align = 8;
1929 else if ((align & 0x3) == 0)
1930 align = 4;
1931 else if ((align & 0x1) == 0)
1932 align = 2;
1933 else
1934 align = 1;
1935 break;
1936
1937 case PLUS:
1938 align = MIN (i960_expr_alignment (XEXP (x, 0), size),
1939 i960_expr_alignment (XEXP (x, 1), size));
1940 break;
1941
1942 case SYMBOL_REF:
1943 /* If this is a valid program, objects are guaranteed to be
1944 correctly aligned for whatever size the reference actually is. */
1945 align = i960_object_bytes_bitalign (size) / BITS_PER_UNIT;
1946 break;
1947
1948 case REG:
1949 if (REGNO (x) == FRAME_POINTER_REGNUM)
1950 align = 16;
1951 break;
1952
1953 case ASHIFT:
1954 align = i960_expr_alignment (XEXP (x, 0));
1955
1956 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
1957 {
1958 align = align << INTVAL (XEXP (x, 1));
1959 align = MIN (align, 16);
1960 }
1961 break;
1962
1963 case MULT:
1964 align = (i960_expr_alignment (XEXP (x, 0), size) *
1965 i960_expr_alignment (XEXP (x, 1), size));
1966
1967 align = MIN (align, 16);
1968 break;
1969 }
1970
1971 return align;
1972 }
1973
1974 /* Return true if it is possible to reference both BASE and OFFSET, which
1975 have alignment at least as great as 4 byte, as if they had alignment valid
1976 for an object of size SIZE. */
1977
1978 int
1979 i960_improve_align (base, offset, size)
1980 rtx base;
1981 rtx offset;
1982 int size;
1983 {
1984 int i, j;
1985
1986 /* We have at least a word reference to the object, so we know it has to
1987 be aligned at least to 4 bytes. */
1988
1989 i = MIN (i960_expr_alignment (base, 4),
1990 i960_expr_alignment (offset, 4));
1991
1992 i = MAX (i, 4);
1993
1994 /* We know the size of the request. If strict align is not enabled, we
1995 can guess that the alignment is OK for the requested size. */
1996
1997 if (! TARGET_STRICT_ALIGN)
1998 if ((j = (i960_object_bytes_bitalign (size) / BITS_PER_UNIT)) > i)
1999 i = j;
2000
2001 return (i >= size);
2002 }
2003
2004 /* Return true if it is possible to access BASE and OFFSET, which have 4 byte
2005 (SImode) alignment as if they had 16 byte (TImode) alignment. */
2006
2007 int
2008 i960_si_ti (base, offset)
2009 rtx base;
2010 rtx offset;
2011 {
2012 return i960_improve_align (base, offset, 16);
2013 }
2014
2015 /* Return true if it is possible to access BASE and OFFSET, which have 4 byte
2016 (SImode) alignment as if they had 8 byte (DImode) alignment. */
2017
2018 int
2019 i960_si_di (base, offset)
2020 rtx base;
2021 rtx offset;
2022 {
2023 return i960_improve_align (base, offset, 8);
2024 }
2025 \f
2026 /* Return raw values of size and alignment (in words) for the data
2027 type being accessed. These values will be rounded by the caller. */
2028
2029 static void
2030 i960_arg_size_and_align (mode, type, size_out, align_out)
2031 enum machine_mode mode;
2032 tree type;
2033 int *size_out;
2034 int *align_out;
2035 {
2036 int size, align;
2037
2038 /* Use formal alignment requirements of type being passed, except make
2039 it at least a word. If we don't have a type, this is a library call,
2040 and the parm has to be of scalar type. In this case, consider its
2041 formal alignment requirement to be its size in words. */
2042
2043 if (mode == BLKmode)
2044 size = (int_size_in_bytes (type) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2045 else if (mode == VOIDmode)
2046 {
2047 /* End of parm list. */
2048 assert (type != 0 && TYPE_MODE (type) == VOIDmode);
2049 size = 1;
2050 }
2051 else
2052 size = (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2053
2054 if (type == 0)
2055 align = size;
2056 else if (TYPE_ALIGN (type) >= BITS_PER_WORD)
2057 align = TYPE_ALIGN (type) / BITS_PER_WORD;
2058 else
2059 align = 1;
2060
2061 *size_out = size;
2062 *align_out = align;
2063 }
2064
2065 /* On the 80960 the first 12 args are in registers and the rest are pushed.
2066 Any arg that is bigger than 4 words is placed on the stack and all
2067 subsequent arguments are placed on the stack.
2068
2069 Additionally, parameters with an alignment requirement stronger than
2070 a word must be be aligned appropriately. */
2071
2072 /* Update CUM to advance past an argument described by MODE and TYPE. */
2073
2074 void
2075 i960_function_arg_advance (cum, mode, type, named)
2076 CUMULATIVE_ARGS *cum;
2077 enum machine_mode mode;
2078 tree type;
2079 int named;
2080 {
2081 int size, align;
2082
2083 i960_arg_size_and_align (mode, type, &size, &align);
2084
2085 if (size > 4 || cum->ca_nstackparms != 0
2086 || (size + ROUND_PARM (cum->ca_nregparms, align)) > NPARM_REGS
2087 || MUST_PASS_IN_STACK (mode, type))
2088 {
2089 /* Indicate that all the registers are in use, even if all are not,
2090 so va_start will compute the right value. */
2091 cum->ca_nregparms = NPARM_REGS;
2092 cum->ca_nstackparms = ROUND_PARM (cum->ca_nstackparms, align) + size;
2093 }
2094 else
2095 cum->ca_nregparms = ROUND_PARM (cum->ca_nregparms, align) + size;
2096 }
2097
2098 /* Return the register that the argument described by MODE and TYPE is
2099 passed in, or else return 0 if it is passed on the stack. */
2100
2101 rtx
2102 i960_function_arg (cum, mode, type, named)
2103 CUMULATIVE_ARGS *cum;
2104 enum machine_mode mode;
2105 tree type;
2106 int named;
2107 {
2108 rtx ret;
2109 int size, align;
2110
2111 i960_arg_size_and_align (mode, type, &size, &align);
2112
2113 if (size > 4 || cum->ca_nstackparms != 0
2114 || (size + ROUND_PARM (cum->ca_nregparms, align)) > NPARM_REGS
2115 || MUST_PASS_IN_STACK (mode, type))
2116 {
2117 cum->ca_nstackparms = ROUND_PARM (cum->ca_nstackparms, align);
2118 ret = 0;
2119 }
2120 else
2121 {
2122 cum->ca_nregparms = ROUND_PARM (cum->ca_nregparms, align);
2123 ret = gen_rtx (REG, mode, cum->ca_nregparms);
2124 }
2125
2126 return ret;
2127 }
2128 \f
2129 /* Floating-point support. */
2130
2131 void
2132 i960_output_long_double (file, value)
2133 FILE *file;
2134 REAL_VALUE_TYPE value;
2135 {
2136 long value_long[3];
2137 char dstr[30];
2138
2139 REAL_VALUE_TO_TARGET_LONG_DOUBLE (value, value_long);
2140 REAL_VALUE_TO_DECIMAL (value, "%.20g", dstr);
2141
2142 fprintf (file,
2143 "\t.word\t0x%08lx\t\t# %s\n\t.word\t0x%08lx\n\t.word\t0x%08lx\n",
2144 value_long[0], dstr, value_long[1], value_long[2]);
2145 fprintf (file, "\t.word\t0x0\n");
2146 }
2147
2148 void
2149 i960_output_double (file, value)
2150 FILE *file;
2151 REAL_VALUE_TYPE value;
2152 {
2153 long value_long[2];
2154 char dstr[30];
2155
2156 REAL_VALUE_TO_TARGET_DOUBLE (value, value_long);
2157 REAL_VALUE_TO_DECIMAL (value, "%.20g", dstr);
2158
2159 fprintf (file, "\t.word\t0x%08lx\t\t# %s\n\t.word\t0x%08lx\n",
2160 value_long[0], dstr, value_long[1]);
2161 }
2162
2163 void
2164 i960_output_float (file, value)
2165 FILE *file;
2166 REAL_VALUE_TYPE value;
2167 {
2168 long value_long;
2169 char dstr[30];
2170
2171 REAL_VALUE_TO_TARGET_SINGLE (value, value_long);
2172 REAL_VALUE_TO_DECIMAL (value, "%.12g", dstr);
2173
2174 fprintf (file, "\t.word\t0x%08lx\t\t# %s (float)\n", value_long, dstr);
2175 }
2176 \f
2177 /* Return the number of bits that an object of size N bytes is aligned to. */
2178
2179 int
2180 i960_object_bytes_bitalign (n)
2181 int n;
2182 {
2183 if (n > 8) n = 128;
2184 else if (n > 4) n = 64;
2185 else if (n > 2) n = 32;
2186 else if (n > 1) n = 16;
2187 else n = 8;
2188
2189 return n;
2190 }
2191
2192 /* Compute the alignment for an aggregate type TSIZE.
2193 Alignment is MAX (greatest member alignment,
2194 MIN (pragma align, structure size alignment)). */
2195
2196 int
2197 i960_round_align (align, tsize)
2198 int align;
2199 tree tsize;
2200 {
2201 int new_align;
2202
2203 if (TREE_CODE (tsize) != INTEGER_CST)
2204 return align;
2205
2206 new_align = i960_object_bytes_bitalign (TREE_INT_CST_LOW (tsize)
2207 / BITS_PER_UNIT);
2208 /* Handle #pragma align. */
2209 if (new_align > i960_maxbitalignment)
2210 new_align = i960_maxbitalignment;
2211
2212 if (align < new_align)
2213 align = new_align;
2214
2215 return align;
2216 }
2217 \f
2218 /* Do any needed setup for a varargs function. For the i960, we must
2219 create a register parameter block if one doesn't exist, and then copy
2220 all register parameters to memory. */
2221
2222 void
2223 i960_setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
2224 CUMULATIVE_ARGS *cum;
2225 enum machine_mode mode;
2226 tree type;
2227 int *pretend_size;
2228 int no_rtl;
2229 {
2230 /* Note: for a varargs fn with only a va_alist argument, this is 0. */
2231 int first_reg = cum->ca_nregparms;
2232
2233 /* Copy only unnamed register arguments to memory. If there are
2234 any stack parms, there are no unnamed arguments in registers, and
2235 an argument block was already allocated by the caller.
2236 Remember that any arg bigger than 4 words is passed on the stack as
2237 are all subsequent args.
2238
2239 If there are no stack arguments but there are exactly NPARM_REGS
2240 registers, either there were no extra arguments or the caller
2241 allocated an argument block. */
2242
2243 if (cum->ca_nstackparms == 0 && first_reg < NPARM_REGS && !no_rtl)
2244 {
2245 rtx label = gen_label_rtx ();
2246 rtx regblock;
2247
2248 /* If arg_pointer_rtx == 0, no arguments were passed on the stack
2249 and we need to allocate a chunk to save the registers (if any
2250 arguments were passed on the stack the caller would allocate the
2251 48 bytes as well). We must allocate all 48 bytes (12*4) because
2252 va_start assumes it. */
2253 emit_insn (gen_cmpsi (arg_pointer_rtx, const0_rtx));
2254 emit_jump_insn (gen_bne (label));
2255 emit_insn (gen_rtx (SET, VOIDmode, arg_pointer_rtx,
2256 stack_pointer_rtx));
2257 emit_insn (gen_rtx (SET, VOIDmode, stack_pointer_rtx,
2258 memory_address (SImode,
2259 plus_constant (stack_pointer_rtx,
2260 48))));
2261 emit_label (label);
2262
2263 /* ??? Note that we unnecessarily store one extra register for stdarg
2264 fns. We could optimize this, but it's kept as for now. */
2265 regblock = gen_rtx (MEM, BLKmode,
2266 plus_constant (arg_pointer_rtx,
2267 first_reg * 4));
2268 move_block_from_reg (first_reg, regblock,
2269 NPARM_REGS - first_reg,
2270 (NPARM_REGS - first_reg) * UNITS_PER_WORD);
2271 }
2272 }
2273
2274 /* Calculate the final size of the reg parm stack space for the current
2275 function, based on how many bytes would be allocated on the stack. */
2276
2277 int
2278 i960_final_reg_parm_stack_space (const_size, var_size)
2279 int const_size;
2280 tree var_size;
2281 {
2282 if (var_size || const_size > 48)
2283 return 48;
2284 else
2285 return 0;
2286 }
2287
2288 /* Calculate the size of the reg parm stack space. This is a bit complicated
2289 on the i960. */
2290
2291 int
2292 i960_reg_parm_stack_space (fndecl)
2293 tree fndecl;
2294 {
2295 /* In this case, we are called from emit_library_call, and we don't need
2296 to pretend we have more space for parameters than what's apparent. */
2297 if (fndecl == 0)
2298 return 0;
2299
2300 /* In this case, we are called from locate_and_pad_parms when we're
2301 not IN_REGS, so we have an arg block. */
2302 if (fndecl != current_function_decl)
2303 return 48;
2304
2305 /* Otherwise, we have an arg block if the current function has more than
2306 48 bytes of parameters. */
2307 if (current_function_args_size != 0 || VARARGS_STDARG_FUNCTION (fndecl))
2308 return 48;
2309 else
2310 return 0;
2311 }
2312 \f
2313 /* Return the register class of a scratch register needed to copy IN into
2314 or out of a register in CLASS in MODE. If it can be done directly,
2315 NO_REGS is returned. */
2316
2317 enum reg_class
2318 secondary_reload_class (class, mode, in)
2319 enum reg_class class;
2320 enum machine_mode mode;
2321 rtx in;
2322 {
2323 int regno = -1;
2324
2325 if (GET_CODE (in) == REG || GET_CODE (in) == SUBREG)
2326 regno = true_regnum (in);
2327
2328 /* We can place anything into LOCAL_OR_GLOBAL_REGS and can put
2329 LOCAL_OR_GLOBAL_REGS into anything. */
2330 if (class == LOCAL_OR_GLOBAL_REGS || class == LOCAL_REGS
2331 || class == GLOBAL_REGS || (regno >= 0 && regno < 32))
2332 return NO_REGS;
2333
2334 /* We can place any hard register, 0.0, and 1.0 into FP_REGS. */
2335 if (class == FP_REGS
2336 && ((regno >= 0 && regno < FIRST_PSEUDO_REGISTER)
2337 || in == CONST0_RTX (mode) || in == CONST1_RTX (mode)))
2338 return NO_REGS;
2339
2340 return LOCAL_OR_GLOBAL_REGS;
2341 }
2342 \f
2343 /* Look at the opcode P, and set i96_last_insn_type to indicate which
2344 function unit it executed on. */
2345
2346 /* ??? This would make more sense as an attribute. */
2347
2348 void
2349 i960_scan_opcode (p)
2350 char *p;
2351 {
2352 switch (*p)
2353 {
2354 case 'a':
2355 case 'd':
2356 case 'e':
2357 case 'm':
2358 case 'n':
2359 case 'o':
2360 case 'r':
2361 /* Ret is not actually of type REG, but it won't matter, because no
2362 insn will ever follow it. */
2363 case 'u':
2364 case 'x':
2365 i960_last_insn_type = I_TYPE_REG;
2366 break;
2367
2368 case 'b':
2369 if (p[1] == 'x' || p[3] == 'x')
2370 i960_last_insn_type = I_TYPE_MEM;
2371 i960_last_insn_type = I_TYPE_CTRL;
2372 break;
2373
2374 case 'f':
2375 case 't':
2376 i960_last_insn_type = I_TYPE_CTRL;
2377 break;
2378
2379 case 'c':
2380 if (p[1] == 'a')
2381 {
2382 if (p[4] == 'x')
2383 i960_last_insn_type = I_TYPE_MEM;
2384 else
2385 i960_last_insn_type = I_TYPE_CTRL;
2386 }
2387 else if (p[1] == 'm')
2388 {
2389 if (p[3] == 'd')
2390 i960_last_insn_type = I_TYPE_REG;
2391 else if (p[4] == 'b' || p[4] == 'j')
2392 i960_last_insn_type = I_TYPE_CTRL;
2393 else
2394 i960_last_insn_type = I_TYPE_REG;
2395 }
2396 else
2397 i960_last_insn_type = I_TYPE_REG;
2398 break;
2399
2400 case 'l':
2401 i960_last_insn_type = I_TYPE_MEM;
2402 break;
2403
2404 case 's':
2405 if (p[1] == 't')
2406 i960_last_insn_type = I_TYPE_MEM;
2407 else
2408 i960_last_insn_type = I_TYPE_REG;
2409 break;
2410 }
2411 }