home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 6 / FreshFish_September1994.bin / bbs / gnu / gcc-2.6.0-src.lha / GNU / src / amiga / gcc-2.6.0 / config / rs6000 / rs6000.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-28  |  57.5 KB  |  2,099 lines

  1. /* Subroutines used for code generation on IBM RS/6000.
  2.    Copyright (C) 1991, 1993, 1994 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. /* Override command line options.  Mostly we process the processor
  68.    type and sometimes adjust other TARGET_ options.  */
  69.  
  70. void
  71. rs6000_override_options ()
  72. {
  73.   int i;
  74.  
  75.   /* Simplify the entries below by making a mask for any POWER
  76.      variant and any PowerPC variant.  */
  77.  
  78. #define POWER_MASKS (MASK_POWER | MASK_POWER2)
  79. #define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \
  80.                | MASK_PPC_GFXOPT | MASK_POWERPC64)
  81. #define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT)
  82.  
  83.   static struct ptt
  84.     {
  85.       char *name;        /* Canonical processor name.  */
  86.       enum processor_type processor; /* Processor type enum value.  */
  87.       int target_enable;    /* Target flags to enable.  */
  88.       int target_disable;    /* Target flags to disable.  */
  89.     } processor_target_table[]
  90.       = {{"common", PROCESSOR_COMMON, 0, POWER_MASKS | POWERPC_MASKS},
  91.      {"power", PROCESSOR_POWER,
  92.         MASK_POWER,
  93.         MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
  94.      {"powerpc", PROCESSOR_POWERPC,
  95.         MASK_POWERPC | MASK_NEW_MNEMONICS,
  96.         POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
  97.      {"rios", PROCESSOR_RIOS1,
  98.         MASK_POWER,
  99.         MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
  100.      {"rios1", PROCESSOR_RIOS1,
  101.         MASK_POWER,
  102.         MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
  103.      {"rsc", PROCESSOR_PPC601,
  104.         MASK_POWER,
  105.         MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
  106.      {"rsc1", PROCESSOR_PPC601,
  107.         MASK_POWER,
  108.         MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
  109.      {"rios2", PROCESSOR_RIOS2,
  110.         MASK_POWER | MASK_POWER2,
  111.         POWERPC_MASKS | MASK_NEW_MNEMONICS},
  112.      {"601", PROCESSOR_PPC601,
  113.         MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS,
  114.         MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
  115.      {"mpc601", PROCESSOR_PPC601,
  116.         MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS,
  117.         MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
  118.      {"ppc601", PROCESSOR_PPC601,
  119.         MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS,
  120.         MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
  121.      {"603", PROCESSOR_PPC603,
  122.         MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
  123.         POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
  124.      {"mpc603", PROCESSOR_PPC603,
  125.         MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
  126.         POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
  127.      {"ppc603", PROCESSOR_PPC603,
  128.         MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
  129.         POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
  130.      {"604", PROCESSOR_PPC604,
  131.         MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
  132.         POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
  133.      {"mpc604", PROCESSOR_PPC604,
  134.         MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
  135.         POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
  136.      {"ppc604", PROCESSOR_PPC604,
  137.         MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
  138.       POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}};
  139.  
  140.   int ptt_size = sizeof (processor_target_table) / sizeof (struct ptt);
  141.  
  142.   profile_block_flag = 0;
  143.  
  144.   /* Identify the processor type */
  145.   if (rs6000_cpu_string == 0)
  146.     rs6000_cpu = PROCESSOR_DEFAULT;
  147.   else
  148.     {
  149.       for (i = 0; i < ptt_size; i++)
  150.     if (! strcmp (rs6000_cpu_string, processor_target_table[i].name))
  151.       {
  152.         rs6000_cpu = processor_target_table[i].processor;
  153.         target_flags |= processor_target_table[i].target_enable;
  154.         target_flags &= ~processor_target_table[i].target_disable;
  155.         break;
  156.       }
  157.  
  158.       if (i == ptt_size)
  159.     {
  160.       error ("bad value (%s) for -mcpu= switch", rs6000_cpu_string);
  161.       rs6000_cpu_string = "default";
  162.       rs6000_cpu = PROCESSOR_DEFAULT;
  163.     }
  164.     }
  165. }
  166.  
  167. /* Return non-zero if this function is known to have a null epilogue.  */
  168.  
  169. int
  170. direct_return ()
  171. {
  172.   return (reload_completed
  173.       && first_reg_to_save () == 32
  174.       && first_fp_reg_to_save () == 64
  175.       && ! regs_ever_live[65]
  176.       && ! rs6000_pushes_stack ());
  177. }
  178.  
  179. /* Returns 1 always.  */
  180.  
  181. int
  182. any_operand (op, mode)
  183.      register rtx op;
  184.      enum machine_mode mode;
  185. {
  186.   return 1;
  187. }
  188.  
  189. /* Return 1 if OP is a constant that can fit in a D field.  */
  190.  
  191. int
  192. short_cint_operand (op, mode)
  193.      register rtx op;
  194.      enum machine_mode mode;
  195. {
  196.   return (GET_CODE (op) == CONST_INT
  197.       && (unsigned) (INTVAL (op) + 0x8000) < 0x10000);
  198. }
  199.  
  200. /* Similar for a unsigned D field.  */
  201.  
  202. int
  203. u_short_cint_operand (op, mode)
  204.      register rtx op;
  205.      enum machine_mode mode;
  206. {
  207.   return (GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffff0000) == 0);
  208. }
  209.  
  210. /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field.  */
  211.  
  212. int
  213. non_short_cint_operand (op, mode)
  214.      register rtx op;
  215.      enum machine_mode mode;
  216. {
  217.   return (GET_CODE (op) == CONST_INT
  218.       && (unsigned) (INTVAL (op) + 0x8000) >= 0x10000);
  219. }
  220.  
  221. /* Returns 1 if OP is a register that is not special (i.e., not MQ,
  222.    ctr, or lr).  */
  223.  
  224. int
  225. gpc_reg_operand (op, mode)
  226.      register rtx op;
  227.      enum machine_mode mode;
  228. {
  229.   return (register_operand (op, mode)
  230.       && (GET_CODE (op) != REG || REGNO (op) >= 67 || REGNO (op) < 64));
  231. }
  232.  
  233. /* Returns 1 if OP is either a pseudo-register or a register denoting a
  234.    CR field.  */
  235.  
  236. int
  237. cc_reg_operand (op, mode)
  238.      register rtx op;
  239.      enum machine_mode mode;
  240. {
  241.   return (register_operand (op, mode)
  242.       && (GET_CODE (op) != REG
  243.           || REGNO (op) >= FIRST_PSEUDO_REGISTER
  244.           || CR_REGNO_P (REGNO (op))));
  245. }
  246.  
  247. /* Returns 1 if OP is either a constant integer valid for a D-field or a
  248.    non-special register.  If a register, it must be in the proper mode unless
  249.    MODE is VOIDmode.  */
  250.  
  251. int
  252. reg_or_short_operand (op, mode)
  253.       register rtx op;
  254.       enum machine_mode mode;
  255. {
  256.   return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
  257. }
  258.  
  259. /* Similar, except check if the negation of the constant would be valid for
  260.    a D-field.  */
  261.  
  262. int
  263. reg_or_neg_short_operand (op, mode)
  264.       register rtx op;
  265.       enum machine_mode mode;
  266. {
  267.   if (GET_CODE (op) == CONST_INT)
  268.     return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
  269.  
  270.   return gpc_reg_operand (op, mode);
  271. }
  272.  
  273. /* Return 1 if the operand is either a register or an integer whose high-order
  274.    16 bits are zero.  */
  275.  
  276. int
  277. reg_or_u_short_operand (op, mode)
  278.      register rtx op;
  279.      enum machine_mode mode;
  280. {
  281.   if (GET_CODE (op) == CONST_INT
  282.       && (INTVAL (op) & 0xffff0000) == 0)
  283.     return 1;
  284.  
  285.   return gpc_reg_operand (op, mode);
  286. }
  287.  
  288. /* Return 1 is the operand is either a non-special register or ANY
  289.    constant integer.  */
  290.  
  291. int
  292. reg_or_cint_operand (op, mode)
  293.     register rtx op;
  294.     enum machine_mode mode;
  295. {
  296.      return GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode);
  297. }
  298.  
  299. /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a register
  300.    with one instruction per word.  We only do this if we can safely read
  301.    CONST_DOUBLE_{LOW,HIGH}.  */
  302.  
  303. int
  304. easy_fp_constant (op, mode)
  305.      register rtx op;
  306.      register enum machine_mode mode;
  307. {
  308.   rtx low, high;
  309.  
  310.   if (GET_CODE (op) != CONST_DOUBLE
  311.       || GET_MODE (op) != mode
  312.       || GET_MODE_CLASS (mode) != MODE_FLOAT)
  313.     return 0;
  314.  
  315.   high = operand_subword (op, 0, 0, mode);
  316.   low = operand_subword (op, 1, 0, mode);
  317.  
  318.   if (high == 0 || ! input_operand (high, word_mode))
  319.     return 0;
  320.  
  321.   return (mode == SFmode
  322.       || (low != 0 && input_operand (low, word_mode)));
  323. }
  324.       
  325. /* Return 1 if the operand is either a floating-point register, a pseudo
  326.    register, or memory.  */
  327.  
  328. int
  329. fp_reg_or_mem_operand (op, mode)
  330.      register rtx op;
  331.      enum machine_mode mode;
  332. {
  333.   return (memory_operand (op, mode)
  334.       || (register_operand (op, mode)
  335.           && (GET_CODE (op) != REG
  336.           || REGNO (op) >= FIRST_PSEUDO_REGISTER
  337.           || FP_REGNO_P (REGNO (op)))));
  338. }
  339.  
  340. /* Return 1 if the operand is either an easy FP constant (see above) or
  341.    memory.  */
  342.  
  343. int
  344. mem_or_easy_const_operand (op, mode)
  345.      register rtx op;
  346.      enum machine_mode mode;
  347. {
  348.   return memory_operand (op, mode) || easy_fp_constant (op, mode);
  349. }
  350.  
  351. /* Return 1 if the operand is either a non-special register or an item
  352.    that can be used as the operand of an SI add insn.  */
  353.  
  354. int
  355. add_operand (op, mode)
  356.     register rtx op;
  357.     enum machine_mode mode;
  358. {
  359.   return (reg_or_short_operand (op, mode)
  360.       || (GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffff) == 0));
  361. }
  362.  
  363. /* Return 1 if OP is a constant but not a valid add_operand.  */
  364.  
  365. int
  366. non_add_cint_operand (op, mode)
  367.      register rtx op;
  368.      enum machine_mode mode;
  369. {
  370.   return (GET_CODE (op) == CONST_INT
  371.       && (unsigned) (INTVAL (op) + 0x8000) >= 0x10000
  372.       && (INTVAL (op) & 0xffff) != 0);
  373. }
  374.  
  375. /* Return 1 if the operand is a non-special register or a constant that
  376.    can be used as the operand of an OR or XOR insn on the RS/6000.  */
  377.  
  378. int
  379. logical_operand (op, mode)
  380.      register rtx op;
  381.      enum machine_mode mode;
  382. {
  383.   return (gpc_reg_operand (op, mode)
  384.       || (GET_CODE (op) == CONST_INT
  385.           && ((INTVAL (op) & 0xffff0000) == 0
  386.           || (INTVAL (op) & 0xffff) == 0)));
  387. }
  388.  
  389. /* Return 1 if C is a constant that is not a logical operand (as
  390.    above).  */
  391.  
  392. int
  393. non_logical_cint_operand (op, mode)
  394.      register rtx op;
  395.      enum machine_mode mode;
  396. {
  397.   return (GET_CODE (op) == CONST_INT
  398.       && (INTVAL (op) & 0xffff0000) != 0
  399.       && (INTVAL (op) & 0xffff) != 0);
  400. }
  401.  
  402. /* Return 1 if C is a constant that can be encoded in a mask on the
  403.    RS/6000.  It is if there are no more than two 1->0 or 0->1 transitions.
  404.    Reject all ones and all zeros, since these should have been optimized
  405.    away and confuse the making of MB and ME.  */
  406.  
  407. int
  408. mask_constant (c)
  409.      register int c;
  410. {
  411.   int i;
  412.   int last_bit_value;
  413.   int transitions = 0;
  414.  
  415.   if (c == 0 || c == ~0)
  416.     return 0;
  417.  
  418.   last_bit_value = c & 1;
  419.  
  420.   for (i = 1; i < 32; i++)
  421.     if (((c >>= 1) & 1) != last_bit_value)
  422.       last_bit_value ^= 1, transitions++;
  423.  
  424.   return transitions <= 2;
  425. }
  426.  
  427. /* Return 1 if the operand is a constant that is a mask on the RS/6000. */
  428.  
  429. int
  430. mask_operand (op, mode)
  431.      register rtx op;
  432.      enum machine_mode mode;
  433. {
  434.   return GET_CODE (op) == CONST_INT && mask_constant (INTVAL (op));
  435. }
  436.  
  437. /* Return 1 if the operand is either a non-special register or a
  438.    constant that can be used as the operand of an RS/6000 logical AND insn.  */
  439.  
  440. int
  441. and_operand (op, mode)
  442.     register rtx op;
  443.     enum machine_mode mode;
  444. {
  445.   return (reg_or_short_operand (op, mode)
  446.       || logical_operand (op, mode)
  447.       || mask_operand (op, mode));
  448. }
  449.  
  450. /* Return 1 if the operand is a constant but not a valid operand for an AND
  451.    insn.  */
  452.  
  453. int
  454. non_and_cint_operand (op, mode)
  455.      register rtx op;
  456.      enum machine_mode mode;
  457. {
  458.   return GET_CODE (op) == CONST_INT && ! and_operand (op, mode);
  459. }
  460.  
  461. /* Return 1 if the operand is a general register or memory operand.  */
  462.  
  463. int
  464. reg_or_mem_operand (op, mode)
  465.      register rtx op;
  466.      register enum machine_mode mode;
  467. {
  468.   return gpc_reg_operand (op, mode) || memory_operand (op, mode);
  469. }
  470.  
  471. /* Return 1 if the operand, used inside a MEM, is a valid first argument
  472.    to CALL.  This is a SYMBOL_REF or a pseudo-register, which will be
  473.    forced to lr.  */
  474.  
  475. int
  476. call_operand (op, mode)
  477.      register rtx op;
  478.      enum machine_mode mode;
  479. {
  480.   if (mode != VOIDmode && GET_MODE (op) != mode)
  481.     return 0;
  482.  
  483.   return (GET_CODE (op) == SYMBOL_REF
  484.       || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER));
  485. }
  486.  
  487.  
  488. /* Return 1 if the operand is a SYMBOL_REF for a function known to be in
  489.    this file.  */
  490.  
  491. int
  492. current_file_function_operand (op, mode)
  493.      register rtx op;
  494.      enum machine_mode mode;
  495. {
  496.   return (GET_CODE (op) == SYMBOL_REF
  497.       && (SYMBOL_REF_FLAG (op)
  498.           || op == XEXP (DECL_RTL (current_function_decl), 0)));
  499. }
  500.  
  501.  
  502. /* Return 1 if this operand is a valid input for a move insn.  */
  503.  
  504. int
  505. input_operand (op, mode)
  506.      register rtx op;
  507.      enum machine_mode mode;
  508. {
  509.   /* Memory is always valid.  */
  510.   if (memory_operand (op, mode))
  511.     return 1;
  512.  
  513.   /* For floating-point, easy constants are valid.  */
  514.   if (GET_MODE_CLASS (mode) == MODE_FLOAT
  515.       && CONSTANT_P (op)
  516.       && easy_fp_constant (op, mode))
  517.     return 1;
  518.  
  519.   /* For floating-point or multi-word mode, the only remaining valid type
  520.      is a register.  */
  521.   if (GET_MODE_CLASS (mode) == MODE_FLOAT
  522.       || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
  523.     return register_operand (op, mode);
  524.  
  525.   /* The only cases left are integral modes one word or smaller (we
  526.      do not get called for MODE_CC values).  These can be in any
  527.      register.  */
  528.   if (register_operand (op, mode))
  529.     return 1;
  530.  
  531.   /* For HImode and QImode, any constant is valid. */
  532.   if ((mode == HImode || mode == QImode)
  533.       && GET_CODE (op) == CONST_INT)
  534.     return 1;
  535.  
  536.   /* Otherwise, we will be doing this SET with an add, so anything valid
  537.      for an add will be valid.  */
  538.   return add_operand (op, mode);
  539. }
  540.  
  541. /* Return 1 if OP is a load multiple operation.  It is known to be a
  542.    PARALLEL and the first section will be tested.  */
  543.  
  544. int
  545. load_multiple_operation (op, mode)
  546.      rtx op;
  547.      enum machine_mode mode;
  548. {
  549.   int count = XVECLEN (op, 0);
  550.   int dest_regno;
  551.   rtx src_addr;
  552.   int i;
  553.  
  554.   /* Perform a quick check so we don't blow up below.  */
  555.   if (count <= 1
  556.       || GET_CODE (XVECEXP (op, 0, 0)) != SET
  557.       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
  558.       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
  559.     return 0;
  560.  
  561.   dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
  562.   src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
  563.  
  564.   for (i = 1; i < count; i++)
  565.     {
  566.       rtx elt = XVECEXP (op, 0, i);
  567.  
  568.       if (GET_CODE (elt) != SET
  569.       || GET_CODE (SET_DEST (elt)) != REG
  570.       || GET_MODE (SET_DEST (elt)) != SImode
  571.       || REGNO (SET_DEST (elt)) != dest_regno + i
  572.       || GET_CODE (SET_SRC (elt)) != MEM
  573.       || GET_MODE (SET_SRC (elt)) != SImode
  574.       || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
  575.       || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
  576.       || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
  577.       || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
  578.     return 0;
  579.     }
  580.  
  581.   return 1;
  582. }
  583.  
  584. /* Similar, but tests for store multiple.  Here, the second vector element
  585.    is a CLOBBER.  It will be tested later.  */
  586.  
  587. int
  588. store_multiple_operation (op, mode)
  589.      rtx op;
  590.      enum machine_mode mode;
  591. {
  592.   int count = XVECLEN (op, 0) - 1;
  593.   int src_regno;
  594.   rtx dest_addr;
  595.   int i;
  596.  
  597.   /* Perform a quick check so we don't blow up below.  */
  598.   if (count <= 1
  599.       || GET_CODE (XVECEXP (op, 0, 0)) != SET
  600.       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
  601.       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
  602.     return 0;
  603.  
  604.   src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
  605.   dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
  606.  
  607.   for (i = 1; i < count; i++)
  608.     {
  609.       rtx elt = XVECEXP (op, 0, i + 1);
  610.  
  611.       if (GET_CODE (elt) != SET
  612.       || GET_CODE (SET_SRC (elt)) != REG
  613.       || GET_MODE (SET_SRC (elt)) != SImode
  614.       || REGNO (SET_SRC (elt)) != src_regno + i
  615.       || GET_CODE (SET_DEST (elt)) != MEM
  616.       || GET_MODE (SET_DEST (elt)) != SImode
  617.       || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
  618.       || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
  619.       || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
  620.       || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
  621.     return 0;
  622.     }
  623.  
  624.   return 1;
  625. }
  626.  
  627. /* Return 1 if OP is a comparison operation that is valid for a branch insn.
  628.    We only check the opcode against the mode of the CC value here.  */
  629.  
  630. int
  631. branch_comparison_operator (op, mode)
  632.      register rtx op;
  633.      enum machine_mode mode;
  634. {
  635.   enum rtx_code code = GET_CODE (op);
  636.   enum machine_mode cc_mode;
  637.  
  638.   if (GET_RTX_CLASS (code) != '<')
  639.     return 0;
  640.  
  641.   cc_mode = GET_MODE (XEXP (op, 0));
  642.   if (GET_MODE_CLASS (cc_mode) != MODE_CC)
  643.     return 0;
  644.  
  645.   if ((code == GT || code == LT || code == GE || code == LE)
  646.       && cc_mode == CCUNSmode)
  647.     return 0;
  648.  
  649.   if ((code == GTU || code == LTU || code == GEU || code == LEU)
  650.       && (cc_mode != CCUNSmode))
  651.     return 0;
  652.  
  653.   return 1;
  654. }
  655.  
  656. /* Return 1 if OP is a comparison operation that is valid for an scc insn.
  657.    We check the opcode against the mode of the CC value and disallow EQ or
  658.    NE comparisons for integers.  */
  659.  
  660. int
  661. scc_comparison_operator (op, mode)
  662.      register rtx op;
  663.      enum machine_mode mode;
  664. {
  665.   enum rtx_code code = GET_CODE (op);
  666.   enum machine_mode cc_mode;
  667.  
  668.   if (GET_MODE (op) != mode && mode != VOIDmode)
  669.     return 0;
  670.  
  671.   if (GET_RTX_CLASS (code) != '<')
  672.     return 0;
  673.  
  674.   cc_mode = GET_MODE (XEXP (op, 0));
  675.   if (GET_MODE_CLASS (cc_mode) != MODE_CC)
  676.     return 0;
  677.  
  678.   if (code == NE && cc_mode != CCFPmode)
  679.     return 0;
  680.  
  681.   if ((code == GT || code == LT || code == GE || code == LE)
  682.       && cc_mode == CCUNSmode)
  683.     return 0;
  684.  
  685.   if ((code == GTU || code == LTU || code == GEU || code == LEU)
  686.       && (cc_mode != CCUNSmode))
  687.     return 0;
  688.  
  689.   if (cc_mode == CCEQmode && code != EQ && code != NE)
  690.     return 0;
  691.  
  692.   return 1;
  693. }
  694.  
  695. /* Return 1 if ANDOP is a mask that has no bits on that are not in the
  696.    mask required to convert the result of a rotate insn into a shift
  697.    left insn of SHIFTOP bits.  Both are known to be CONST_INT.  */
  698.  
  699. int
  700. includes_lshift_p (shiftop, andop)
  701.      register rtx shiftop;
  702.      register rtx andop;
  703. {
  704.   int shift_mask = (~0 << INTVAL (shiftop));
  705.  
  706.   return (INTVAL (andop) & ~shift_mask) == 0;
  707. }
  708.  
  709. /* Similar, but for right shift.  */
  710.  
  711. int
  712. includes_rshift_p (shiftop, andop)
  713.      register rtx shiftop;
  714.      register rtx andop;
  715. {
  716.   unsigned shift_mask = ~0;
  717.  
  718.   shift_mask >>= INTVAL (shiftop);
  719.  
  720.   return (INTVAL (andop) & ~ shift_mask) == 0;
  721. }
  722.  
  723. /* Return the register class of a scratch register needed to copy IN into
  724.    or out of a register in CLASS in MODE.  If it can be done directly,
  725.    NO_REGS is returned.  */
  726.  
  727. enum reg_class
  728. secondary_reload_class (class, mode, in)
  729.      enum reg_class class;
  730.      enum machine_mode mode;
  731.      rtx in;
  732. {
  733.   int regno = true_regnum (in);
  734.  
  735.   if (regno >= FIRST_PSEUDO_REGISTER)
  736.     regno = -1;
  737.  
  738.   /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
  739.      into anything.  */
  740.   if (class == GENERAL_REGS || class == BASE_REGS
  741.       || (regno >= 0 && INT_REGNO_P (regno)))
  742.     return NO_REGS;
  743.  
  744.   /* Constants, memory, and FP registers can go into FP registers.  */
  745.   if ((regno == -1 || FP_REGNO_P (regno))
  746.       && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
  747.     return NO_REGS;
  748.  
  749.   /* We can copy among the CR registers.  */
  750.   if ((class == CR_REGS || class == CR0_REGS)
  751.       && regno >= 0 && CR_REGNO_P (regno))
  752.     return NO_REGS;
  753.  
  754.   /* Otherwise, we need GENERAL_REGS.  */
  755.   return GENERAL_REGS;
  756. }
  757.  
  758. /* Given a comparison operation, return the bit number in CCR to test.  We
  759.    know this is a valid comparison.  
  760.  
  761.    SCC_P is 1 if this is for an scc.  That means that %D will have been
  762.    used instead of %C, so the bits will be in different places.
  763.  
  764.    Return -1 if OP isn't a valid comparison for some reason.  */
  765.  
  766. int
  767. ccr_bit (op, scc_p)
  768.      register rtx op;
  769.      int scc_p;
  770. {
  771.   enum rtx_code code = GET_CODE (op);
  772.   enum machine_mode cc_mode;
  773.   int cc_regnum;
  774.   int base_bit;
  775.  
  776.   if (GET_RTX_CLASS (code) != '<')
  777.     return -1;
  778.  
  779.   cc_mode = GET_MODE (XEXP (op, 0));
  780.   cc_regnum = REGNO (XEXP (op, 0));
  781.   base_bit = 4 * (cc_regnum - 68);
  782.  
  783.   /* In CCEQmode cases we have made sure that the result is always in the
  784.      third bit of the CR field.  */
  785.  
  786.   if (cc_mode == CCEQmode)
  787.     return base_bit + 3;
  788.  
  789.   switch (code)
  790.     {
  791.     case NE:
  792.       return scc_p ? base_bit + 3 : base_bit + 2;
  793.     case EQ:
  794.       return base_bit + 2;
  795.     case GT:  case GTU:
  796.       return base_bit + 1;
  797.     case LT:  case LTU:
  798.       return base_bit;
  799.  
  800.     case GE:  case GEU:
  801.       /* If floating-point, we will have done a cror to put the bit in the
  802.      unordered position.  So test that bit.  For integer, this is ! LT
  803.      unless this is an scc insn.  */
  804.       return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit;
  805.  
  806.     case LE:  case LEU:
  807.       return cc_mode == CCFPmode || scc_p ? base_bit + 3 : base_bit + 1;
  808.  
  809.     default:
  810.       abort ();
  811.     }
  812. }
  813.  
  814. /* Print an operand.  Recognize special options, documented below.  */
  815.  
  816. void
  817. print_operand (file, x, code)
  818.     FILE *file;
  819.     rtx x;
  820.     char code;
  821. {
  822.   int i;
  823.   int val;
  824.  
  825.   /* These macros test for integers and extract the low-order bits.  */
  826. #define INT_P(X)  \
  827. ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE)    \
  828.  && GET_MODE (X) == VOIDmode)
  829.  
  830. #define INT_LOWPART(X) \
  831.   (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
  832.  
  833.   switch (code)
  834.     {
  835.     case '.':
  836.       /* Write out an instruction after the call which may be replaced
  837.      with glue code by the loader.  This depends on the AIX version.  */
  838.       asm_fprintf (file, RS6000_CALL_GLUE);
  839.       return;
  840.  
  841.     case 'A':
  842.       /* If X is a constant integer whose low-order 5 bits are zero,
  843.      write 'l'.  Otherwise, write 'r'.  This is a kludge to fix a bug
  844.      in the AIX assembler where "sri" with a zero shift count
  845.      write a trash instruction.  */
  846.       if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
  847.     putc ('l', file);
  848.       else
  849.     putc ('r', file);
  850.       return;
  851.  
  852.     case 'b':
  853.       /* Low-order 16 bits of constant, unsigned.  */
  854.       if (! INT_P (x))
  855.     output_operand_lossage ("invalid %%b value");
  856.  
  857.       fprintf (file, "%d", INT_LOWPART (x) & 0xffff);
  858.       return;
  859.  
  860.     case 'C':
  861.       /* This is an optional cror needed for LE or GE floating-point
  862.      comparisons.  Otherwise write nothing.  */
  863.       if ((GET_CODE (x) == LE || GET_CODE (x) == GE)
  864.       && GET_MODE (XEXP (x, 0)) == CCFPmode)
  865.     {
  866.       int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
  867.  
  868.       fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
  869.            base_bit + 2, base_bit + (GET_CODE (x) == GE));
  870.     }
  871.       return;
  872.  
  873.     case 'D':
  874.       /* Similar, except that this is for an scc, so we must be able to
  875.      encode the test in a single bit that is one.  We do the above
  876.      for any LE, GE, GEU, or LEU and invert the bit for NE.  */
  877.       if (GET_CODE (x) == LE || GET_CODE (x) == GE
  878.       || GET_CODE (x) == LEU || GET_CODE (x) == GEU)
  879.     {
  880.       int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
  881.  
  882.       fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
  883.            base_bit + 2,
  884.            base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU));
  885.     }
  886.  
  887.       else if (GET_CODE (x) == NE)
  888.     {
  889.       int base_bit = 4 * (REGNO (XEXP (x, 0)) - 68);
  890.  
  891.       fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3,
  892.            base_bit + 2, base_bit + 2);
  893.     }
  894.       return;
  895.  
  896.     case 'E':
  897.       /* X is a CR register.  Print the number of the third bit of the CR */
  898.       if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
  899.     output_operand_lossage ("invalid %%E value");
  900.  
  901.       fprintf(file, "%d", 4 * (REGNO (x) - 68) + 3);
  902.       return;
  903.  
  904.     case 'f':
  905.       /* X is a CR register.  Print the shift count needed to move it
  906.      to the high-order four bits.  */
  907.       if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
  908.     output_operand_lossage ("invalid %%f value");
  909.       else
  910.     fprintf (file, "%d", 4 * (REGNO (x) - 68));
  911.       return;
  912.  
  913.     case 'F':
  914.       /* Similar, but print the count for the rotate in the opposite
  915.      direction.  */
  916.       if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
  917.     output_operand_lossage ("invalid %%F value");
  918.       else
  919.     fprintf (file, "%d", 32 - 4 * (REGNO (x) - 68));
  920.       return;
  921.  
  922.     case 'G':
  923.       /* X is a constant integer.  If it is negative, print "m",
  924.      otherwise print "z".  This is to make a aze or ame insn.  */
  925.       if (GET_CODE (x) != CONST_INT)
  926.     output_operand_lossage ("invalid %%G value");
  927.       else if (INTVAL (x) >= 0)
  928.     putc ('z', file);
  929.       else
  930.     putc ('m', file);
  931.       return;
  932.     
  933.     case 'h':
  934.       /* If constant, output low-order five bits.  Otherwise,
  935.      write normally. */
  936.       if (INT_P (x))
  937.     fprintf (file, "%d", INT_LOWPART (x) & 31);
  938.       else
  939.     print_operand (file, x, 0);
  940.       return;
  941.  
  942.     case 'H':
  943.       /* X must be a constant.  Output the low order 5 bits plus 24.  */
  944.       if (! INT_P (x))
  945.     output_operand_lossage ("invalid %%H value");
  946.  
  947.       fprintf (file, "%d", (INT_LOWPART (x) + 24) & 31);
  948.       return;
  949.  
  950.     case 'I':
  951.       /* Print `i' if this is a constant, else nothing.  */
  952.       if (INT_P (x))
  953.     putc ('i', file);
  954.       return;
  955.  
  956.     case 'j':
  957.       /* Write the bit number in CCR for jump.  */
  958.       i = ccr_bit (x, 0);
  959.       if (i == -1)
  960.     output_operand_lossage ("invalid %%j code");
  961.       else
  962.     fprintf (file, "%d", i);
  963.       return;
  964.  
  965.     case 'J':
  966.       /* Similar, but add one for shift count in rlinm for scc and pass
  967.      scc flag to `ccr_bit'.  */
  968.       i = ccr_bit (x, 1);
  969.       if (i == -1)
  970.     output_operand_lossage ("invalid %%J code");
  971.       else
  972.     /* If we want bit 31, write a shift count of zero, not 32.  */
  973.     fprintf (file, "%d", i == 31 ? 0 : i + 1);
  974.       return;
  975.  
  976.     case 'k':
  977.       /* X must be a constant.  Write the 1's complement of the
  978.      constant.  */
  979.       if (! INT_P (x))
  980.     output_operand_lossage ("invalid %%k value");
  981.  
  982.       fprintf (file, "%d", ~ INT_LOWPART (x));
  983.       return;
  984.  
  985.     case 'L':
  986.       /* Write second word of DImode or DFmode reference.  Works on register
  987.      or non-indexed memory only.  */
  988.       if (GET_CODE (x) == REG)
  989.     fprintf (file, "%d", REGNO (x) + 1);
  990.       else if (GET_CODE (x) == MEM)
  991.     {
  992.       /* Handle possible auto-increment.  Since it is pre-increment and
  993.          we have already done it, we can just use an offset of four.  */
  994.       if (GET_CODE (XEXP (x, 0)) == PRE_INC
  995.           || GET_CODE (XEXP (x, 0)) == PRE_DEC)
  996.         output_address (plus_constant (XEXP (XEXP (x, 0), 0), 4));
  997.       else
  998.         output_address (plus_constant (XEXP (x, 0), 4));
  999.     }
  1000.       return;
  1001.                 
  1002.     case 'm':
  1003.       /* MB value for a mask operand.  */
  1004.       if (! mask_operand (x, VOIDmode))
  1005.     output_operand_lossage ("invalid %%m value");
  1006.  
  1007.       val = INT_LOWPART (x);
  1008.  
  1009.       /* If the high bit is set and the low bit is not, the value is zero.
  1010.      If the high bit is zero, the value is the first 1 bit we find from
  1011.      the left.  */
  1012.       if (val < 0 && (val & 1) == 0)
  1013.     {
  1014.       fprintf (file, "0");
  1015.       return;
  1016.     }
  1017.       else if (val >= 0)
  1018.     {
  1019.       for (i = 1; i < 32; i++)
  1020.         if ((val <<= 1) < 0)
  1021.           break;
  1022.       fprintf (file, "%d", i);
  1023.       return;
  1024.     }
  1025.       
  1026.       /* Otherwise, look for the first 0 bit from the right.  The result is its
  1027.      number plus 1. We know the low-order bit is one.  */
  1028.       for (i = 0; i < 32; i++)
  1029.     if (((val >>= 1) & 1) == 0)
  1030.       break;
  1031.  
  1032.       /* If we ended in ...01, I would be 0.  The correct value is 31, so
  1033.      we want 31 - i.  */
  1034.       fprintf (file, "%d", 31 - i);
  1035.       return;
  1036.  
  1037.     case 'M':
  1038.       /* ME value for a mask operand.  */
  1039.       if (! mask_operand (x, VOIDmode))
  1040.     output_operand_lossage ("invalid %%m value");
  1041.  
  1042.       val = INT_LOWPART (x);
  1043.  
  1044.       /* If the low bit is set and the high bit is not, the value is 31.
  1045.      If the low bit is zero, the value is the first 1 bit we find from
  1046.      the right.  */
  1047.       if ((val & 1) && val >= 0)
  1048.     {
  1049.       fputs ("31", file);
  1050.       return;
  1051.     }
  1052.       else if ((val & 1) == 0)
  1053.     {
  1054.       for (i = 0; i < 32; i++)
  1055.         if ((val >>= 1) & 1)
  1056.           break;
  1057.  
  1058.       /* If we had ....10, I would be 0.  The result should be
  1059.          30, so we need 30 - i.  */
  1060.       fprintf (file, "%d", 30 - i);
  1061.       return;
  1062.     }
  1063.       
  1064.       /* Otherwise, look for the first 0 bit from the left.  The result is its
  1065.      number minus 1. We know the high-order bit is one.  */
  1066.       for (i = 0; i < 32; i++)
  1067.     if ((val <<= 1) >= 0)
  1068.       break;
  1069.  
  1070.       fprintf (file, "%d", i);
  1071.       return;
  1072.  
  1073.     case 'N':
  1074.       /* Write the number of elements in the vector times 4.  */
  1075.       if (GET_CODE (x) != PARALLEL)
  1076.     output_operand_lossage ("invalid %%N value");
  1077.  
  1078.       fprintf (file, "%d", XVECLEN (x, 0) * 4);
  1079.       return;
  1080.  
  1081.     case 'O':
  1082.       /* Similar, but subtract 1 first.  */
  1083.       if (GET_CODE (x) != PARALLEL)
  1084.     output_operand_lossage ("invalid %%N value");
  1085.  
  1086.       fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
  1087.       return;
  1088.  
  1089.     case 'p':
  1090.       /* X is a CONST_INT that is a power of two.  Output the logarithm.  */
  1091.       if (! INT_P (x)
  1092.       || (i = exact_log2 (INT_LOWPART (x))) < 0)
  1093.     output_operand_lossage ("invalid %%p value");
  1094.  
  1095.       fprintf (file, "%d", i);
  1096.       return;
  1097.  
  1098.     case 'P':
  1099.       /* The operand must be an indirect memory reference.  The result
  1100.      is the register number. */
  1101.       if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
  1102.       || REGNO (XEXP (x, 0)) >= 32)
  1103.     output_operand_lossage ("invalid %%P value");
  1104.  
  1105.       fprintf (file, "%d", REGNO (XEXP (x, 0)));
  1106.       return;
  1107.  
  1108.     case 'R':
  1109.       /* X is a CR register.  Print the mask for `mtcrf'.  */
  1110.       if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
  1111.     output_operand_lossage ("invalid %%R value");
  1112.       else
  1113.     fprintf (file, "%d", 128 >> (REGNO (x) - 68));
  1114.       return;
  1115.  
  1116.     case 's':
  1117.       /* Low 5 bits of 32 - value */
  1118.       if (! INT_P (x))
  1119.     output_operand_lossage ("invalid %%s value");
  1120.  
  1121.       fprintf (file, "%d", (32 - INT_LOWPART (x)) & 31);
  1122.       return;
  1123.  
  1124.     case 'S':
  1125.       /* Low 5 bits of 31 - value */
  1126.       if (! INT_P (x))
  1127.     output_operand_lossage ("invalid %%S value");
  1128.  
  1129.       fprintf (file, "%d", (31 - INT_LOWPART (x)) & 31);
  1130.       return;
  1131.  
  1132.     case 't':
  1133.       /* Write 12 if this jump operation will branch if true, 4 otherwise. 
  1134.      All floating-point operations except NE branch true and integer
  1135.      EQ, LT, GT, LTU and GTU also branch true.  */
  1136.       if (GET_RTX_CLASS (GET_CODE (x)) != '<')
  1137.     output_operand_lossage ("invalid %%t value");
  1138.  
  1139.       else if ((GET_MODE (XEXP (x, 0)) == CCFPmode
  1140.         && GET_CODE (x) != NE)
  1141.            || GET_CODE (x) == EQ
  1142.            || GET_CODE (x) == LT || GET_CODE (x) == GT
  1143.            || GET_CODE (x) == LTU || GET_CODE (x) == GTU)
  1144.     fputs ("12", file);
  1145.       else
  1146.     putc ('4', file);
  1147.       return;
  1148.       
  1149.     case 'T':
  1150.       /* Opposite of 't': write 4 if this jump operation will branch if true,
  1151.      12 otherwise.   */
  1152.       if (GET_RTX_CLASS (GET_CODE (x)) != '<')
  1153.     output_operand_lossage ("invalid %%t value");
  1154.  
  1155.       else if ((GET_MODE (XEXP (x, 0)) == CCFPmode
  1156.         && GET_CODE (x) != NE)
  1157.            || GET_CODE (x) == EQ
  1158.            || GET_CODE (x) == LT || GET_CODE (x) == GT
  1159.            || GET_CODE (x) == LTU || GET_CODE (x) == GTU)
  1160.     putc ('4', file);
  1161.       else
  1162.     fputs ("12", file);
  1163.       return;
  1164.       
  1165.     case 'u':
  1166.       /* High-order 16 bits of constant.  */
  1167.       if (! INT_P (x))
  1168.     output_operand_lossage ("invalid %%u value");
  1169.  
  1170.       fprintf (file, "0x%x", (INT_LOWPART (x) >> 16) & 0xffff);
  1171.       return;
  1172.  
  1173.     case 'U':
  1174.       /* Print `u' if this has an auto-increment or auto-decrement.  */
  1175.       if (GET_CODE (x) == MEM
  1176.       && (GET_CODE (XEXP (x, 0)) == PRE_INC
  1177.           || GET_CODE (XEXP (x, 0)) == PRE_DEC))
  1178.     putc ('u', file);
  1179.       return;
  1180.  
  1181.     case 'w':
  1182.       /* If constant, low-order 16 bits of constant, signed.  Otherwise, write
  1183.      normally.  */
  1184.       if (INT_P (x))
  1185.     fprintf (file, "%d",
  1186.          (INT_LOWPART (x) & 0xffff) - 2 * (INT_LOWPART (x) & 0x8000));
  1187.       else
  1188.     print_operand (file, x, 0);
  1189.       return;
  1190.  
  1191.     case 'W':
  1192.       /* If constant, low-order 16 bits of constant, unsigned.
  1193.      Otherwise, write normally.  */
  1194.       if (INT_P (x))
  1195.     fprintf (file, "%d", INT_LOWPART (x) & 0xffff);
  1196.       else
  1197.     print_operand (file, x, 0);
  1198.       return;
  1199.  
  1200.     case 'X':
  1201.       if (GET_CODE (x) == MEM
  1202.       && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0)))
  1203.     putc ('x', file);
  1204.       return;
  1205.  
  1206.     case 'Y':
  1207.       /* Like 'L', for third word of TImode  */
  1208.       if (GET_CODE (x) == REG)
  1209.     fprintf (file, "%d", REGNO (x) + 2);
  1210.       else if (GET_CODE (x) == MEM)
  1211.     {
  1212.       if (GET_CODE (XEXP (x, 0)) == PRE_INC
  1213.           || GET_CODE (XEXP (x, 0)) == PRE_DEC)
  1214.         output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
  1215.       else
  1216.         output_address (plus_constant (XEXP (x, 0), 8));
  1217.     }
  1218.       return;
  1219.                 
  1220.     case 'z':
  1221.       /* X is a SYMBOL_REF.  Write out the name preceded by a
  1222.      period and without any trailing data in brackets.  Used for function
  1223.      names.  */
  1224.       if (GET_CODE (x) != SYMBOL_REF)
  1225.     abort ();
  1226.  
  1227.       putc ('.', file);
  1228.       RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
  1229.       return;
  1230.  
  1231.     case 'Z':
  1232.       /* Like 'L', for last word of TImode.  */
  1233.       if (GET_CODE (x) == REG)
  1234.     fprintf (file, "%d", REGNO (x) + 3);
  1235.       else if (GET_CODE (x) == MEM)
  1236.     {
  1237.       if (GET_CODE (XEXP (x, 0)) == PRE_INC
  1238.           || GET_CODE (XEXP (x, 0)) == PRE_DEC)
  1239.         output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
  1240.       else
  1241.         output_address (plus_constant (XEXP (x, 0), 12));
  1242.     }
  1243.       return;
  1244.                 
  1245.     case 0:
  1246.       if (GET_CODE (x) == REG)
  1247.     fprintf (file, "%s", reg_names[REGNO (x)]);
  1248.       else if (GET_CODE (x) == MEM)
  1249.     {
  1250.       /* We need to handle PRE_INC and PRE_DEC here, since we need to
  1251.          know the width from the mode.  */
  1252.       if (GET_CODE (XEXP (x, 0)) == PRE_INC)
  1253.         fprintf (file, "%d(%d)", GET_MODE_SIZE (GET_MODE (x)),
  1254.              REGNO (XEXP (XEXP (x, 0), 0)));
  1255.       else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
  1256.         fprintf (file, "%d(%d)", - GET_MODE_SIZE (GET_MODE (x)),
  1257.              REGNO (XEXP (XEXP (x, 0), 0)));
  1258.       else
  1259.         output_address (XEXP (x, 0));
  1260.     }
  1261.       else
  1262.     output_addr_const (file, x);
  1263.       return;
  1264.  
  1265.     default:
  1266.       output_operand_lossage ("invalid %%xn code");
  1267.     }
  1268. }
  1269.  
  1270. /* Print the address of an operand.  */
  1271.  
  1272. void
  1273. print_operand_address (file, x)
  1274.      FILE *file;
  1275.      register rtx x;
  1276. {
  1277.   if (GET_CODE (x) == REG)
  1278.     fprintf (file, "0(%d)", REGNO (x));
  1279.   else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
  1280.     {
  1281.       output_addr_const (file, x);
  1282.       /* When TARGET_MINIMAL_TOC, use the indirected toc table pointer instead
  1283.      of the toc pointer.  */
  1284.       if (TARGET_MINIMAL_TOC)
  1285.     fprintf (file, "(30)");
  1286.       else
  1287.     fprintf (file, "(2)");
  1288.     }
  1289.   else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
  1290.     {
  1291.       if (REGNO (XEXP (x, 0)) == 0)
  1292.     fprintf (file, "%d,%d", REGNO (XEXP (x, 1)), REGNO (XEXP (x, 0)));
  1293.       else
  1294.     fprintf (file, "%d,%d", REGNO (XEXP (x, 0)), REGNO (XEXP (x, 1)));
  1295.     }
  1296.   else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
  1297.     fprintf (file, "%d(%d)", INTVAL (XEXP (x, 1)), REGNO (XEXP (x, 0)));
  1298.   else
  1299.     abort ();
  1300. }
  1301.  
  1302. /* This page contains routines that are used to determine what the function
  1303.    prologue and epilogue code will do and write them out.  */
  1304.  
  1305. /*  Return the first fixed-point register that is required to be saved. 32 if
  1306.     none.  */
  1307.  
  1308. int
  1309. first_reg_to_save ()
  1310. {
  1311.   int first_reg;
  1312.  
  1313.   /* Find lowest numbered live register.  */
  1314.   for (first_reg = 13; first_reg <= 31; first_reg++)
  1315.     if (regs_ever_live[first_reg])
  1316.       break;
  1317.  
  1318.   /* If profiling, then we must save/restore every register that contains
  1319.      a parameter before/after the .mcount call.  Use registers from 30 down
  1320.      to 23 to do this.  Don't use the frame pointer in reg 31.
  1321.  
  1322.      For now, save enough room for all of the parameter registers.  */
  1323.   if (profile_flag)
  1324.     if (first_reg > 23)
  1325.       first_reg = 23;
  1326.  
  1327.   return first_reg;
  1328. }
  1329.  
  1330. /* Similar, for FP regs.  */
  1331.  
  1332. int
  1333. first_fp_reg_to_save ()
  1334. {
  1335.   int first_reg;
  1336.  
  1337.   /* Find lowest numbered live register.  */
  1338.   for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
  1339.     if (regs_ever_live[first_reg])
  1340.       break;
  1341.  
  1342.   return first_reg;
  1343. }
  1344.  
  1345. /* Return 1 if we need to save CR.  */
  1346.  
  1347. int
  1348. must_save_cr ()
  1349. {
  1350.   return regs_ever_live[70] || regs_ever_live[71] || regs_ever_live[72];
  1351. }
  1352.  
  1353. /* Compute the size of the save area in the stack, including the space for
  1354.    the fixed area.  */
  1355.  
  1356. int
  1357. rs6000_sa_size ()
  1358. {
  1359.   int size;
  1360.  
  1361.   /* We have the six fixed words, plus the size of the register save 
  1362.      areas, rounded to a double-word.  */
  1363.   size = 6 + (32 - first_reg_to_save ()) + (64 - first_fp_reg_to_save ()) * 2;
  1364.   if (size & 1)
  1365.     size++;
  1366.  
  1367.   return size * 4;
  1368. }
  1369.  
  1370. /* Return non-zero if this function makes calls.  */
  1371.  
  1372. int
  1373. rs6000_makes_calls ()
  1374. {
  1375.   rtx insn;
  1376.  
  1377.   /* If we are profiling, we will be making a call to mcount.  */
  1378.   if (profile_flag)
  1379.     return 1;
  1380.  
  1381.   for (insn = get_insns (); insn; insn = next_insn (insn))
  1382.     if (GET_CODE (insn) == CALL_INSN)
  1383.       return 1;
  1384.  
  1385.   return 0;
  1386. }
  1387.  
  1388. /* Return non-zero if this function needs to push space on the stack.  */
  1389.  
  1390. int
  1391. rs6000_pushes_stack ()
  1392. {
  1393.   int total_size = (rs6000_sa_size () + get_frame_size ()
  1394.             + current_function_outgoing_args_size);
  1395.  
  1396.   /* We need to push the stack if a frame pointer is needed (because the
  1397.      stack might be dynamically adjusted), if we are debugging, if the
  1398.      total stack size is more than 220 bytes, or if we make calls.  */
  1399.  
  1400.   return (frame_pointer_needed || write_symbols != NO_DEBUG
  1401.       || total_size > 220
  1402.       || rs6000_makes_calls ());
  1403. }
  1404.  
  1405. /* Write function prologue.  */
  1406.  
  1407. void
  1408. output_prolog (file, size)
  1409.      FILE *file;
  1410.      int size;
  1411. {
  1412.   int first_reg = first_reg_to_save ();
  1413.   int must_push = rs6000_pushes_stack ();
  1414.   int first_fp_reg = first_fp_reg_to_save ();
  1415.   int basic_size = rs6000_sa_size ();
  1416.   int total_size = (basic_size + size + current_function_outgoing_args_size);
  1417.  
  1418.   /* Round size to multiple of 8 bytes.  */
  1419.   total_size = (total_size + 7) & ~7;
  1420.  
  1421.   /* Write .extern for any function we will call to save and restore fp
  1422.      values.  */
  1423.   if (first_fp_reg < 62)
  1424.     fprintf (file, "\t.extern ._savef%d\n\t.extern ._restf%d\n",
  1425.          first_fp_reg - 32, first_fp_reg - 32);
  1426.  
  1427.   /* Write .extern for truncation routines, if needed.  */
  1428.   if (rs6000_trunc_used && ! trunc_defined)
  1429.     {
  1430.       fprintf (file, "\t.extern .%s\n\t.extern .%s\n",
  1431.            RS6000_ITRUNC, RS6000_UITRUNC);
  1432.       trunc_defined = 1;
  1433.     }
  1434.   /* Write .extern for AIX common mode routines, if needed.  */
  1435.   if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
  1436.     {
  1437.       fputs ("\t.extern __mulh\n", file);
  1438.       fputs ("\t.extern __mull\n", file);
  1439.       fputs ("\t.extern __divss\n", file);
  1440.       fputs ("\t.extern __divus\n", file);
  1441.       fputs ("\t.extern __quoss\n", file);
  1442.       fputs ("\t.extern __quous\n", file);
  1443.       common_mode_defined = 1;
  1444.     }
  1445.  
  1446.   /* If we have to call a function to save fpr's, or if we are doing profiling,
  1447.      then we will be using LR.  */
  1448.   if (first_fp_reg < 62 || profile_flag)
  1449.     regs_ever_live[65] = 1;
  1450.  
  1451.   /* If we use the link register, get it into r0.  */
  1452.   if (regs_ever_live[65])
  1453.     asm_fprintf (file, "\tmflr 0\n");
  1454.  
  1455.   /* If we need to save CR, put it into r12.  */
  1456.   if (must_save_cr ())
  1457.     asm_fprintf (file, "\tmfcr 12\n");
  1458.  
  1459.   /* Do any required saving of fpr's.  If only one or two to save, do it
  1460.      ourself.  Otherwise, call function.  Note that since they are statically
  1461.      linked, we do not need a nop following them.  */
  1462.   if (first_fp_reg == 62)
  1463.     asm_fprintf (file, "\tstfd 30,-16(1)\n\tstfd 31,-8(1)\n");
  1464.   else if (first_fp_reg == 63)
  1465.     asm_fprintf (file, "\tstfd 31,-8(1)\n");
  1466.   else if (first_fp_reg != 64)
  1467.     asm_fprintf (file, "\tbl ._savef%d\n", first_fp_reg - 32);
  1468.  
  1469.   /* Now save gpr's.  */
  1470.   if (! TARGET_POWER || first_reg == 31)
  1471.     {
  1472.       int regno, loc;
  1473.  
  1474.       for (regno = first_reg,
  1475.        loc = - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8;
  1476.        regno < 32;
  1477.        regno++, loc += 4)
  1478.     asm_fprintf (file, "\t{st|stw} %d,%d(1)\n", regno, loc);
  1479.     }
  1480.  
  1481.   else if (first_reg != 32)
  1482.     asm_fprintf (file, "\t{stm|stmw} %d,%d(1)\n", first_reg,
  1483.          - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8);
  1484.  
  1485.   /* Save lr if we used it.  */
  1486.   if (regs_ever_live[65])
  1487.     asm_fprintf (file, "\t{st|stw} 0,8(1)\n");
  1488.  
  1489.   /* Save CR if we use any that must be preserved.  */
  1490.   if (must_save_cr ())
  1491.     asm_fprintf (file, "\t{st|stw} 12,4(1)\n");
  1492.  
  1493.   /* Update stack and set back pointer.  */
  1494.   if (must_push)
  1495.     {
  1496.       if (total_size < 32767)
  1497.     asm_fprintf (file, "\t{stu|stwu} 1,%d(1)\n", - total_size);
  1498.       else
  1499.     {
  1500.       asm_fprintf (file, "\t{cau 0,0,%d|lis 0,%d}\n\t{oril|ori} 0,0,%d\n",
  1501.            (total_size >> 16) & 0xffff, total_size & 0xffff);
  1502.       if (TARGET_POWERPC)
  1503.         asm_fprintf (file, "\tsubf 12,0,1\n");
  1504.       else
  1505.         asm_fprintf (file, "\t{sf|subfc} 12,0,1\n");
  1506.       asm_fprintf (file, "\t{st|stw} 1,0(12)\n\tmr 1,12\n");
  1507.     }
  1508.     }
  1509.  
  1510.   /* Set frame pointer, if needed.  */
  1511.   if (frame_pointer_needed)
  1512.     asm_fprintf (file, "\tmr 31,1\n");
  1513.  
  1514.   /* If TARGET_MINIMAL_TOC, and the constant pool is needed, then load the
  1515.      TOC_TABLE address into register 30.  */
  1516.   if (TARGET_MINIMAL_TOC && get_pool_size () != 0)
  1517.     {
  1518.       char buf[100];
  1519.  
  1520.       ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 0);
  1521.       asm_fprintf (file, "\t{l|lwz} 30,");
  1522.       assemble_name (file, buf);
  1523.       asm_fprintf (file, "(2)\n");
  1524.     }
  1525. }
  1526.  
  1527. /* Write function epilogue.  */
  1528.  
  1529. void
  1530. output_epilog (file, size)
  1531.      FILE *file;
  1532.      int size;
  1533. {
  1534.   int first_reg = first_reg_to_save ();
  1535.   int must_push = rs6000_pushes_stack ();
  1536.   int first_fp_reg = first_fp_reg_to_save ();
  1537.   int basic_size = rs6000_sa_size ();
  1538.   int total_size = (basic_size + size + current_function_outgoing_args_size);
  1539.   rtx insn = get_last_insn ();
  1540.  
  1541.   /* Round size to multiple of 8 bytes.  */
  1542.   total_size = (total_size + 7) & ~7;
  1543.  
  1544.   /* If the last insn was a BARRIER, we don't have to write anything except
  1545.      the trace table.  */
  1546.   if (GET_CODE (insn) == NOTE)
  1547.     insn = prev_nonnote_insn (insn);
  1548.   if (insn == 0 ||  GET_CODE (insn) != BARRIER)
  1549.     {
  1550.       /* If we have a frame pointer, a call to alloca,  or a large stack
  1551.      frame, restore the old stack pointer using the backchain.  Otherwise,
  1552.      we know what size to update it with.  */
  1553.       if (frame_pointer_needed || current_function_calls_alloca
  1554.       || total_size > 32767)
  1555.     asm_fprintf (file, "\t{l|lwz} 1,0(1)\n");
  1556.       else if (must_push)
  1557.     asm_fprintf (file, "\t{cal 1,%d(1)|addi 1,1,%d}\n", total_size);
  1558.  
  1559.       /* Get the old lr if we saved it.  */
  1560.       if (regs_ever_live[65])
  1561.     asm_fprintf (file, "\t{l|lwz} 0,8(1)\n");
  1562.  
  1563.       /* Get the old cr if we saved it.  */
  1564.       if (must_save_cr ())
  1565.     asm_fprintf (file, "\t{l|lwz} 12,4(1)\n");
  1566.  
  1567.       /* Set LR here to try to overlap restores below.  */
  1568.       if (regs_ever_live[65])
  1569.     asm_fprintf (file, "\tmtlr 0\n");
  1570.  
  1571.       /* Restore gpr's.  */
  1572.       if (! TARGET_POWER || first_reg == 31)
  1573.     {
  1574.       int regno, loc;
  1575.  
  1576.       for (regno = first_reg,
  1577.            loc = - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8;
  1578.            regno < 32;
  1579.            regno++, loc += 4)
  1580.         asm_fprintf (file, "\t{l|lwz} %d,%d(1)\n", regno, loc);
  1581.     }
  1582.  
  1583.       else if (first_reg != 32)
  1584.     asm_fprintf (file, "\t{lm|lmw} %d,%d(1)\n", first_reg,
  1585.          - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8);
  1586.  
  1587.       /* Restore fpr's if we can do it without calling a function.  */
  1588.       if (first_fp_reg == 62)
  1589.     asm_fprintf (file, "\tlfd 30,-16(1)\n\tlfd 31,-8(1)\n");
  1590.       else if (first_fp_reg == 63)
  1591.     asm_fprintf (file, "\tlfd 31,-8(1)\n");
  1592.  
  1593.       /* If we saved cr, restore it here.  Just those of cr2, cr3, and cr4
  1594.      that were used.  */
  1595.       if (must_save_cr ())
  1596.     asm_fprintf (file, "\tmtcrf %d,12\n",
  1597.              (regs_ever_live[70] != 0) * 0x20
  1598.              + (regs_ever_live[71] != 0) * 0x10
  1599.              + (regs_ever_live[72] != 0) * 0x8);
  1600.  
  1601.       /* If we have to restore more than two FP registers, branch to the
  1602.      restore function.  It will return to our caller.  */
  1603.       if (first_fp_reg < 62)
  1604.     asm_fprintf (file, "\tb ._restf%d\n", first_fp_reg - 32);
  1605.       else
  1606.     asm_fprintf (file, "\t{br|blr}\n");
  1607.     }
  1608.  
  1609.   /* Output a traceback table here.  See /usr/include/sys/debug.h for info
  1610.      on its format.
  1611.  
  1612.      We don't output a traceback table if -finhibit-size-directive was
  1613.      used.  The documentation for -finhibit-size-directive reads
  1614.      ``don't output a @code{.size} assembler directive, or anything
  1615.      else that would cause trouble if the function is split in the
  1616.      middle, and the two halves are placed at locations far apart in
  1617.      memory.''  The traceback table has this property, since it
  1618.      includes the offset from the start of the function to the
  1619.      traceback table itself.  */
  1620.   if (! flag_inhibit_size_directive)
  1621.     {
  1622.       char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
  1623.       int fixed_parms, float_parms, parm_info;
  1624.       int i;
  1625.  
  1626.       /* Need label immediately before tbtab, so we can compute its offset
  1627.      from the function start.  */
  1628.       if (*fname == '*')
  1629.     ++fname;
  1630.       ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
  1631.       ASM_OUTPUT_LABEL (file, fname);
  1632.  
  1633.       /* The .tbtab pseudo-op can only be used for the first eight
  1634.      expressions, since it can't handle the possibly variable
  1635.      length fields that follow.  However, if you omit the optional
  1636.      fields, the assembler outputs zeros for all optional fields
  1637.      anyways, giving each variable length field is minimum length
  1638.      (as defined in sys/debug.h).  Thus we can not use the .tbtab
  1639.      pseudo-op at all.  */
  1640.  
  1641.       /* An all-zero word flags the start of the tbtab, for debuggers
  1642.      that have to find it by searching forward from the entry
  1643.      point or from the current pc.  */
  1644.       fprintf (file, "\t.long 0\n");
  1645.  
  1646.       /* Tbtab format type.  Use format type 0.  */
  1647.       fprintf (file, "\t.byte 0,");
  1648.  
  1649.       /* Language type.  Unfortunately, there doesn't seem to be any
  1650.      official way to get this info, so we use language_string.  C
  1651.      is 0.  C++ is 9.  No number defined for Obj-C, so use the
  1652.      value for C for now.  */
  1653.       if (! strcmp (language_string, "GNU C")
  1654.       || ! strcmp (language_string, "GNU Obj-C"))
  1655.     i = 0;
  1656.       else if (! strcmp (language_string, "GNU F77"))
  1657.     i = 1;
  1658.       else if (! strcmp (language_string, "GNU Ada"))
  1659.     i = 3;
  1660.       else if (! strcmp (language_string, "GNU PASCAL"))
  1661.     i = 2;
  1662.       else if (! strcmp (language_string, "GNU C++"))
  1663.     i = 9;
  1664.       else
  1665.     abort ();
  1666.       fprintf (file, "%d,", i);
  1667.  
  1668.       /* 8 single bit fields: global linkage (not set for C extern linkage,
  1669.      apparently a PL/I convention?), out-of-line epilogue/prologue, offset
  1670.      from start of procedure stored in tbtab, internal function, function
  1671.      has controlled storage, function has no toc, function uses fp,
  1672.      function logs/aborts fp operations.  */
  1673.       /* Assume that fp operations are used if any fp reg must be saved.  */
  1674.       fprintf (file, "%d,", (1 << 5) | ((first_fp_reg != 64) << 1));
  1675.  
  1676.       /* 6 bitfields: function is interrupt handler, name present in
  1677.      proc table, function calls alloca, on condition directives
  1678.      (controls stack walks, 3 bits), saves condition reg, saves
  1679.      link reg.  */
  1680.       /* The `function calls alloca' bit seems to be set whenever reg 31 is
  1681.      set up as a frame pointer, even when there is no alloca call.  */
  1682.       fprintf (file, "%d,",
  1683.            ((1 << 6) | (frame_pointer_needed << 5)
  1684.         | (must_save_cr () << 1) | (regs_ever_live[65])));
  1685.  
  1686.       /* 3 bitfields: saves backchain, spare bit, number of fpr saved
  1687.      (6 bits).  */
  1688.       fprintf (file, "%d,",
  1689.            (must_push << 7) | (64 - first_fp_reg_to_save ()));
  1690.  
  1691.       /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits).  */
  1692.       fprintf (file, "%d,", (32 - first_reg_to_save ()));
  1693.  
  1694.       {
  1695.     /* Compute the parameter info from the function decl argument
  1696.        list.  */
  1697.     tree decl;
  1698.     int next_parm_info_bit;
  1699.  
  1700.     next_parm_info_bit = 31;
  1701.     parm_info = 0;
  1702.     fixed_parms = 0;
  1703.     float_parms = 0;
  1704.  
  1705.     for (decl = DECL_ARGUMENTS (current_function_decl);
  1706.          decl; decl = TREE_CHAIN (decl))
  1707.       {
  1708.         rtx parameter = DECL_INCOMING_RTL (decl);
  1709.         enum machine_mode mode = GET_MODE (parameter);
  1710.  
  1711.         if (GET_CODE (parameter) == REG)
  1712.           {
  1713.         if (GET_MODE_CLASS (mode) == MODE_FLOAT)
  1714.           {
  1715.             int bits;
  1716.  
  1717.             float_parms++;
  1718.  
  1719.             if (mode == SFmode)
  1720.               bits = 0x2;
  1721.             else if (mode == DFmode)
  1722.               bits = 0x3;
  1723.             else
  1724.               abort ();
  1725.  
  1726.             /* If only one bit will fit, don't or in this entry.  */
  1727.             if (next_parm_info_bit > 0)
  1728.               parm_info |= (bits << (next_parm_info_bit - 1));
  1729.             next_parm_info_bit -= 2;
  1730.           }
  1731.         else
  1732.           {
  1733.             fixed_parms += ((GET_MODE_SIZE (mode)
  1734.                      + (UNITS_PER_WORD - 1))
  1735.                     / UNITS_PER_WORD);
  1736.             next_parm_info_bit -= 1;
  1737.           }
  1738.           }
  1739.       }
  1740.       }
  1741.  
  1742.       /* Number of fixed point parameters.  */
  1743.       /* This is actually the number of words of fixed point parameters; thus
  1744.      an 8 byte struct counts as 2; and thus the maximum value is 8.  */
  1745.       fprintf (file, "%d,", fixed_parms);
  1746.  
  1747.       /* 2 bitfields: number of floating point parameters (7 bits), parameters
  1748.      all on stack.  */
  1749.       /* This is actually the number of fp registers that hold parameters;
  1750.      and thus the maximum value is 13.  */
  1751.       /* Set parameters on stack bit if parameters are not in their original
  1752.      registers, regardless of whether they are on the stack?  Xlc
  1753.      seems to set the bit when not optimizing.  */
  1754.       fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
  1755.  
  1756.       /* Optional fields follow.  Some are variable length.  */
  1757.  
  1758.       /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
  1759.      11 double float.  */
  1760.       /* There is an entry for each parameter in a register, in the order that
  1761.      they occur in the parameter list.  Any intervening arguments on the
  1762.      stack are ignored.  If the list overflows a long (max possible length
  1763.      34 bits) then completely leave off all elements that don't fit.  */
  1764.       /* Only emit this long if there was at least one parameter.  */
  1765.       if (fixed_parms || float_parms)
  1766.     fprintf (file, "\t.long %d\n", parm_info);
  1767.  
  1768.       /* Offset from start of code to tb table.  */
  1769.       fprintf (file, "\t.long ");
  1770.       ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
  1771.       RS6000_OUTPUT_BASENAME (file, fname);
  1772.       fprintf (file, "-.");
  1773.       RS6000_OUTPUT_BASENAME (file, fname);
  1774.       fprintf (file, "\n");
  1775.  
  1776.       /* Interrupt handler mask.  */
  1777.       /* Omit this long, since we never set the interrupt handler bit
  1778.      above.  */
  1779.  
  1780.       /* Number of CTL (controlled storage) anchors.  */
  1781.       /* Omit this long, since the has_ctl bit is never set above.  */
  1782.  
  1783.       /* Displacement into stack of each CTL anchor.  */
  1784.       /* Omit this list of longs, because there are no CTL anchors.  */
  1785.  
  1786.       /* Length of function name.  */
  1787.       fprintf (file, "\t.short %d\n", strlen (fname));
  1788.  
  1789.       /* Function name.  */
  1790.       assemble_string (fname, strlen (fname));
  1791.  
  1792.       /* Register for alloca automatic storage; this is always reg 31.
  1793.      Only emit this if the alloca bit was set above.  */
  1794.       if (frame_pointer_needed)
  1795.     fprintf (file, "\t.byte 31\n");
  1796.     }
  1797. }
  1798.  
  1799. /* Output a TOC entry.  We derive the entry name from what is
  1800.    being written.  */
  1801.  
  1802. void
  1803. output_toc (file, x, labelno)
  1804.      FILE *file;
  1805.      rtx x;
  1806.      int labelno;
  1807. {
  1808.   char buf[256];
  1809.   char *name = buf;
  1810.   rtx base = x;
  1811.   int offset = 0;
  1812.  
  1813.   ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno);
  1814.  
  1815.   /* Handle FP constants specially.  Note that if we have a minimal
  1816.      TOC, things we put here aren't actually in the TOC, so we can allow
  1817.      FP constants.  */
  1818.   if (GET_CODE (x) == CONST_DOUBLE
  1819.       && GET_MODE (x) == DFmode
  1820.       && TARGET_FLOAT_FORMAT == HOST_FLOAT_FORMAT
  1821.       && BITS_PER_WORD == HOST_BITS_PER_INT
  1822.       && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
  1823.     {
  1824.       if (TARGET_MINIMAL_TOC)
  1825.     fprintf (file, "\t.long %d\n\t.long %d\n",
  1826.          CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x));
  1827.       else
  1828.     fprintf (file, "\t.tc FD_%x_%x[TC],%d,%d\n",
  1829.          CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x),
  1830.          CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x));
  1831.       return;
  1832.     }
  1833.   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode
  1834.        && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
  1835.     {
  1836.       rtx val = operand_subword (x, 0, 0, SFmode);
  1837.  
  1838.       if (val == 0 || GET_CODE (val) != CONST_INT)
  1839.     abort ();
  1840.  
  1841.       if (TARGET_MINIMAL_TOC)
  1842.     fprintf (file, "\t.long %d\n", INTVAL (val));
  1843.       else
  1844.     fprintf (file, "\t.tc FS_%x[TC],%d\n", INTVAL (val), INTVAL (val));
  1845.       return;
  1846.     }
  1847.  
  1848.   if (GET_CODE (x) == CONST)
  1849.     {
  1850.       base = XEXP (XEXP (x, 0), 0);
  1851.       offset = INTVAL (XEXP (XEXP (x, 0), 1));
  1852.     }
  1853.   
  1854.   if (GET_CODE (base) == SYMBOL_REF)
  1855.     name = XSTR (base, 0);
  1856.   else if (GET_CODE (base) == LABEL_REF)
  1857.     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
  1858.   else if (GET_CODE (base) == CODE_LABEL)
  1859.     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
  1860.   else
  1861.     abort ();
  1862.  
  1863.   if (TARGET_MINIMAL_TOC)
  1864.     fprintf (file, "\t.long ");
  1865.   else
  1866.     {
  1867.       fprintf (file, "\t.tc ");
  1868.       RS6000_OUTPUT_BASENAME (file, name);
  1869.  
  1870.       if (offset < 0)
  1871.     fprintf (file, ".N%d", - offset);
  1872.       else if (offset)
  1873.     fprintf (file, ".P%d", offset);
  1874.  
  1875.       fprintf (file, "[TC],");
  1876.     }
  1877.   output_addr_const (file, x);
  1878.   fprintf (file, "\n");
  1879. }
  1880.  
  1881. /* Output an assembler pseudo-op to write an ASCII string of N characters
  1882.    starting at P to FILE.
  1883.  
  1884.    On the RS/6000, we have to do this using the .byte operation and
  1885.    write out special characters outside the quoted string.
  1886.    Also, the assembler is broken; very long strings are truncated,
  1887.    so we must artificially break them up early. */
  1888.  
  1889. void
  1890. output_ascii (file, p, n)
  1891.      FILE *file;
  1892.      char *p;
  1893.      int n;
  1894. {
  1895.   char c;
  1896.   int i, count_string;
  1897.   char *for_string = "\t.byte \"";
  1898.   char *for_decimal = "\t.byte ";
  1899.   char *to_close = NULL;
  1900.  
  1901.   count_string = 0;
  1902.   for (i = 0; i < n; i++)
  1903.     {
  1904.       c = *p++;
  1905.       if (c >= ' ' && c < 0177)
  1906.     {
  1907.       if (for_string)
  1908.         fputs (for_string, file);
  1909.       putc (c, file);
  1910.  
  1911.       /* Write two quotes to get one.  */
  1912.       if (c == '"')
  1913.         {
  1914.           putc (c, file);
  1915.           ++count_string;
  1916.         }
  1917.  
  1918.       for_string = NULL;
  1919.       for_decimal = "\"\n\t.byte ";
  1920.       to_close = "\"\n";
  1921.       ++count_string;
  1922.  
  1923.       if (count_string >= 512)
  1924.         {
  1925.           fputs (to_close, file);
  1926.  
  1927.           for_string = "\t.byte \"";
  1928.           for_decimal = "\t.byte ";
  1929.           to_close = NULL;
  1930.           count_string = 0;
  1931.         }
  1932.     }
  1933.       else
  1934.     {
  1935.       if (for_decimal)
  1936.         fputs (for_decimal, file);
  1937.       fprintf (file, "%d", c);
  1938.  
  1939.       for_string = "\n\t.byte \"";
  1940.       for_decimal = ", ";
  1941.       to_close = "\n";
  1942.       count_string = 0;
  1943.     }
  1944.     }
  1945.  
  1946.   /* Now close the string if we have written one.  Then end the line.  */
  1947.   if (to_close)
  1948.     fprintf (file, to_close);
  1949. }
  1950.  
  1951. /* Generate a unique section name for FILENAME for a section type
  1952.    represented by SECTION_DESC.  Output goes into BUF.
  1953.  
  1954.    SECTION_DESC can be any string, as long as it is different for each
  1955.    possible section type.
  1956.  
  1957.    We name the section in the same manner as xlc.  The name begins with an
  1958.    underscore followed by the filename (after stripping any leading directory
  1959.    names) with the last period replaced by the string SECTION_DESC.  If
  1960.    FILENAME does not contain a period, SECTION_DESC is appended to the end of
  1961.    the name.  */
  1962.  
  1963. void
  1964. rs6000_gen_section_name (buf, filename, section_desc)
  1965.      char **buf;
  1966.      char *filename;
  1967.      char *section_desc;
  1968. {
  1969.   char *q, *after_last_slash, *last_period;
  1970.   char *p;
  1971.   int len;
  1972.  
  1973.   after_last_slash = filename;
  1974.   for (q = filename; *q; q++)
  1975.     {
  1976.       if (*q == '/')
  1977.     after_last_slash = q + 1;
  1978.       else if (*q == '.')
  1979.     last_period = q;
  1980.     }
  1981.  
  1982.   len = strlen (after_last_slash) + strlen (section_desc) + 2;
  1983.   *buf = (char *) permalloc (len);
  1984.  
  1985.   p = *buf;
  1986.   *p++ = '_';
  1987.  
  1988.   for (q = after_last_slash; *q; q++)
  1989.     {
  1990.       if (q == last_period)
  1991.         {
  1992.       strcpy (p, section_desc);
  1993.       p += strlen (section_desc);
  1994.         }
  1995.  
  1996.       else if (isalnum (*q))
  1997.         *p++ = *q;
  1998.     }
  1999.  
  2000.   if (last_period == 0)
  2001.     strcpy (p, section_desc);
  2002.   else
  2003.     *p = '\0';
  2004. }
  2005.  
  2006. /* Write function profiler code. */
  2007.  
  2008. void
  2009. output_function_profiler (file, labelno)
  2010.   FILE *file;
  2011.   int labelno;
  2012. {
  2013.   /* The last used parameter register.  */
  2014.   int last_parm_reg;
  2015.   int i, j;
  2016.   char buf[100];
  2017.  
  2018.   /* Set up a TOC entry for the profiler label.  */
  2019.   toc_section ();
  2020.   ASM_OUTPUT_INTERNAL_LABEL (file, "LPC", labelno);
  2021.   ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
  2022.   if (TARGET_MINIMAL_TOC)
  2023.     {
  2024.       fprintf (file, "\t.long ");
  2025.       assemble_name (file, buf);
  2026.       fprintf (file, "\n");
  2027.     }
  2028.   else
  2029.     {
  2030.       fprintf (file, "\t.tc\t");
  2031.       assemble_name (file, buf);
  2032.       fprintf (file, "[TC],");
  2033.       assemble_name (file, buf);
  2034.       fprintf (file, "\n");
  2035.     }
  2036.   text_section ();
  2037.  
  2038.   /* Figure out last used parameter register.  The proper thing to do is
  2039.      to walk incoming args of the function.  A function might have live
  2040.      parameter registers even if it has no incoming args.  */
  2041.  
  2042.   for (last_parm_reg = 10;
  2043.        last_parm_reg > 2 && ! regs_ever_live [last_parm_reg];
  2044.        last_parm_reg--)
  2045.     ;
  2046.  
  2047.   /* Save parameter registers in regs 23-30.  Don't overwrite reg 31, since
  2048.      it might be set up as the frame pointer.  */
  2049.  
  2050.   for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
  2051.     fprintf (file, "\tai %d,%d,0\n", j, i);
  2052.  
  2053.   /* Load location address into r3, and call mcount.  */
  2054.  
  2055.   ASM_GENERATE_INTERNAL_LABEL (buf, "LPC", labelno);
  2056.   fprintf (file, "\tl 3,");
  2057.   assemble_name (file, buf);
  2058.   fprintf (file, "(2)\n\tbl .mcount\n");
  2059.  
  2060.   /* Restore parameter registers.  */
  2061.  
  2062.   for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
  2063.     fprintf (file, "\tai %d,%d,0\n", i, j);
  2064. }
  2065.  
  2066. /* Adjust the cost of a scheduling dependency.  Return the new cost of
  2067.    a dependency LINK or INSN on DEP_INSN.  COST is the current cost.  */
  2068.  
  2069. int
  2070. rs6000_adjust_cost (insn, link, dep_insn, cost)
  2071.      rtx insn;
  2072.      rtx link;
  2073.      rtx dep_insn;
  2074.      int cost;
  2075. {
  2076.   if (! recog_memoized (insn))
  2077.     return 0;
  2078.  
  2079.   if (REG_NOTE_KIND (link) != 0)
  2080.     return 0;
  2081.  
  2082.   if (REG_NOTE_KIND (link) == 0)
  2083.     {
  2084.       /* Data dependency; DEP_INSN writes a register that INSN reads some
  2085.      cycles later.  */
  2086.  
  2087.       /* Tell the first scheduling pass about the latency between a mtctr
  2088.      and bctr (and mtlr and br/blr).  The first scheduling pass will not
  2089.      know about this latency since the mtctr instruction, which has the
  2090.      latency associated to it, will be generated by reload.  */
  2091.       if (get_attr_type (insn) == TYPE_JMPREG)
  2092.     return TARGET_POWER ? 5 : 4;
  2093.  
  2094.       /* Fall out to return default cost.  */
  2095.     }
  2096.  
  2097.   return cost;
  2098. }
  2099.