OSDN Git Service

b3d07461701fd0d4f91bc780b9157a017c9cb23b
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / rs6000.c
1 /* Subroutines used for code generation on IBM RS/6000.
2    Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc.
3    Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
20
21 #include <stdio.h>
22 #include <ctype.h>
23 #include "config.h"
24 #include "rtl.h"
25 #include "regs.h"
26 #include "hard-reg-set.h"
27 #include "real.h"
28 #include "insn-config.h"
29 #include "conditions.h"
30 #include "insn-flags.h"
31 #include "output.h"
32 #include "insn-attr.h"
33 #include "flags.h"
34 #include "recog.h"
35 #include "expr.h"
36 #include "obstack.h"
37 #include "tree.h"
38
39 extern char *language_string;
40 extern int profile_block_flag;
41
42 #define min(A,B)        ((A) < (B) ? (A) : (B))
43 #define max(A,B)        ((A) > (B) ? (A) : (B))
44
45 /* Target cpu type */
46
47 enum processor_type rs6000_cpu;
48 char *rs6000_cpu_string;
49
50 /* Set to non-zero by "fix" operation to indicate that itrunc and
51    uitrunc must be defined.  */
52
53 int rs6000_trunc_used;
54
55 /* Set to non-zero once they have been defined.  */
56
57 static int trunc_defined;
58
59 /* Set to non-zero once AIX common-mode calls have been defined.  */
60 static int common_mode_defined;
61 /* Save information from a "cmpxx" operation until the branch or scc is
62    emitted.  */
63
64 rtx rs6000_compare_op0, rs6000_compare_op1;
65 int rs6000_compare_fp_p;
66
67 #ifdef USING_SVR4_H
68 /* Label number of label created for -mrelocatable, to call to so we can
69    get the address of the GOT section */
70 int rs6000_pic_labelno;
71 #endif
72 \f
73 /* Override command line options.  Mostly we process the processor
74    type and sometimes adjust other TARGET_ options.  */
75
76 void
77 rs6000_override_options ()
78 {
79   int i;
80
81   /* Simplify the entries below by making a mask for any POWER
82      variant and any PowerPC variant.  */
83
84 #define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE)
85 #define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \
86                        | MASK_PPC_GFXOPT | MASK_POWERPC64)
87 #define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT)
88
89   static struct ptt
90     {
91       char *name;               /* Canonical processor name.  */
92       enum processor_type processor; /* Processor type enum value.  */
93       int target_enable;        /* Target flags to enable.  */
94       int target_disable;       /* Target flags to disable.  */
95     } processor_target_table[]
96       = {{"common", PROCESSOR_COMMON, 0, POWER_MASKS | POWERPC_MASKS},
97          {"power", PROCESSOR_POWER,
98             MASK_POWER | MASK_MULTIPLE,
99             MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
100          {"powerpc", PROCESSOR_POWERPC,
101             MASK_POWERPC | MASK_NEW_MNEMONICS,
102             POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
103          {"rios", PROCESSOR_RIOS1,
104             MASK_POWER | MASK_MULTIPLE,
105             MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
106          {"rios1", PROCESSOR_RIOS1,
107             MASK_POWER | MASK_MULTIPLE,
108             MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
109          {"rsc", PROCESSOR_PPC601,
110             MASK_POWER | MASK_MULTIPLE,
111             MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
112          {"rsc1", PROCESSOR_PPC601,
113             MASK_POWER | MASK_MULTIPLE,
114             MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
115          {"rios2", PROCESSOR_RIOS2,
116             MASK_POWER | MASK_MULTIPLE | MASK_POWER2,
117             POWERPC_MASKS | MASK_NEW_MNEMONICS},
118          {"403", PROCESSOR_PPC403,
119             MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
120             POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
121          {"mpc403", PROCESSOR_PPC403,
122             MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
123             POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
124          {"ppc403", PROCESSOR_PPC403,
125             MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
126             POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
127          {"601", PROCESSOR_PPC601,
128             MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE,
129             MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
130          {"mpc601", PROCESSOR_PPC601,
131             MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE,
132             MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
133          {"ppc601", PROCESSOR_PPC601,
134             MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE,
135             MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
136          {"603", PROCESSOR_PPC603,
137             MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
138             POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
139          {"mpc603", PROCESSOR_PPC603,
140             MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
141             POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
142          {"ppc603", PROCESSOR_PPC603,
143             MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
144             POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
145          {"604", PROCESSOR_PPC604,
146             MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
147             POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
148          {"mpc604", PROCESSOR_PPC604,
149             MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
150             POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
151          {"ppc604", PROCESSOR_PPC604,
152             MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
153           POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}};
154
155   int ptt_size = sizeof (processor_target_table) / sizeof (struct ptt);
156
157   int multiple = TARGET_MULTIPLE;       /* save current -mmultiple/-mno-multiple status */
158
159   profile_block_flag = 0;
160
161   /* Identify the processor type */
162   if (rs6000_cpu_string == 0)
163     rs6000_cpu = PROCESSOR_DEFAULT;
164   else
165     {
166       for (i = 0; i < ptt_size; i++)
167         if (! strcmp (rs6000_cpu_string, processor_target_table[i].name))
168           {
169             rs6000_cpu = processor_target_table[i].processor;
170             target_flags |= processor_target_table[i].target_enable;
171             target_flags &= ~processor_target_table[i].target_disable;
172             break;
173           }
174
175       if (i == ptt_size)
176         {
177           error ("bad value (%s) for -mcpu= switch", rs6000_cpu_string);
178           rs6000_cpu_string = "default";
179           rs6000_cpu = PROCESSOR_DEFAULT;
180         }
181     }
182
183   /* If -mmultiple or -mno-multiple was explicitly used, don't
184      override with the processor default */
185   if (TARGET_MULTIPLE_SET)
186     target_flags = (target_flags & ~MASK_MULTIPLE) | multiple;
187
188   /* Don't allow -mmultiple or -mstring on little endian systems, because the
189      hardware doesn't support the instructions used in little endian mode */
190   if (!BYTES_BIG_ENDIAN)
191     {
192       if (TARGET_MULTIPLE)
193         {
194           target_flags &= ~MASK_MULTIPLE;
195           if (TARGET_MULTIPLE_SET)
196             warning ("-mmultiple is not supported on little endian systems");
197         }
198
199       if (TARGET_STRING)
200         {
201           target_flags &= ~MASK_STRING;
202           warning ("-mstring is not supported on little endian systems");
203         }
204     }
205
206 #ifdef SUBTARGET_OVERRIDE_OPTIONS
207   SUBTARGET_OVERRIDE_OPTIONS;
208 #endif
209 }
210 \f
211 /* Create a CONST_DOUBLE like immed_double_const, except reverse the
212    two parts of the constant if the target is little endian.  */
213
214 struct rtx_def *rs6000_immed_double_const (i0, i1, mode)
215      HOST_WIDE_INT i0, i1;
216      enum machine_mode mode;
217 {
218   if (! WORDS_BIG_ENDIAN)
219     return immed_double_const (i1, i0, mode);
220
221   return immed_double_const (i0, i1, mode);
222 }
223
224 \f
225 /* Return non-zero if this function is known to have a null epilogue.  */
226
227 int
228 direct_return ()
229 {
230   return (reload_completed
231           && first_reg_to_save () == 32
232           && first_fp_reg_to_save () == 64
233           && ! regs_ever_live[65]
234           && ! rs6000_pushes_stack ());
235 }
236
237 /* Returns 1 always.  */
238
239 int
240 any_operand (op, mode)
241      register rtx op;
242      enum machine_mode mode;
243 {
244   return 1;
245 }
246
247 /* Return 1 if OP is a constant that can fit in a D field.  */
248
249 int
250 short_cint_operand (op, mode)
251      register rtx op;
252      enum machine_mode mode;
253 {
254   return (GET_CODE (op) == CONST_INT
255           && (unsigned) (INTVAL (op) + 0x8000) < 0x10000);
256 }
257
258 /* Similar for a unsigned D field.  */
259
260 int
261 u_short_cint_operand (op, mode)
262      register rtx op;
263      enum machine_mode mode;
264 {
265   return (GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffff0000) == 0);
266 }
267
268 /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field.  */
269
270 int
271 non_short_cint_operand (op, mode)
272      register rtx op;
273      enum machine_mode mode;
274 {
275   return (GET_CODE (op) == CONST_INT
276           && (unsigned) (INTVAL (op) + 0x8000) >= 0x10000);
277 }
278
279 /* Returns 1 if OP is a register that is not special (i.e., not MQ,
280    ctr, or lr).  */
281
282 int
283 gpc_reg_operand (op, mode)
284      register rtx op;
285      enum machine_mode mode;
286 {
287   return (register_operand (op, mode)
288           && (GET_CODE (op) != REG || REGNO (op) >= 67 || REGNO (op) < 64));
289 }
290
291 /* Returns 1 if OP is either a pseudo-register or a register denoting a
292    CR field.  */
293
294 int
295 cc_reg_operand (op, mode)
296      register rtx op;
297      enum machine_mode mode;
298 {
299   return (register_operand (op, mode)
300           && (GET_CODE (op) != REG
301               || REGNO (op) >= FIRST_PSEUDO_REGISTER
302               || CR_REGNO_P (REGNO (op))));
303 }
304
305 /* Returns 1 if OP is either a constant integer valid for a D-field or a
306    non-special register.  If a register, it must be in the proper mode unless
307    MODE is VOIDmode.  */
308
309 int
310 reg_or_short_operand (op, mode)
311       register rtx op;
312       enum machine_mode mode;
313 {
314   return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
315 }
316
317 /* Similar, except check if the negation of the constant would be valid for
318    a D-field.  */
319
320 int
321 reg_or_neg_short_operand (op, mode)
322       register rtx op;
323       enum machine_mode mode;
324 {
325   if (GET_CODE (op) == CONST_INT)
326     return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
327
328   return gpc_reg_operand (op, mode);
329 }
330
331 /* Return 1 if the operand is either a register or an integer whose high-order
332    16 bits are zero.  */
333
334 int
335 reg_or_u_short_operand (op, mode)
336      register rtx op;
337      enum machine_mode mode;
338 {
339   if (GET_CODE (op) == CONST_INT
340       && (INTVAL (op) & 0xffff0000) == 0)
341     return 1;
342
343   return gpc_reg_operand (op, mode);
344 }
345
346 /* Return 1 is the operand is either a non-special register or ANY
347    constant integer.  */
348
349 int
350 reg_or_cint_operand (op, mode)
351     register rtx op;
352     enum machine_mode mode;
353 {
354      return GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode);
355 }
356
357 /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a register
358    with one instruction per word.  We only do this if we can safely read
359    CONST_DOUBLE_{LOW,HIGH}.  */
360
361 int
362 easy_fp_constant (op, mode)
363      register rtx op;
364      register enum machine_mode mode;
365 {
366   rtx low, high;
367
368   if (GET_CODE (op) != CONST_DOUBLE
369       || GET_MODE (op) != mode
370       || GET_MODE_CLASS (mode) != MODE_FLOAT)
371     return 0;
372
373   high = operand_subword (op, 0, 0, mode);
374   low = operand_subword (op, 1, 0, mode);
375
376   if (high == 0 || ! input_operand (high, word_mode))
377     return 0;
378
379   return (mode == SFmode
380           || (low != 0 && input_operand (low, word_mode)));
381 }
382       
383 /* Return 1 if the operand is a constant whose low-order 32 bits are
384    zero.  */
385
386 int
387 low_32_bit_operand (op, mode)
388      register rtx op;
389      enum machine_mode mode;
390 {
391   rtx low;
392
393   if (GET_CODE (op) != CONST_DOUBLE && GET_CODE (op) != CONST_INT)
394     return 0;
395
396   low = operand_subword (op, 1, 0, mode);
397   return low != 0 && GET_CODE (low) == CONST_INT && INTVAL (low) == 0;
398 }
399
400 /* Return 1 if the operand is either a floating-point register, a pseudo
401    register, or memory.  */
402
403 int
404 fp_reg_or_mem_operand (op, mode)
405      register rtx op;
406      enum machine_mode mode;
407 {
408   return (memory_operand (op, mode)
409           || (register_operand (op, mode)
410               && (GET_CODE (op) != REG
411                   || REGNO (op) >= FIRST_PSEUDO_REGISTER
412                   || FP_REGNO_P (REGNO (op)))));
413 }
414
415 /* Return 1 if the operand is either an easy FP constant (see above) or
416    memory.  */
417
418 int
419 mem_or_easy_const_operand (op, mode)
420      register rtx op;
421      enum machine_mode mode;
422 {
423   return memory_operand (op, mode) || easy_fp_constant (op, mode);
424 }
425
426 /* Return 1 if the operand is either a non-special register or an item
427    that can be used as the operand of an SI add insn.  */
428
429 int
430 add_operand (op, mode)
431     register rtx op;
432     enum machine_mode mode;
433 {
434   return (reg_or_short_operand (op, mode)
435           || (GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffff) == 0));
436 }
437
438 /* Return 1 if OP is a constant but not a valid add_operand.  */
439
440 int
441 non_add_cint_operand (op, mode)
442      register rtx op;
443      enum machine_mode mode;
444 {
445   return (GET_CODE (op) == CONST_INT
446           && (unsigned) (INTVAL (op) + 0x8000) >= 0x10000
447           && (INTVAL (op) & 0xffff) != 0);
448 }
449
450 /* Return 1 if the operand is a non-special register or a constant that
451    can be used as the operand of an OR or XOR insn on the RS/6000.  */
452
453 int
454 logical_operand (op, mode)
455      register rtx op;
456      enum machine_mode mode;
457 {
458   return (gpc_reg_operand (op, mode)
459           || (GET_CODE (op) == CONST_INT
460               && ((INTVAL (op) & 0xffff0000) == 0
461                   || (INTVAL (op) & 0xffff) == 0)));
462 }
463
464 /* Return 1 if C is a constant that is not a logical operand (as
465    above).  */
466
467 int
468 non_logical_cint_operand (op, mode)
469      register rtx op;
470      enum machine_mode mode;
471 {
472   return (GET_CODE (op) == CONST_INT
473           && (INTVAL (op) & 0xffff0000) != 0
474           && (INTVAL (op) & 0xffff) != 0);
475 }
476
477 /* Return 1 if C is a constant that can be encoded in a mask on the
478    RS/6000.  It is if there are no more than two 1->0 or 0->1 transitions.
479    Reject all ones and all zeros, since these should have been optimized
480    away and confuse the making of MB and ME.  */
481
482 int
483 mask_constant (c)
484      register int c;
485 {
486   int i;
487   int last_bit_value;
488   int transitions = 0;
489
490   if (c == 0 || c == ~0)
491     return 0;
492
493   last_bit_value = c & 1;
494
495   for (i = 1; i < 32; i++)
496     if (((c >>= 1) & 1) != last_bit_value)
497       last_bit_value ^= 1, transitions++;
498
499   return transitions <= 2;
500 }
501
502 /* Return 1 if the operand is a constant that is a mask on the RS/6000. */
503
504 int
505 mask_operand (op, mode)
506      register rtx op;
507      enum machine_mode mode;
508 {
509   return GET_CODE (op) == CONST_INT && mask_constant (INTVAL (op));
510 }
511
512 /* Return 1 if the operand is either a non-special register or a
513    constant that can be used as the operand of an RS/6000 logical AND insn.  */
514
515 int
516 and_operand (op, mode)
517     register rtx op;
518     enum machine_mode mode;
519 {
520   return (reg_or_short_operand (op, mode)
521           || logical_operand (op, mode)
522           || mask_operand (op, mode));
523 }
524
525 /* Return 1 if the operand is a constant but not a valid operand for an AND
526    insn.  */
527
528 int
529 non_and_cint_operand (op, mode)
530      register rtx op;
531      enum machine_mode mode;
532 {
533   return GET_CODE (op) == CONST_INT && ! and_operand (op, mode);
534 }
535
536 /* Return 1 if the operand is a general register or memory operand.  */
537
538 int
539 reg_or_mem_operand (op, mode)
540      register rtx op;
541      register enum machine_mode mode;
542 {
543   return gpc_reg_operand (op, mode) || memory_operand (op, mode);
544 }
545
546 /* Return 1 if the operand is a general register or memory operand without
547    pre-inc or pre_dec which produces invalid form of PowerPC lwa
548    instruction.  */
549
550 int
551 lwa_operand (op, mode)
552      register rtx op;
553      register enum machine_mode mode;
554 {
555   rtx inner = op;
556
557   if (reload_completed && GET_CODE (inner) == SUBREG)
558     inner = SUBREG_REG (inner);
559     
560   return gpc_reg_operand (inner, mode)
561     || (memory_operand (inner, mode)
562         && GET_CODE (XEXP (inner, 0)) != PRE_INC
563         && GET_CODE (XEXP (inner, 0)) != PRE_DEC);
564 }
565
566 /* Return 1 if the operand, used inside a MEM, is a valid first argument
567    to CALL.  This is a SYMBOL_REF or a pseudo-register, which will be
568    forced to lr.  */
569
570 int
571 call_operand (op, mode)
572      register rtx op;
573      enum machine_mode mode;
574 {
575   if (mode != VOIDmode && GET_MODE (op) != mode)
576     return 0;
577
578   return (GET_CODE (op) == SYMBOL_REF
579           || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER));
580 }
581
582
583 /* Return 1 if the operand is a SYMBOL_REF for a function known to be in
584    this file.  */
585
586 int
587 current_file_function_operand (op, mode)
588      register rtx op;
589      enum machine_mode mode;
590 {
591   return (GET_CODE (op) == SYMBOL_REF
592           && (SYMBOL_REF_FLAG (op)
593               || op == XEXP (DECL_RTL (current_function_decl), 0)));
594 }
595
596
597 /* Return 1 if this operand is a valid input for a move insn.  */
598
599 int
600 input_operand (op, mode)
601      register rtx op;
602      enum machine_mode mode;
603 {
604   /* Memory is always valid.  */
605   if (memory_operand (op, mode))
606     return 1;
607
608   /* For floating-point, easy constants are valid.  */
609   if (GET_MODE_CLASS (mode) == MODE_FLOAT
610       && CONSTANT_P (op)
611       && easy_fp_constant (op, mode))
612     return 1;
613
614   /* For floating-point or multi-word mode, the only remaining valid type
615      is a register.  */
616   if (GET_MODE_CLASS (mode) == MODE_FLOAT
617       || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
618     return register_operand (op, mode);
619
620   /* The only cases left are integral modes one word or smaller (we
621      do not get called for MODE_CC values).  These can be in any
622      register.  */
623   if (register_operand (op, mode))
624     return 1;
625
626   /* For HImode and QImode, any constant is valid. */
627   if ((mode == HImode || mode == QImode)
628       && GET_CODE (op) == CONST_INT)
629     return 1;
630
631   /* A SYMBOL_REF referring to the TOC is valid.  */
632   if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op))
633     return 1;
634
635   /* Otherwise, we will be doing this SET with an add, so anything valid
636      for an add will be valid.  */
637   return add_operand (op, mode);
638 }
639 \f
640 /* Expand a block move operation, and return 1 if successful.  Return 0
641    if we should let the compiler generate normal code.
642
643    operands[0] is the destination
644    operands[1] is the source
645    operands[2] is the length
646    operands[3] is the alignment */
647
648 #define MAX_MOVE_REG 4
649
650 int
651 expand_block_move (operands)
652      rtx operands[];
653 {
654   rtx bytes_rtx = operands[2];
655   rtx align_rtx = operands[3];
656   int constp    = (GET_CODE (bytes_rtx) == CONST_INT);
657   int align     = XINT (align_rtx, 0);
658   int bytes;
659   int offset;
660   int num_reg;
661   int i;
662   rtx src_reg;
663   rtx dest_reg;
664   rtx src_addr;
665   rtx dest_addr;
666   rtx tmp_reg;
667   rtx stores[MAX_MOVE_REG];
668   int move_bytes;
669
670   /* If this is not a fixed size move, just call memcpy */
671   if (!constp)
672     return 0;
673
674   /* Anything to move? */
675   bytes = INTVAL (bytes_rtx);
676   if (bytes <= 0)
677     return 1;
678
679   /* Don't support real large moves.  If string instructions are not used,
680      then don't generate more than 8 loads.  */
681   if (TARGET_STRING)
682     {
683       if (bytes > 64)
684         return 0;
685     }
686   else if (!STRICT_ALIGNMENT)
687     {
688       if (bytes > 4*8)
689         return 0;
690     }
691   else if (bytes > 8*align)
692     return 0;
693
694   /* Move the address into scratch registers.  */
695   dest_reg = copy_addr_to_reg (XEXP (operands[0], 0));
696   src_reg  = copy_addr_to_reg (XEXP (operands[1], 0));
697
698   if (TARGET_STRING)    /* string instructions are available */
699     {
700       for ( ; bytes > 0; bytes -= move_bytes)
701         {
702           if (bytes > 24                /* move up to 32 bytes at a time */
703               && !fixed_regs[5]
704               && !fixed_regs[6]
705               && !fixed_regs[7]
706               && !fixed_regs[8]
707               && !fixed_regs[9]
708               && !fixed_regs[10]
709               && !fixed_regs[11]
710               && !fixed_regs[12])
711             {
712               move_bytes = (bytes > 32) ? 32 : bytes;
713               emit_insn (gen_movstrsi_8reg (dest_reg,
714                                             src_reg,
715                                             GEN_INT ((move_bytes == 32) ? 0 : move_bytes),
716                                             align_rtx,
717                                             GEN_INT ((bytes > move_bytes) ? move_bytes : 0)));
718             }
719           else if (bytes > 16   /* move up to 24 bytes at a time */
720                    && !fixed_regs[7]
721                    && !fixed_regs[8]
722                    && !fixed_regs[9]
723                    && !fixed_regs[10]
724                    && !fixed_regs[11]
725                    && !fixed_regs[12])
726             {
727               move_bytes = (bytes > 24) ? 24 : bytes;
728               emit_insn (gen_movstrsi_6reg (dest_reg,
729                                             src_reg,
730                                             GEN_INT (move_bytes),
731                                             align_rtx,
732                                             GEN_INT ((bytes > move_bytes) ? move_bytes : 0)));
733             }
734           else if (bytes > 8    /* move up to 16 bytes at a time */
735                    && !fixed_regs[9]
736                    && !fixed_regs[10]
737                    && !fixed_regs[11]
738                    && !fixed_regs[12])
739             {
740               move_bytes = (bytes > 16) ? 16 : bytes;
741               emit_insn (gen_movstrsi_4reg (dest_reg,
742                                             src_reg,
743                                             GEN_INT (move_bytes),
744                                             align_rtx,
745                                             GEN_INT ((bytes > move_bytes) ? move_bytes : 0)));
746             }
747           else if (bytes > 4 && !TARGET_64BIT)
748             {                   /* move up to 8 bytes at a time */
749               move_bytes = (bytes > 8) ? 8 : bytes;
750               emit_insn (gen_movstrsi_2reg (dest_reg,
751                                             src_reg,
752                                             GEN_INT (move_bytes),
753                                             align_rtx,
754                                             GEN_INT ((bytes > move_bytes) ? move_bytes : 0)));
755             }
756           else if (bytes >= 4 && (align >= 4 || !STRICT_ALIGNMENT))
757             {                   /* move 4 bytes */
758               move_bytes = 4;
759               tmp_reg = gen_reg_rtx (SImode);
760               emit_move_insn (tmp_reg, gen_rtx (MEM, SImode, src_reg));
761               emit_move_insn (gen_rtx (MEM, SImode, dest_reg), tmp_reg);
762               if (bytes > move_bytes)
763                 {
764                   emit_insn (gen_addsi3 (src_reg, src_reg, GEN_INT (move_bytes)));
765                   emit_insn (gen_addsi3 (dest_reg, dest_reg, GEN_INT (move_bytes)));
766                 }
767             }
768           else if (bytes == 2 && (align >= 2 || !STRICT_ALIGNMENT))
769             {                   /* move 2 bytes */
770               move_bytes = 2;
771               tmp_reg = gen_reg_rtx (HImode);
772               emit_move_insn (tmp_reg, gen_rtx (MEM, HImode, src_reg));
773               emit_move_insn (gen_rtx (MEM, HImode, dest_reg), tmp_reg);
774             }
775           else if (bytes == 1)  /* move 1 byte */
776             {
777               move_bytes = 1;
778               tmp_reg = gen_reg_rtx (QImode);
779               emit_move_insn (tmp_reg, gen_rtx (MEM, QImode, src_reg));
780               emit_move_insn (gen_rtx (MEM, QImode, dest_reg), tmp_reg);
781             }
782           else
783             {                   /* move up to 4 bytes at a time */
784               move_bytes = (bytes > 4) ? 4 : bytes;
785               emit_insn (gen_movstrsi_1reg (dest_reg,
786                                             src_reg,
787                                             GEN_INT (move_bytes),
788                                             align_rtx,
789                                             GEN_INT ((bytes > move_bytes) ? move_bytes : 0)));
790             }
791         }
792     }
793
794   else                  /* string instructions not available */
795     {
796       num_reg = offset = 0;
797       for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes))
798         {
799           /* Calculate the correct offset for src/dest */
800           if (offset == 0)
801             {
802               src_addr  = src_reg;
803               dest_addr = dest_reg;
804             }
805           else
806             {
807               src_addr  = gen_rtx (PLUS, Pmode, src_reg,  GEN_INT (offset));
808               dest_addr = gen_rtx (PLUS, Pmode, dest_reg, GEN_INT (offset));
809             }
810
811           /* Generate the appropriate load and store, saving the stores for later */
812           if (bytes >= 4 && (align >= 4 || !STRICT_ALIGNMENT))
813             {
814               move_bytes = 4;
815               tmp_reg = gen_reg_rtx (SImode);
816               emit_insn (gen_movsi (tmp_reg, gen_rtx (MEM, SImode, src_addr)));
817               stores[ num_reg++ ] = gen_movsi (gen_rtx (MEM, SImode, dest_addr), tmp_reg);
818             }
819           else if (bytes >= 2 && (align >= 2 || !STRICT_ALIGNMENT))
820             {
821               move_bytes = 2;
822               tmp_reg = gen_reg_rtx (HImode);
823               emit_insn (gen_movhi (tmp_reg, gen_rtx (MEM, HImode, src_addr)));
824               stores[ num_reg++ ] = gen_movhi (gen_rtx (MEM, HImode, dest_addr), tmp_reg);
825             }
826           else
827             {
828               move_bytes = 1;
829               tmp_reg = gen_reg_rtx (QImode);
830               emit_insn (gen_movqi (tmp_reg, gen_rtx (MEM, QImode, src_addr)));
831               stores[ num_reg++ ] = gen_movqi (gen_rtx (MEM, QImode, dest_addr), tmp_reg);
832             }
833
834           if (num_reg >= MAX_MOVE_REG)
835             {
836               for (i = 0; i < num_reg; i++)
837                 emit_insn (stores[i]);
838               num_reg = 0;
839             }
840         }
841
842       if (num_reg > 0)
843         {
844           for (i = 0; i < num_reg; i++)
845             emit_insn (stores[i]);
846         }
847     }
848
849   return 1;
850 }
851
852 \f
853 /* Return 1 if OP is a load multiple operation.  It is known to be a
854    PARALLEL and the first section will be tested.  */
855
856 int
857 load_multiple_operation (op, mode)
858      rtx op;
859      enum machine_mode mode;
860 {
861   int count = XVECLEN (op, 0);
862   int dest_regno;
863   rtx src_addr;
864   int i;
865
866   /* Perform a quick check so we don't blow up below.  */
867   if (count <= 1
868       || GET_CODE (XVECEXP (op, 0, 0)) != SET
869       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
870       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
871     return 0;
872
873   dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
874   src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
875
876   for (i = 1; i < count; i++)
877     {
878       rtx elt = XVECEXP (op, 0, i);
879
880       if (GET_CODE (elt) != SET
881           || GET_CODE (SET_DEST (elt)) != REG
882           || GET_MODE (SET_DEST (elt)) != SImode
883           || REGNO (SET_DEST (elt)) != dest_regno + i
884           || GET_CODE (SET_SRC (elt)) != MEM
885           || GET_MODE (SET_SRC (elt)) != SImode
886           || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
887           || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
888           || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
889           || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
890         return 0;
891     }
892
893   return 1;
894 }
895
896 /* Similar, but tests for store multiple.  Here, the second vector element
897    is a CLOBBER.  It will be tested later.  */
898
899 int
900 store_multiple_operation (op, mode)
901      rtx op;
902      enum machine_mode mode;
903 {
904   int count = XVECLEN (op, 0) - 1;
905   int src_regno;
906   rtx dest_addr;
907   int i;
908
909   /* Perform a quick check so we don't blow up below.  */
910   if (count <= 1
911       || GET_CODE (XVECEXP (op, 0, 0)) != SET
912       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
913       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
914     return 0;
915
916   src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
917   dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
918
919   for (i = 1; i < count; i++)
920     {
921       rtx elt = XVECEXP (op, 0, i + 1);
922
923       if (GET_CODE (elt) != SET
924           || GET_CODE (SET_SRC (elt)) != REG
925           || GET_MODE (SET_SRC (elt)) != SImode
926           || REGNO (SET_SRC (elt)) != src_regno + i
927           || GET_CODE (SET_DEST (elt)) != MEM
928           || GET_MODE (SET_DEST (elt)) != SImode
929           || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
930           || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
931           || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
932           || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
933         return 0;
934     }
935
936   return 1;
937 }
938 \f
939 /* Return 1 if OP is a comparison operation that is valid for a branch insn.
940    We only check the opcode against the mode of the CC value here.  */
941
942 int
943 branch_comparison_operator (op, mode)
944      register rtx op;
945      enum machine_mode mode;
946 {
947   enum rtx_code code = GET_CODE (op);
948   enum machine_mode cc_mode;
949
950   if (GET_RTX_CLASS (code) != '<')
951     return 0;
952
953   cc_mode = GET_MODE (XEXP (op, 0));
954   if (GET_MODE_CLASS (cc_mode) != MODE_CC)
955     return 0;
956
957   if ((code == GT || code == LT || code == GE || code == LE)
958       && cc_mode == CCUNSmode)
959     return 0;
960
961   if ((code == GTU || code == LTU || code == GEU || code == LEU)
962       && (cc_mode != CCUNSmode))
963     return 0;
964
965   return 1;
966 }
967
968 /* Return 1 if OP is a comparison operation that is valid for an scc insn.
969    We check the opcode against the mode of the CC value and disallow EQ or
970    NE comparisons for integers.  */
971
972 int
973 scc_comparison_operator (op, mode)
974      register rtx op;
975      enum machine_mode mode;
976 {
977   enum rtx_code code = GET_CODE (op);
978   enum machine_mode cc_mode;
979
980   if (GET_MODE (op) != mode && mode != VOIDmode)
981     return 0;
982
983   if (GET_RTX_CLASS (code) != '<')
984     return 0;
985
986   cc_mode = GET_MODE (XEXP (op, 0));
987   if (GET_MODE_CLASS (cc_mode) != MODE_CC)
988     return 0;
989
990   if (code == NE && cc_mode != CCFPmode)
991     return 0;
992
993   if ((code == GT || code == LT || code == GE || code == LE)
994       && cc_mode == CCUNSmode)
995     return 0;
996
997   if ((code == GTU || code == LTU || code == GEU || code == LEU)
998       && (cc_mode != CCUNSmode))
999     return 0;
1000
1001   if (cc_mode == CCEQmode && code != EQ && code != NE)
1002     return 0;
1003
1004   return 1;
1005 }
1006 \f
1007 /* Return 1 if ANDOP is a mask that has no bits on that are not in the
1008    mask required to convert the result of a rotate insn into a shift
1009    left insn of SHIFTOP bits.  Both are known to be CONST_INT.  */
1010
1011 int
1012 includes_lshift_p (shiftop, andop)
1013      register rtx shiftop;
1014      register rtx andop;
1015 {
1016   int shift_mask = (~0 << INTVAL (shiftop));
1017
1018   return (INTVAL (andop) & ~shift_mask) == 0;
1019 }
1020
1021 /* Similar, but for right shift.  */
1022
1023 int
1024 includes_rshift_p (shiftop, andop)
1025      register rtx shiftop;
1026      register rtx andop;
1027 {
1028   unsigned shift_mask = ~0;
1029
1030   shift_mask >>= INTVAL (shiftop);
1031
1032   return (INTVAL (andop) & ~ shift_mask) == 0;
1033 }
1034
1035 /* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
1036    for lfq and stfq insns.
1037
1038    Note reg1 and reg2 *must* be hard registers.  To be sure we will
1039    abort if we are passed pseudo registers.  */
1040
1041 int
1042 registers_ok_for_quad_peep (reg1, reg2)
1043      rtx reg1, reg2;
1044 {
1045   /* We might have been passed a SUBREG.  */
1046   if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG) 
1047     return 0;
1048
1049   return (REGNO (reg1) == REGNO (reg2) - 1);
1050 }
1051
1052 /* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.  addr1 and
1053    addr2 must be in consecutive memory locations (addr2 == addr1 + 8).  */
1054
1055 int
1056 addrs_ok_for_quad_peep (addr1, addr2)
1057      register rtx addr1;
1058      register rtx addr2;
1059 {
1060   int reg1;
1061   int offset1;
1062
1063   /* Extract an offset (if used) from the first addr.  */
1064   if (GET_CODE (addr1) == PLUS)
1065     {
1066       /* If not a REG, return zero.  */
1067       if (GET_CODE (XEXP (addr1, 0)) != REG)
1068         return 0;
1069       else
1070         {
1071           reg1 = REGNO (XEXP (addr1, 0));
1072           /* The offset must be constant!  */
1073           if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
1074             return 0;
1075           offset1 = INTVAL (XEXP (addr1, 1));
1076         }
1077     }
1078   else if (GET_CODE (addr1) != REG)
1079     return 0;
1080   else
1081     {
1082       reg1 = REGNO (addr1);
1083       /* This was a simple (mem (reg)) expression.  Offset is 0.  */
1084       offset1 = 0;
1085     }
1086
1087   /* Make sure the second address is a (mem (plus (reg) (const_int).  */
1088   if (GET_CODE (addr2) != PLUS)
1089     return 0;
1090
1091   if (GET_CODE (XEXP (addr2, 0)) != REG
1092       || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
1093     return 0;
1094
1095   if (reg1 != REGNO (XEXP (addr2, 0)))
1096     return 0;
1097
1098   /* The offset for the second addr must be 8 more than the first addr.  */
1099   if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
1100     return 0;
1101
1102   /* All the tests passed.  addr1 and addr2 are valid for lfq or stfq
1103      instructions.  */
1104   return 1;
1105 }
1106 \f
1107 /* Return the register class of a scratch register needed to copy IN into
1108    or out of a register in CLASS in MODE.  If it can be done directly,
1109    NO_REGS is returned.  */
1110
1111 enum reg_class
1112 secondary_reload_class (class, mode, in)
1113      enum reg_class class;
1114      enum machine_mode mode;
1115      rtx in;
1116 {
1117   int regno = true_regnum (in);
1118
1119   if (regno >= FIRST_PSEUDO_REGISTER)
1120     regno = -1;
1121
1122   /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
1123      into anything.  */
1124   if (class == GENERAL_REGS || class == BASE_REGS
1125       || (regno >= 0 && INT_REGNO_P (regno)))
1126     return NO_REGS;
1127
1128   /* Constants, memory, and FP registers can go into FP registers.  */
1129   if ((regno == -1 || FP_REGNO_P (regno))
1130       && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
1131     return NO_REGS;
1132
1133   /* We can copy among the CR registers.  */
1134   if ((class == CR_REGS || class == CR0_REGS)
1135       && regno >= 0 && CR_REGNO_P (regno))
1136     return NO_REGS;
1137
1138   /* Otherwise, we need GENERAL_REGS.  */
1139   return GENERAL_REGS;
1140 }
1141 \f
1142 /* Given a comparison operation, return the bit number in CCR to test.  We
1143    know this is a valid comparison.  
1144
1145    SCC_P is 1 if this is for an scc.  That means that %D will have been
1146    used instead of %C, so the bits will be in different places.
1147
1148    Return -1 if OP isn't a valid comparison for some reason.  */
1149
1150 int
1151 ccr_bit (op, scc_p)
1152      register rtx op;
1153      int scc_p;
1154 {
1155   enum rtx_code code = GET_CODE (op);
1156   enum machine_mode cc_mode;
1157   int cc_regnum;
1158   int base_bit;
1159
1160   if (GET_RTX_CLASS (code) != '<')
1161     return -1;
1162
1163   cc_mode = GET_MODE (XEXP (op, 0));
1164   cc_regnum = REGNO (XEXP (op, 0));
1165   base_bit = 4 * (cc_regnum - 68);
1166
1167   /* In CCEQmode cases we have made sure that the result is always in the
1168      third bit of the CR field.  */
1169
1170   if (cc_mode == CCEQmode)
1171     return base_bit + 3;
1172
1173   switch (code)
1174     {
1175     case NE:
1176       return scc_p ? base_bit + 3 : base_bit + 2;
1177     case EQ:
1178       return base_bit + 2;
1179     case GT:  case GTU:
1180       return base_bit + 1;
1181     case LT:  case LTU:
1182       return base_bit;
1183
1184     case GE:  case GEU:
1185       /* If floating-point, we will have done a cror to put the bit in the
1186          unordered position.  So test that bit.  For integer, this is ! LT
1187          unless this is an scc insn.  */
1188       return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit;
1189
1190     case LE:  case LEU:
1191       return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit + 1;
1192
1193     default:
1194       abort ();
1195     }
1196 }
1197 \f
1198 /* Print an operand.  Recognize special options, documented below.  */
1199
1200 void
1201 print_operand (file, x, code)
1202     FILE *file;
1203     rtx x;
1204     char code;
1205 {
1206   int i;
1207   int val;
1208
1209   /* These macros test for integers and extract the low-order bits.  */
1210 #define INT_P(X)  \
1211 ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE)    \
1212  && GET_MODE (X) == VOIDmode)
1213
1214 #define INT_LOWPART(X) \
1215   (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
1216
1217   switch (code)
1218     {
1219     case '.':
1220       /* Write out an instruction after the call which may be replaced
1221          with glue code by the loader.  This depends on the AIX version.  */
1222       asm_fprintf (file, RS6000_CALL_GLUE);
1223       return;
1224
1225     case '*':
1226       /* Write the register number of the TOC register.  */
1227       fputs (TARGET_MINIMAL_TOC ? "30" : "2", file);
1228       return;
1229
1230     case 'A':
1231       /* If X is a constant integer whose low-order 5 bits are zero,
1232          write 'l'.  Otherwise, write 'r'.  This is a kludge to fix a bug
1233          in the AIX assembler where "sri" with a zero shift count
1234          write a trash instruction.  */
1235       if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
1236         putc ('l', file);
1237       else
1238         putc ('r', file);
1239       return;
1240
1241     case 'b':
1242       /* Low-order 16 bits of constant, unsigned.  */
1243       if (! INT_P (x))
1244         output_operand_lossage ("invalid %%b value");
1245
1246       fprintf (file, "%d", INT_LOWPART (x) & 0xffff);
1247       return;
1248
1249     case 'C':
1250       /* This is an optional cror needed for LE or GE floating-point
1251          comparisons.  Otherwise write nothing.  */
1252       if ((GET_CODE (x) == LE || GET_CODE (x) == GE)
1253           && GET_MODE (XEXP (x, 0)) == CCFPmode)
1254         {
1255           int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
1256
1257           fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
1258                    base_bit + 2, base_bit + (GET_CODE (x) == GE));
1259         }
1260       return;
1261
1262     case 'D':
1263       /* Similar, except that this is for an scc, so we must be able to
1264          encode the test in a single bit that is one.  We do the above
1265          for any LE, GE, GEU, or LEU and invert the bit for NE.  */
1266       if (GET_CODE (x) == LE || GET_CODE (x) == GE
1267           || GET_CODE (x) == LEU || GET_CODE (x) == GEU)
1268         {
1269           int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
1270
1271           fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
1272                    base_bit + 2,
1273                    base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU));
1274         }
1275
1276       else if (GET_CODE (x) == NE)
1277         {
1278           int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
1279
1280           fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3,
1281                    base_bit + 2, base_bit + 2);
1282         }
1283       return;
1284
1285     case 'E':
1286       /* X is a CR register.  Print the number of the third bit of the CR */
1287       if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
1288         output_operand_lossage ("invalid %%E value");
1289
1290       fprintf(file, "%d", 4 * (REGNO (x) - 68) + 3);
1291       return;
1292
1293     case 'f':
1294       /* X is a CR register.  Print the shift count needed to move it
1295          to the high-order four bits.  */
1296       if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
1297         output_operand_lossage ("invalid %%f value");
1298       else
1299         fprintf (file, "%d", 4 * (REGNO (x) - 68));
1300       return;
1301
1302     case 'F':
1303       /* Similar, but print the count for the rotate in the opposite
1304          direction.  */
1305       if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
1306         output_operand_lossage ("invalid %%F value");
1307       else
1308         fprintf (file, "%d", 32 - 4 * (REGNO (x) - 68));
1309       return;
1310
1311     case 'G':
1312       /* X is a constant integer.  If it is negative, print "m",
1313          otherwise print "z".  This is to make a aze or ame insn.  */
1314       if (GET_CODE (x) != CONST_INT)
1315         output_operand_lossage ("invalid %%G value");
1316       else if (INTVAL (x) >= 0)
1317         putc ('z', file);
1318       else
1319         putc ('m', file);
1320       return;
1321         
1322     case 'h':
1323       /* If constant, output low-order five bits.  Otherwise,
1324          write normally. */
1325       if (INT_P (x))
1326         fprintf (file, "%d", INT_LOWPART (x) & 31);
1327       else
1328         print_operand (file, x, 0);
1329       return;
1330
1331     case 'I':
1332       /* Print `i' if this is a constant, else nothing.  */
1333       if (INT_P (x))
1334         putc ('i', file);
1335       return;
1336
1337     case 'j':
1338       /* Write the bit number in CCR for jump.  */
1339       i = ccr_bit (x, 0);
1340       if (i == -1)
1341         output_operand_lossage ("invalid %%j code");
1342       else
1343         fprintf (file, "%d", i);
1344       return;
1345
1346     case 'J':
1347       /* Similar, but add one for shift count in rlinm for scc and pass
1348          scc flag to `ccr_bit'.  */
1349       i = ccr_bit (x, 1);
1350       if (i == -1)
1351         output_operand_lossage ("invalid %%J code");
1352       else
1353         /* If we want bit 31, write a shift count of zero, not 32.  */
1354         fprintf (file, "%d", i == 31 ? 0 : i + 1);
1355       return;
1356
1357     case 'k':
1358       /* X must be a constant.  Write the 1's complement of the
1359          constant.  */
1360       if (! INT_P (x))
1361         output_operand_lossage ("invalid %%k value");
1362
1363       fprintf (file, "%d", ~ INT_LOWPART (x));
1364       return;
1365
1366     case 'L':
1367       /* Write second word of DImode or DFmode reference.  Works on register
1368          or non-indexed memory only.  */
1369       if (GET_CODE (x) == REG)
1370         fprintf (file, "%d", REGNO (x) + 1);
1371       else if (GET_CODE (x) == MEM)
1372         {
1373           /* Handle possible auto-increment.  Since it is pre-increment and
1374              we have already done it, we can just use an offset of four.  */
1375           if (GET_CODE (XEXP (x, 0)) == PRE_INC
1376               || GET_CODE (XEXP (x, 0)) == PRE_DEC)
1377             output_address (plus_constant (XEXP (XEXP (x, 0), 0), 4));
1378           else
1379             output_address (plus_constant (XEXP (x, 0), 4));
1380         }
1381       return;
1382                             
1383     case 'm':
1384       /* MB value for a mask operand.  */
1385       if (! mask_operand (x, VOIDmode))
1386         output_operand_lossage ("invalid %%m value");
1387
1388       val = INT_LOWPART (x);
1389
1390       /* If the high bit is set and the low bit is not, the value is zero.
1391          If the high bit is zero, the value is the first 1 bit we find from
1392          the left.  */
1393       if (val < 0 && (val & 1) == 0)
1394         {
1395           fprintf (file, "0");
1396           return;
1397         }
1398       else if (val >= 0)
1399         {
1400           for (i = 1; i < 32; i++)
1401             if ((val <<= 1) < 0)
1402               break;
1403           fprintf (file, "%d", i);
1404           return;
1405         }
1406           
1407       /* Otherwise, look for the first 0 bit from the right.  The result is its
1408          number plus 1. We know the low-order bit is one.  */
1409       for (i = 0; i < 32; i++)
1410         if (((val >>= 1) & 1) == 0)
1411           break;
1412
1413       /* If we ended in ...01, I would be 0.  The correct value is 31, so
1414          we want 31 - i.  */
1415       fprintf (file, "%d", 31 - i);
1416       return;
1417
1418     case 'M':
1419       /* ME value for a mask operand.  */
1420       if (! mask_operand (x, VOIDmode))
1421         output_operand_lossage ("invalid %%m value");
1422
1423       val = INT_LOWPART (x);
1424
1425       /* If the low bit is set and the high bit is not, the value is 31.
1426          If the low bit is zero, the value is the first 1 bit we find from
1427          the right.  */
1428       if ((val & 1) && val >= 0)
1429         {
1430           fputs ("31", file);
1431           return;
1432         }
1433       else if ((val & 1) == 0)
1434         {
1435           for (i = 0; i < 32; i++)
1436             if ((val >>= 1) & 1)
1437               break;
1438
1439           /* If we had ....10, I would be 0.  The result should be
1440              30, so we need 30 - i.  */
1441           fprintf (file, "%d", 30 - i);
1442           return;
1443         }
1444           
1445       /* Otherwise, look for the first 0 bit from the left.  The result is its
1446          number minus 1. We know the high-order bit is one.  */
1447       for (i = 0; i < 32; i++)
1448         if ((val <<= 1) >= 0)
1449           break;
1450
1451       fprintf (file, "%d", i);
1452       return;
1453
1454     case 'N':
1455       /* Write the number of elements in the vector times 4.  */
1456       if (GET_CODE (x) != PARALLEL)
1457         output_operand_lossage ("invalid %%N value");
1458
1459       fprintf (file, "%d", XVECLEN (x, 0) * 4);
1460       return;
1461
1462     case 'O':
1463       /* Similar, but subtract 1 first.  */
1464       if (GET_CODE (x) != PARALLEL)
1465         output_operand_lossage ("invalid %%N value");
1466
1467       fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
1468       return;
1469
1470     case 'p':
1471       /* X is a CONST_INT that is a power of two.  Output the logarithm.  */
1472       if (! INT_P (x)
1473           || (i = exact_log2 (INT_LOWPART (x))) < 0)
1474         output_operand_lossage ("invalid %%p value");
1475
1476       fprintf (file, "%d", i);
1477       return;
1478
1479     case 'P':
1480       /* The operand must be an indirect memory reference.  The result
1481          is the register number. */
1482       if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
1483           || REGNO (XEXP (x, 0)) >= 32)
1484         output_operand_lossage ("invalid %%P value");
1485
1486       fprintf (file, "%d", REGNO (XEXP (x, 0)));
1487       return;
1488
1489     case 'R':
1490       /* X is a CR register.  Print the mask for `mtcrf'.  */
1491       if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
1492         output_operand_lossage ("invalid %%R value");
1493       else
1494         fprintf (file, "%d", 128 >> (REGNO (x) - 68));
1495       return;
1496
1497     case 's':
1498       /* Low 5 bits of 32 - value */
1499       if (! INT_P (x))
1500         output_operand_lossage ("invalid %%s value");
1501
1502       fprintf (file, "%d", (32 - INT_LOWPART (x)) & 31);
1503       return;
1504
1505     case 't':
1506       /* Write 12 if this jump operation will branch if true, 4 otherwise. 
1507          All floating-point operations except NE branch true and integer
1508          EQ, LT, GT, LTU and GTU also branch true.  */
1509       if (GET_RTX_CLASS (GET_CODE (x)) != '<')
1510         output_operand_lossage ("invalid %%t value");
1511
1512       else if ((GET_MODE (XEXP (x, 0)) == CCFPmode
1513                 && GET_CODE (x) != NE)
1514                || GET_CODE (x) == EQ
1515                || GET_CODE (x) == LT || GET_CODE (x) == GT
1516                || GET_CODE (x) == LTU || GET_CODE (x) == GTU)
1517         fputs ("12", file);
1518       else
1519         putc ('4', file);
1520       return;
1521       
1522     case 'T':
1523       /* Opposite of 't': write 4 if this jump operation will branch if true,
1524          12 otherwise.   */
1525       if (GET_RTX_CLASS (GET_CODE (x)) != '<')
1526         output_operand_lossage ("invalid %%t value");
1527
1528       else if ((GET_MODE (XEXP (x, 0)) == CCFPmode
1529                 && GET_CODE (x) != NE)
1530                || GET_CODE (x) == EQ
1531                || GET_CODE (x) == LT || GET_CODE (x) == GT
1532                || GET_CODE (x) == LTU || GET_CODE (x) == GTU)
1533         putc ('4', file);
1534       else
1535         fputs ("12", file);
1536       return;
1537       
1538     case 'u':
1539       /* High-order 16 bits of constant.  */
1540       if (! INT_P (x))
1541         output_operand_lossage ("invalid %%u value");
1542
1543       fprintf (file, "0x%x", (INT_LOWPART (x) >> 16) & 0xffff);
1544       return;
1545
1546     case 'U':
1547       /* Print `u' if this has an auto-increment or auto-decrement.  */
1548       if (GET_CODE (x) == MEM
1549           && (GET_CODE (XEXP (x, 0)) == PRE_INC
1550               || GET_CODE (XEXP (x, 0)) == PRE_DEC))
1551         putc ('u', file);
1552       return;
1553
1554     case 'w':
1555       /* If constant, low-order 16 bits of constant, signed.  Otherwise, write
1556          normally.  */
1557       if (INT_P (x))
1558         fprintf (file, "%d",
1559                  (INT_LOWPART (x) & 0xffff) - 2 * (INT_LOWPART (x) & 0x8000));
1560       else
1561         print_operand (file, x, 0);
1562       return;
1563
1564     case 'W':
1565       /* If constant, low-order 16 bits of constant, unsigned.
1566          Otherwise, write normally.  */
1567       if (INT_P (x))
1568         fprintf (file, "%d", INT_LOWPART (x) & 0xffff);
1569       else
1570         print_operand (file, x, 0);
1571       return;
1572
1573     case 'X':
1574       if (GET_CODE (x) == MEM
1575           && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0)))
1576         putc ('x', file);
1577       return;
1578
1579     case 'Y':
1580       /* Like 'L', for third word of TImode  */
1581       if (GET_CODE (x) == REG)
1582         fprintf (file, "%d", REGNO (x) + 2);
1583       else if (GET_CODE (x) == MEM)
1584         {
1585           if (GET_CODE (XEXP (x, 0)) == PRE_INC
1586               || GET_CODE (XEXP (x, 0)) == PRE_DEC)
1587             output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
1588           else
1589             output_address (plus_constant (XEXP (x, 0), 8));
1590         }
1591       return;
1592                             
1593     case 'z':
1594       /* X is a SYMBOL_REF.  Write out the name preceded by a
1595          period and without any trailing data in brackets.  Used for function
1596          names.  If we are configured for System V (or the embedded ABI) on
1597          the PowerPC, do not emit the period, since those systems do not use
1598          TOCs and the like.  */
1599       if (GET_CODE (x) != SYMBOL_REF)
1600         abort ();
1601
1602 #ifndef USING_SVR4_H
1603       putc ('.', file);
1604 #endif
1605       RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
1606       return;
1607
1608     case 'Z':
1609       /* Like 'L', for last word of TImode.  */
1610       if (GET_CODE (x) == REG)
1611         fprintf (file, "%d", REGNO (x) + 3);
1612       else if (GET_CODE (x) == MEM)
1613         {
1614           if (GET_CODE (XEXP (x, 0)) == PRE_INC
1615               || GET_CODE (XEXP (x, 0)) == PRE_DEC)
1616             output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
1617           else
1618             output_address (plus_constant (XEXP (x, 0), 12));
1619         }
1620       return;
1621                             
1622     case 0:
1623       if (GET_CODE (x) == REG)
1624         fprintf (file, "%s", reg_names[REGNO (x)]);
1625       else if (GET_CODE (x) == MEM)
1626         {
1627           /* We need to handle PRE_INC and PRE_DEC here, since we need to
1628              know the width from the mode.  */
1629           if (GET_CODE (XEXP (x, 0)) == PRE_INC)
1630             fprintf (file, "%d(%d)", GET_MODE_SIZE (GET_MODE (x)),
1631                      REGNO (XEXP (XEXP (x, 0), 0)));
1632           else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
1633             fprintf (file, "%d(%d)", - GET_MODE_SIZE (GET_MODE (x)),
1634                      REGNO (XEXP (XEXP (x, 0), 0)));
1635           else
1636             output_address (XEXP (x, 0));
1637         }
1638       else
1639         output_addr_const (file, x);
1640       return;
1641
1642     default:
1643       output_operand_lossage ("invalid %%xn code");
1644     }
1645 }
1646 \f
1647 /* Print the address of an operand.  */
1648
1649 void
1650 print_operand_address (file, x)
1651      FILE *file;
1652      register rtx x;
1653 {
1654   if (GET_CODE (x) == REG)
1655     fprintf (file, "0(%d)", REGNO (x));
1656   else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
1657     {
1658       output_addr_const (file, x);
1659       /* When TARGET_MINIMAL_TOC, use the indirected toc table pointer instead
1660          of the toc pointer.  */
1661       if (TARGET_MINIMAL_TOC)
1662         fprintf (file, "(30)");
1663       else
1664         fprintf (file, "(2)");
1665     }
1666   else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
1667     {
1668       if (REGNO (XEXP (x, 0)) == 0)
1669         fprintf (file, "%d,%d", REGNO (XEXP (x, 1)), REGNO (XEXP (x, 0)));
1670       else
1671         fprintf (file, "%d,%d", REGNO (XEXP (x, 0)), REGNO (XEXP (x, 1)));
1672     }
1673   else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
1674     fprintf (file, "%d(%d)", INTVAL (XEXP (x, 1)), REGNO (XEXP (x, 0)));
1675   else
1676     abort ();
1677 }
1678 \f
1679 /* This page contains routines that are used to determine what the function
1680    prologue and epilogue code will do and write them out.  */
1681
1682 /*  Return the first fixed-point register that is required to be saved. 32 if
1683     none.  */
1684
1685 int
1686 first_reg_to_save ()
1687 {
1688   int first_reg;
1689
1690   /* Find lowest numbered live register.  */
1691   for (first_reg = 13; first_reg <= 31; first_reg++)
1692     if (regs_ever_live[first_reg])
1693       break;
1694
1695   /* If profiling, then we must save/restore every register that contains
1696      a parameter before/after the .mcount call.  Use registers from 30 down
1697      to 23 to do this.  Don't use the frame pointer in reg 31.
1698
1699      For now, save enough room for all of the parameter registers.  */
1700   if (profile_flag)
1701     if (first_reg > 23)
1702       first_reg = 23;
1703
1704   return first_reg;
1705 }
1706
1707 /* Similar, for FP regs.  */
1708
1709 int
1710 first_fp_reg_to_save ()
1711 {
1712   int first_reg;
1713
1714   /* Find lowest numbered live register.  */
1715   for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
1716     if (regs_ever_live[first_reg])
1717       break;
1718
1719   return first_reg;
1720 }
1721
1722 /* Return 1 if we need to save CR.  */
1723
1724 int
1725 must_save_cr ()
1726 {
1727   return regs_ever_live[70] || regs_ever_live[71] || regs_ever_live[72];
1728 }
1729
1730 /* Compute the size of the save area in the stack, including the space for
1731    the fixed area.  */
1732
1733 int
1734 rs6000_sa_size ()
1735 {
1736   int size;
1737
1738   /* We have the six fixed words, plus the size of the register save 
1739      areas, rounded to a double-word.  */
1740   size = 6 + (32 - first_reg_to_save ()) + (64 - first_fp_reg_to_save ()) * 2;
1741   if (size & 1)
1742     size++;
1743
1744   return size * 4;
1745 }
1746
1747 /* Return non-zero if this function makes calls.  */
1748
1749 int
1750 rs6000_makes_calls ()
1751 {
1752   rtx insn;
1753
1754   /* If we are profiling, we will be making a call to mcount.  */
1755   if (profile_flag)
1756     return 1;
1757
1758   for (insn = get_insns (); insn; insn = next_insn (insn))
1759     if (GET_CODE (insn) == CALL_INSN)
1760       return 1;
1761
1762   return 0;
1763 }
1764
1765 /* Return non-zero if this function needs to push space on the stack.  */
1766
1767 int
1768 rs6000_pushes_stack ()
1769 {
1770   int total_size = (rs6000_sa_size () + get_frame_size ()
1771                     + current_function_outgoing_args_size);
1772
1773   /* We need to push the stack if a frame pointer is needed (because the
1774      stack might be dynamically adjusted), if we are debugging, if the
1775      total stack size is more than 220 bytes, or if we make calls.  */
1776
1777   return (frame_pointer_needed || write_symbols != NO_DEBUG
1778           || total_size > 220
1779           || rs6000_makes_calls ());
1780 }
1781
1782 #ifdef USING_SVR4_H
1783 /* Write out a System V.4 style traceback table before the prologue
1784
1785    At present, only emit the basic tag table (ie, do not emit tag_types other
1786    than 0, which might use more than 1 tag word).
1787
1788    The first tag word looks like:
1789
1790     0                   1                   2                   3
1791     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1792    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1793    |         0 |ver| tag |e|s| alloca  | # fprs  | # gprs  |s|l|c|f|
1794    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1795
1796 */
1797
1798 void
1799 svr4_traceback (file, name, decl)
1800      FILE *file;
1801      tree name, decl;
1802 {
1803
1804   int first_reg         = first_reg_to_save ();
1805   int first_fp_reg      = first_fp_reg_to_save ();
1806   int pushes_stack      = rs6000_pushes_stack ();
1807   long tag;
1808   long version          = 0;                    /* version number */
1809   long tag_type         = 0;                    /* function type */
1810   long extended_tag     = 0;                    /* additional tag words needed */
1811   long spare            = 0;                    /* reserved for future use */
1812   long alloca_reg;                              /* stack/frame register */
1813   long fpr_max          = 64 - first_fp_reg;    /* # of floating point registers saved */
1814   long gpr_max          = 32 - first_reg;       /* # of general purpose registers saved */
1815   long sp_max;                                  /* 1 if the function acquires a stack frame */
1816   long lr_max;                                  /* 1 if the function stores the link register */
1817   long cr_max;                                  /* 1 if the function has a CR save word */
1818   long fpscr_max        = 0;                    /* 1 if the function has a FPSCR save word */
1819
1820   if (frame_pointer_needed)
1821     alloca_reg = 31;
1822
1823   else if (pushes_stack != 0)
1824     alloca_reg = 1;
1825
1826   else
1827     alloca_reg = 0;
1828
1829   lr_max = (regs_ever_live[65] || first_fp_reg < 62 || profile_flag);
1830   cr_max = (must_save_cr () != 0);
1831   sp_max = (pushes_stack != 0);
1832
1833   tag = (((version & 3) << 24)
1834          | ((tag_type & 7) << 21)
1835          | ((extended_tag & 1) << 20)
1836          | ((spare & 1) << 19)
1837          | ((alloca_reg & 0x1f) << 14)
1838          | ((fpr_max & 0x1f) << 9)
1839          | ((gpr_max & 0x1f) << 4)
1840          | ((sp_max & 1) << 3)
1841          | ((lr_max & 1) << 2)
1842          | ((cr_max & 1) << 1)
1843          | ((fpscr_max & 1) << 0));
1844            
1845   fprintf (file, "\t.long 0x%lx\n", tag);
1846 }
1847
1848 #endif /* USING_SVR4_H */
1849
1850 /* Write function prologue.  */
1851
1852 void
1853 output_prolog (file, size)
1854      FILE *file;
1855      int size;
1856 {
1857   int first_reg = first_reg_to_save ();
1858   int must_push = rs6000_pushes_stack ();
1859   int first_fp_reg = first_fp_reg_to_save ();
1860   int basic_size = rs6000_sa_size ();
1861   int total_size = (basic_size + size + current_function_outgoing_args_size);
1862   char buf[256];
1863
1864   /* If this is eabi, call __eabi with main, but do so before the minimal TOC
1865      is setup, so we can't use the normal mechanism.  */
1866 #if defined(USING_SVR4_H) && defined(NAME__MAIN) && !defined(INVOKE__main)
1867   int main_p = 0;
1868
1869   if (IDENTIFIER_LENGTH (DECL_NAME (current_function_decl)) == 4
1870       && !strcmp (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)), "main"))
1871     {
1872       main_p = 1;
1873       regs_ever_live[65] = 1;
1874     }
1875 #endif
1876
1877   /* Round size to multiple of 8 bytes.  */
1878   total_size = (total_size + 7) & ~7;
1879
1880   /* Write .extern for any function we will call to save and restore fp
1881      values.  */
1882   if (first_fp_reg < 62)
1883     fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
1884              SAVE_FP_PREFIX, first_fp_reg - 32, SAVE_FP_SUFFIX,
1885              RESTORE_FP_PREFIX, first_fp_reg - 32, RESTORE_FP_SUFFIX);
1886
1887   /* Write .extern for truncation routines, if needed.  */
1888   if (rs6000_trunc_used && ! trunc_defined)
1889     {
1890       fprintf (file, "\t.extern .%s\n\t.extern .%s\n",
1891                RS6000_ITRUNC, RS6000_UITRUNC);
1892       trunc_defined = 1;
1893     }
1894   /* Write .extern for AIX common mode routines, if needed.  */
1895   if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
1896     {
1897       fputs ("\t.extern __mulh\n", file);
1898       fputs ("\t.extern __mull\n", file);
1899       fputs ("\t.extern __divss\n", file);
1900       fputs ("\t.extern __divus\n", file);
1901       fputs ("\t.extern __quoss\n", file);
1902       fputs ("\t.extern __quous\n", file);
1903       common_mode_defined = 1;
1904     }
1905
1906 #ifdef USING_SVR4_H
1907   /* If we have a relocatable GOT section, we need to save the LR. */
1908   if (TARGET_RELOCATABLE && get_pool_size () != 0)
1909     regs_ever_live[65] = 1;
1910 #endif
1911
1912   /* If we have to call a function to save fpr's, or if we are doing profiling,
1913      then we will be using LR.  */
1914   if (first_fp_reg < 62 || profile_flag)
1915     regs_ever_live[65] = 1;
1916
1917   /* If we use the link register, get it into r0.  */
1918   if (regs_ever_live[65])
1919     asm_fprintf (file, "\tmflr 0\n");
1920
1921   /* If we need to save CR, put it into r12.  */
1922   if (must_save_cr ())
1923     asm_fprintf (file, "\tmfcr 12\n");
1924
1925   /* Do any required saving of fpr's.  If only one or two to save, do it
1926      ourself.  Otherwise, call function.  Note that since they are statically
1927      linked, we do not need a nop following them.  */
1928   if (first_fp_reg == 62)
1929     asm_fprintf (file, "\tstfd 30,-16(1)\n\tstfd 31,-8(1)\n");
1930   else if (first_fp_reg == 63)
1931     asm_fprintf (file, "\tstfd 31,-8(1)\n");
1932   else if (first_fp_reg != 64)
1933     asm_fprintf (file, "\tbl %s%d%s\n", SAVE_FP_PREFIX, first_fp_reg - 32, SAVE_FP_SUFFIX);
1934
1935   /* Now save gpr's.  */
1936   if (! TARGET_MULTIPLE || first_reg == 31)
1937     {
1938       int regno, loc;
1939
1940       for (regno = first_reg,
1941            loc = - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8;
1942            regno < 32;
1943            regno++, loc += 4)
1944         asm_fprintf (file, "\t{st|stw} %d,%d(1)\n", regno, loc);
1945     }
1946
1947   else if (first_reg != 32)
1948     asm_fprintf (file, "\t{stm|stmw} %d,%d(1)\n", first_reg,
1949              - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8);
1950
1951   /* Save lr if we used it.  */
1952   if (regs_ever_live[65])
1953     asm_fprintf (file, "\t{st|stw} 0,8(1)\n");
1954
1955   /* Save CR if we use any that must be preserved.  */
1956   if (must_save_cr ())
1957     asm_fprintf (file, "\t{st|stw} 12,4(1)\n");
1958
1959   /* Update stack and set back pointer.  */
1960   if (must_push)
1961     {
1962       if (total_size < 32767)
1963         asm_fprintf (file, "\t{stu|stwu} 1,%d(1)\n", - total_size);
1964       else
1965         {
1966           asm_fprintf (file, "\t{liu|lis} 0,%d\n\t{oril|ori} 0,0,%d\n",
1967                    (total_size >> 16) & 0xffff, total_size & 0xffff);
1968           if (TARGET_POWERPC)
1969             asm_fprintf (file, "\tsubf 12,0,1\n");
1970           else
1971             asm_fprintf (file, "\t{sf|subfc} 12,0,1\n");
1972           asm_fprintf (file, "\t{st|stw} 1,0(12)\n\tmr 1,12\n");
1973         }
1974     }
1975
1976   /* Set frame pointer, if needed.  */
1977   if (frame_pointer_needed)
1978     asm_fprintf (file, "\tmr 31,1\n");
1979
1980   /* If this is eabi, call __eabi before loading up the minimal TOC */
1981 #if defined(USING_SVR4_H) && defined(NAME__MAIN) && !defined(INVOKE__main)
1982   if (main_p)
1983     fprintf (file, "\tbl %s\n", NAME__MAIN);
1984 #endif
1985
1986   /* If TARGET_MINIMAL_TOC, and the constant pool is needed, then load the
1987      TOC_TABLE address into register 30.  */
1988   if (TARGET_MINIMAL_TOC && get_pool_size () != 0)
1989     {
1990       char buf[256];
1991
1992 #ifdef USING_SVR4_H
1993       if (TARGET_RELOCATABLE)
1994         {
1995           ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
1996           fprintf (file, "\tbl ");
1997           assemble_name (file, buf);
1998           fprintf (file, "\n");
1999
2000           ASM_OUTPUT_INTERNAL_LABEL (file, "LCF", rs6000_pic_labelno);
2001           fprintf (file, "\tmflr 30\n");
2002
2003           if (TARGET_POWERPC64)
2004             fprintf (file, "\tld 0,");
2005           else if (TARGET_NEW_MNEMONICS)
2006             fprintf (file, "\tlwz 0,");
2007           else
2008             fprintf (file, "\tl 0,");
2009
2010           fprintf (file, "(");
2011           ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
2012           assemble_name (file, buf);
2013           fprintf (file, "-");
2014           ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
2015           assemble_name (file, buf);
2016           fprintf (file, ")(30)\n");
2017           asm_fprintf (file, "\t{cax|add} 30,0,30\n");
2018           rs6000_pic_labelno++;
2019         }
2020       else if (TARGET_NO_TOC)
2021         {
2022           ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
2023           asm_fprintf (file, "\t{cau|addis} 30,0,");
2024           assemble_name (file, buf);
2025           asm_fprintf (file, "@ha\n");
2026           asm_fprintf (file, "\t{cal|addi} 30,30,");
2027           assemble_name (file, buf);
2028           asm_fprintf (file, "@l\n");
2029         }
2030       else
2031 #endif /* USING_SVR4_H */
2032         {
2033           ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 0);
2034           asm_fprintf (file, "\t{l|lwz} 30,");
2035           assemble_name (file, buf);
2036           asm_fprintf (file, "(2)\n");
2037         }
2038     }
2039 }
2040
2041 /* Write function epilogue.  */
2042
2043 void
2044 output_epilog (file, size)
2045      FILE *file;
2046      int size;
2047 {
2048   int first_reg = first_reg_to_save ();
2049   int must_push = rs6000_pushes_stack ();
2050   int first_fp_reg = first_fp_reg_to_save ();
2051   int basic_size = rs6000_sa_size ();
2052   int total_size = (basic_size + size + current_function_outgoing_args_size);
2053   rtx insn = get_last_insn ();
2054
2055   /* Round size to multiple of 8 bytes.  */
2056   total_size = (total_size + 7) & ~7;
2057
2058   /* If the last insn was a BARRIER, we don't have to write anything except
2059      the trace table.  */
2060   if (GET_CODE (insn) == NOTE)
2061     insn = prev_nonnote_insn (insn);
2062   if (insn == 0 ||  GET_CODE (insn) != BARRIER)
2063     {
2064       /* If we have a frame pointer, a call to alloca,  or a large stack
2065          frame, restore the old stack pointer using the backchain.  Otherwise,
2066          we know what size to update it with.  */
2067       if (frame_pointer_needed || current_function_calls_alloca
2068           || total_size > 32767)
2069         asm_fprintf (file, "\t{l|lwz} 1,0(1)\n");
2070       else if (must_push)
2071         asm_fprintf (file, "\t{cal 1,%d(1)|addi 1,1,%d}\n", total_size);
2072
2073       /* Get the old lr if we saved it.  */
2074       if (regs_ever_live[65])
2075         asm_fprintf (file, "\t{l|lwz} 0,8(1)\n");
2076
2077       /* Get the old cr if we saved it.  */
2078       if (must_save_cr ())
2079         asm_fprintf (file, "\t{l|lwz} 12,4(1)\n");
2080
2081       /* Set LR here to try to overlap restores below.  */
2082       if (regs_ever_live[65])
2083         asm_fprintf (file, "\tmtlr 0\n");
2084
2085       /* Restore gpr's.  */
2086       if (! TARGET_MULTIPLE || first_reg == 31)
2087         {
2088           int regno, loc;
2089
2090           for (regno = first_reg,
2091                loc = - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8;
2092                regno < 32;
2093                regno++, loc += 4)
2094             asm_fprintf (file, "\t{l|lwz} %d,%d(1)\n", regno, loc);
2095         }
2096
2097       else if (first_reg != 32)
2098         asm_fprintf (file, "\t{lm|lmw} %d,%d(1)\n", first_reg,
2099              - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8);
2100
2101       /* Restore fpr's if we can do it without calling a function.  */
2102       if (first_fp_reg == 62)
2103         asm_fprintf (file, "\tlfd 30,-16(1)\n\tlfd 31,-8(1)\n");
2104       else if (first_fp_reg == 63)
2105         asm_fprintf (file, "\tlfd 31,-8(1)\n");
2106
2107       /* If we saved cr, restore it here.  Just those of cr2, cr3, and cr4
2108          that were used.  */
2109       if (must_save_cr ())
2110         asm_fprintf (file, "\tmtcrf %d,12\n",
2111                      (regs_ever_live[70] != 0) * 0x20
2112                      + (regs_ever_live[71] != 0) * 0x10
2113                      + (regs_ever_live[72] != 0) * 0x8);
2114
2115       /* If we have to restore more than two FP registers, branch to the
2116          restore function.  It will return to our caller.  */
2117       if (first_fp_reg < 62)
2118         asm_fprintf (file, "\tb %s%d%s\n", RESTORE_FP_PREFIX, first_fp_reg - 32, RESTORE_FP_SUFFIX);
2119       else
2120         asm_fprintf (file, "\t{br|blr}\n");
2121     }
2122
2123   /* Output a traceback table here.  See /usr/include/sys/debug.h for info
2124      on its format.
2125
2126      We don't output a traceback table if -finhibit-size-directive was
2127      used.  The documentation for -finhibit-size-directive reads
2128      ``don't output a @code{.size} assembler directive, or anything
2129      else that would cause trouble if the function is split in the
2130      middle, and the two halves are placed at locations far apart in
2131      memory.''  The traceback table has this property, since it
2132      includes the offset from the start of the function to the
2133      traceback table itself.
2134
2135      System V.4 Powerpc's (and the embedded ABI derived from it) use a
2136      different traceback table located before the prologue.  */
2137 #ifndef USING_SVR4_H
2138   if (! flag_inhibit_size_directive)
2139     {
2140       char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
2141       int fixed_parms, float_parms, parm_info;
2142       int i;
2143
2144       /* Need label immediately before tbtab, so we can compute its offset
2145          from the function start.  */
2146       if (*fname == '*')
2147         ++fname;
2148       ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
2149       ASM_OUTPUT_LABEL (file, fname);
2150
2151       /* The .tbtab pseudo-op can only be used for the first eight
2152          expressions, since it can't handle the possibly variable
2153          length fields that follow.  However, if you omit the optional
2154          fields, the assembler outputs zeros for all optional fields
2155          anyways, giving each variable length field is minimum length
2156          (as defined in sys/debug.h).  Thus we can not use the .tbtab
2157          pseudo-op at all.  */
2158
2159       /* An all-zero word flags the start of the tbtab, for debuggers
2160          that have to find it by searching forward from the entry
2161          point or from the current pc.  */
2162       fprintf (file, "\t.long 0\n");
2163
2164       /* Tbtab format type.  Use format type 0.  */
2165       fprintf (file, "\t.byte 0,");
2166
2167       /* Language type.  Unfortunately, there doesn't seem to be any
2168          official way to get this info, so we use language_string.  C
2169          is 0.  C++ is 9.  No number defined for Obj-C, so use the
2170          value for C for now.  */
2171       if (! strcmp (language_string, "GNU C")
2172           || ! strcmp (language_string, "GNU Obj-C"))
2173         i = 0;
2174       else if (! strcmp (language_string, "GNU F77"))
2175         i = 1;
2176       else if (! strcmp (language_string, "GNU Ada"))
2177         i = 3;
2178       else if (! strcmp (language_string, "GNU PASCAL"))
2179         i = 2;
2180       else if (! strcmp (language_string, "GNU C++"))
2181         i = 9;
2182       else
2183         abort ();
2184       fprintf (file, "%d,", i);
2185
2186       /* 8 single bit fields: global linkage (not set for C extern linkage,
2187          apparently a PL/I convention?), out-of-line epilogue/prologue, offset
2188          from start of procedure stored in tbtab, internal function, function
2189          has controlled storage, function has no toc, function uses fp,
2190          function logs/aborts fp operations.  */
2191       /* Assume that fp operations are used if any fp reg must be saved.  */
2192       fprintf (file, "%d,", (1 << 5) | ((first_fp_reg != 64) << 1));
2193
2194       /* 6 bitfields: function is interrupt handler, name present in
2195          proc table, function calls alloca, on condition directives
2196          (controls stack walks, 3 bits), saves condition reg, saves
2197          link reg.  */
2198       /* The `function calls alloca' bit seems to be set whenever reg 31 is
2199          set up as a frame pointer, even when there is no alloca call.  */
2200       fprintf (file, "%d,",
2201                ((1 << 6) | (frame_pointer_needed << 5)
2202                 | (must_save_cr () << 1) | (regs_ever_live[65])));
2203
2204       /* 3 bitfields: saves backchain, spare bit, number of fpr saved
2205          (6 bits).  */
2206       fprintf (file, "%d,",
2207                (must_push << 7) | (64 - first_fp_reg_to_save ()));
2208
2209       /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits).  */
2210       fprintf (file, "%d,", (32 - first_reg_to_save ()));
2211
2212       {
2213         /* Compute the parameter info from the function decl argument
2214            list.  */
2215         tree decl;
2216         int next_parm_info_bit;
2217
2218         next_parm_info_bit = 31;
2219         parm_info = 0;
2220         fixed_parms = 0;
2221         float_parms = 0;
2222
2223         for (decl = DECL_ARGUMENTS (current_function_decl);
2224              decl; decl = TREE_CHAIN (decl))
2225           {
2226             rtx parameter = DECL_INCOMING_RTL (decl);
2227             enum machine_mode mode = GET_MODE (parameter);
2228
2229             if (GET_CODE (parameter) == REG)
2230               {
2231                 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
2232                   {
2233                     int bits;
2234
2235                     float_parms++;
2236
2237                     if (mode == SFmode)
2238                       bits = 0x2;
2239                     else if (mode == DFmode)
2240                       bits = 0x3;
2241                     else
2242                       abort ();
2243
2244                     /* If only one bit will fit, don't or in this entry.  */
2245                     if (next_parm_info_bit > 0)
2246                       parm_info |= (bits << (next_parm_info_bit - 1));
2247                     next_parm_info_bit -= 2;
2248                   }
2249                 else
2250                   {
2251                     fixed_parms += ((GET_MODE_SIZE (mode)
2252                                      + (UNITS_PER_WORD - 1))
2253                                     / UNITS_PER_WORD);
2254                     next_parm_info_bit -= 1;
2255                   }
2256               }
2257           }
2258       }
2259
2260       /* Number of fixed point parameters.  */
2261       /* This is actually the number of words of fixed point parameters; thus
2262          an 8 byte struct counts as 2; and thus the maximum value is 8.  */
2263       fprintf (file, "%d,", fixed_parms);
2264
2265       /* 2 bitfields: number of floating point parameters (7 bits), parameters
2266          all on stack.  */
2267       /* This is actually the number of fp registers that hold parameters;
2268          and thus the maximum value is 13.  */
2269       /* Set parameters on stack bit if parameters are not in their original
2270          registers, regardless of whether they are on the stack?  Xlc
2271          seems to set the bit when not optimizing.  */
2272       fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
2273
2274       /* Optional fields follow.  Some are variable length.  */
2275
2276       /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
2277          11 double float.  */
2278       /* There is an entry for each parameter in a register, in the order that
2279          they occur in the parameter list.  Any intervening arguments on the
2280          stack are ignored.  If the list overflows a long (max possible length
2281          34 bits) then completely leave off all elements that don't fit.  */
2282       /* Only emit this long if there was at least one parameter.  */
2283       if (fixed_parms || float_parms)
2284         fprintf (file, "\t.long %d\n", parm_info);
2285
2286       /* Offset from start of code to tb table.  */
2287       fprintf (file, "\t.long ");
2288       ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
2289       RS6000_OUTPUT_BASENAME (file, fname);
2290       fprintf (file, "-.");
2291       RS6000_OUTPUT_BASENAME (file, fname);
2292       fprintf (file, "\n");
2293
2294       /* Interrupt handler mask.  */
2295       /* Omit this long, since we never set the interrupt handler bit
2296          above.  */
2297
2298       /* Number of CTL (controlled storage) anchors.  */
2299       /* Omit this long, since the has_ctl bit is never set above.  */
2300
2301       /* Displacement into stack of each CTL anchor.  */
2302       /* Omit this list of longs, because there are no CTL anchors.  */
2303
2304       /* Length of function name.  */
2305       fprintf (file, "\t.short %d\n", strlen (fname));
2306
2307       /* Function name.  */
2308       assemble_string (fname, strlen (fname));
2309
2310       /* Register for alloca automatic storage; this is always reg 31.
2311          Only emit this if the alloca bit was set above.  */
2312       if (frame_pointer_needed)
2313         fprintf (file, "\t.byte 31\n");
2314     }
2315 #endif /* !USING_SVR4_H */
2316 }
2317 \f
2318 /* Output a TOC entry.  We derive the entry name from what is
2319    being written.  */
2320
2321 void
2322 output_toc (file, x, labelno)
2323      FILE *file;
2324      rtx x;
2325      int labelno;
2326 {
2327   char buf[256];
2328   char *name = buf;
2329   rtx base = x;
2330   int offset = 0;
2331
2332 #ifdef USING_SVR4_H
2333   if (TARGET_MINIMAL_TOC)
2334     {
2335       ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
2336       fprintf (file, "%d = .-", labelno);
2337       ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LCTOC");
2338       fprintf (file, "1\n");
2339     }
2340   else
2341 #endif /* USING_SVR4_H */
2342     ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno);
2343
2344   /* Handle FP constants specially.  Note that if we have a minimal
2345      TOC, things we put here aren't actually in the TOC, so we can allow
2346      FP constants.  */
2347   if (GET_CODE (x) == CONST_DOUBLE
2348       && GET_MODE (x) == DFmode
2349       && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
2350     {
2351       REAL_VALUE_TYPE r;
2352       long l[2];
2353
2354       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
2355       REAL_VALUE_TO_TARGET_DOUBLE (r, l);
2356       if (TARGET_MINIMAL_TOC)
2357         fprintf (file, "\t.long %ld\n\t.long %ld\n", l[0], l[1]);
2358       else
2359         fprintf (file, "\t.tc FD_%lx_%lx[TC],%ld,%ld\n",
2360                  l[0], l[1], l[0], l[1]);
2361       return;
2362     }
2363   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode
2364            && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
2365     {
2366       rtx val = operand_subword (x, 0, 0, SFmode);
2367
2368       if (val == 0 || GET_CODE (val) != CONST_INT)
2369         abort ();
2370
2371       if (TARGET_MINIMAL_TOC)
2372         fprintf (file, "\t.long %d\n", INTVAL (val));
2373       else
2374         fprintf (file, "\t.tc FS_%x[TC],%d\n", INTVAL (val), INTVAL (val));
2375       return;
2376     }
2377
2378   if (GET_CODE (x) == CONST)
2379     {
2380       base = XEXP (XEXP (x, 0), 0);
2381       offset = INTVAL (XEXP (XEXP (x, 0), 1));
2382     }
2383   
2384   if (GET_CODE (base) == SYMBOL_REF)
2385     name = XSTR (base, 0);
2386   else if (GET_CODE (base) == LABEL_REF)
2387     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
2388   else if (GET_CODE (base) == CODE_LABEL)
2389     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
2390   else
2391     abort ();
2392
2393   if (TARGET_MINIMAL_TOC)
2394     fprintf (file, "\t.long ");
2395   else
2396     {
2397       fprintf (file, "\t.tc ");
2398       RS6000_OUTPUT_BASENAME (file, name);
2399
2400       if (offset < 0)
2401         fprintf (file, ".N%d", - offset);
2402       else if (offset)
2403         fprintf (file, ".P%d", offset);
2404
2405       fprintf (file, "[TC],");
2406     }
2407   output_addr_const (file, x);
2408   fprintf (file, "\n");
2409 }
2410 \f
2411 /* Output an assembler pseudo-op to write an ASCII string of N characters
2412    starting at P to FILE.
2413
2414    On the RS/6000, we have to do this using the .byte operation and
2415    write out special characters outside the quoted string.
2416    Also, the assembler is broken; very long strings are truncated,
2417    so we must artificially break them up early. */
2418
2419 void
2420 output_ascii (file, p, n)
2421      FILE *file;
2422      char *p;
2423      int n;
2424 {
2425   char c;
2426   int i, count_string;
2427   char *for_string = "\t.byte \"";
2428   char *for_decimal = "\t.byte ";
2429   char *to_close = NULL;
2430
2431   count_string = 0;
2432   for (i = 0; i < n; i++)
2433     {
2434       c = *p++;
2435       if (c >= ' ' && c < 0177)
2436         {
2437           if (for_string)
2438             fputs (for_string, file);
2439           putc (c, file);
2440
2441           /* Write two quotes to get one.  */
2442           if (c == '"')
2443             {
2444               putc (c, file);
2445               ++count_string;
2446             }
2447
2448           for_string = NULL;
2449           for_decimal = "\"\n\t.byte ";
2450           to_close = "\"\n";
2451           ++count_string;
2452
2453           if (count_string >= 512)
2454             {
2455               fputs (to_close, file);
2456
2457               for_string = "\t.byte \"";
2458               for_decimal = "\t.byte ";
2459               to_close = NULL;
2460               count_string = 0;
2461             }
2462         }
2463       else
2464         {
2465           if (for_decimal)
2466             fputs (for_decimal, file);
2467           fprintf (file, "%d", c);
2468
2469           for_string = "\n\t.byte \"";
2470           for_decimal = ", ";
2471           to_close = "\n";
2472           count_string = 0;
2473         }
2474     }
2475
2476   /* Now close the string if we have written one.  Then end the line.  */
2477   if (to_close)
2478     fprintf (file, to_close);
2479 }
2480 \f
2481 /* Generate a unique section name for FILENAME for a section type
2482    represented by SECTION_DESC.  Output goes into BUF.
2483
2484    SECTION_DESC can be any string, as long as it is different for each
2485    possible section type.
2486
2487    We name the section in the same manner as xlc.  The name begins with an
2488    underscore followed by the filename (after stripping any leading directory
2489    names) with the last period replaced by the string SECTION_DESC.  If
2490    FILENAME does not contain a period, SECTION_DESC is appended to the end of
2491    the name.  */
2492
2493 void
2494 rs6000_gen_section_name (buf, filename, section_desc)
2495      char **buf;
2496      char *filename;
2497      char *section_desc;
2498 {
2499   char *q, *after_last_slash, *last_period;
2500   char *p;
2501   int len;
2502
2503   after_last_slash = filename;
2504   for (q = filename; *q; q++)
2505     {
2506       if (*q == '/')
2507         after_last_slash = q + 1;
2508       else if (*q == '.')
2509         last_period = q;
2510     }
2511
2512   len = strlen (after_last_slash) + strlen (section_desc) + 2;
2513   *buf = (char *) permalloc (len);
2514
2515   p = *buf;
2516   *p++ = '_';
2517
2518   for (q = after_last_slash; *q; q++)
2519     {
2520       if (q == last_period)
2521         {
2522           strcpy (p, section_desc);
2523           p += strlen (section_desc);
2524         }
2525
2526       else if (isalnum (*q))
2527         *p++ = *q;
2528     }
2529
2530   if (last_period == 0)
2531     strcpy (p, section_desc);
2532   else
2533     *p = '\0';
2534 }
2535 \f
2536 /* Write function profiler code. */
2537
2538 void
2539 output_function_profiler (file, labelno)
2540   FILE *file;
2541   int labelno;
2542 {
2543 #ifdef USING_SVR4_H
2544   abort ();
2545 #else
2546   /* The last used parameter register.  */
2547   int last_parm_reg;
2548   int i, j;
2549   char buf[100];
2550
2551   /* Set up a TOC entry for the profiler label.  */
2552   toc_section ();
2553   ASM_OUTPUT_INTERNAL_LABEL (file, "LPC", labelno);
2554   ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
2555   if (TARGET_MINIMAL_TOC)
2556     {
2557       fprintf (file, "\t.long ");
2558       assemble_name (file, buf);
2559       fprintf (file, "\n");
2560     }
2561   else
2562     {
2563       fprintf (file, "\t.tc\t");
2564       assemble_name (file, buf);
2565       fprintf (file, "[TC],");
2566       assemble_name (file, buf);
2567       fprintf (file, "\n");
2568     }
2569   text_section ();
2570
2571   /* Figure out last used parameter register.  The proper thing to do is
2572      to walk incoming args of the function.  A function might have live
2573      parameter registers even if it has no incoming args.  */
2574
2575   for (last_parm_reg = 10;
2576        last_parm_reg > 2 && ! regs_ever_live [last_parm_reg];
2577        last_parm_reg--)
2578     ;
2579
2580   /* Save parameter registers in regs 23-30.  Don't overwrite reg 31, since
2581      it might be set up as the frame pointer.  */
2582
2583   for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
2584     fprintf (file, "\tai %d,%d,0\n", j, i);
2585
2586   /* Load location address into r3, and call mcount.  */
2587
2588   ASM_GENERATE_INTERNAL_LABEL (buf, "LPC", labelno);
2589   fprintf (file, "\tl 3,");
2590   assemble_name (file, buf);
2591   fprintf (file, "(2)\n\tbl .mcount\n");
2592
2593   /* Restore parameter registers.  */
2594
2595   for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
2596     fprintf (file, "\tai %d,%d,0\n", i, j);
2597 #endif
2598 }
2599
2600 /* Adjust the cost of a scheduling dependency.  Return the new cost of
2601    a dependency LINK or INSN on DEP_INSN.  COST is the current cost.  */
2602
2603 int
2604 rs6000_adjust_cost (insn, link, dep_insn, cost)
2605      rtx insn;
2606      rtx link;
2607      rtx dep_insn;
2608      int cost;
2609 {
2610   if (! recog_memoized (insn))
2611     return 0;
2612
2613   if (REG_NOTE_KIND (link) != 0)
2614     return 0;
2615
2616   if (REG_NOTE_KIND (link) == 0)
2617     {
2618       /* Data dependency; DEP_INSN writes a register that INSN reads some
2619          cycles later.  */
2620
2621       /* Tell the first scheduling pass about the latency between a mtctr
2622          and bctr (and mtlr and br/blr).  The first scheduling pass will not
2623          know about this latency since the mtctr instruction, which has the
2624          latency associated to it, will be generated by reload.  */
2625       if (get_attr_type (insn) == TYPE_JMPREG)
2626         return TARGET_POWER ? 5 : 4;
2627
2628       /* Fall out to return default cost.  */
2629     }
2630
2631   return cost;
2632 }