OSDN Git Service

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