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