OSDN Git Service

(output_move_double): Handle reg[n,n+1] = mem[reg[n] + reg[n+1]].
[pf3gnuchains/gcc-fork.git] / gcc / config / i860 / i860.c
1 /* Subroutines for insn-output.c for Intel 860
2    Copyright (C) 1989, 1991 Free Software Foundation, Inc.
3    Derived from sparc.c.
4
5    Written by Richard Stallman (rms@ai.mit.edu).
6
7    Hacked substantially by Ron Guilmette (rfg@ncd.com) to cater
8    to the whims of the System V Release 4 assembler.
9
10 This file is part of GNU CC.
11
12 GNU CC is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option)
15 any later version.
16
17 GNU CC is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with GNU CC; see the file COPYING.  If not, write to
24 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
25
26
27 #include "config.h"
28 #include "flags.h"
29 #include "rtl.h"
30 #include "regs.h"
31 #include "hard-reg-set.h"
32 #include "real.h"
33 #include "insn-config.h"
34 #include "conditions.h"
35 #include "insn-flags.h"
36 #include "output.h"
37 #include "recog.h"
38 #include "insn-attr.h"
39
40 #include <stdio.h>
41
42 static rtx find_addr_reg ();
43
44 #ifndef I860_REG_PREFIX
45 #define I860_REG_PREFIX ""
46 #endif
47
48 char *i860_reg_prefix = I860_REG_PREFIX;
49
50 /* Save information from a "cmpxx" operation until the branch is emitted.  */
51
52 rtx i860_compare_op0, i860_compare_op1;
53 \f
54 /* Return non-zero if this pattern, can be evaluated safely, even if it
55    was not asked for.  */
56 int
57 safe_insn_src_p (op, mode)
58      rtx op;
59      enum machine_mode mode;
60 {
61   /* Just experimenting.  */
62
63   /* No floating point src is safe if it contains an arithmetic
64      operation, since that operation may trap.  */
65   switch (GET_CODE (op))
66     {
67     case CONST_INT:
68     case LABEL_REF:
69     case SYMBOL_REF:
70     case CONST:
71       return 1;
72
73     case REG:
74       return 1;
75
76     case MEM:
77       return CONSTANT_ADDRESS_P (XEXP (op, 0));
78
79       /* We never need to negate or complement constants.  */
80     case NEG:
81       return (mode != SFmode && mode != DFmode);
82     case NOT:
83     case ZERO_EXTEND:
84       return 1;
85
86     case EQ:
87     case NE:
88     case LT:
89     case GT:
90     case LE:
91     case GE:
92     case LTU:
93     case GTU:
94     case LEU:
95     case GEU:
96     case MINUS:
97     case PLUS:
98       return (mode != SFmode && mode != DFmode);
99     case AND:
100     case IOR:
101     case XOR:
102     case LSHIFT:
103     case ASHIFT:
104     case ASHIFTRT:
105     case LSHIFTRT:
106       if ((GET_CODE (XEXP (op, 0)) == CONST_INT && ! SMALL_INT (XEXP (op, 0)))
107           || (GET_CODE (XEXP (op, 1)) == CONST_INT && ! SMALL_INT (XEXP (op, 1))))
108         return 0;
109       return 1;
110
111     default:
112       return 0;
113     }
114 }
115
116 /* Return 1 if REG is clobbered in IN.
117    Return 2 if REG is used in IN. 
118    Return 3 if REG is both used and clobbered in IN.
119    Return 0 if neither.  */
120
121 static int
122 reg_clobbered_p (reg, in)
123      rtx reg;
124      rtx in;
125 {
126   register enum rtx_code code;
127
128   if (in == 0)
129     return 0;
130
131   code = GET_CODE (in);
132
133   if (code == SET || code == CLOBBER)
134     {
135       rtx dest = SET_DEST (in);
136       int set = 0;
137       int used = 0;
138
139       while (GET_CODE (dest) == STRICT_LOW_PART
140              || GET_CODE (dest) == SUBREG
141              || GET_CODE (dest) == SIGN_EXTRACT
142              || GET_CODE (dest) == ZERO_EXTRACT)
143         dest = XEXP (dest, 0);
144
145       if (dest == reg)
146         set = 1;
147       else if (GET_CODE (dest) == REG
148                && refers_to_regno_p (REGNO (reg),
149                                      REGNO (reg) + HARD_REGNO_NREGS (reg, GET_MODE (reg)),
150                                      SET_DEST (in), 0))
151         {
152           set = 1;
153           /* Anything that sets just part of the register
154              is considered using as well as setting it.
155              But note that a straight SUBREG of a single-word value
156              clobbers the entire value.   */
157           if (dest != SET_DEST (in)
158               && ! (GET_CODE (SET_DEST (in)) == SUBREG
159                     || UNITS_PER_WORD >= GET_MODE_SIZE (GET_MODE (dest))))
160             used = 1;
161         }
162
163       if (code == SET)
164         {
165           if (set)
166             used = refers_to_regno_p (REGNO (reg),
167                                       REGNO (reg) + HARD_REGNO_NREGS (reg, GET_MODE (reg)),
168                                       SET_SRC (in), 0);
169           else
170             used = refers_to_regno_p (REGNO (reg),
171                                       REGNO (reg) + HARD_REGNO_NREGS (reg, GET_MODE (reg)),
172                                       in, 0);
173         }
174
175       return set + used * 2;
176     }
177
178   if (refers_to_regno_p (REGNO (reg),
179                          REGNO (reg) + HARD_REGNO_NREGS (reg, GET_MODE (reg)),
180                          in, 0))
181     return 2;
182   return 0;
183 }
184
185 /* Return non-zero if OP can be written to without screwing up
186    GCC's model of what's going on.  It is assumed that this operand
187    appears in the dest position of a SET insn in a conditional
188    branch's delay slot.  AFTER is the label to start looking from.  */
189 int
190 operand_clobbered_before_used_after (op, after)
191      rtx op;
192      rtx after;
193 {
194   /* Just experimenting.  */
195   if (GET_CODE (op) == CC0)
196     return 1;
197   if (GET_CODE (op) == REG)
198     {
199       rtx insn;
200
201       if (op == stack_pointer_rtx)
202         return 0;
203
204       /* Scan forward from the label, to see if the value of OP
205          is clobbered before the first use.  */
206
207       for (insn = NEXT_INSN (after); insn; insn = NEXT_INSN (insn))
208         {
209           if (GET_CODE (insn) == NOTE)
210             continue;
211           if (GET_CODE (insn) == INSN
212               || GET_CODE (insn) == JUMP_INSN
213               || GET_CODE (insn) == CALL_INSN)
214             {
215               switch (reg_clobbered_p (op, PATTERN (insn)))
216                 {
217                 default:
218                   return 0;
219                 case 1:
220                   return 1;
221                 case 0:
222                   break;
223                 }
224             }
225           /* If we reach another label without clobbering OP,
226              then we cannot safely write it here.  */
227           else if (GET_CODE (insn) == CODE_LABEL)
228             return 0;
229           if (GET_CODE (insn) == JUMP_INSN)
230             {
231               if (condjump_p (insn))
232                 return 0;
233               /* This is a jump insn which has already
234                  been mangled.  We can't tell what it does.  */
235               if (GET_CODE (PATTERN (insn)) == PARALLEL)
236                 return 0;
237               if (! JUMP_LABEL (insn))
238                 return 0;
239               /* Keep following jumps.  */
240               insn = JUMP_LABEL (insn);
241             }
242         }
243       return 1;
244     }
245
246   /* In both of these cases, the first insn executed
247      for this op will be a orh whatever%h,%?r0,%?r31,
248      which is tolerable.  */
249   if (GET_CODE (op) == MEM)
250     return (CONSTANT_ADDRESS_P (XEXP (op, 0)));
251
252   return 0;
253 }
254
255 /* Return non-zero if this pattern, as a source to a "SET",
256    is known to yield an instruction of unit size.  */
257 int
258 single_insn_src_p (op, mode)
259      rtx op;
260      enum machine_mode mode;
261 {
262   switch (GET_CODE (op))
263     {
264     case CONST_INT:
265       /* This is not always a single insn src, technically,
266          but output_delayed_branch knows how to deal with it.  */
267       return 1;
268
269     case SYMBOL_REF:
270     case CONST:
271       /* This is not a single insn src, technically,
272          but output_delayed_branch knows how to deal with it.  */
273       return 1;
274
275     case REG:
276       return 1;
277
278     case MEM:
279       return 1;
280
281       /* We never need to negate or complement constants.  */
282     case NEG:
283       return (mode != DFmode);
284     case NOT:
285     case ZERO_EXTEND:
286       return 1;
287
288     case PLUS:
289     case MINUS:
290       /* Detect cases that require multiple instructions.  */
291       if (CONSTANT_P (XEXP (op, 1))
292           && !(GET_CODE (XEXP (op, 1)) == CONST_INT
293                && SMALL_INT (XEXP (op, 1))))
294         return 0;
295     case EQ:
296     case NE:
297     case LT:
298     case GT:
299     case LE:
300     case GE:
301     case LTU:
302     case GTU:
303     case LEU:
304     case GEU:
305       /* Not doing floating point, since they probably
306          take longer than the branch slot they might fill.  */
307       return (mode != SFmode && mode != DFmode);
308
309     case AND:
310       if (GET_CODE (XEXP (op, 1)) == NOT)
311         {
312           rtx arg = XEXP (XEXP (op, 1), 0);
313           if (CONSTANT_P (arg)
314               && !(GET_CODE (arg) == CONST_INT
315                    && (SMALL_INT (arg)
316                        || INTVAL (arg) & 0xffff == 0)))
317             return 0;
318         }
319     case IOR:
320     case XOR:
321       /* Both small and round numbers take one instruction;
322          others take two.  */
323       if (CONSTANT_P (XEXP (op, 1))
324           && !(GET_CODE (XEXP (op, 1)) == CONST_INT
325                && (SMALL_INT (XEXP (op, 1))
326                    || INTVAL (XEXP (op, 1)) & 0xffff == 0)))
327         return 0;
328
329     case LSHIFT:
330     case ASHIFT:
331     case ASHIFTRT:
332     case LSHIFTRT:
333       return 1;
334
335     case SUBREG:
336       if (SUBREG_WORD (op) != 0)
337         return 0;
338       return single_insn_src_p (SUBREG_REG (op), mode);
339
340       /* Not doing floating point, since they probably
341          take longer than the branch slot they might fill.  */
342     case FLOAT_EXTEND:
343     case FLOAT_TRUNCATE:
344     case FLOAT:
345     case FIX:
346     case UNSIGNED_FLOAT:
347     case UNSIGNED_FIX:
348       return 0;
349
350     default:
351       return 0;
352     }
353 }
354 \f
355 /* Return non-zero only if OP is a register of mode MODE,
356    or const0_rtx.  */
357 int
358 reg_or_0_operand (op, mode)
359      rtx op;
360      enum machine_mode mode;
361 {
362   return (op == const0_rtx || register_operand (op, mode)
363           || op == CONST0_RTX (mode));
364 }
365
366 /* Return truth value of whether OP can be used as an operands in a three
367    address add/subtract insn (such as add %o1,7,%l2) of mode MODE.  */
368
369 int
370 arith_operand (op, mode)
371      rtx op;
372      enum machine_mode mode;
373 {
374   return (register_operand (op, mode)
375           || (GET_CODE (op) == CONST_INT && SMALL_INT (op)));
376 }
377
378 /* Return 1 if OP is a valid first operand for a logical insn of mode MODE.  */
379
380 int
381 logic_operand (op, mode)
382      rtx op;
383      enum machine_mode mode;
384 {
385   return (register_operand (op, mode)
386           || (GET_CODE (op) == CONST_INT && LOGIC_INT (op)));
387 }
388
389 /* Return 1 if OP is a valid first operand for a shift insn of mode MODE.  */
390
391 int
392 shift_operand (op, mode)
393      rtx op;
394      enum machine_mode mode;
395 {
396   return (register_operand (op, mode)
397           || (GET_CODE (op) == CONST_INT));
398 }
399
400 /* Return 1 if OP is a valid first operand for either a logical insn
401    or an add insn of mode MODE.  */
402
403 int
404 compare_operand (op, mode)
405      rtx op;
406      enum machine_mode mode;
407 {
408   return (register_operand (op, mode)
409           || (GET_CODE (op) == CONST_INT && SMALL_INT (op) && LOGIC_INT (op)));
410 }
411
412 /* Return truth value of whether OP can be used as the 5-bit immediate
413    operand of a bte or btne insn.  */
414
415 int
416 bte_operand (op, mode)
417      rtx op;
418      enum machine_mode mode;
419 {
420   return (register_operand (op, mode)
421           || (GET_CODE (op) == CONST_INT
422               && (unsigned) INTVAL (op) < 0x20));
423 }
424
425 /* Return 1 if OP is an indexed memory reference of mode MODE.  */
426
427 int
428 indexed_operand (op, mode)
429      rtx op;
430      enum machine_mode mode;
431 {
432   return (GET_CODE (op) == MEM && GET_MODE (op) == mode
433           && GET_CODE (XEXP (op, 0)) == PLUS
434           && GET_MODE (XEXP (op, 0)) == SImode
435           && register_operand (XEXP (XEXP (op, 0), 0), SImode)
436           && register_operand (XEXP (XEXP (op, 0), 1), SImode));
437 }
438
439 /* Return 1 if OP is a suitable source operand for a load insn
440    with mode MODE.  */
441
442 int
443 load_operand (op, mode)
444      rtx op;
445      enum machine_mode mode;
446 {
447   return (memory_operand (op, mode) || indexed_operand (op, mode));
448 }
449
450 /* Return truth value of whether OP is a integer which fits the
451    range constraining immediate operands in add/subtract insns.  */
452
453 int
454 small_int (op, mode)
455      rtx op;
456      enum machine_mode mode;
457 {
458   return (GET_CODE (op) == CONST_INT && SMALL_INT (op));
459 }
460
461 /* Return truth value of whether OP is a integer which fits the
462    range constraining immediate operands in logic insns.  */
463
464 int
465 logic_int (op, mode)
466      rtx op;
467      enum machine_mode mode;
468 {
469   return (GET_CODE (op) == CONST_INT && LOGIC_INT (op));
470 }
471
472 /* Test for a valid operand for a call instruction.
473    Don't allow the arg pointer register or virtual regs
474    since they may change into reg + const, which the patterns
475    can't handle yet.  */
476
477 int
478 call_insn_operand (op, mode)
479      rtx op;
480      enum machine_mode mode;
481 {
482   if (GET_CODE (op) == MEM
483       && (CONSTANT_ADDRESS_P (XEXP (op, 0))
484           || (GET_CODE (XEXP (op, 0)) == REG
485               && XEXP (op, 0) != arg_pointer_rtx
486               && !(REGNO (XEXP (op, 0)) >= FIRST_PSEUDO_REGISTER
487                    && REGNO (XEXP (op, 0)) <= LAST_VIRTUAL_REGISTER))))
488     return 1;
489   return 0;
490 }
491 \f
492 /* Return the best assembler insn template
493    for moving operands[1] into operands[0] as a fullword.  */
494
495 static char *
496 singlemove_string (operands)
497      rtx *operands;
498 {
499   if (GET_CODE (operands[0]) == MEM)
500     {
501       if (GET_CODE (operands[1]) != MEM)
502         if (CONSTANT_ADDRESS_P (XEXP (operands[0], 0)))
503           {
504             if (! ((cc_prev_status.flags & CC_KNOW_HI_R31)
505                    && (cc_prev_status.flags & CC_HI_R31_ADJ)
506                    && cc_prev_status.mdep == XEXP (operands[0], 0)))
507               {
508                 CC_STATUS_INIT;
509                 output_asm_insn ("orh %h0,%?r0,%?r31", operands);
510               }
511             cc_status.flags |= CC_KNOW_HI_R31 | CC_HI_R31_ADJ;
512             cc_status.mdep = XEXP (operands[0], 0);
513             return "st.l %r1,%L0(%?r31)";
514           }
515         else
516           return "st.l %r1,%0";
517       else
518         abort ();
519 #if 0
520         {
521           rtx xoperands[2];
522
523           cc_status.flags &= ~CC_F0_IS_0;
524           xoperands[0] = gen_rtx (REG, SFmode, 32);
525           xoperands[1] = operands[1];
526           output_asm_insn (singlemove_string (xoperands), xoperands);
527           xoperands[1] = xoperands[0];
528           xoperands[0] = operands[0];
529           output_asm_insn (singlemove_string (xoperands), xoperands);
530           return "";
531         }
532 #endif
533     }
534   if (GET_CODE (operands[1]) == MEM)
535     {
536       if (CONSTANT_ADDRESS_P (XEXP (operands[1], 0)))
537         {
538           if (! ((cc_prev_status.flags & CC_KNOW_HI_R31)
539                  && (cc_prev_status.flags & CC_HI_R31_ADJ)
540                  && cc_prev_status.mdep == XEXP (operands[1], 0)))
541             {
542               CC_STATUS_INIT;
543               output_asm_insn ("orh %h1,%?r0,%?r31", operands);
544             }
545           cc_status.flags |= CC_KNOW_HI_R31 | CC_HI_R31_ADJ;
546           cc_status.mdep = XEXP (operands[1], 0);
547           return "ld.l %L1(%?r31),%0";
548         }
549       return "ld.l %m1,%0";
550     }
551  if (GET_CODE (operands[1]) == CONST_INT)
552    {
553      if (operands[1] == const0_rtx)
554       return "mov %?r0,%0";
555      if((INTVAL (operands[1]) & 0xffff0000) == 0)
556       return "or %L1,%?r0,%0";
557      if((INTVAL (operands[1]) & 0xffff8000) == 0xffff8000)
558       return "adds %1,%?r0,%0";
559      if((INTVAL (operands[1]) & 0x0000ffff) == 0)
560       return "orh %H1,%?r0,%0";
561    }
562   return "mov %1,%0";
563 }
564 \f
565 /* Output assembler code to perform a doubleword move insn
566    with operands OPERANDS.  */
567
568 char *
569 output_move_double (operands)
570      rtx *operands;
571 {
572   enum { REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP } optype0, optype1;
573   rtx latehalf[2];
574   rtx addreg0 = 0, addreg1 = 0;
575
576   /* First classify both operands.  */
577
578   if (REG_P (operands[0]))
579     optype0 = REGOP;
580   else if (offsettable_memref_p (operands[0]))
581     optype0 = OFFSOP;
582   else if (GET_CODE (operands[0]) == MEM)
583     optype0 = MEMOP;
584   else
585     optype0 = RNDOP;
586
587   if (REG_P (operands[1]))
588     optype1 = REGOP;
589   else if (CONSTANT_P (operands[1]))
590     optype1 = CNSTOP;
591   else if (offsettable_memref_p (operands[1]))
592     optype1 = OFFSOP;
593   else if (GET_CODE (operands[1]) == MEM)
594     optype1 = MEMOP;
595   else
596     optype1 = RNDOP;
597
598   /* Check for the cases that the operand constraints are not
599      supposed to allow to happen.  Abort if we get one,
600      because generating code for these cases is painful.  */
601
602   if (optype0 == RNDOP || optype1 == RNDOP)
603     abort ();
604
605   /* If an operand is an unoffsettable memory ref, find a register
606      we can increment temporarily to make it refer to the second word.  */
607
608   if (optype0 == MEMOP)
609     addreg0 = find_addr_reg (XEXP (operands[0], 0));
610
611   if (optype1 == MEMOP)
612     addreg1 = find_addr_reg (XEXP (operands[1], 0));
613
614 /* ??? Perhaps in some cases move double words
615    if there is a spare pair of floating regs.  */
616
617   /* Ok, we can do one word at a time.
618      Normally we do the low-numbered word first,
619      but if either operand is autodecrementing then we
620      do the high-numbered word first.
621
622      In either case, set up in LATEHALF the operands to use
623      for the high-numbered word and in some cases alter the
624      operands in OPERANDS to be suitable for the low-numbered word.  */
625
626   if (optype0 == REGOP)
627     latehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 1);
628   else if (optype0 == OFFSOP)
629     latehalf[0] = adj_offsettable_operand (operands[0], 4);
630   else
631     latehalf[0] = operands[0];
632
633   if (optype1 == REGOP)
634     latehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
635   else if (optype1 == OFFSOP)
636     latehalf[1] = adj_offsettable_operand (operands[1], 4);
637   else if (optype1 == CNSTOP)
638     {
639       if (GET_CODE (operands[1]) == CONST_DOUBLE)
640         split_double (operands[1], &operands[1], &latehalf[1]);
641       else if (CONSTANT_P (operands[1]))
642         latehalf[1] = const0_rtx;
643     }
644   else
645     latehalf[1] = operands[1];
646
647   /* If the first move would clobber the source of the second one,
648      do them in the other order.
649
650      RMS says "This happens only for registers;
651      such overlap can't happen in memory unless the user explicitly
652      sets it up, and that is an undefined circumstance."
653
654      but it happens on the sparc when loading parameter registers,
655      so I am going to define that circumstance, and make it work
656      as expected.  */
657
658   if (optype0 == REGOP && optype1 == REGOP
659       && REGNO (operands[0]) == REGNO (latehalf[1]))
660     {
661       CC_STATUS_PARTIAL_INIT;
662       /* Make any unoffsettable addresses point at high-numbered word.  */
663       if (addreg0)
664         output_asm_insn ("adds 0x4,%0,%0", &addreg0);
665       if (addreg1)
666         output_asm_insn ("adds 0x4,%0,%0", &addreg1);
667
668       /* Do that word.  */
669       output_asm_insn (singlemove_string (latehalf), latehalf);
670
671       /* Undo the adds we just did.  */
672       if (addreg0)
673         output_asm_insn ("adds -0x4,%0,%0", &addreg0);
674       if (addreg1)
675         output_asm_insn ("adds -0x4,%0,%0", &addreg1);
676
677       /* Do low-numbered word.  */
678       return singlemove_string (operands);
679     }
680   else if (optype0 == REGOP && optype1 != REGOP
681            && reg_overlap_mentioned_p (operands[0], operands[1]))
682     {
683       if (reg_mentioned_p (op0, XEXP (op1, 0))
684           && reg_mentioned_p (latehalf[0], XEXP (op1, 0)))
685         {
686           /* If both halves of dest are used in the src memory address,
687              add the two regs and put them in the low reg (op0).
688              Then it works to load latehalf first.  */
689           rtx xops[2];
690           xops[0] = latehalf[0];
691           xops[1] = op0;
692           output_asm_insn ("adds %1,%0,%1", xops);
693           operands[1] = gen_rtx (MEM, DImode, latehalf[0]);
694           latehalf[1] = adj_offsettable_operand (operands[1], 4);
695         }
696       /* Do the late half first.  */
697       output_asm_insn (singlemove_string (latehalf), latehalf);
698       /* Then clobber.  */
699       return singlemove_string (operands);
700     }
701
702   /* Normal case: do the two words, low-numbered first.  */
703
704   output_asm_insn (singlemove_string (operands), operands);
705
706   CC_STATUS_PARTIAL_INIT;
707   /* Make any unoffsettable addresses point at high-numbered word.  */
708   if (addreg0)
709     output_asm_insn ("adds 0x4,%0,%0", &addreg0);
710   if (addreg1)
711     output_asm_insn ("adds 0x4,%0,%0", &addreg1);
712
713   /* Do that word.  */
714   output_asm_insn (singlemove_string (latehalf), latehalf);
715
716   /* Undo the adds we just did.  */
717   if (addreg0)
718     output_asm_insn ("adds -0x4,%0,%0", &addreg0);
719   if (addreg1)
720     output_asm_insn ("adds -0x4,%0,%0", &addreg1);
721
722   return "";
723 }
724 \f
725 char *
726 output_fp_move_double (operands)
727      rtx *operands;
728 {
729   /* If the source operand is any sort of zero, use f0 instead.  */
730
731   if (operands[1] == CONST0_RTX (GET_MODE (operands[1])))
732     operands[1] = gen_rtx (REG, DFmode, F0_REGNUM);
733
734   if (FP_REG_P (operands[0]))
735     {
736       if (FP_REG_P (operands[1]))
737         return "fmov.dd %1,%0";
738       if (GET_CODE (operands[1]) == REG)
739         {
740           output_asm_insn ("ixfr %1,%0", operands);
741           operands[0] = gen_rtx (REG, VOIDmode, REGNO (operands[0]) + 1);
742           operands[1] = gen_rtx (REG, VOIDmode, REGNO (operands[1]) + 1);
743           return "ixfr %1,%0";
744         }
745       if (operands[1] == CONST0_RTX (DFmode))
746         return "fmov.dd f0,%0";
747       if (CONSTANT_ADDRESS_P (XEXP (operands[1], 0)))
748         {
749           if (! ((cc_prev_status.flags & CC_KNOW_HI_R31)
750                  && (cc_prev_status.flags & CC_HI_R31_ADJ)
751                  && cc_prev_status.mdep == XEXP (operands[1], 0)))
752             {
753               CC_STATUS_INIT;
754               output_asm_insn ("orh %h1,%?r0,%?r31", operands);
755             }
756           cc_status.flags |= CC_KNOW_HI_R31 | CC_HI_R31_ADJ;
757           cc_status.mdep = XEXP (operands[1], 0);
758           return "fld.d %L1(%?r31),%0";
759         }
760       return "fld.d %1,%0";
761     }
762   else if (FP_REG_P (operands[1]))
763     {
764       if (GET_CODE (operands[0]) == REG)
765         {
766           output_asm_insn ("fxfr %1,%0", operands);
767           operands[0] = gen_rtx (REG, VOIDmode, REGNO (operands[0]) + 1);
768           operands[1] = gen_rtx (REG, VOIDmode, REGNO (operands[1]) + 1);
769           return "fxfr %1,%0";
770         }
771       if (CONSTANT_ADDRESS_P (XEXP (operands[0], 0)))
772         {
773           if (! ((cc_prev_status.flags & CC_KNOW_HI_R31)
774                  && (cc_prev_status.flags & CC_HI_R31_ADJ)
775                  && cc_prev_status.mdep == XEXP (operands[0], 0)))
776             {
777               CC_STATUS_INIT;
778               output_asm_insn ("orh %h0,%?r0,%?r31", operands);
779             }
780           cc_status.flags |= CC_KNOW_HI_R31 | CC_HI_R31_ADJ;
781           cc_status.mdep = XEXP (operands[0], 0);
782           return "fst.d %1,%L0(%?r31)";
783         }
784       return "fst.d %1,%0";
785     }
786   else
787     abort ();
788   /* NOTREACHED */
789   return NULL;
790 }
791 \f
792 /* Return a REG that occurs in ADDR with coefficient 1.
793    ADDR can be effectively incremented by incrementing REG.  */
794
795 static rtx
796 find_addr_reg (addr)
797      rtx addr;
798 {
799   while (GET_CODE (addr) == PLUS)
800     {
801       if (GET_CODE (XEXP (addr, 0)) == REG)
802         addr = XEXP (addr, 0);
803       else if (GET_CODE (XEXP (addr, 1)) == REG)
804         addr = XEXP (addr, 1);
805       else if (CONSTANT_P (XEXP (addr, 0)))
806         addr = XEXP (addr, 1);
807       else if (CONSTANT_P (XEXP (addr, 1)))
808         addr = XEXP (addr, 0);
809       else
810         abort ();
811     }
812   if (GET_CODE (addr) == REG)
813     return addr;
814   abort ();
815   /* NOTREACHED */
816   return NULL;
817 }
818
819 /* Return a template for a load instruction with mode MODE and
820    arguments from the string ARGS.
821
822    This string is in static storage.   */
823
824 static char *
825 load_opcode (mode, args, reg)
826      enum machine_mode mode;
827      char *args;
828      rtx reg;
829 {
830   static char buf[30];
831   char *opcode;
832
833   switch (mode)
834     {
835     case QImode:
836       opcode = "ld.b";
837       break;
838
839     case HImode:
840       opcode = "ld.s";
841       break;
842
843     case SImode:
844     case SFmode:
845       if (FP_REG_P (reg))
846         opcode = "fld.l";
847       else
848         opcode = "ld.l";
849       break;
850
851     case DImode:
852       if (!FP_REG_P (reg))
853         abort ();
854     case DFmode:
855       opcode = "fld.d";
856       break;
857
858     default:
859       abort ();
860     }
861
862   sprintf (buf, "%s %s", opcode, args);
863   return buf;
864 }
865
866 /* Return a template for a store instruction with mode MODE and
867    arguments from the string ARGS.
868
869    This string is in static storage.   */
870
871 static char *
872 store_opcode (mode, args, reg)
873      enum machine_mode mode;
874      char *args;
875      rtx reg;
876 {
877   static char buf[30];
878   char *opcode;
879
880   switch (mode)
881     {
882     case QImode:
883       opcode = "st.b";
884       break;
885
886     case HImode:
887       opcode = "st.s";
888       break;
889
890     case SImode:
891     case SFmode:
892       if (FP_REG_P (reg))
893         opcode = "fst.l";
894       else
895         opcode = "st.l";
896       break;
897
898     case DImode:
899       if (!FP_REG_P (reg))
900         abort ();
901     case DFmode:
902       opcode = "fst.d";
903       break;
904
905     default:
906       abort ();
907     }
908
909   sprintf (buf, "%s %s", opcode, args);
910   return buf;
911 }
912 \f
913 /* Output a store-in-memory whose operands are OPERANDS[0,1].
914    OPERANDS[0] is a MEM, and OPERANDS[1] is a reg or zero.
915
916    This function returns a template for an insn.
917    This is in static storage.
918
919    It may also output some insns directly.
920    It may alter the values of operands[0] and operands[1].  */
921
922 char *
923 output_store (operands)
924      rtx *operands;
925 {
926   enum machine_mode mode = GET_MODE (operands[0]);
927   rtx address = XEXP (operands[0], 0);
928   char *string;
929
930   cc_status.flags |= CC_KNOW_HI_R31 | CC_HI_R31_ADJ;
931   cc_status.mdep = address;
932
933   if (! ((cc_prev_status.flags & CC_KNOW_HI_R31)
934          && (cc_prev_status.flags & CC_HI_R31_ADJ)
935          && address == cc_prev_status.mdep))
936     {
937       CC_STATUS_INIT;
938       output_asm_insn ("orh %h0,%?r0,%?r31", operands);
939       cc_prev_status.mdep = address;
940     }
941
942   /* Store zero in two parts when appropriate.  */
943   if (mode == DFmode && operands[1] == CONST0_RTX (DFmode))
944     return store_opcode (DFmode, "%r1,%L0(%?r31)", operands[1]);
945
946   /* Code below isn't smart enough to move a doubleword in two parts,
947      so use output_move_double to do that in the cases that require it.  */
948   if ((mode == DImode || mode == DFmode)
949       && ! FP_REG_P (operands[1]))
950     return output_move_double (operands);
951
952   return store_opcode (mode, "%r1,%L0(%?r31)", operands[1]);
953 }
954
955 /* Output a load-from-memory whose operands are OPERANDS[0,1].
956    OPERANDS[0] is a reg, and OPERANDS[1] is a mem.
957
958    This function returns a template for an insn.
959    This is in static storage.
960
961    It may also output some insns directly.
962    It may alter the values of operands[0] and operands[1].  */
963
964 char *
965 output_load (operands)
966      rtx *operands;
967 {
968   enum machine_mode mode = GET_MODE (operands[0]);
969   rtx address = XEXP (operands[1], 0);
970
971   /* We don't bother trying to see if we know %hi(address).
972      This is because we are doing a load, and if we know the
973      %hi value, we probably also know that value in memory.  */
974   cc_status.flags |= CC_KNOW_HI_R31 | CC_HI_R31_ADJ;
975   cc_status.mdep = address;
976
977   if (! ((cc_prev_status.flags & CC_KNOW_HI_R31)
978          && (cc_prev_status.flags & CC_HI_R31_ADJ)
979          && address == cc_prev_status.mdep
980          && cc_prev_status.mdep == cc_status.mdep))
981     {
982       CC_STATUS_INIT;
983       output_asm_insn ("orh %h1,%?r0,%?r31", operands);
984       cc_prev_status.mdep = address;
985     }
986
987   /* Code below isn't smart enough to move a doubleword in two parts,
988      so use output_move_double to do that in the cases that require it.  */
989   if ((mode == DImode || mode == DFmode)
990       && ! FP_REG_P (operands[0]))
991     return output_move_double (operands);
992
993   return load_opcode (mode, "%L1(%?r31),%0", operands[0]);
994 }
995 \f
996 #if 0
997 /* Load the address specified by OPERANDS[3] into the register
998    specified by OPERANDS[0].
999
1000    OPERANDS[3] may be the result of a sum, hence it could either be:
1001
1002    (1) CONST
1003    (2) REG
1004    (2) REG + CONST_INT
1005    (3) REG + REG + CONST_INT
1006    (4) REG + REG  (special case of 3).
1007
1008    Note that (3) is not a legitimate address.
1009    All cases are handled here.  */
1010
1011 void
1012 output_load_address (operands)
1013      rtx *operands;
1014 {
1015   rtx base, offset;
1016
1017   if (CONSTANT_P (operands[3]))
1018     {
1019       output_asm_insn ("mov %3,%0", operands);
1020       return;
1021     }
1022
1023   if (REG_P (operands[3]))
1024     {
1025       if (REGNO (operands[0]) != REGNO (operands[3]))
1026         output_asm_insn ("shl %?r0,%3,%0", operands);
1027       return;
1028     }
1029
1030   if (GET_CODE (operands[3]) != PLUS)
1031     abort ();
1032
1033   base = XEXP (operands[3], 0);
1034   offset = XEXP (operands[3], 1);
1035
1036   if (GET_CODE (base) == CONST_INT)
1037     {
1038       rtx tmp = base;
1039       base = offset;
1040       offset = tmp;
1041     }
1042
1043   if (GET_CODE (offset) != CONST_INT)
1044     {
1045       /* Operand is (PLUS (REG) (REG)).  */
1046       base = operands[3];
1047       offset = const0_rtx;
1048     }
1049
1050   if (REG_P (base))
1051     {
1052       operands[6] = base;
1053       operands[7] = offset;
1054       CC_STATUS_PARTIAL_INIT;
1055       if (SMALL_INT (offset))
1056         output_asm_insn ("adds %7,%6,%0", operands);
1057       else
1058         output_asm_insn ("mov %7,%0\n\tadds %0,%6,%0", operands);
1059     }
1060   else if (GET_CODE (base) == PLUS)
1061     {
1062       operands[6] = XEXP (base, 0);
1063       operands[7] = XEXP (base, 1);
1064       operands[8] = offset;
1065
1066       CC_STATUS_PARTIAL_INIT;
1067       if (SMALL_INT (offset))
1068         output_asm_insn ("adds %6,%7,%0\n\tadds %8,%0,%0", operands);
1069       else
1070         output_asm_insn ("mov %8,%0\n\tadds %0,%6,%0\n\tadds %0,%7,%0", operands);
1071     }
1072   else
1073     abort ();
1074 }
1075 #endif
1076
1077 /* Output code to place a size count SIZE in register REG.
1078    Because block moves are pipelined, we don't include the
1079    first element in the transfer of SIZE to REG.
1080    For this, we subtract ALIGN.  (Actually, I think it is not
1081    right to subtract on this machine, so right now we don't.)  */
1082
1083 static void
1084 output_size_for_block_move (size, reg, align)
1085      rtx size, reg, align;
1086 {
1087   rtx xoperands[3];
1088
1089   xoperands[0] = reg;
1090   xoperands[1] = size;
1091   xoperands[2] = align;
1092
1093 #if 1
1094   cc_status.flags &= ~ CC_KNOW_HI_R31;
1095   output_asm_insn (singlemove_string (xoperands), xoperands);
1096 #else
1097   if (GET_CODE (size) == REG)
1098     output_asm_insn ("sub %2,%1,%0", xoperands);
1099   else
1100     {
1101       xoperands[1]
1102         = gen_rtx (CONST_INT, VOIDmode, INTVAL (size) - INTVAL (align));
1103       cc_status.flags &= ~ CC_KNOW_HI_R31;
1104       output_asm_insn ("mov %1,%0", xoperands);
1105     }
1106 #endif
1107 }
1108
1109 /* Emit code to perform a block move.
1110
1111    OPERANDS[0] is the destination.
1112    OPERANDS[1] is the source.
1113    OPERANDS[2] is the size.
1114    OPERANDS[3] is the known safe alignment.
1115    OPERANDS[4..6] are pseudos we can safely clobber as temps.  */
1116
1117 char *
1118 output_block_move (operands)
1119      rtx *operands;
1120 {
1121   /* A vector for our computed operands.  Note that load_output_address
1122      makes use of (and can clobber) up to the 8th element of this vector.  */
1123   rtx xoperands[10];
1124   rtx zoperands[10];
1125   static int movstrsi_label = 0;
1126   int i, j;
1127   rtx temp1 = operands[4];
1128   rtx alignrtx = operands[3];
1129   int align = INTVAL (alignrtx);
1130   int chunk_size;
1131
1132   xoperands[0] = operands[0];
1133   xoperands[1] = operands[1];
1134   xoperands[2] = temp1;
1135
1136   /* We can't move more than four bytes at a time
1137      because we have only one register to move them through.  */
1138   if (align > 4)
1139     {
1140       align = 4;
1141       alignrtx = gen_rtx (CONST_INT, VOIDmode, 4);
1142     }
1143
1144   /* Recognize special cases of block moves.  These occur
1145      when GNU C++ is forced to treat something as BLKmode
1146      to keep it in memory, when its mode could be represented
1147      with something smaller.
1148
1149      We cannot do this for global variables, since we don't know
1150      what pages they don't cross.  Sigh.  */
1151   if (GET_CODE (operands[2]) == CONST_INT
1152       && ! CONSTANT_ADDRESS_P (operands[0])
1153       && ! CONSTANT_ADDRESS_P (operands[1]))
1154     {
1155       int size = INTVAL (operands[2]);
1156       rtx op0 = xoperands[0];
1157       rtx op1 = xoperands[1];
1158
1159       if ((align & 3) == 0 && (size & 3) == 0 && (size >> 2) <= 16)
1160         {
1161           if (memory_address_p (SImode, plus_constant (op0, size))
1162               && memory_address_p (SImode, plus_constant (op1, size)))
1163             {
1164               cc_status.flags &= ~CC_KNOW_HI_R31;
1165               for (i = (size>>2)-1; i >= 0; i--)
1166                 {
1167                   xoperands[0] = plus_constant (op0, i * 4);
1168                   xoperands[1] = plus_constant (op1, i * 4);
1169                   output_asm_insn ("ld.l %a1,%?r31\n\tst.l %?r31,%a0",
1170                                    xoperands);
1171                 }
1172               return "";
1173             }
1174         }
1175       else if ((align & 1) == 0 && (size & 1) == 0 && (size >> 1) <= 16)
1176         {
1177           if (memory_address_p (HImode, plus_constant (op0, size))
1178               && memory_address_p (HImode, plus_constant (op1, size)))
1179             {
1180               cc_status.flags &= ~CC_KNOW_HI_R31;
1181               for (i = (size>>1)-1; i >= 0; i--)
1182                 {
1183                   xoperands[0] = plus_constant (op0, i * 2);
1184                   xoperands[1] = plus_constant (op1, i * 2);
1185                   output_asm_insn ("ld.s %a1,%?r31\n\tst.s %?r31,%a0",
1186                                    xoperands);
1187                 }
1188               return "";
1189             }
1190         }
1191       else if (size <= 16)
1192         {
1193           if (memory_address_p (QImode, plus_constant (op0, size))
1194               && memory_address_p (QImode, plus_constant (op1, size)))
1195             {
1196               cc_status.flags &= ~CC_KNOW_HI_R31;
1197               for (i = size-1; i >= 0; i--)
1198                 {
1199                   xoperands[0] = plus_constant (op0, i);
1200                   xoperands[1] = plus_constant (op1, i);
1201                   output_asm_insn ("ld.b %a1,%?r31\n\tst.b %?r31,%a0",
1202                                    xoperands);
1203                 }
1204               return "";
1205             }
1206         }
1207     }
1208
1209   /* Since we clobber untold things, nix the condition codes.  */
1210   CC_STATUS_INIT;
1211
1212   /* This is the size of the transfer.
1213      Either use the register which already contains the size,
1214      or use a free register (used by no operands).  */
1215   output_size_for_block_move (operands[2], operands[4], alignrtx);
1216
1217 #if 0
1218   /* Also emit code to decrement the size value by ALIGN.  */
1219   zoperands[0] = operands[0];
1220   zoperands[3] = plus_constant (operands[0], align);
1221   output_load_address (zoperands);
1222 #endif
1223
1224   /* Generate number for unique label.  */
1225
1226   xoperands[3] = gen_rtx (CONST_INT, VOIDmode, movstrsi_label++);
1227
1228   /* Calculate the size of the chunks we will be trying to move first.  */
1229
1230 #if 0
1231   if ((align & 3) == 0)
1232     chunk_size = 4;
1233   else if ((align & 1) == 0)
1234     chunk_size = 2;
1235   else
1236 #endif
1237     chunk_size = 1;
1238
1239   /* Copy the increment (negative) to a register for bla insn.  */
1240
1241   xoperands[4] = gen_rtx (CONST_INT, VOIDmode, - chunk_size);
1242   xoperands[5] = operands[5];
1243   output_asm_insn ("adds %4,%?r0,%5", xoperands);
1244
1245   /* Predecrement the loop counter.  This happens again also in the `bla'
1246      instruction which precedes the loop, but we need to have it done
1247      two times before we enter the loop because of the bizarre semantics
1248      of the bla instruction.  */
1249
1250   output_asm_insn ("adds %5,%2,%2", xoperands);
1251
1252   /* Check for the case where the original count was less than or equal to
1253      zero.  Avoid going through the loop at all if the original count was
1254      indeed less than or equal to zero.  Note that we treat the count as
1255      if it were a signed 32-bit quantity here, rather than an unsigned one,
1256      even though we really shouldn't.  We have to do this because of the
1257      semantics of the `ble' instruction, which assume that the count is
1258      a signed 32-bit value.  Anyway, in practice it won't matter because
1259      nobody is going to try to do a memcpy() of more than half of the
1260      entire address space (i.e. 2 gigabytes) anyway.  */
1261
1262   output_asm_insn ("bc .Le%3", xoperands);
1263
1264   /* Make available a register which is a temporary.  */
1265
1266   xoperands[6] = operands[6];
1267
1268   /* Now the actual loop.
1269      In xoperands, elements 1 and 0 are the input and output vectors.
1270      Element 2 is the loop index.  Element 5 is the increment.  */
1271
1272   output_asm_insn ("subs %1,%5,%1", xoperands);
1273   output_asm_insn ("bla %5,%2,.Lm%3", xoperands);
1274   output_asm_insn ("adds %0,%2,%6", xoperands);
1275   output_asm_insn ("\n.Lm%3:", xoperands);          /* Label for bla above.  */
1276   output_asm_insn ("\n.Ls%3:",  xoperands);         /* Loop start label. */
1277   output_asm_insn ("adds %5,%6,%6", xoperands);
1278
1279   /* NOTE:  The code here which is supposed to handle the cases where the
1280      sources and destinations are known to start on a 4 or 2 byte boundary
1281      are currently broken.  They fail to do anything about the overflow
1282      bytes which might still need to be copied even after we have copied
1283      some number of words or halfwords.  Thus, for now we use the lowest
1284      common denominator, i.e. the code which just copies some number of
1285      totally unaligned individual bytes.  (See the calculation of
1286      chunk_size above.  */
1287
1288   if (chunk_size == 4)
1289     {
1290       output_asm_insn ("ld.l %2(%1),%?r31", xoperands);
1291       output_asm_insn ("bla %5,%2,.Ls%3", xoperands);
1292       output_asm_insn ("st.l %?r31,8(%6)", xoperands);
1293     }
1294   else if (chunk_size == 2)
1295     {
1296       output_asm_insn ("ld.s %2(%1),%?r31", xoperands);
1297       output_asm_insn ("bla %5,%2,.Ls%3", xoperands);
1298       output_asm_insn ("st.s %?r31,4(%6)", xoperands);
1299     }
1300   else /* chunk_size == 1 */
1301     {
1302       output_asm_insn ("ld.b %2(%1),%?r31", xoperands);
1303       output_asm_insn ("bla %5,%2,.Ls%3", xoperands);
1304       output_asm_insn ("st.b %?r31,2(%6)", xoperands);
1305     }
1306   output_asm_insn ("\n.Le%3:", xoperands);          /* Here if count <= 0.  */
1307
1308   return "";
1309 }
1310 \f
1311 /* Output a delayed branch insn with the delay insn in its
1312    branch slot.  The delayed branch insn template is in TEMPLATE,
1313    with operands OPERANDS.  The insn in its delay slot is INSN.
1314
1315    As a special case, since we know that all memory transfers are via
1316    ld/st insns, if we see a (MEM (SYMBOL_REF ...)) we divide the memory
1317    reference around the branch as
1318
1319         orh ha%x,%?r0,%?r31
1320         b ...
1321         ld/st l%x(%?r31),...
1322
1323    As another special case, we handle loading (SYMBOL_REF ...) and
1324    other large constants around branches as well:
1325
1326         orh h%x,%?r0,%0
1327         b ...
1328         or l%x,%0,%1
1329
1330    */
1331
1332 char *
1333 output_delayed_branch (template, operands, insn)
1334      char *template;
1335      rtx *operands;
1336      rtx insn;
1337 {
1338   rtx src = XVECEXP (PATTERN (insn), 0, 1);
1339   rtx dest = XVECEXP (PATTERN (insn), 0, 0);
1340
1341   /* See if we are doing some branch together with setting some register
1342      to some 32-bit value which does (or may) have some of the high-order
1343      16 bits set.  If so, we need to set the register in two stages.  One
1344      stage must be done before the branch, and the other one can be done
1345      in the delay slot.  */
1346
1347   if ( (GET_CODE (src) == CONST_INT
1348         && ((unsigned) INTVAL (src) & (unsigned) 0xffff0000) != (unsigned) 0)
1349       || (GET_CODE (src) == SYMBOL_REF)
1350       || (GET_CODE (src) == LABEL_REF)
1351       || (GET_CODE (src) == CONST))
1352     {
1353       rtx xoperands[2];
1354       xoperands[0] = dest;
1355       xoperands[1] = src;
1356
1357       CC_STATUS_PARTIAL_INIT;
1358       /* Output the `orh' insn.  */
1359       output_asm_insn ("orh %H1,%?r0,%0", xoperands);
1360
1361       /* Output the branch instruction next.  */
1362       output_asm_insn (template, operands);
1363
1364       /* Now output the `or' insn.  */
1365       output_asm_insn ("or %L1,%0,%0", xoperands);
1366     }
1367   else if ((GET_CODE (src) == MEM
1368             && CONSTANT_ADDRESS_P (XEXP (src, 0)))
1369            || (GET_CODE (dest) == MEM
1370                && CONSTANT_ADDRESS_P (XEXP (dest, 0))))
1371     {
1372       rtx xoperands[2];
1373       char *split_template;
1374       xoperands[0] = dest;
1375       xoperands[1] = src;
1376
1377       /* Output the `orh' insn.  */
1378       if (GET_CODE (src) == MEM)
1379         {
1380           if (! ((cc_prev_status.flags & CC_KNOW_HI_R31)
1381                  && (cc_prev_status.flags & CC_HI_R31_ADJ)
1382                  && cc_prev_status.mdep == XEXP (operands[1], 0)))
1383             {
1384               CC_STATUS_INIT;
1385               output_asm_insn ("orh %h1,%?r0,%?r31", xoperands);
1386             }
1387           split_template = load_opcode (GET_MODE (dest),
1388                                         "%L1(%?r31),%0", dest);
1389         }
1390       else
1391         {
1392           if (! ((cc_prev_status.flags & CC_KNOW_HI_R31)
1393                  && (cc_prev_status.flags & CC_HI_R31_ADJ)
1394                  && cc_prev_status.mdep == XEXP (operands[0], 0)))
1395             {
1396               CC_STATUS_INIT;
1397               output_asm_insn ("orh %h0,%?r0,%?r31", xoperands);
1398             }
1399           split_template = store_opcode (GET_MODE (dest),
1400                                          "%r1,%L0(%?r31)", src);
1401         }
1402
1403       /* Output the branch instruction next.  */
1404       output_asm_insn (template, operands);
1405
1406       /* Now output the load or store.
1407          No need to do a CC_STATUS_INIT, because we are branching anyway.  */
1408       output_asm_insn (split_template, xoperands);
1409     }
1410   else
1411     {
1412       int insn_code_number;
1413       rtx pat = gen_rtx (SET, VOIDmode, dest, src);
1414       rtx delay_insn = gen_rtx (INSN, VOIDmode, 0, 0, 0, pat, -1, 0, 0);
1415       int i;
1416
1417       /* Output the branch instruction first.  */
1418       output_asm_insn (template, operands);
1419
1420       /* Now recognize the insn which we put in its delay slot.
1421          We must do this after outputting the branch insn,
1422          since operands may just be a pointer to `recog_operand'.  */
1423       INSN_CODE (delay_insn) = insn_code_number = recog (pat, delay_insn);
1424       if (insn_code_number == -1)
1425         abort ();
1426
1427       for (i = 0; i < insn_n_operands[insn_code_number]; i++)
1428         {
1429           if (GET_CODE (recog_operand[i]) == SUBREG)
1430             recog_operand[i] = alter_subreg (recog_operand[i]);
1431         }
1432
1433       insn_extract (delay_insn);
1434       if (! constrain_operands (insn_code_number, 1))
1435         fatal_insn_not_found (delay_insn);
1436
1437       template = insn_template[insn_code_number];
1438       if (template == 0)
1439         template = (*insn_outfun[insn_code_number]) (recog_operand, delay_insn);
1440       output_asm_insn (template, recog_operand);
1441     }
1442   CC_STATUS_INIT;
1443   return "";
1444 }
1445
1446 /* Output a newly constructed insn DELAY_INSN.  */
1447 char *
1448 output_delay_insn (delay_insn)
1449      rtx delay_insn;
1450 {
1451   char *template;
1452   int insn_code_number;
1453   int i;
1454
1455   /* Now recognize the insn which we put in its delay slot.
1456      We must do this after outputting the branch insn,
1457      since operands may just be a pointer to `recog_operand'.  */
1458   insn_code_number = recog_memoized (delay_insn);
1459   if (insn_code_number == -1)
1460     abort ();
1461
1462   /* Extract the operands of this delay insn.  */
1463   INSN_CODE (delay_insn) = insn_code_number;
1464   insn_extract (delay_insn);
1465
1466   /* It is possible that this insn has not been properly scanned by final
1467      yet.  If this insn's operands don't appear in the peephole's
1468      actual operands, then they won't be fixed up by final, so we
1469      make sure they get fixed up here.  -- This is a kludge.  */
1470   for (i = 0; i < insn_n_operands[insn_code_number]; i++)
1471     {
1472       if (GET_CODE (recog_operand[i]) == SUBREG)
1473         recog_operand[i] = alter_subreg (recog_operand[i]);
1474     }
1475
1476 #ifdef REGISTER_CONSTRAINTS
1477   if (! constrain_operands (insn_code_number))
1478     abort ();
1479 #endif
1480
1481   cc_prev_status = cc_status;
1482
1483   /* Update `cc_status' for this instruction.
1484      The instruction's output routine may change it further.
1485      If the output routine for a jump insn needs to depend
1486      on the cc status, it should look at cc_prev_status.  */
1487
1488   NOTICE_UPDATE_CC (PATTERN (delay_insn), delay_insn);
1489
1490   /* Now get the template for what this insn would
1491      have been, without the branch.  */
1492
1493   template = insn_template[insn_code_number];
1494   if (template == 0)
1495     template = (*insn_outfun[insn_code_number]) (recog_operand, delay_insn);
1496   output_asm_insn (template, recog_operand);
1497   return "";
1498 }
1499 \f
1500 /* Special routine to convert an SFmode value represented as a
1501    CONST_DOUBLE into its equivalent unsigned long bit pattern.
1502    We convert the value from a double precision floating-point
1503    value to single precision first, and thence to a bit-wise
1504    equivalent unsigned long value.  This routine is used when
1505    generating an immediate move of an SFmode value directly
1506    into a general register because the svr4 assembler doesn't
1507    grok floating literals in instruction operand contexts.  */
1508
1509 unsigned long
1510 sfmode_constant_to_ulong (x)
1511      rtx x;
1512 {
1513   REAL_VALUE_TYPE d;
1514   union { float f; unsigned long i; } u2;
1515
1516   if (GET_CODE (x) != CONST_DOUBLE || GET_MODE (x) != SFmode)
1517     abort ();
1518
1519 #if TARGET_FLOAT_FORMAT != HOST_FLOAT_FORMAT
1520  error IEEE emulation needed
1521 #endif
1522   REAL_VALUE_FROM_CONST_DOUBLE (d, x);
1523   u2.f = d;
1524   return u2.i;
1525 }
1526 \f
1527 /* This function generates the assembly code for function entry.
1528    The macro FUNCTION_PROLOGUE in i860.h is defined to call this function.
1529
1530    ASM_FILE is a stdio stream to output the code to.
1531    SIZE is an int: how many units of temporary storage to allocate.
1532
1533    Refer to the array `regs_ever_live' to determine which registers
1534    to save; `regs_ever_live[I]' is nonzero if register number I
1535    is ever used in the function.  This macro is responsible for
1536    knowing which registers should not be saved even if used.
1537
1538    NOTE: `frame_lower_bytes' is the count of bytes which will lie
1539    between the new `fp' value and the new `sp' value after the
1540    prologue is done.  `frame_upper_bytes' is the count of bytes
1541    that will lie between the new `fp' and the *old* `sp' value
1542    after the new `fp' is setup (in the prologue).  The upper
1543    part of each frame always includes at least 2 words (8 bytes)
1544    to hold the saved frame pointer and the saved return address.
1545
1546    The svr4 ABI for the i860 now requires that the values of the
1547    stack pointer and frame pointer registers be kept aligned to
1548    16-byte boundaries at all times.  We obey that restriction here.
1549
1550    The svr4 ABI for the i860 is entirely vague when it comes to specifying
1551    exactly where the "preserved" registers should be saved.  The native
1552    svr4 C compiler I now have doesn't help to clarify the requirements
1553    very much because it is plainly out-of-date and non-ABI-compliant
1554    (in at least one important way, i.e. how it generates function
1555    epilogues).
1556
1557    The native svr4 C compiler saves the "preserved" registers (i.e.
1558    r4-r15 and f2-f7) in the lower part of a frame (i.e. at negative
1559    offsets from the frame pointer).
1560
1561    Previous versions of GCC also saved the "preserved" registers in the
1562    "negative" part of the frame, but they saved them using positive
1563    offsets from the (adjusted) stack pointer (after it had been adjusted
1564    to allocate space for the new frame).  That's just plain wrong
1565    because if the current function calls alloca(), the stack pointer
1566    will get moved, and it will be impossible to restore the registers
1567    properly again after that.
1568
1569    Both compilers handled parameter registers (i.e. r16-r27 and f8-f15)
1570    by copying their values either into various "preserved" registers or
1571    into stack slots in the lower part of the current frame (as seemed
1572    appropriate, depending upon subsequent usage of these values).
1573
1574    Here we want to save the preserved registers at some offset from the
1575    frame pointer register so as to avoid any possible problems arising
1576    from calls to alloca().  We can either save them at small positive
1577    offsets from the frame pointer, or at small negative offsets from
1578    the frame pointer.  If we save them at small negative offsets from
1579    the frame pointer (i.e. in the lower part of the frame) then we
1580    must tell the rest of GCC (via STARTING_FRAME_OFFSET) exactly how
1581    many bytes of space we plan to use in the lower part of the frame
1582    for this purpose.  Since other parts of the compiler reference the
1583    value of STARTING_FRAME_OFFSET long before final() calls this function,
1584    we would have to go ahead and assume the worst-case storage requirements
1585    for saving all of the "preserved" registers (and use that number, i.e.
1586    `80', to define STARTING_FRAME_OFFSET) if we wanted to save them in
1587    the lower part of the frame.  That could potentially be very wasteful,
1588    and that wastefulness could really hamper people compiling for embedded
1589    i860 targets with very tight limits on stack space.  Thus, we choose
1590    here to save the preserved registers in the upper part of the
1591    frame, so that we can decide at the very last minute how much (or how
1592    little) space we must allocate for this purpose.
1593
1594    To satisfy the needs of the svr4 ABI "tdesc" scheme, preserved
1595    registers must always be saved so that the saved values of registers
1596    with higher numbers are at higher addresses.  We obey that restriction
1597    here.
1598
1599    There are two somewhat different ways that you can generate prologues
1600    here... i.e. pedantically ABI-compliant, and the "other" way.  The
1601    "other" way is more consistent with what is currently generated by the
1602    "native" svr4 C compiler for the i860.  That's important if you want
1603    to use the current (as of 8/91) incarnation of svr4 SDB for the i860.
1604    The SVR4 SDB for the i860 insists on having function prologues be
1605    non-ABI-compliant!
1606
1607    To get fully ABI-compliant prologues, define I860_STRICT_ABI_PROLOGUES
1608    in the i860svr4.h file.  (By default this is *not* defined).
1609
1610    The differences between the ABI-compliant and non-ABI-compliant prologues
1611    are that (a) the ABI version seems to require the use of *signed*
1612    (rather than unsigned) adds and subtracts, and (b) the ordering of
1613    the various steps (e.g. saving preserved registers, saving the
1614    return address, setting up the new frame pointer value) is different.
1615
1616    For strict ABI compliance, it seems to be the case that the very last
1617    thing that is supposed to happen in the prologue is getting the frame
1618    pointer set to its new value (but only after everything else has
1619    already been properly setup).  We do that here, but only if the symbol
1620    I860_STRICT_ABI_PROLOGUES is defined.
1621 */
1622
1623 #ifndef STACK_ALIGNMENT
1624 #define STACK_ALIGNMENT 16
1625 #endif
1626
1627 extern char call_used_regs[];
1628 extern int leaf_function_p ();
1629
1630 char *current_function_original_name;
1631
1632 static int must_preserve_r1;
1633 static unsigned must_preserve_bytes;
1634
1635 void
1636 function_prologue (asm_file, local_bytes)
1637      register FILE *asm_file;
1638      register unsigned local_bytes;
1639 {
1640   register unsigned frame_lower_bytes;
1641   register unsigned frame_upper_bytes;
1642   register unsigned total_fsize;
1643   register unsigned preserved_reg_bytes = 0;
1644   register unsigned i;
1645   register unsigned preserved_so_far = 0;
1646
1647   must_preserve_r1 = (optimize < 2 || ! leaf_function_p ());
1648   must_preserve_bytes = 4 + (must_preserve_r1 ? 4 : 0);
1649
1650   /* Count registers that need preserving.  Ignore r0.  It never needs
1651      preserving.  */
1652
1653   for (i = 1; i < FIRST_PSEUDO_REGISTER; i++)
1654     {
1655       if (regs_ever_live[i] && ! call_used_regs[i])
1656         preserved_reg_bytes += 4;
1657     }
1658
1659   /* Round-up the frame_lower_bytes so that it's a multiple of 16. */
1660
1661   frame_lower_bytes = (local_bytes + STACK_ALIGNMENT - 1) & -STACK_ALIGNMENT;
1662
1663   /* The upper part of each frame will contain the saved fp,
1664      the saved r1, and stack slots for all of the other "preserved"
1665      registers that we find we will need to save & restore. */
1666
1667   frame_upper_bytes = must_preserve_bytes + preserved_reg_bytes;
1668
1669   /* Round-up the frame_upper_bytes so that it's a multiple of 16. */
1670
1671   frame_upper_bytes
1672     = (frame_upper_bytes + STACK_ALIGNMENT - 1) & -STACK_ALIGNMENT;
1673
1674   total_fsize = frame_upper_bytes + frame_lower_bytes;
1675
1676 #ifndef I860_STRICT_ABI_PROLOGUES
1677
1678   /* There are two kinds of function prologues.
1679      You use the "small" version if the total frame size is
1680      small enough so that it can fit into an immediate 16-bit
1681      value in one instruction.  Otherwise, you use the "large"
1682      version of the function prologue.  */
1683
1684   if (total_fsize > 0x7fff)
1685     {
1686       /* Adjust the stack pointer.  The ABI sez to do this using `adds',
1687          but the native C compiler on svr4 uses `addu'.  */
1688
1689       fprintf (asm_file, "\taddu -%d,%ssp,%ssp\n",
1690         frame_upper_bytes, i860_reg_prefix, i860_reg_prefix);
1691
1692       /* Save the old frame pointer.  */
1693
1694       fprintf (asm_file, "\tst.l %sfp,0(%ssp)\n",
1695         i860_reg_prefix, i860_reg_prefix);
1696
1697       /* Setup the new frame pointer.  The ABI sez to do this after
1698          preserving registers (using adds), but that's not what the
1699          native C compiler on svr4 does.  */
1700
1701       fprintf (asm_file, "\taddu 0,%ssp,%sfp\n",
1702         i860_reg_prefix, i860_reg_prefix);
1703
1704       /* Get the value of frame_lower_bytes into r31.  */
1705
1706       fprintf (asm_file, "\torh %d,%sr0,%sr31\n",
1707         frame_lower_bytes >> 16, i860_reg_prefix, i860_reg_prefix);
1708       fprintf (asm_file, "\tor %d,%sr31,%sr31\n",
1709         frame_lower_bytes & 0xffff, i860_reg_prefix, i860_reg_prefix);
1710
1711       /* Now re-adjust the stack pointer using the value in r31.
1712          The ABI sez to do this with `subs' but SDB may prefer `subu'.  */
1713
1714       fprintf (asm_file, "\tsubu %ssp,%sr31,%ssp\n",
1715         i860_reg_prefix, i860_reg_prefix, i860_reg_prefix);
1716
1717       /* Preserve registers.  The ABI sez to do this before setting
1718          up the new frame pointer, but that's not what the native
1719          C compiler on svr4 does.  */
1720
1721       for (i = 1; i < 32; i++)
1722         if (regs_ever_live[i] && ! call_used_regs[i])
1723           fprintf (asm_file, "\tst.l %s%s,%d(%sfp)\n",
1724             i860_reg_prefix, reg_names[i],
1725             must_preserve_bytes  + (4 * preserved_so_far++),
1726             i860_reg_prefix);
1727
1728       for (i = 32; i < 64; i++)
1729         if (regs_ever_live[i] && ! call_used_regs[i])
1730           fprintf (asm_file, "\tfst.l %s%s,%d(%sfp)\n",
1731             i860_reg_prefix, reg_names[i],
1732             must_preserve_bytes + (4 * preserved_so_far++),
1733             i860_reg_prefix);
1734
1735       /* Save the return address.  */
1736
1737       if (must_preserve_r1)
1738         fprintf (asm_file, "\tst.l %sr1,4(%sfp)\n",
1739           i860_reg_prefix, i860_reg_prefix);
1740     }
1741   else
1742     {
1743       /* Adjust the stack pointer.  The ABI sez to do this using `adds',
1744          but the native C compiler on svr4 uses `addu'.  */
1745
1746       fprintf (asm_file, "\taddu -%d,%ssp,%ssp\n",
1747         total_fsize, i860_reg_prefix, i860_reg_prefix);
1748
1749       /* Save the old frame pointer.  */
1750
1751       fprintf (asm_file, "\tst.l %sfp,%d(%ssp)\n",
1752         i860_reg_prefix, frame_lower_bytes, i860_reg_prefix);
1753
1754       /* Setup the new frame pointer.  The ABI sez to do this after
1755          preserving registers and after saving the return address,
1756         (and its saz to do this using adds), but that's not what the
1757          native C compiler on svr4 does.  */
1758
1759       fprintf (asm_file, "\taddu %d,%ssp,%sfp\n",
1760         frame_lower_bytes, i860_reg_prefix, i860_reg_prefix);
1761
1762       /* Preserve registers.  The ABI sez to do this before setting
1763          up the new frame pointer, but that's not what the native
1764          compiler on svr4 does.  */
1765
1766       for (i = 1; i < 32; i++)
1767         if (regs_ever_live[i] && ! call_used_regs[i])
1768           fprintf (asm_file, "\tst.l %s%s,%d(%sfp)\n",
1769             i860_reg_prefix, reg_names[i],
1770             must_preserve_bytes + (4 * preserved_so_far++),
1771             i860_reg_prefix);
1772
1773       for (i = 32; i < 64; i++)
1774         if (regs_ever_live[i] && ! call_used_regs[i])
1775           fprintf (asm_file, "\tfst.l %s%s,%d(%sfp)\n",
1776             i860_reg_prefix, reg_names[i],
1777             must_preserve_bytes + (4 * preserved_so_far++),
1778             i860_reg_prefix);
1779
1780       /* Save the return address.  The ABI sez to do this earlier,
1781          and also via an offset from %sp, but the native C compiler
1782          on svr4 does it later (i.e. now) and uses an offset from
1783          %fp.  */
1784
1785       if (must_preserve_r1)
1786         fprintf (asm_file, "\tst.l %sr1,4(%sfp)\n",
1787           i860_reg_prefix, i860_reg_prefix);
1788     }
1789
1790 #else /* defined(I860_STRICT_ABI_PROLOGUES) */
1791
1792   /* There are two kinds of function prologues.
1793      You use the "small" version if the total frame size is
1794      small enough so that it can fit into an immediate 16-bit
1795      value in one instruction.  Otherwise, you use the "large"
1796      version of the function prologue.  */
1797
1798   if (total_fsize > 0x7fff)
1799     {
1800       /* Adjust the stack pointer (thereby allocating a new frame).  */
1801
1802       fprintf (asm_file, "\tadds -%d,%ssp,%ssp\n",
1803         frame_upper_bytes, i860_reg_prefix, i860_reg_prefix);
1804
1805       /* Save the caller's frame pointer.  */
1806
1807       fprintf (asm_file, "\tst.l %sfp,0(%ssp)\n",
1808         i860_reg_prefix, i860_reg_prefix);
1809
1810       /* Save return address.  */
1811
1812       if (must_preserve_r1)
1813         fprintf (asm_file, "\tst.l %sr1,4(%ssp)\n",
1814           i860_reg_prefix, i860_reg_prefix);
1815
1816       /* Get the value of frame_lower_bytes into r31 for later use.  */
1817
1818       fprintf (asm_file, "\torh %d,%sr0,%sr31\n",
1819         frame_lower_bytes >> 16, i860_reg_prefix, i860_reg_prefix);
1820       fprintf (asm_file, "\tor %d,%sr31,%sr31\n",
1821         frame_lower_bytes & 0xffff, i860_reg_prefix, i860_reg_prefix);
1822
1823       /* Now re-adjust the stack pointer using the value in r31.  */
1824
1825       fprintf (asm_file, "\tsubs %ssp,%sr31,%ssp\n",
1826         i860_reg_prefix, i860_reg_prefix, i860_reg_prefix);
1827
1828       /* Pre-compute value to be used as the new frame pointer.  */
1829
1830       fprintf (asm_file, "\tadds %ssp,%sr31,%sr31\n",
1831         i860_reg_prefix, i860_reg_prefix, i860_reg_prefix);
1832
1833       /* Preserve registers.  */
1834
1835       for (i = 1; i < 32; i++)
1836         if (regs_ever_live[i] && ! call_used_regs[i])
1837           fprintf (asm_file, "\tst.l %s%s,%d(%sr31)\n",
1838             i860_reg_prefix, reg_names[i],
1839             must_preserve_bytes + (4 * preserved_so_far++),
1840             i860_reg_prefix);
1841
1842       for (i = 32; i < 64; i++)
1843         if (regs_ever_live[i] && ! call_used_regs[i])
1844           fprintf (asm_file, "\tfst.l %s%s,%d(%sr31)\n",
1845             i860_reg_prefix, reg_names[i],
1846             must_preserve_bytes + (4 * preserved_so_far++),
1847             i860_reg_prefix);
1848
1849       /* Actually set the new value of the frame pointer.  */
1850
1851       fprintf (asm_file, "\tmov %sr31,%sfp\n",
1852         i860_reg_prefix, i860_reg_prefix);
1853     }
1854   else
1855     {
1856       /* Adjust the stack pointer.  */
1857
1858       fprintf (asm_file, "\tadds -%d,%ssp,%ssp\n",
1859         total_fsize, i860_reg_prefix, i860_reg_prefix);
1860
1861       /* Save the caller's frame pointer.  */
1862
1863       fprintf (asm_file, "\tst.l %sfp,%d(%ssp)\n",
1864         i860_reg_prefix, frame_lower_bytes, i860_reg_prefix);
1865
1866       /* Save the return address.  */
1867
1868       if (must_preserve_r1)
1869         fprintf (asm_file, "\tst.l %sr1,%d(%ssp)\n",
1870           i860_reg_prefix, frame_lower_bytes + 4, i860_reg_prefix);
1871
1872       /* Preserve registers.  */
1873
1874       for (i = 1; i < 32; i++)
1875         if (regs_ever_live[i] && ! call_used_regs[i])
1876           fprintf (asm_file, "\tst.l %s%s,%d(%ssp)\n",
1877             i860_reg_prefix, reg_names[i],
1878             frame_lower_bytes + must_preserve_bytes + (4 * preserved_so_far++),
1879             i860_reg_prefix);
1880
1881       for (i = 32; i < 64; i++)
1882         if (regs_ever_live[i] && ! call_used_regs[i])
1883           fprintf (asm_file, "\tfst.l %s%s,%d(%ssp)\n",
1884             i860_reg_prefix, reg_names[i],
1885             frame_lower_bytes + must_preserve_bytes + (4 * preserved_so_far++),
1886             i860_reg_prefix);
1887
1888       /* Setup the new frame pointer.  */
1889
1890       fprintf (asm_file, "\tadds %d,%ssp,%sfp\n",
1891         frame_lower_bytes, i860_reg_prefix, i860_reg_prefix);
1892     }
1893 #endif /* defined(I860_STRICT_ABI_PROLOGUES) */
1894
1895 #ifdef ASM_OUTPUT_PROLOGUE_SUFFIX
1896   ASM_OUTPUT_PROLOGUE_SUFFIX (asm_file);
1897 #endif /* defined(ASM_OUTPUT_PROLOGUE_SUFFIX) */
1898 }
1899 \f
1900 /* This function generates the assembly code for function exit.
1901    The macro FUNCTION_EPILOGUE in i860.h is defined to call this function.
1902
1903    ASM_FILE is a stdio stream to output the code to.
1904    SIZE is an int: how many units of temporary storage to allocate.
1905
1906    The function epilogue should not depend on the current stack pointer!
1907    It should use the frame pointer only.  This is mandatory because
1908    of alloca; we also take advantage of it to omit stack adjustments
1909    before returning.
1910
1911    Note that when we go to restore the preserved register values we must
1912    not try to address their slots by using offsets from the stack pointer.
1913    That's because the stack pointer may have been moved during the function
1914    execution due to a call to alloca().  Rather, we must restore all
1915    preserved registers via offsets from the frame pointer value.
1916
1917    Note also that when the current frame is being "popped" (by adjusting
1918    the value of the stack pointer) on function exit, we must (for the
1919    sake of alloca) set the new value of the stack pointer based upon
1920    the current value of the frame pointer.  We can't just add what we
1921    believe to be the (static) frame size to the stack pointer because
1922    if we did that, and alloca() had been called during this function,
1923    we would end up returning *without* having fully deallocated all of
1924    the space grabbed by alloca.  If that happened, and a function
1925    containing one or more alloca() calls was called over and over again,
1926    then the stack would grow without limit!
1927
1928    Finally note that the epilogues generated here are completely ABI
1929    compliant.  They go out of their way to insure that the value in
1930    the frame pointer register is never less than the value in the stack
1931    pointer register.  It's not clear why this relationship needs to be
1932    maintained at all times, but maintaining it only costs one extra
1933    instruction, so what the hell.
1934 */
1935
1936 /* This corresponds to a version 4 TDESC structure. Lower numbered
1937    versions successively omit the last word of the structure. We
1938    don't try to handle version 5 here. */
1939
1940 typedef struct TDESC_flags {
1941         int version:4;
1942         int reg_packing:1;
1943         int callable_block:1;
1944         int reserved:4;
1945         int fregs:6;    /* fp regs 2-7 */
1946         int iregs:16;   /* regs 0-15 */
1947 } TDESC_flags;
1948
1949 typedef struct TDESC {
1950         TDESC_flags flags;
1951         int integer_reg_offset;         /* same as must_preserve_bytes */
1952         int floating_point_reg_offset;
1953         unsigned int positive_frame_size;       /* same as frame_upper_bytes */
1954         unsigned int negative_frame_size;       /* same as frame_lower_bytes */
1955 } TDESC;
1956
1957 void
1958 function_epilogue (asm_file, local_bytes)
1959      register FILE *asm_file;
1960      register unsigned local_bytes;
1961 {
1962   register unsigned frame_upper_bytes;
1963   register unsigned frame_lower_bytes;
1964   register unsigned preserved_reg_bytes = 0;
1965   register unsigned i;
1966   register unsigned restored_so_far = 0;
1967   register unsigned int_restored;
1968   register unsigned mask;
1969   unsigned intflags=0;
1970   register TDESC_flags *flags = (TDESC_flags *) &intflags;
1971
1972   flags->version = 4;
1973   flags->reg_packing = 1;
1974   flags->iregs = 8;     /* old fp always gets saved */
1975
1976   /* Round-up the frame_lower_bytes so that it's a multiple of 16. */
1977
1978   frame_lower_bytes = (local_bytes + STACK_ALIGNMENT - 1) & -STACK_ALIGNMENT;
1979
1980   /* Count the number of registers that were preserved in the prologue.
1981      Ignore r0.  It is never preserved.  */
1982
1983   for (i = 1; i < FIRST_PSEUDO_REGISTER; i++)
1984     {
1985       if (regs_ever_live[i] && ! call_used_regs[i])
1986         preserved_reg_bytes += 4;
1987     }
1988
1989   /* The upper part of each frame will contain only saved fp,
1990      the saved r1, and stack slots for all of the other "preserved"
1991      registers that we find we will need to save & restore. */
1992
1993   frame_upper_bytes = must_preserve_bytes + preserved_reg_bytes;
1994
1995   /* Round-up frame_upper_bytes so that t is a multiple of 16. */
1996
1997   frame_upper_bytes
1998     = (frame_upper_bytes + STACK_ALIGNMENT - 1) & -STACK_ALIGNMENT;
1999
2000   /* Restore all of the "preserved" registers that need restoring.  */
2001
2002   mask = 2;
2003
2004   for (i = 1; i < 32; i++, mask<<=1)
2005     if (regs_ever_live[i] && ! call_used_regs[i]) {
2006       fprintf (asm_file, "\tld.l %d(%sfp),%s%s\n",
2007         must_preserve_bytes + (4 * restored_so_far++),
2008         i860_reg_prefix, i860_reg_prefix, reg_names[i]);
2009       if (i > 3 && i < 16)
2010         flags->iregs |= mask;
2011     }
2012
2013   int_restored = restored_so_far;
2014   mask = 1;
2015
2016   for (i = 32; i < 64; i++) {
2017     if (regs_ever_live[i] && ! call_used_regs[i]) {
2018       fprintf (asm_file, "\tfld.l %d(%sfp),%s%s\n",
2019         must_preserve_bytes + (4 * restored_so_far++),
2020         i860_reg_prefix, i860_reg_prefix, reg_names[i]);
2021       if (i > 33 & i < 40)
2022         flags->fregs |= mask;
2023     }
2024     if (i > 33 && i < 40)
2025       mask<<=1;
2026   }
2027
2028   /* Get the value we plan to use to restore the stack pointer into r31.  */
2029
2030   fprintf (asm_file, "\tadds %d,%sfp,%sr31\n",
2031     frame_upper_bytes, i860_reg_prefix, i860_reg_prefix);
2032
2033   /* Restore the return address and the old frame pointer.  */
2034
2035   if (must_preserve_r1) {
2036     fprintf (asm_file, "\tld.l 4(%sfp),%sr1\n",
2037       i860_reg_prefix, i860_reg_prefix);
2038     flags->iregs |= 2;
2039   }
2040
2041   fprintf (asm_file, "\tld.l 0(%sfp),%sfp\n",
2042     i860_reg_prefix, i860_reg_prefix);
2043
2044   /* Return and restore the old stack pointer value.  */
2045
2046   fprintf (asm_file, "\tbri %sr1\n\tmov %sr31,%ssp\n",
2047     i860_reg_prefix, i860_reg_prefix, i860_reg_prefix);
2048
2049 #ifdef  OUTPUT_TDESC    /* Output an ABI-compliant TDESC entry */
2050   if (! frame_lower_bytes) {
2051     flags->version--;
2052     if (! frame_upper_bytes) {
2053       flags->version--;
2054       if (restored_so_far == int_restored)      /* No FP saves */
2055         flags->version--;
2056     }
2057   }
2058   assemble_name(asm_file,current_function_original_name);
2059   fputs(".TDESC:\n", asm_file);
2060   fprintf(asm_file, "%s 0x%0x\n", ASM_LONG, intflags);
2061   fprintf(asm_file, "%s %d\n", ASM_LONG,
2062         int_restored ? must_preserve_bytes : 0);
2063   if (flags->version > 1) {
2064     fprintf(asm_file, "%s %d\n", ASM_LONG,
2065         (restored_so_far == int_restored) ? 0 : must_preserve_bytes +
2066           (4 * int_restored));
2067     if (flags->version > 2) {
2068       fprintf(asm_file, "%s %d\n", ASM_LONG, frame_upper_bytes);
2069       if (flags->version > 3)
2070         fprintf(asm_file, "%s %d\n", ASM_LONG, frame_lower_bytes);
2071     }
2072   }
2073   tdesc_section();
2074   fprintf(asm_file, "%s ", ASM_LONG);
2075   assemble_name(asm_file, current_function_original_name);
2076   fprintf(asm_file, "\n%s ", ASM_LONG);
2077   assemble_name(asm_file, current_function_original_name);
2078   fputs(".TDESC\n", asm_file);
2079   text_section();
2080 #endif
2081 }