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