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