OSDN Git Service

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