OSDN Git Service

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