home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / gcc / config / i386 / i386.c < prev    next >
C/C++ Source or Header  |  1996-06-12  |  91KB  |  3,439 lines

  1. /* Subroutines for insn-output.c for Intel X86.
  2.    Copyright (C) 1988, 1992, 1994, 1995 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 59 Temple Place - Suite 330,
  19. Boston, MA 02111-1307, USA.  */
  20.  
  21. #include <stdio.h>
  22. #include <setjmp.h>
  23. #include <ctype.h>
  24. #include "config.h"
  25. #include "rtl.h"
  26. #include "regs.h"
  27. #include "hard-reg-set.h"
  28. #include "real.h"
  29. #include "insn-config.h"
  30. #include "conditions.h"
  31. #include "insn-flags.h"
  32. #include "output.h"
  33. #include "insn-attr.h"
  34. #include "tree.h"
  35. #include "flags.h"
  36. #include "function.h"
  37.  
  38. #ifdef MACHO_PIC
  39. #include "insn-codes.h"
  40. #include "next/machopic.h"
  41. #endif
  42.  
  43. #ifdef EXTRA_CONSTRAINT
  44. /* If EXTRA_CONSTRAINT is defined, then the 'S'
  45.    constraint in REG_CLASS_FROM_LETTER will no longer work, and various
  46.    asm statements that need 'S' for class SIREG will break.  */
  47.  error EXTRA_CONSTRAINT conflicts with S constraint letter
  48. /* The previous line used to be #error, but some compilers barf
  49.    even if the conditional was untrue.  */
  50. #endif
  51.  
  52. #define AT_BP(mode) (gen_rtx (MEM, (mode), frame_pointer_rtx))
  53.  
  54. extern FILE *asm_out_file;
  55. extern char *strcat ();
  56.  
  57. char *singlemove_string ();
  58. char *output_move_const_single ();
  59. char *output_fp_cc0_set ();
  60.  
  61. char *hi_reg_name[] = HI_REGISTER_NAMES;
  62. char *qi_reg_name[] = QI_REGISTER_NAMES;
  63. char *qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES;
  64.  
  65. #ifdef NEXT_SEMANTICS
  66. static rtx lookup_i386_stack_local ();
  67. #endif
  68.  
  69. /* Array of the smallest class containing reg number REGNO, indexed by
  70.    REGNO.  Used by REGNO_REG_CLASS in i386.h. */
  71.  
  72. enum reg_class regclass_map[FIRST_PSEUDO_REGISTER] =
  73. {
  74.   /* ax, dx, cx, bx */
  75.   AREG, DREG, CREG, BREG,
  76.   /* si, di, bp, sp */
  77.   SIREG, DIREG, INDEX_REGS, GENERAL_REGS,
  78.   /* FP registers */
  79.   FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS,
  80.   FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS,       
  81.   /* arg pointer */
  82.   INDEX_REGS
  83. };
  84.  
  85. /* Test and compare insns in i386.md store the information needed to
  86.    generate branch and scc insns here.  */
  87.  
  88. struct rtx_def *i386_compare_op0 = NULL_RTX;
  89. struct rtx_def *i386_compare_op1 = NULL_RTX;
  90. struct rtx_def *(*i386_compare_gen)(), *(*i386_compare_gen_eq)();
  91.  
  92. /* Register allocation order */
  93. char *i386_reg_alloc_order;
  94. static char regs_allocated[FIRST_PSEUDO_REGISTER];
  95.  
  96. /* # of registers to use to pass arguments. */
  97. char *i386_regparm_string;            /* # registers to use to pass args */
  98. int i386_regparm;                /* i386_regparm_string as a number */
  99.  
  100. /* Alignment to use for loops and jumps */
  101. char *i386_align_loops_string;            /* power of two alignment for loops */
  102. char *i386_align_jumps_string;            /* power of two alignment for non-loop jumps */
  103. char *i386_align_funcs_string;            /* power of two alignment for functions */
  104.  
  105. int i386_align_loops;                /* power of two alignment for loops */
  106. int i386_align_jumps;                /* power of two alignment for non-loop jumps */
  107. int i386_align_funcs;                /* power of two alignment for functions */
  108.  
  109.  
  110. /* Sometimes certain combinations of command options do not make
  111.    sense on a particular target machine.  You can define a macro
  112.    `OVERRIDE_OPTIONS' to take account of this.  This macro, if
  113.    defined, is executed once just after all the command options have
  114.    been parsed.
  115.  
  116.    Don't use this macro to turn on various extra optimizations for
  117.    `-O'.  That is what `OPTIMIZATION_OPTIONS' is for.  */
  118.  
  119. void
  120. override_options ()
  121. {
  122.   int ch, i, regno;
  123.   char *p;
  124.   int def_align;
  125.  
  126. #ifdef SUBTARGET_OVERRIDE_OPTIONS
  127.   SUBTARGET_OVERRIDE_OPTIONS;
  128. #endif
  129.  
  130.   /* Validate registers in register allocation order */
  131.   if (i386_reg_alloc_order)
  132.     {
  133.       for (i = 0; (ch = i386_reg_alloc_order[i]) != '\0'; i++)
  134.     {
  135.       switch (ch)
  136.         {
  137.         case 'a':    regno = 0;    break;
  138.         case 'd':    regno = 1;    break;
  139.         case 'c':    regno = 2;    break;
  140.         case 'b':    regno = 3;    break;
  141.         case 'S':    regno = 4;    break;
  142.         case 'D':    regno = 5;    break;
  143.         case 'B':    regno = 6;    break;
  144.  
  145.         default:    fatal ("Register '%c' is unknown", ch);
  146.         }
  147.  
  148.       if (regs_allocated[regno])
  149.         fatal ("Register '%c' was already specified in the allocation order", ch);
  150.  
  151.       regs_allocated[regno] = 1;
  152.     }
  153.     }
  154.  
  155.   /* Validate -mregparm= value */
  156.   if (i386_regparm_string)
  157.     {
  158.       i386_regparm = atoi (i386_regparm_string);
  159.       if (i386_regparm < 0 || i386_regparm > REGPARM_MAX)
  160.     fatal ("-mregparm=%d is not between 0 and %d", i386_regparm, REGPARM_MAX);
  161.     }
  162.  
  163.   def_align = (TARGET_386) ? 2 : 4;
  164.  
  165.   /* Validate -malign-loops= value, or provide default */
  166.   if (i386_align_loops_string)
  167.     {
  168.       i386_align_loops = atoi (i386_align_loops_string);
  169.       if (i386_align_loops < 0 || i386_align_loops > MAX_CODE_ALIGN)
  170.     fatal ("-malign-loops=%d is not between 0 and %d",
  171.            i386_align_loops, MAX_CODE_ALIGN);
  172.     }
  173.   else
  174.     i386_align_loops = 2;
  175.  
  176.   /* Validate -malign-jumps= value, or provide default */
  177.   if (i386_align_jumps_string)
  178.     {
  179.       i386_align_jumps = atoi (i386_align_jumps_string);
  180.       if (i386_align_jumps < 0 || i386_align_jumps > MAX_CODE_ALIGN)
  181.     fatal ("-malign-jumps=%d is not between 0 and %d",
  182.            i386_align_jumps, MAX_CODE_ALIGN);
  183.     }
  184.   else
  185.     i386_align_jumps = def_align;
  186.  
  187.   /* Validate -malign-functions= value, or provide default */
  188.   if (i386_align_funcs_string)
  189.     {
  190.       i386_align_funcs = atoi (i386_align_funcs_string);
  191.       if (i386_align_funcs < 0 || i386_align_funcs > MAX_CODE_ALIGN)
  192.     fatal ("-malign-functions=%d is not between 0 and %d",
  193.            i386_align_funcs, MAX_CODE_ALIGN);
  194.     }
  195.   else
  196.     i386_align_funcs = def_align;
  197. }
  198.  
  199. /* A C statement (sans semicolon) to choose the order in which to
  200.    allocate hard registers for pseudo-registers local to a basic
  201.    block.
  202.  
  203.    Store the desired register order in the array `reg_alloc_order'.
  204.    Element 0 should be the register to allocate first; element 1, the
  205.    next register; and so on.
  206.  
  207.    The macro body should not assume anything about the contents of
  208.    `reg_alloc_order' before execution of the macro.
  209.  
  210.    On most machines, it is not necessary to define this macro.  */
  211.  
  212. void
  213. order_regs_for_local_alloc ()
  214. {
  215.   int i, ch, order, regno;
  216.  
  217.   /* User specified the register allocation order */
  218.   if (i386_reg_alloc_order)
  219.     {
  220.       for (i = order = 0; (ch = i386_reg_alloc_order[i]) != '\0'; i++)
  221.     {
  222.       switch (ch)
  223.         {
  224.         case 'a':    regno = 0;    break;
  225.         case 'd':    regno = 1;    break;
  226.         case 'c':    regno = 2;    break;
  227.         case 'b':    regno = 3;    break;
  228.         case 'S':    regno = 4;    break;
  229.         case 'D':    regno = 5;    break;
  230.         case 'B':    regno = 6;    break;
  231.         }
  232.  
  233.       reg_alloc_order[order++] = regno;
  234.     }
  235.  
  236.       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  237.     {
  238.       if (!regs_allocated[i])
  239.         reg_alloc_order[order++] = i;
  240.     }
  241.     }
  242.  
  243.   /* If users did not specify a register allocation order, favor eax
  244.      normally except if DImode variables are used, in which case
  245.      favor edx before eax, which seems to cause less spill register
  246.      not found messages.  */
  247.   else
  248.     {
  249.       rtx insn;
  250.  
  251.       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  252.     reg_alloc_order[i] = i;
  253.  
  254.       if (optimize)
  255.     {
  256.       int use_dca = FALSE;
  257.  
  258.       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  259.         {
  260.           if (GET_CODE (insn) == INSN)
  261.         {
  262.           rtx set = NULL_RTX;
  263.           rtx pattern = PATTERN (insn);
  264.  
  265.           if (GET_CODE (pattern) == SET)
  266.             set = pattern;
  267.  
  268.           else if ((GET_CODE (pattern) == PARALLEL
  269.                 || GET_CODE (pattern) == SEQUENCE)
  270.                && GET_CODE (XVECEXP (pattern, 0, 0)) == SET)
  271.             set = XVECEXP (pattern, 0, 0);
  272.  
  273.           if (set && GET_MODE (SET_SRC (set)) == DImode)
  274.             {
  275.               use_dca = TRUE;
  276.               break;
  277.             }
  278.         }
  279.         }
  280.  
  281.       if (use_dca)
  282.         {
  283.           reg_alloc_order[0] = 1;    /* edx */
  284.           reg_alloc_order[1] = 2;    /* ecx */
  285.           reg_alloc_order[2] = 0;    /* eax */
  286.         }
  287.     }
  288.     }
  289. }
  290.  
  291.  
  292. /* Return nonzero if IDENTIFIER with arguments ARGS is a valid machine specific
  293.    attribute for DECL.  The attributes in ATTRIBUTES have previously been
  294.    assigned to DECL.  */
  295.  
  296. int
  297. i386_valid_decl_attribute_p (decl, attributes, identifier, args)
  298.      tree decl;
  299.      tree attributes;
  300.      tree identifier;
  301.      tree args;
  302. {
  303.   return 0;
  304. }
  305.  
  306. /* Return nonzero if IDENTIFIER with arguments ARGS is a valid machine specific
  307.    attribute for TYPE.  The attributes in ATTRIBUTES have previously been
  308.    assigned to TYPE.  */
  309.  
  310. int
  311. i386_valid_type_attribute_p (type, attributes, identifier, args)
  312.      tree type;
  313.      tree attributes;
  314.      tree identifier;
  315.      tree args;
  316. {
  317.   if (TREE_CODE (type) != FUNCTION_TYPE
  318.       && TREE_CODE (type) != FIELD_DECL
  319.       && TREE_CODE (type) != TYPE_DECL)
  320.     return 0;
  321.  
  322.   /* Stdcall attribute says callee is responsible for popping arguments
  323.      if they are not variable.  */
  324.   if (is_attribute_p ("stdcall", identifier))
  325.     return (args == NULL_TREE);
  326.  
  327.   /* Cdecl attribute says the callee is a normal C declaration */
  328.   if (is_attribute_p ("cdecl", identifier))
  329.     return (args == NULL_TREE);
  330.  
  331.   /* Regparm attribute specifies how many integer arguments are to be
  332.      passed in registers */
  333.   if (is_attribute_p ("regparm", identifier))
  334.     {
  335.       tree cst;
  336.  
  337.       if (!args || TREE_CODE (args) != TREE_LIST
  338.       || TREE_CHAIN (args) != NULL_TREE
  339.       || TREE_VALUE (args) == NULL_TREE)
  340.     return 0;
  341.  
  342.       cst = TREE_VALUE (args);
  343.       if (TREE_CODE (cst) != INTEGER_CST)
  344.     return 0;
  345.  
  346.       if (TREE_INT_CST_HIGH (cst) != 0
  347.       || TREE_INT_CST_LOW (cst) < 0
  348.       || TREE_INT_CST_LOW (cst) > REGPARM_MAX)
  349.     return 0;
  350.  
  351.       return 1;
  352.     }
  353.  
  354.   return 0;
  355. }
  356.  
  357. /* Return 0 if the attributes for two types are incompatible, 1 if they
  358.    are compatible, and 2 if they are nearly compatible (which causes a
  359.    warning to be generated).  */
  360.  
  361. int
  362. i386_comp_type_attributes (type1, type2)
  363.      tree type1;
  364.      tree type2;
  365. {
  366.   return 1;
  367. }
  368.  
  369.  
  370. /* Value is the number of bytes of arguments automatically
  371.    popped when returning from a subroutine call.
  372.    FUNDECL is the declaration node of the function (as a tree),
  373.    FUNTYPE is the data type of the function (as a tree),
  374.    or for a library call it is an identifier node for the subroutine name.
  375.    SIZE is the number of bytes of arguments passed on the stack.
  376.  
  377.    On the 80386, the RTD insn may be used to pop them if the number
  378.      of args is fixed, but if the number is variable then the caller
  379.      must pop them all.  RTD can't be used for library calls now
  380.      because the library is compiled with the Unix compiler.
  381.    Use of RTD is a selectable option, since it is incompatible with
  382.    standard Unix calling sequences.  If the option is not selected,
  383.    the caller must always pop the args.
  384.  
  385.    The attribute stdcall is equivalent to RTD on a per module basis.  */
  386.  
  387. int
  388. i386_return_pops_args (fundecl, funtype, size)
  389.      tree fundecl;
  390.      tree funtype;
  391.      int size;
  392. {
  393.   int rtd = TARGET_RTD;
  394.  
  395.   if (TREE_CODE (funtype) == IDENTIFIER_NODE)
  396.     return 0;
  397.  
  398.   /* Cdecl functions override -mrtd, and never pop the stack */
  399.   if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (funtype)))
  400.     return 0;
  401.  
  402.   /* Stdcall functions will pop the stack if not variable args */
  403. #if defined (_WIN32) && defined (NEXT_PDO)
  404.   if (fundecl && TYPE_STDCALL (fundecl) || TYPE_STDCALL (funtype))
  405.     /* What if variable args???  */
  406.     return size;
  407. #endif
  408.   if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype)))
  409.     rtd = 1;
  410.  
  411.   if (rtd)
  412.     {
  413.       if (TYPE_ARG_TYPES (funtype) == NULL_TREE
  414.       || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (funtype))) == void_type_node))
  415.     return size;
  416.  
  417.       if (aggregate_value_p (TREE_TYPE (funtype)))
  418.     return GET_MODE_SIZE (Pmode);
  419.     }
  420.  
  421.   return 0;
  422. }
  423.  
  424.  
  425. /* Argument support functions.  */
  426.  
  427. /* Initialize a variable CUM of type CUMULATIVE_ARGS
  428.    for a call to a function whose data type is FNTYPE.
  429.    For a library call, FNTYPE is 0.  */
  430.  
  431. void
  432. init_cumulative_args (cum, fntype, libname)
  433.      CUMULATIVE_ARGS *cum;    /* argument info to initialize */
  434.      tree fntype;        /* tree ptr for function decl */
  435.      rtx libname;        /* SYMBOL_REF of library name or 0 */
  436. {
  437.   static CUMULATIVE_ARGS zero_cum;
  438.   tree param, next_param;
  439.  
  440.   if (TARGET_DEBUG_ARG)
  441.     {
  442.       fprintf (stderr, "\ninit_cumulative_args (");
  443.       if (fntype)
  444.     {
  445.       tree ret_type = TREE_TYPE (fntype);
  446.       fprintf (stderr, "fntype code = %s, ret code = %s",
  447.            tree_code_name[ (int)TREE_CODE (fntype) ],
  448.            tree_code_name[ (int)TREE_CODE (ret_type) ]);
  449.     }
  450.       else
  451.     fprintf (stderr, "no fntype");
  452.  
  453.       if (libname)
  454.     fprintf (stderr, ", libname = %s", XSTR (libname, 0));
  455.     }
  456.  
  457.   *cum = zero_cum;
  458.  
  459.   /* Set up the number of registers to use for passing arguments.  */
  460.   cum->nregs = i386_regparm;
  461.   if (fntype)
  462.     {
  463.       tree attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (fntype));
  464.       if (attr)
  465.     cum->nregs = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
  466.     }
  467.  
  468.   /* Determine if this function has variable arguments.  This is
  469.      indicated by the last argument being 'void_type_mode' if there
  470.      are no variable arguments.  If there are variable arguments, then
  471.      we won't pass anything in registers */
  472.  
  473.   if (cum->nregs)
  474.     {
  475.       for (param = (fntype) ? TYPE_ARG_TYPES (fntype) : 0;
  476.        param != (tree)0;
  477.        param = next_param)
  478.     {
  479.       next_param = TREE_CHAIN (param);
  480.       if (next_param == (tree)0 && TREE_VALUE (param) != void_type_node)
  481.         cum->nregs = 0;
  482.     }
  483.     }
  484.  
  485.   if (TARGET_DEBUG_ARG)
  486.     fprintf (stderr, ", nregs=%d )\n", cum->nregs);
  487.  
  488.   return;
  489. }
  490.  
  491. /* Update the data in CUM to advance over an argument
  492.    of mode MODE and data type TYPE.
  493.    (TYPE is null for libcalls where that information may not be available.)  */
  494.  
  495. void
  496. function_arg_advance (cum, mode, type, named)
  497.      CUMULATIVE_ARGS *cum;    /* current arg information */
  498.      enum machine_mode mode;    /* current arg mode */
  499.      tree type;            /* type of the argument or 0 if lib support */
  500.      int named;            /* whether or not the argument was named */
  501. {
  502.   int bytes = (mode == BLKmode) ? int_size_in_bytes (type) : GET_MODE_SIZE (mode);
  503.   int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
  504.  
  505.   if (TARGET_DEBUG_ARG)
  506.     fprintf (stderr,
  507.          "function_adv( size=%d, words=%2d, nregs=%d, mode=%4s, named=%d )\n\n",
  508.          words, cum->words, cum->nregs, GET_MODE_NAME (mode), named);
  509.  
  510.   cum->words += words;
  511.   cum->nregs -= words;
  512.   cum->regno += words;
  513.  
  514.   if (cum->nregs <= 0)
  515.     {
  516.       cum->nregs = 0;
  517.       cum->regno = 0;
  518.     }
  519.  
  520.   return;
  521. }
  522.  
  523. /* Define where to put the arguments to a function.
  524.    Value is zero to push the argument on the stack,
  525.    or a hard register in which to store the argument.
  526.  
  527.    MODE is the argument's machine mode.
  528.    TYPE is the data type of the argument (as a tree).
  529.     This is null for libcalls where that information may
  530.     not be available.
  531.    CUM is a variable of type CUMULATIVE_ARGS which gives info about
  532.     the preceding args and about the function being called.
  533.    NAMED is nonzero if this argument is a named parameter
  534.     (otherwise it is an extra parameter matching an ellipsis).  */
  535.  
  536. struct rtx_def *
  537. function_arg (cum, mode, type, named)
  538.      CUMULATIVE_ARGS *cum;    /* current arg information */
  539.      enum machine_mode mode;    /* current arg mode */
  540.      tree type;            /* type of the argument or 0 if lib support */
  541.      int named;            /* != 0 for normal args, == 0 for ... args */
  542. {
  543.   rtx ret   = NULL_RTX;
  544.   int bytes = (mode == BLKmode) ? int_size_in_bytes (type) : GET_MODE_SIZE (mode);
  545.   int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
  546.  
  547.   switch (mode)
  548.     {
  549.     default:            /* for now, pass fp/complex values on the stack */
  550.       break;
  551.  
  552.     case BLKmode:
  553.     case DImode:
  554.     case SImode:
  555.     case HImode:
  556.     case QImode:
  557.       if (words <= cum->nregs)
  558.     ret = gen_rtx (REG, mode, cum->regno);
  559.       break;
  560.     }
  561.  
  562.   if (TARGET_DEBUG_ARG)
  563.     {
  564.       fprintf (stderr,
  565.            "function_arg( size=%d, words=%2d, nregs=%d, mode=%4s, named=%d",
  566.            words, cum->words, cum->nregs, GET_MODE_NAME (mode), named);
  567.  
  568.       if (ret)
  569.     fprintf (stderr, ", reg=%%e%s", reg_names[ REGNO(ret) ]);
  570.       else
  571.     fprintf (stderr, ", stack");
  572.  
  573.       fprintf (stderr, " )\n");
  574.     }
  575.  
  576.   return ret;
  577. }
  578.  
  579. /* For an arg passed partly in registers and partly in memory,
  580.    this is the number of registers used.
  581.    For args passed entirely in registers or entirely in memory, zero.  */
  582.  
  583. int
  584. function_arg_partial_nregs (cum, mode, type, named)
  585.      CUMULATIVE_ARGS *cum;    /* current arg information */
  586.      enum machine_mode mode;    /* current arg mode */
  587.      tree type;            /* type of the argument or 0 if lib support */
  588.      int named;            /* != 0 for normal args, == 0 for ... args */
  589. {
  590.   return 0;
  591. }
  592.  
  593.  
  594. /* Output an insn whose source is a 386 integer register.  SRC is the
  595.    rtx for the register, and TEMPLATE is the op-code template.  SRC may
  596.    be either SImode or DImode.
  597.  
  598.    The template will be output with operands[0] as SRC, and operands[1]
  599.    as a pointer to the top of the 386 stack.  So a call from floatsidf2
  600.    would look like this:
  601.  
  602.       output_op_from_reg (operands[1], AS1 (fild%z0,%1));
  603.  
  604.    where %z0 corresponds to the caller's operands[1], and is used to
  605.    emit the proper size suffix.
  606.  
  607.    ??? Extend this to handle HImode - a 387 can load and store HImode
  608.    values directly. */
  609.  
  610. void
  611. output_op_from_reg (src, template)
  612.      rtx src;
  613.      char *template;
  614. {
  615.   rtx xops[4];
  616.   int size = GET_MODE_SIZE (GET_MODE (src));
  617.  
  618.   xops[0] = src;
  619.   xops[1] = AT_SP (Pmode);
  620.   xops[2] = GEN_INT (size);
  621.   xops[3] = stack_pointer_rtx;
  622.  
  623.   if (size > UNITS_PER_WORD)
  624.     {
  625.       rtx high;
  626.       if (size > 2 * UNITS_PER_WORD)
  627.     {
  628.       high = gen_rtx (REG, SImode, REGNO (src) + 2);
  629.       output_asm_insn (AS1 (push%L0,%0), &high);
  630.     }
  631.       high = gen_rtx (REG, SImode, REGNO (src) + 1);
  632.       output_asm_insn (AS1 (push%L0,%0), &high);
  633.     }
  634.   output_asm_insn (AS1 (push%L0,%0), &src);
  635.  
  636.   output_asm_insn (template, xops);
  637.  
  638.   output_asm_insn (AS2 (add%L3,%2,%3), xops);
  639. }
  640.  
  641. /* Output an insn to pop an value from the 387 top-of-stack to 386
  642.    register DEST. The 387 register stack is popped if DIES is true.  If
  643.    the mode of DEST is an integer mode, a `fist' integer store is done,
  644.    otherwise a `fst' float store is done. */
  645.  
  646. void
  647. output_to_reg (dest, dies)
  648.      rtx dest;
  649.      int dies;
  650. {
  651.   rtx xops[4];
  652.   int size = GET_MODE_SIZE (GET_MODE (dest));
  653.  
  654.   xops[0] = AT_SP (Pmode);
  655.   xops[1] = stack_pointer_rtx;
  656.   xops[2] = GEN_INT (size);
  657.   xops[3] = dest;
  658.  
  659.   output_asm_insn (AS2 (sub%L1,%2,%1), xops);
  660.  
  661.   if (GET_MODE_CLASS (GET_MODE (dest)) == MODE_INT)
  662.     {
  663.       if (dies)
  664.     output_asm_insn (AS1 (fistp%z3,%y0), xops);
  665.       else
  666.     output_asm_insn (AS1 (fist%z3,%y0), xops);
  667.     }
  668.   else if (GET_MODE_CLASS (GET_MODE (dest)) == MODE_FLOAT)
  669.     {
  670.       if (dies)
  671.     output_asm_insn (AS1 (fstp%z3,%y0), xops);
  672.       else
  673.     {
  674.       if (GET_MODE (dest) == XFmode)
  675.         {
  676.           output_asm_insn (AS1 (fstp%z3,%y0), xops);
  677.           output_asm_insn (AS1 (fld%z3,%y0), xops);
  678.         }
  679.       else
  680.         output_asm_insn (AS1 (fst%z3,%y0), xops);
  681.     }
  682.     }
  683.   else
  684.     abort ();
  685.  
  686.   output_asm_insn (AS1 (pop%L0,%0), &dest);
  687.  
  688.   if (size > UNITS_PER_WORD)
  689.     {
  690.       dest = gen_rtx (REG, SImode, REGNO (dest) + 1);
  691.       output_asm_insn (AS1 (pop%L0,%0), &dest);
  692.       if (size > 2 * UNITS_PER_WORD)
  693.     {
  694.       dest = gen_rtx (REG, SImode, REGNO (dest) + 1);
  695.       output_asm_insn (AS1 (pop%L0,%0), &dest);
  696.     }
  697.     }
  698. }
  699.  
  700. char *
  701. singlemove_string (operands)
  702.      rtx *operands;
  703. {
  704.   rtx x;
  705.   if (GET_CODE (operands[0]) == MEM
  706.       && GET_CODE (x = XEXP (operands[0], 0)) == PRE_DEC)
  707.     {
  708.       if (XEXP (x, 0) != stack_pointer_rtx)
  709.     abort ();
  710.       return "push%L1 %1";
  711.     }
  712.   else if (GET_CODE (operands[1]) == CONST_DOUBLE)
  713.     {
  714.       return output_move_const_single (operands);
  715.     }
  716.   else if (GET_CODE (operands[0]) == REG || GET_CODE (operands[1]) == REG)
  717.     return AS2 (mov%L0,%1,%0);
  718.   else if (CONSTANT_P (operands[1]))
  719.     return AS2 (mov%L0,%1,%0);
  720.   else
  721.     {
  722.       output_asm_insn ("push%L1 %1", operands);
  723.       return "pop%L0 %0";
  724.     }
  725. }
  726.  
  727. /* Return a REG that occurs in ADDR with coefficient 1.
  728.    ADDR can be effectively incremented by incrementing REG.  */
  729.  
  730. static rtx
  731. find_addr_reg (addr)
  732.      rtx addr;
  733. {
  734.   while (GET_CODE (addr) == PLUS)
  735.     {
  736.       if (GET_CODE (XEXP (addr, 0)) == REG)
  737.     addr = XEXP (addr, 0);
  738.       else if (GET_CODE (XEXP (addr, 1)) == REG)
  739.     addr = XEXP (addr, 1);
  740.       else if (CONSTANT_P (XEXP (addr, 0)))
  741.     addr = XEXP (addr, 1);
  742.       else if (CONSTANT_P (XEXP (addr, 1)))
  743.     addr = XEXP (addr, 0);
  744.       else
  745.     abort ();
  746.     }
  747.   if (GET_CODE (addr) == REG)
  748.     return addr;
  749.   abort ();
  750. }
  751.  
  752.  
  753. /* Output an insn to add the constant N to the register X.  */
  754.  
  755. static void
  756. asm_add (n, x)
  757.      int n;
  758.      rtx x;
  759. {
  760.   rtx xops[2];
  761.   xops[0] = x;
  762.  
  763.   if (n == -1)
  764.     output_asm_insn (AS1 (dec%L0,%0), xops);
  765.   else if (n == 1)
  766.     output_asm_insn (AS1 (inc%L0,%0), xops);
  767.   else if (n < 0)
  768.     {
  769.       xops[1] = GEN_INT (-n);
  770.       output_asm_insn (AS2 (sub%L0,%1,%0), xops);
  771.     }
  772.   else if (n > 0)
  773.     {
  774.       xops[1] = GEN_INT (n);
  775.       output_asm_insn (AS2 (add%L0,%1,%0), xops);
  776.     }
  777. }
  778.  
  779.  
  780. /* Output assembler code to perform a doubleword move insn
  781.    with operands OPERANDS.  */
  782.  
  783. char *
  784. output_move_double (operands)
  785.      rtx *operands;
  786. {
  787.   enum {REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP } optype0, optype1;
  788.   rtx latehalf[2];
  789.   rtx middlehalf[2];
  790.   rtx xops[2];
  791.   rtx addreg0 = 0, addreg1 = 0;
  792.   int dest_overlapped_low = 0;
  793.   int size = GET_MODE_SIZE (GET_MODE (operands[0]));
  794.  
  795.   middlehalf[0] = 0;
  796.   middlehalf[1] = 0;
  797.  
  798.   /* First classify both operands.  */
  799.  
  800.   if (REG_P (operands[0]))
  801.     optype0 = REGOP;
  802.   else if (offsettable_memref_p (operands[0]))
  803.     optype0 = OFFSOP;
  804.   else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
  805.     optype0 = POPOP;
  806.   else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
  807.     optype0 = PUSHOP;
  808.   else if (GET_CODE (operands[0]) == MEM)
  809.     optype0 = MEMOP;
  810.   else
  811.     optype0 = RNDOP;
  812.  
  813.   if (REG_P (operands[1]))
  814.     optype1 = REGOP;
  815.   else if (CONSTANT_P (operands[1]))
  816.     optype1 = CNSTOP;
  817.   else if (offsettable_memref_p (operands[1]))
  818.     optype1 = OFFSOP;
  819.   else if (GET_CODE (XEXP (operands[1], 0)) == POST_INC)
  820.     optype1 = POPOP;
  821.   else if (GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)
  822.     optype1 = PUSHOP;
  823.   else if (GET_CODE (operands[1]) == MEM)
  824.     optype1 = MEMOP;
  825.   else
  826.     optype1 = RNDOP;
  827.  
  828.   /* Check for the cases that the operand constraints are not
  829.      supposed to allow to happen.  Abort if we get one,
  830.      because generating code for these cases is painful.  */
  831.  
  832.   if (optype0 == RNDOP || optype1 == RNDOP)
  833.     abort ();
  834.  
  835.   /* If one operand is decrementing and one is incrementing
  836.      decrement the former register explicitly
  837.      and change that operand into ordinary indexing.  */
  838.  
  839.   if (optype0 == PUSHOP && optype1 == POPOP)
  840.     {
  841.       /* ??? Can this ever happen on i386? */
  842.       operands[0] = XEXP (XEXP (operands[0], 0), 0);
  843.       asm_add (-size, operands[0]);
  844.       if (GET_MODE (operands[1]) == XFmode)
  845.         operands[0] = gen_rtx (MEM, XFmode, operands[0]);
  846.       else if (GET_MODE (operands[0]) == DFmode)
  847.         operands[0] = gen_rtx (MEM, DFmode, operands[0]);
  848.       else
  849.         operands[0] = gen_rtx (MEM, DImode, operands[0]);
  850.       optype0 = OFFSOP;
  851.     }
  852.  
  853.   if (optype0 == POPOP && optype1 == PUSHOP)
  854.     {
  855.       /* ??? Can this ever happen on i386? */
  856.       operands[1] = XEXP (XEXP (operands[1], 0), 0);
  857.       asm_add (-size, operands[1]);
  858.       if (GET_MODE (operands[1]) == XFmode)
  859.         operands[1] = gen_rtx (MEM, XFmode, operands[1]);
  860.       else if (GET_MODE (operands[1]) == DFmode)
  861.         operands[1] = gen_rtx (MEM, DFmode, operands[1]);
  862.       else
  863.         operands[1] = gen_rtx (MEM, DImode, operands[1]);
  864.       optype1 = OFFSOP;
  865.     }
  866.  
  867.   /* If an operand is an unoffsettable memory ref, find a register
  868.      we can increment temporarily to make it refer to the second word.  */
  869.  
  870.   if (optype0 == MEMOP)
  871.     addreg0 = find_addr_reg (XEXP (operands[0], 0));
  872.  
  873.   if (optype1 == MEMOP)
  874.     addreg1 = find_addr_reg (XEXP (operands[1], 0));
  875.  
  876.   /* Ok, we can do one word at a time.
  877.      Normally we do the low-numbered word first,
  878.      but if either operand is autodecrementing then we
  879.      do the high-numbered word first.
  880.  
  881.      In either case, set up in LATEHALF the operands to use
  882.      for the high-numbered word and in some cases alter the
  883.      operands in OPERANDS to be suitable for the low-numbered word.  */
  884.  
  885.   if (size == 12)
  886.     {
  887.       if (optype0 == REGOP)
  888.     {
  889.       middlehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 1);
  890.       latehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 2);
  891.     }
  892.       else if (optype0 == OFFSOP)
  893.     {
  894.       middlehalf[0] = adj_offsettable_operand (operands[0], 4);
  895.       latehalf[0] = adj_offsettable_operand (operands[0], 8);
  896.     }
  897.       else
  898.     {
  899.          middlehalf[0] = operands[0];
  900.          latehalf[0] = operands[0];
  901.     }
  902.     
  903.       if (optype1 == REGOP)
  904.     {
  905.           middlehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
  906.           latehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 2);
  907.     }
  908.       else if (optype1 == OFFSOP)
  909.     {
  910.           middlehalf[1] = adj_offsettable_operand (operands[1], 4);
  911.           latehalf[1] = adj_offsettable_operand (operands[1], 8);
  912.     }
  913.       else if (optype1 == CNSTOP)
  914.     {
  915.       if (GET_CODE (operands[1]) == CONST_DOUBLE)
  916.         {
  917.           REAL_VALUE_TYPE r; long l[3];
  918.  
  919.           REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
  920.           REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
  921.           operands[1] = GEN_INT (l[0]);
  922.           middlehalf[1] = GEN_INT (l[1]);
  923.           latehalf[1] = GEN_INT (l[2]);
  924.         }
  925.       else if (CONSTANT_P (operands[1]))
  926.         /* No non-CONST_DOUBLE constant should ever appear here.  */
  927.         abort ();
  928.         }
  929.       else
  930.     {
  931.       middlehalf[1] = operands[1];
  932.       latehalf[1] = operands[1];
  933.     }
  934.     }
  935.   else /* size is not 12: */
  936.     {
  937.       if (optype0 == REGOP)
  938.     latehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 1);
  939.       else if (optype0 == OFFSOP)
  940.     latehalf[0] = adj_offsettable_operand (operands[0], 4);
  941.       else
  942.     latehalf[0] = operands[0];
  943.  
  944.       if (optype1 == REGOP)
  945.     latehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
  946.       else if (optype1 == OFFSOP)
  947.     latehalf[1] = adj_offsettable_operand (operands[1], 4);
  948.       else if (optype1 == CNSTOP)
  949.     split_double (operands[1], &operands[1], &latehalf[1]);
  950.       else
  951.     latehalf[1] = operands[1];
  952.     }
  953.  
  954.   /* If insn is effectively movd N (sp),-(sp) then we will do the
  955.      high word first.  We should use the adjusted operand 1
  956.      (which is N+4 (sp) or N+8 (sp))
  957.      for the low word and middle word as well,
  958.      to compensate for the first decrement of sp.  */
  959.   if (optype0 == PUSHOP
  960.       && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM
  961.       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
  962.     middlehalf[1] = operands[1] = latehalf[1];
  963.  
  964.   /* For (set (reg:DI N) (mem:DI ... (reg:SI N) ...)),
  965.      if the upper part of reg N does not appear in the MEM, arrange to
  966.      emit the move late-half first.  Otherwise, compute the MEM address
  967.      into the upper part of N and use that as a pointer to the memory
  968.      operand.  */
  969.   if (optype0 == REGOP
  970.       && (optype1 == OFFSOP || optype1 == MEMOP))
  971.     {
  972.       if (reg_mentioned_p (operands[0], XEXP (operands[1], 0))
  973.       && reg_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
  974.     {
  975.       /* If both halves of dest are used in the src memory address,
  976.          compute the address into latehalf of dest.  */
  977. compadr:
  978.       xops[0] = latehalf[0];
  979.       xops[1] = XEXP (operands[1], 0);
  980.       output_asm_insn (AS2 (lea%L0,%a1,%0), xops);
  981.       if( GET_MODE (operands[1]) == XFmode )
  982.         {
  983. /*        abort (); */
  984.           operands[1] = gen_rtx (MEM, XFmode, latehalf[0]);
  985.           middlehalf[1] = adj_offsettable_operand (operands[1], size-8);
  986.           latehalf[1] = adj_offsettable_operand (operands[1], size-4);
  987.         }
  988.       else
  989.         {
  990.           operands[1] = gen_rtx (MEM, DImode, latehalf[0]);
  991.           latehalf[1] = adj_offsettable_operand (operands[1], size-4);
  992.         }
  993.     }
  994.       else if (size == 12
  995.          && reg_mentioned_p (middlehalf[0], XEXP (operands[1], 0)))
  996.     {
  997.       /* Check for two regs used by both source and dest. */
  998.       if (reg_mentioned_p (operands[0], XEXP (operands[1], 0))
  999.         || reg_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
  1000.         goto compadr;
  1001.  
  1002.       /* JRV says this can't happen: */
  1003.       if (addreg0 || addreg1)
  1004.           abort();
  1005.  
  1006.       /* Only the middle reg conflicts; simply put it last. */
  1007.       output_asm_insn (singlemove_string (operands), operands);
  1008.       output_asm_insn (singlemove_string (latehalf), latehalf);
  1009.       output_asm_insn (singlemove_string (middlehalf), middlehalf);
  1010.       return "";
  1011.     }
  1012.       else if (reg_mentioned_p (operands[0], XEXP (operands[1], 0)))
  1013.     /* If the low half of dest is mentioned in the source memory
  1014.        address, the arrange to emit the move late half first.  */
  1015.     dest_overlapped_low = 1;
  1016.     }
  1017.  
  1018.   /* If one or both operands autodecrementing,
  1019.      do the two words, high-numbered first.  */
  1020.  
  1021.   /* Likewise,  the first move would clobber the source of the second one,
  1022.      do them in the other order.  This happens only for registers;
  1023.      such overlap can't happen in memory unless the user explicitly
  1024.      sets it up, and that is an undefined circumstance.  */
  1025.  
  1026. /*
  1027.   if (optype0 == PUSHOP || optype1 == PUSHOP
  1028.       || (optype0 == REGOP && optype1 == REGOP
  1029.       && REGNO (operands[0]) == REGNO (latehalf[1]))
  1030.       || dest_overlapped_low)
  1031. */
  1032.   if (optype0 == PUSHOP || optype1 == PUSHOP
  1033.       || (optype0 == REGOP && optype1 == REGOP
  1034.       && ((middlehalf[1] && REGNO (operands[0]) == REGNO (middlehalf[1]))
  1035.           || REGNO (operands[0]) == REGNO (latehalf[1])))
  1036.       || dest_overlapped_low)
  1037.     {
  1038.       /* Make any unoffsettable addresses point at high-numbered word.  */
  1039.       if (addreg0)
  1040.     asm_add (size-4, addreg0);
  1041.       if (addreg1)
  1042.     asm_add (size-4, addreg1);
  1043.  
  1044.       /* Do that word.  */
  1045.       output_asm_insn (singlemove_string (latehalf), latehalf);
  1046.  
  1047.       /* Undo the adds we just did.  */
  1048.       if (addreg0)
  1049.          asm_add (-4, addreg0);
  1050.       if (addreg1)
  1051.     asm_add (-4, addreg1);
  1052.  
  1053.       if (size == 12)
  1054.         {
  1055.         output_asm_insn (singlemove_string (middlehalf), middlehalf);
  1056.         if (addreg0)
  1057.            asm_add (-4, addreg0);
  1058.         if (addreg1)
  1059.        asm_add (-4, addreg1);
  1060.     }
  1061.  
  1062.       /* Do low-numbered word.  */
  1063.       return singlemove_string (operands);
  1064.     }
  1065.  
  1066.   /* Normal case: do the two words, low-numbered first.  */
  1067.  
  1068.   output_asm_insn (singlemove_string (operands), operands);
  1069.  
  1070.   /* Do the middle one of the three words for long double */
  1071.   if (size == 12)
  1072.     {
  1073.       if (addreg0)
  1074.         asm_add (4, addreg0);
  1075.       if (addreg1)
  1076.         asm_add (4, addreg1);
  1077.  
  1078.       output_asm_insn (singlemove_string (middlehalf), middlehalf);
  1079.     }
  1080.  
  1081.   /* Make any unoffsettable addresses point at high-numbered word.  */
  1082.   if (addreg0)
  1083.     asm_add (4, addreg0);
  1084.   if (addreg1)
  1085.     asm_add (4, addreg1);
  1086.  
  1087.   /* Do that word.  */
  1088.   output_asm_insn (singlemove_string (latehalf), latehalf);
  1089.  
  1090.   /* Undo the adds we just did.  */
  1091.   if (addreg0)
  1092.     asm_add (4-size, addreg0);
  1093.   if (addreg1)
  1094.     asm_add (4-size, addreg1);
  1095.  
  1096.   return "";
  1097. }
  1098.  
  1099.  
  1100. #define MAX_TMPS 2        /* max temporary registers used */
  1101.  
  1102. /* Output the appropriate code to move push memory on the stack */
  1103.  
  1104. char *
  1105. output_move_pushmem (operands, insn, length, tmp_start, n_operands)
  1106.      rtx operands[];
  1107.      rtx insn;
  1108.      int length;
  1109.      int tmp_start;
  1110.      int n_operands;
  1111. {
  1112.  
  1113.   struct {
  1114.     char *load;
  1115.     char *push;
  1116.     rtx   xops[2];
  1117.   } tmp_info[MAX_TMPS];
  1118.  
  1119.   rtx src = operands[1];
  1120.   int max_tmps = 0;
  1121.   int offset = 0;
  1122.   int stack_p = reg_overlap_mentioned_p (stack_pointer_rtx, src);
  1123.   int stack_offset = 0;
  1124.   int i, num_tmps;
  1125.   rtx xops[1];
  1126.  
  1127.   if (!offsettable_memref_p (src))
  1128.     fatal_insn ("Source is not offsettable", insn);
  1129.  
  1130.   if ((length & 3) != 0)
  1131.     fatal_insn ("Pushing non-word aligned size", insn);
  1132.  
  1133.   /* Figure out which temporary registers we have available */
  1134.   for (i = tmp_start; i < n_operands; i++)
  1135.     {
  1136.       if (GET_CODE (operands[i]) == REG)
  1137.     {
  1138.       if (reg_overlap_mentioned_p (operands[i], src))
  1139.         continue;
  1140.  
  1141.       tmp_info[ max_tmps++ ].xops[1] = operands[i];
  1142.       if (max_tmps == MAX_TMPS)
  1143.         break;
  1144.     }
  1145.     }
  1146.  
  1147.   if (max_tmps == 0)
  1148.     for (offset = length - 4; offset >= 0; offset -= 4)
  1149.       {
  1150.     xops[0] = adj_offsettable_operand (src, offset + stack_offset);
  1151.     output_asm_insn (AS1(push%L0,%0), xops);
  1152.     if (stack_p)
  1153.       stack_offset += 4;
  1154.       }
  1155.  
  1156.   else
  1157.     for (offset = length - 4; offset >= 0; )
  1158.       {
  1159.     for (num_tmps = 0; num_tmps < max_tmps && offset >= 0; num_tmps++)
  1160.       {
  1161.         tmp_info[num_tmps].load    = AS2(mov%L0,%0,%1);
  1162.         tmp_info[num_tmps].push    = AS1(push%L0,%1);
  1163.         tmp_info[num_tmps].xops[0] = adj_offsettable_operand (src, offset + stack_offset);
  1164.         offset -= 4;
  1165.       }
  1166.  
  1167.     for (i = 0; i < num_tmps; i++)
  1168.       output_asm_insn (tmp_info[i].load, tmp_info[i].xops);
  1169.  
  1170.     for (i = 0; i < num_tmps; i++)
  1171.       output_asm_insn (tmp_info[i].push, tmp_info[i].xops);
  1172.  
  1173.     if (stack_p)
  1174.       stack_offset += 4*num_tmps;
  1175.       }
  1176.  
  1177.   return "";
  1178. }
  1179.  
  1180.  
  1181.  
  1182. /* Output the appropriate code to move data between two memory locations */
  1183.  
  1184. char *
  1185. output_move_memory (operands, insn, length, tmp_start, n_operands)
  1186.      rtx operands[];
  1187.      rtx insn;
  1188.      int length;
  1189.      int tmp_start;
  1190.      int n_operands;
  1191. {
  1192.   struct {
  1193.     char *load;
  1194.     char *store;
  1195.     rtx   xops[3];
  1196.   } tmp_info[MAX_TMPS];
  1197.  
  1198.   rtx dest = operands[0];
  1199.   rtx src  = operands[1];
  1200.   rtx qi_tmp = NULL_RTX;
  1201.   int max_tmps = 0;
  1202.   int offset = 0;
  1203.   int i, num_tmps;
  1204.   rtx xops[3];
  1205.  
  1206.   if (GET_CODE (dest) == MEM
  1207.       && GET_CODE (XEXP (dest, 0)) == PRE_INC
  1208.       && XEXP (XEXP (dest, 0), 0) == stack_pointer_rtx)
  1209.     return output_move_pushmem (operands, insn, length, tmp_start, n_operands);
  1210.  
  1211.   if (!offsettable_memref_p (src))
  1212.     fatal_insn ("Source is not offsettable", insn);
  1213.  
  1214.   if (!offsettable_memref_p (dest))
  1215.     fatal_insn ("Destination is not offsettable", insn);
  1216.  
  1217.   /* Figure out which temporary registers we have available */
  1218.   for (i = tmp_start; i < n_operands; i++)
  1219.     {
  1220.       if (GET_CODE (operands[i]) == REG)
  1221.     {
  1222.       if ((length & 1) != 0 && !qi_tmp && QI_REG_P (operands[i]))
  1223.         qi_tmp = operands[i];
  1224.  
  1225.       if (reg_overlap_mentioned_p (operands[i], dest))
  1226.         fatal_insn ("Temporary register overlaps the destination", insn);
  1227.  
  1228.       if (reg_overlap_mentioned_p (operands[i], src))
  1229.         fatal_insn ("Temporary register overlaps the source", insn);
  1230.  
  1231.       tmp_info[ max_tmps++ ].xops[2] = operands[i];
  1232.       if (max_tmps == MAX_TMPS)
  1233.         break;
  1234.     }
  1235.     }
  1236.  
  1237.   if (max_tmps == 0)
  1238.     fatal_insn ("No scratch registers were found to do memory->memory moves", insn);
  1239.  
  1240.   if ((length & 1) != 0)
  1241.     {
  1242.       if (!qi_tmp)
  1243.     fatal_insn ("No byte register found when moving odd # of bytes.", insn);
  1244.     }
  1245.  
  1246.   while (length > 1)
  1247.     {
  1248.       for (num_tmps = 0; num_tmps < max_tmps; num_tmps++)
  1249.     {
  1250.       if (length >= 4)
  1251.         {
  1252.           tmp_info[num_tmps].load    = AS2(mov%L0,%1,%2);
  1253.           tmp_info[num_tmps].store   = AS2(mov%L0,%2,%0);
  1254.           tmp_info[num_tmps].xops[0] = adj_offsettable_operand (dest, offset);
  1255.           tmp_info[num_tmps].xops[1] = adj_offsettable_operand (src, offset);
  1256.           offset += 4;
  1257.           length -= 4;
  1258.         }
  1259.       else if (length >= 2)
  1260.         {
  1261.           tmp_info[num_tmps].load    = AS2(mov%W0,%1,%2);
  1262.           tmp_info[num_tmps].store   = AS2(mov%W0,%2,%0);
  1263.           tmp_info[num_tmps].xops[0] = adj_offsettable_operand (dest, offset);
  1264.           tmp_info[num_tmps].xops[1] = adj_offsettable_operand (src, offset);
  1265.           offset += 2;
  1266.           length -= 2;
  1267.         }
  1268.       else
  1269.         break;
  1270.     }
  1271.  
  1272.       for (i = 0; i < num_tmps; i++)
  1273.     output_asm_insn (tmp_info[i].load, tmp_info[i].xops);
  1274.  
  1275.       for (i = 0; i < num_tmps; i++)
  1276.     output_asm_insn (tmp_info[i].store, tmp_info[i].xops);
  1277.     }
  1278.  
  1279.   if (length == 1)
  1280.     {
  1281.       xops[0] = adj_offsettable_operand (dest, offset);
  1282.       xops[1] = adj_offsettable_operand (src, offset);
  1283.       xops[2] = qi_tmp;
  1284.       output_asm_insn (AS2(mov%B0,%1,%2), xops);
  1285.       output_asm_insn (AS2(mov%B0,%2,%0), xops);
  1286.     }
  1287.  
  1288.   return "";
  1289. }
  1290.  
  1291.  
  1292. int
  1293. standard_80387_constant_p (x)
  1294.      rtx x;
  1295. {
  1296. #if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
  1297.   REAL_VALUE_TYPE d;
  1298.   jmp_buf handler;
  1299.   int is0, is1;
  1300.  
  1301.   if (setjmp (handler))
  1302.     return 0;
  1303.  
  1304.   set_float_handler (handler);
  1305.   REAL_VALUE_FROM_CONST_DOUBLE (d, x);
  1306.   is0 = REAL_VALUES_EQUAL (d, dconst0);
  1307.   is1 = REAL_VALUES_EQUAL (d, dconst1);
  1308.   set_float_handler (NULL_PTR);
  1309.  
  1310.   if (is0)
  1311.     return 1;
  1312.  
  1313.   if (is1)
  1314.     return 2;
  1315.  
  1316.   /* Note that on the 80387, other constants, such as pi,
  1317.      are much slower to load as standard constants
  1318.      than to load from doubles in memory!  */
  1319. #endif
  1320.  
  1321.   return 0;
  1322. }
  1323.  
  1324. char *
  1325. output_move_const_single (operands)
  1326.      rtx *operands;
  1327. {
  1328.   if (FP_REG_P (operands[0]))
  1329.     {
  1330.       int conval = standard_80387_constant_p (operands[1]);
  1331.  
  1332.       if (conval == 1)
  1333.     return "fldz";
  1334.  
  1335.       if (conval == 2)
  1336.     return "fld1";
  1337.     }
  1338.   if (GET_CODE (operands[1]) == CONST_DOUBLE)
  1339.     {
  1340.       REAL_VALUE_TYPE r; long l;
  1341.  
  1342.       if (GET_MODE (operands[1]) == XFmode)
  1343.     abort ();
  1344.  
  1345.       REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
  1346.       REAL_VALUE_TO_TARGET_SINGLE (r, l);
  1347.       operands[1] = GEN_INT (l);
  1348.     }
  1349.   return singlemove_string (operands);
  1350. }
  1351.  
  1352. /* Returns 1 if OP is either a symbol reference or a sum of a symbol
  1353.    reference and a constant.  */
  1354.  
  1355. int
  1356. symbolic_operand (op, mode)
  1357.      register rtx op;
  1358.      enum machine_mode mode;
  1359. {
  1360.   switch (GET_CODE (op))
  1361.     {
  1362.     case SYMBOL_REF:
  1363.     case LABEL_REF:
  1364.       return 1;
  1365.     case CONST:
  1366.       op = XEXP (op, 0);
  1367.       return (
  1368. #ifdef NEXT_SEMANTICS
  1369.           GET_CODE (op) == SYMBOL_REF ||
  1370. #endif
  1371.           (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
  1372.            || GET_CODE (XEXP (op, 0)) == LABEL_REF)
  1373.           && GET_CODE (XEXP (op, 1)) == CONST_INT);
  1374.     default:
  1375.       return 0;
  1376.     }
  1377. }
  1378.  
  1379. /* Test for a valid operand for a call instruction.
  1380.    Don't allow the arg pointer register or virtual regs
  1381.    since they may change into reg + const, which the patterns
  1382.    can't handle yet.  */
  1383.  
  1384. int
  1385. call_insn_operand (op, mode)
  1386.      rtx op;
  1387.      enum machine_mode mode;
  1388. {
  1389.   if (GET_CODE (op) == MEM
  1390.       && ((CONSTANT_ADDRESS_P (XEXP (op, 0))
  1391.        /* This makes a difference for PIC.  */
  1392.        && general_operand (XEXP (op, 0), Pmode))
  1393.       || (GET_CODE (XEXP (op, 0)) == REG
  1394.           && XEXP (op, 0) != arg_pointer_rtx
  1395.           && !(REGNO (XEXP (op, 0)) >= FIRST_PSEUDO_REGISTER
  1396.            && REGNO (XEXP (op, 0)) <= LAST_VIRTUAL_REGISTER))))
  1397.     return 1;
  1398.   return 0;
  1399. }
  1400.  
  1401. /* Like call_insn_operand but allow (mem (symbol_ref ...))
  1402.    even if pic.  */
  1403.  
  1404. int
  1405. expander_call_insn_operand (op, mode)
  1406.      rtx op;
  1407.      enum machine_mode mode;
  1408. {
  1409.   if (GET_CODE (op) == MEM
  1410.       && (CONSTANT_ADDRESS_P (XEXP (op, 0))
  1411.       || (GET_CODE (XEXP (op, 0)) == REG
  1412.           && XEXP (op, 0) != arg_pointer_rtx
  1413.           && !(REGNO (XEXP (op, 0)) >= FIRST_PSEUDO_REGISTER
  1414.            && REGNO (XEXP (op, 0)) <= LAST_VIRTUAL_REGISTER))))
  1415.     return 1;
  1416.   return 0;
  1417. }
  1418.  
  1419. /* Return 1 if OP is a comparison operator that can use the condition code
  1420.    generated by an arithmetic operation. */
  1421.  
  1422. int
  1423. arithmetic_comparison_operator (op, mode)
  1424.      register rtx op;
  1425.      enum machine_mode mode;
  1426. {
  1427.   enum rtx_code code;
  1428.  
  1429.   if (mode != VOIDmode && mode != GET_MODE (op))
  1430.     return 0;
  1431.   code = GET_CODE (op);
  1432.   if (GET_RTX_CLASS (code) != '<')
  1433.     return 0;
  1434.  
  1435.   return (code != GT && code != LE);
  1436. }
  1437.  
  1438. /* Returns 1 if OP contains a symbol reference */
  1439.  
  1440. int
  1441. symbolic_reference_mentioned_p (op)
  1442.      rtx op;
  1443. {
  1444.   register char *fmt;
  1445.   register int i;
  1446.  
  1447.   if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
  1448.     return 1;
  1449.  
  1450.   fmt = GET_RTX_FORMAT (GET_CODE (op));
  1451.   for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
  1452.     {
  1453.       if (fmt[i] == 'E')
  1454.     {
  1455.       register int j;
  1456.  
  1457.       for (j = XVECLEN (op, i) - 1; j >= 0; j--)
  1458.         if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
  1459.           return 1;
  1460.     }
  1461.       else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
  1462.     return 1;
  1463.     }
  1464.  
  1465.   return 0;
  1466. }
  1467.  
  1468. /* This function generates the assembly code for function entry.
  1469.    FILE is an stdio stream to output the code to.
  1470.    SIZE is an int: how many units of temporary storage to allocate. */
  1471.  
  1472. void
  1473. function_prologue (file, size)
  1474.      FILE *file;
  1475.      int size;
  1476. {
  1477.   register int regno;
  1478.   int limit;
  1479.   rtx xops[4];
  1480.   int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table
  1481.                   || current_function_uses_const_pool);
  1482.  
  1483.   xops[0] = stack_pointer_rtx;
  1484.   xops[1] = frame_pointer_rtx;
  1485.   xops[2] = GEN_INT (size);
  1486.   if (frame_pointer_needed)
  1487.     {
  1488.       output_asm_insn ("push%L1 %1", xops);
  1489.       output_asm_insn (AS2 (mov%L0,%0,%1), xops);
  1490.     }
  1491.  
  1492. #ifdef _WIN32
  1493.   /* In Windows, the stack is bounded by a "guard" page.  When
  1494.      a function writes to the guard page, a page fault occurs and
  1495.      the system moves the guard page to the next available contiguous
  1496.      page (potentially reserving additional memory if necessary) and
  1497.      then commits the new page to physical memory.  The problem
  1498.      is if the program writes to a page beyond the guard page.  In
  1499.      this case the system just page faults and causes a stack 
  1500.      overflow exception and the program crashes.  The Microsoft
  1501.      compiler performs stack checking in the function prologue.  
  1502.      Generally this call to __chkstk is only emitted when a function
  1503.      needs stack space that is greater than the vm page size (4K).
  1504.      For the MS compiler there is the option to turn this on for 
  1505.      all functions (at the price of performance) but we're not 
  1506.      interested in that so we only check for stack sizes greater
  1507.      than the vm_page size. 
  1508.      
  1509.      To do the stack check, put the size needed into eax and then call
  1510.      __chkstk.  This will safely allocate the space and adjust the 
  1511.      stack pointer.  */
  1512.   if (size >= 4096)
  1513.     {
  1514.       rtx yops[4];
  1515.       yops[0] = gen_rtx( REG, SImode, 0 );        // Get rtx for eax
  1516.       yops[1] = GEN_INT( size );            // Get rtx for the size
  1517.  
  1518.       output_asm_insn( AS2( mov%L1, %1, %0 ), yops );    // Move size to eax
  1519.       output_asm_insn( "call __chkstk", yops );        // Call __chkstk
  1520.     }
  1521.   else
  1522. #endif /* _WIN32 */
  1523.   if (size)
  1524.     output_asm_insn (AS2 (sub%L0,%2,%0), xops);
  1525.  
  1526.   /* Note If use enter it is NOT reversed args.
  1527.      This one is not reversed from intel!!
  1528.      I think enter is slower.  Also sdb doesn't like it.
  1529.      But if you want it the code is:
  1530.      {
  1531.      xops[3] = const0_rtx;
  1532.      output_asm_insn ("enter %2,%3", xops);
  1533.      }
  1534.      */
  1535.   limit = (frame_pointer_needed ? FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM);
  1536.   for (regno = limit - 1; regno >= 0; regno--)
  1537.     if ((regs_ever_live[regno] && ! call_used_regs[regno])
  1538. #ifndef MACHO_PIC
  1539.     || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)
  1540. #endif
  1541.        )
  1542.       {
  1543.     xops[0] = gen_rtx (REG, SImode, regno);
  1544.     output_asm_insn ("push%L0 %0", xops);
  1545.       }
  1546.  
  1547. #ifdef NeXT
  1548.     if (profile_flag)
  1549.       {
  1550.         extern int profile_label_no;
  1551.  
  1552.         fprintf (file, "\tmovl $%sP%d,%%eax\n", LPREFIX, profile_label_no);    
  1553.         fprintf (file, "\tcall mcount\n");                
  1554.       }    
  1555. #endif                                
  1556.  
  1557.   if (pic_reg_used)
  1558.     {
  1559. #ifdef MACHO_PIC
  1560.       if (PIC_OFFSET_TABLE_REGNUM < FIRST_PSEUDO_REGISTER)
  1561. #endif
  1562.       xops[0] = pic_offset_table_rtx;
  1563. #ifdef MACHO_PIC
  1564.       else if (reg_renumber[PIC_OFFSET_TABLE_REGNUM] != -1)
  1565.     xops[0] = regno_reg_rtx [PIC_OFFSET_TABLE_REGNUM];
  1566.       else
  1567.     xops[0] = lookup_i386_stack_local (SImode, 2);
  1568.     }
  1569.   if (pic_reg_used && xops[0])
  1570.     {
  1571. #endif
  1572.       xops[1] = (rtx) gen_label_rtx ();
  1573.  
  1574.       output_asm_insn (AS1 (call,%P1), xops);
  1575.       ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (xops[1]));
  1576. #ifdef MACHO_PIC
  1577.       assemble_name (file, machopic_function_base_name ());
  1578.       asm_fprintf (file, ":\n");
  1579. #endif
  1580.       output_asm_insn (AS1 (pop%L0,%0), xops);
  1581. #ifdef MACHO_PIC
  1582.       {
  1583.           xops[1] = lookup_i386_stack_local (SImode, 2);
  1584.           if (xops[1] != NULL_RTX && xops[0] != xops[1])
  1585.             {
  1586.               if (GET_CODE(xops[0]) == REG)
  1587.                   output_asm_insn ("movl %0,%1", xops);
  1588.               else
  1589.                 {
  1590.                     output_asm_insn ("pushl %0", xops);
  1591.                     output_asm_insn ("popl %1", xops);
  1592.                 }
  1593.             }
  1594.       }
  1595. #else
  1596.       output_asm_insn ("addl $_GLOBAL_OFFSET_TABLE_+[.-%P1],%0", xops);
  1597. #endif
  1598.     }
  1599.  
  1600. #ifdef NEXT_SEMANTICS
  1601.   if (size)
  1602.     {
  1603.       extern int flag_check_mem;
  1604.       xops[2] = GEN_INT (size);
  1605.       if (flag_check_mem)
  1606.     output_asm_insn ("push%L0 %2\n\tcall _check_mem_enter", xops);
  1607.     }
  1608. #endif
  1609.  
  1610. }
  1611.  
  1612. /* Return 1 if it is appropriate to emit `ret' instructions in the
  1613.    body of a function.  Do this only if the epilogue is simple, needing a
  1614.    couple of insns.  Prior to reloading, we can't tell how many registers
  1615.    must be saved, so return 0 then.
  1616.  
  1617.    If NON_SAVING_SETJMP is defined and true, then it is not possible
  1618.    for the epilogue to be simple, so return 0.  This is a special case
  1619.    since NON_SAVING_SETJMP will not cause regs_ever_live to change until
  1620.    final, but jump_optimize may need to know sooner if a `return' is OK.  */
  1621.  
  1622. int
  1623. simple_386_epilogue ()
  1624. {
  1625.   int regno;
  1626.   int nregs = 0;
  1627.   int reglimit = (frame_pointer_needed
  1628.           ? FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM);
  1629.   int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table
  1630.                   || current_function_uses_const_pool);
  1631.  
  1632. #ifdef NON_SAVING_SETJMP
  1633.   if (NON_SAVING_SETJMP && current_function_calls_setjmp)
  1634.     return 0;
  1635. #endif
  1636.  
  1637.   if (! reload_completed)
  1638.     return 0;
  1639.  
  1640.   for (regno = reglimit - 1; regno >= 0; regno--)
  1641.     if ((regs_ever_live[regno] && ! call_used_regs[regno])
  1642. #ifndef MACHO_PIC
  1643.     || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)
  1644. #endif
  1645.        )
  1646.       nregs++;
  1647.  
  1648.   return nregs == 0 || ! frame_pointer_needed;
  1649. }
  1650.  
  1651.  
  1652. /* This function generates the assembly code for function exit.
  1653.    FILE is an stdio stream to output the code to.
  1654.    SIZE is an int: how many units of temporary storage to deallocate. */
  1655.  
  1656. void
  1657. function_epilogue (file, size)
  1658.      FILE *file;
  1659.      int size;
  1660. {
  1661.   register int regno;
  1662.   register int nregs, limit;
  1663.   int offset;
  1664.   rtx xops[3];
  1665.   int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table
  1666.                   || current_function_uses_const_pool);
  1667.  
  1668.   /* Compute the number of registers to pop */
  1669.  
  1670.   limit = (frame_pointer_needed
  1671.        ? FRAME_POINTER_REGNUM
  1672.        : STACK_POINTER_REGNUM);
  1673.  
  1674.   nregs = 0;
  1675.  
  1676.   for (regno = limit - 1; regno >= 0; regno--)
  1677.     if ((regs_ever_live[regno] && ! call_used_regs[regno])
  1678. #ifndef MACHO_PIC
  1679.     || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)
  1680. #endif
  1681.        )
  1682.       nregs++;
  1683.  
  1684.   /* sp is often  unreliable so we must go off the frame pointer,
  1685.    */
  1686.  
  1687.   /* In reality, we may not care if sp is unreliable, because we can
  1688.      restore the register relative to the frame pointer.  In theory,
  1689.      since each move is the same speed as a pop, and we don't need the
  1690.      leal, this is faster.  For now restore multiple registers the old
  1691.      way. */
  1692.  
  1693.   offset = -size - (nregs * UNITS_PER_WORD);
  1694.  
  1695.   xops[2] = stack_pointer_rtx;
  1696.  
  1697.   if (nregs > 1 || ! frame_pointer_needed)
  1698.     {
  1699.       if (frame_pointer_needed)
  1700.     {
  1701.       xops[0] = adj_offsettable_operand (AT_BP (Pmode), offset);
  1702.       output_asm_insn (AS2 (lea%L2,%0,%2), xops);
  1703.     }
  1704.  
  1705.       for (regno = 0; regno < limit; regno++)
  1706.     if ((regs_ever_live[regno] && ! call_used_regs[regno])
  1707. #ifndef MACHO_PIC
  1708.         || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)
  1709. #endif
  1710.       )
  1711.       {
  1712.         xops[0] = gen_rtx (REG, SImode, regno);
  1713.         output_asm_insn ("pop%L0 %0", xops);
  1714.       }
  1715.     }
  1716.   else
  1717.     for (regno = 0; regno < limit; regno++)
  1718.       if ((regs_ever_live[regno] && ! call_used_regs[regno])
  1719. #ifndef MACHO_PIC
  1720.       || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)
  1721. #endif
  1722.      )
  1723.     {
  1724.       xops[0] = gen_rtx (REG, SImode, regno);
  1725.       xops[1] = adj_offsettable_operand (AT_BP (Pmode), offset);
  1726.       output_asm_insn (AS2 (mov%L0,%1,%0), xops);
  1727.       offset += 4;
  1728.     }
  1729.  
  1730.   if (frame_pointer_needed)
  1731.     {
  1732.       /* On i486, mov & pop is faster than "leave". */
  1733.  
  1734.       if (!TARGET_386)
  1735.     {
  1736.       xops[0] = frame_pointer_rtx;
  1737.       output_asm_insn (AS2 (mov%L2,%0,%2), xops);
  1738.       output_asm_insn ("pop%L0 %0", xops);
  1739.     }
  1740.       else
  1741.     output_asm_insn ("leave", xops);
  1742.     }
  1743.   else if (size)
  1744.     {
  1745.       /* If there is no frame pointer, we must still release the frame. */
  1746.  
  1747.       xops[0] = GEN_INT (size);
  1748.       output_asm_insn (AS2 (add%L2,%0,%2), xops);
  1749.     }
  1750.  
  1751. #ifdef NEXT_SEMANTICS
  1752.   if (flag_check_mem)
  1753.     {
  1754.       xops[0] = GEN_INT (size);
  1755.       output_asm_insn ("push%L0 %0\n\tcall _check_mem_exit", xops);
  1756.     }
  1757. #endif
  1758.  
  1759.   if (current_function_pops_args && current_function_args_size)
  1760.     {
  1761.       xops[1] = GEN_INT (current_function_pops_args);
  1762.  
  1763.       /* i386 can only pop 32K bytes (maybe 64K?  Is it signed?).  If
  1764.      asked to pop more, pop return address, do explicit add, and jump
  1765.      indirectly to the caller. */
  1766.  
  1767.       if (current_function_pops_args >= 32768)
  1768.     {
  1769.       /* ??? Which register to use here? */
  1770.       xops[0] = gen_rtx (REG, SImode, 2);
  1771.       output_asm_insn ("pop%L0 %0", xops);
  1772.       output_asm_insn (AS2 (add%L2,%1,%2), xops);
  1773.       output_asm_insn ("jmp %*%0", xops);
  1774.     }
  1775.       else
  1776.       output_asm_insn ("ret %1", xops);
  1777.     }
  1778.   else
  1779.     output_asm_insn ("ret", xops);
  1780. }
  1781.  
  1782.  
  1783. /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
  1784.    that is a valid memory address for an instruction.
  1785.    The MODE argument is the machine mode for the MEM expression
  1786.    that wants to use this address.
  1787.  
  1788.    On x86, legitimate addresses are:
  1789.     base                movl (base),reg
  1790.     displacement            movl disp,reg
  1791.     base + displacement        movl disp(base),reg
  1792.     index + base            movl (base,index),reg
  1793.     (index + base) + displacement    movl disp(base,index),reg
  1794.     index*scale            movl (,index,scale),reg
  1795.     index*scale + disp        movl disp(,index,scale),reg
  1796.     index*scale + base         movl (base,index,scale),reg
  1797.     (index*scale + base) + disp    movl disp(base,index,scale),reg
  1798.  
  1799.     In each case, scale can be 1, 2, 4, 8.  */
  1800.  
  1801. /* This is exactly the same as print_operand_addr, except that
  1802.    it recognizes addresses instead of printing them.
  1803.  
  1804.    It only recognizes address in canonical form.  LEGITIMIZE_ADDRESS should
  1805.    convert common non-canonical forms to canonical form so that they will
  1806.    be recognized.  */
  1807.  
  1808. #define ADDR_INVALID(msg,insn)                        \
  1809. do {                                    \
  1810.   if (TARGET_DEBUG_ADDR)                        \
  1811.     {                                    \
  1812.       fprintf (stderr, msg);                        \
  1813.       debug_rtx (insn);                            \
  1814.     }                                    \
  1815. } while (0)
  1816.  
  1817. int
  1818. legitimate_address_p (mode, addr, strict)
  1819.      enum machine_mode mode;
  1820.      register rtx addr;
  1821.      int strict;
  1822. {
  1823.   rtx base  = NULL_RTX;
  1824.   rtx indx  = NULL_RTX;
  1825.   rtx scale = NULL_RTX;
  1826.   rtx disp  = NULL_RTX;
  1827.  
  1828.   if (TARGET_DEBUG_ADDR)
  1829.     {
  1830.       fprintf (stderr,
  1831.            "\n==========\nGO_IF_LEGITIMATE_ADDRESS, mode = %s, strict = %d\n",
  1832.            GET_MODE_NAME (mode), strict);
  1833.  
  1834.       debug_rtx (addr);
  1835.     }
  1836.  
  1837.   if (GET_CODE (addr) == REG || GET_CODE (addr) == SUBREG)
  1838.       base = addr;                /* base reg */
  1839.  
  1840.   else if (GET_CODE (addr) == PLUS)
  1841.     {
  1842.       rtx op0 = XEXP (addr, 0);
  1843.       rtx op1 = XEXP (addr, 1);
  1844.       enum rtx_code code0 = GET_CODE (op0);
  1845.       enum rtx_code code1 = GET_CODE (op1);
  1846.  
  1847.       if (code0 == REG || code0 == SUBREG)
  1848.     {
  1849.       if (code1 == REG || code1 == SUBREG)
  1850.         {
  1851.           indx = op0;            /* index + base */
  1852.           base = op1;
  1853.         }
  1854.  
  1855.       else
  1856.         {
  1857.           base = op0;            /* base + displacement */
  1858.           disp = op1;
  1859.         }
  1860.     }
  1861.  
  1862.       else if (code0 == MULT)
  1863.     {
  1864.       indx  = XEXP (op0, 0);
  1865.       scale = XEXP (op0, 1);
  1866.  
  1867.       if (code1 == REG || code1 == SUBREG)
  1868.         base = op1;                /* index*scale + base */
  1869.  
  1870.       else
  1871.         disp = op1;                /* index*scale + disp */
  1872.     }
  1873.  
  1874.       else if (code0 == PLUS && GET_CODE (XEXP (op0, 0)) == MULT)
  1875.     {
  1876.       indx  = XEXP (XEXP (op0, 0), 0);    /* index*scale + base + disp */
  1877.       scale = XEXP (XEXP (op0, 0), 1);
  1878.       base  = XEXP (op0, 1);
  1879.       disp  = op1;
  1880.     }
  1881.  
  1882.       else if (code0 == PLUS)
  1883.     {
  1884.       indx = XEXP (op0, 0);            /* index + base + disp */
  1885.       base = XEXP (op0, 1);
  1886.       disp = op1;
  1887.     }
  1888.  
  1889.       else
  1890.     {
  1891.       ADDR_INVALID ("PLUS subcode is not valid.\n", op0);
  1892.       return FALSE;
  1893.     }
  1894.     }
  1895.  
  1896.   else if (GET_CODE (addr) == MULT)
  1897.     {
  1898.       indx  = XEXP (addr, 0);            /* index*scale */
  1899.       scale = XEXP (addr, 1);
  1900.     }
  1901.  
  1902.   else
  1903.     disp = addr;                /* displacement */
  1904.  
  1905.   /* Allow arg pointer and stack pointer as index if there is not scaling */
  1906.   if (base && indx && !scale
  1907.       && (indx == arg_pointer_rtx || indx == stack_pointer_rtx))
  1908.     {
  1909.       rtx tmp = base;
  1910.       base = indx;
  1911.       indx = tmp;
  1912.     }
  1913.  
  1914.   /* Validate base register */
  1915.   /* Don't allow SUBREG's here, it can lead to spill failures when the base
  1916.      is one word out of a two word structure, which is represented internally
  1917.      as a DImode int.  */
  1918.   if (base)
  1919.     {
  1920.       if (GET_CODE (base) != REG)
  1921.     {
  1922.       ADDR_INVALID ("Base is not a register.\n", base);
  1923.       return FALSE;
  1924.     }
  1925.  
  1926.       if ((strict && !REG_OK_FOR_BASE_STRICT_P (base))
  1927.       || (!strict && !REG_OK_FOR_BASE_NONSTRICT_P (base)))
  1928.     {
  1929.       ADDR_INVALID ("Base is not valid.\n", base);
  1930.       return FALSE;
  1931.     }
  1932.     }
  1933.  
  1934.   /* Validate index register */
  1935.   /* Don't allow SUBREG's here, it can lead to spill failures when the index
  1936.      is one word out of a two word structure, which is represented internally
  1937.      as a DImode int.  */
  1938.   if (indx)
  1939.     {
  1940.       if (GET_CODE (indx) != REG)
  1941.     {
  1942.       ADDR_INVALID ("Index is not a register.\n", indx);
  1943.       return FALSE;
  1944.     }
  1945.  
  1946.       if ((strict && !REG_OK_FOR_INDEX_STRICT_P (indx))
  1947.       || (!strict && !REG_OK_FOR_INDEX_NONSTRICT_P (indx)))
  1948.     {
  1949.       ADDR_INVALID ("Index is not valid.\n", indx);
  1950.       return FALSE;
  1951.     }
  1952.     }
  1953.   else if (scale)
  1954.     abort ();                    /* scale w/o index invalid */
  1955.  
  1956.   /* Validate scale factor */
  1957.   if (scale)
  1958.     {
  1959.       HOST_WIDE_INT value;
  1960.  
  1961.       if (GET_CODE (scale) != CONST_INT)
  1962.     {
  1963.       ADDR_INVALID ("Scale is not valid.\n", scale);
  1964.       return FALSE;
  1965.     }
  1966.  
  1967.       value = INTVAL (scale);
  1968.       if (value != 1 && value != 2 && value != 4 && value != 8)
  1969.     {
  1970.       ADDR_INVALID ("Scale is not a good multiplier.\n", scale);
  1971.       return FALSE;
  1972.     }
  1973.     }
  1974.  
  1975.   /* Validate displacement */
  1976.   if (disp)
  1977.     {
  1978.       if (!CONSTANT_ADDRESS_P (disp))
  1979.     {
  1980.       ADDR_INVALID ("Displacement is not valid.\n", disp);
  1981.       return FALSE;
  1982.     }
  1983.  
  1984.       if (GET_CODE (disp) == CONST_DOUBLE)
  1985.     {
  1986.       ADDR_INVALID ("Displacement is a const_double.\n", disp);
  1987.       return FALSE;
  1988.     }
  1989.  
  1990.       if (flag_pic && SYMBOLIC_CONST (disp) && base != pic_offset_table_rtx
  1991.       && (indx != pic_offset_table_rtx || scale != NULL_RTX))
  1992.     {
  1993.       ADDR_INVALID ("Displacement is an invalid pic reference.\n", disp);
  1994.       return FALSE;
  1995.     }
  1996.  
  1997.       if (HALF_PIC_P () && HALF_PIC_ADDRESS_P (disp)
  1998.       && (base != NULL_RTX || indx != NULL_RTX))
  1999.     {
  2000.       ADDR_INVALID ("Displacement is an invalid half-pic reference.\n", disp);
  2001.       return FALSE;
  2002.     }
  2003.     }
  2004.  
  2005.   if (TARGET_DEBUG_ADDR)
  2006.     fprintf (stderr, "Address is valid.\n");
  2007.  
  2008.   /* Everything looks valid, return true */
  2009.   return TRUE;
  2010. }
  2011.  
  2012.  
  2013. /* Return a legitimate reference for ORIG (an address) using the
  2014.    register REG.  If REG is 0, a new pseudo is generated.
  2015.  
  2016.    There are three types of references that must be handled:
  2017.  
  2018.    1. Global data references must load the address from the GOT, via
  2019.       the PIC reg.  An insn is emitted to do this load, and the reg is
  2020.       returned.
  2021.  
  2022.    2. Static data references must compute the address as an offset
  2023.       from the GOT, whose base is in the PIC reg.  An insn is emitted to
  2024.       compute the address into a reg, and the reg is returned.  Static
  2025.       data objects have SYMBOL_REF_FLAG set to differentiate them from
  2026.       global data objects.
  2027.  
  2028.    3. Constant pool addresses must be handled special.  They are
  2029.       considered legitimate addresses, but only if not used with regs.
  2030.       When printed, the output routines know to print the reference with the
  2031.       PIC reg, even though the PIC reg doesn't appear in the RTL.
  2032.  
  2033.    GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
  2034.    reg also appears in the address (except for constant pool references,
  2035.    noted above).
  2036.  
  2037.    "switch" statements also require special handling when generating
  2038.    PIC code.  See comments by the `casesi' insn in i386.md for details.  */
  2039.  
  2040. rtx
  2041. legitimize_pic_address (orig, reg)
  2042.      rtx orig;
  2043.      rtx reg;
  2044. {
  2045.   rtx addr = orig;
  2046.   rtx new = orig;
  2047.  
  2048. #ifdef MACHO_PIC
  2049.   if (reg == 0)
  2050.     reg = gen_reg_rtx (Pmode);
  2051.   return machopic_legitimize_pic_address (orig, GET_MODE (orig), reg);
  2052. #endif
  2053.  
  2054.   if (GET_CODE (addr) == SYMBOL_REF || GET_CODE (addr) == LABEL_REF)
  2055.     {
  2056.       if (GET_CODE (addr) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (addr))
  2057.     reg = new = orig;
  2058.       else
  2059.     {
  2060.       if (reg == 0)
  2061.         reg = gen_reg_rtx (Pmode);
  2062.  
  2063.       if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_FLAG (addr))
  2064.           || GET_CODE (addr) == LABEL_REF)
  2065.         new = gen_rtx (PLUS, Pmode, pic_offset_table_rtx, orig);
  2066.       else
  2067.         new = gen_rtx (MEM, Pmode,
  2068.                gen_rtx (PLUS, Pmode,
  2069.                     pic_offset_table_rtx, orig));
  2070.  
  2071.       emit_move_insn (reg, new);
  2072.     }
  2073.       current_function_uses_pic_offset_table = 1;
  2074.       return reg;
  2075.     }
  2076.   else if (GET_CODE (addr) == CONST || GET_CODE (addr) == PLUS)
  2077.     {
  2078.       rtx base;
  2079.  
  2080.       if (GET_CODE (addr) == CONST)
  2081.     {
  2082.       addr = XEXP (addr, 0);
  2083.       if (GET_CODE (addr) != PLUS)
  2084.         abort ();
  2085.     }
  2086.  
  2087.       if (XEXP (addr, 0) == pic_offset_table_rtx)
  2088.     return orig;
  2089.  
  2090.       if (reg == 0)
  2091.     reg = gen_reg_rtx (Pmode);
  2092.  
  2093.       base = legitimize_pic_address (XEXP (addr, 0), reg);
  2094.       addr = legitimize_pic_address (XEXP (addr, 1),
  2095.                      base == reg ? NULL_RTX : reg);
  2096.  
  2097.       if (GET_CODE (addr) == CONST_INT)
  2098.     return plus_constant (base, INTVAL (addr));
  2099.  
  2100.       if (GET_CODE (addr) == PLUS && CONSTANT_P (XEXP (addr, 1)))
  2101.     {
  2102.       base = gen_rtx (PLUS, Pmode, base, XEXP (addr, 0));
  2103.       addr = XEXP (addr, 1);
  2104.     }
  2105.     return gen_rtx (PLUS, Pmode, base, addr);
  2106.     }
  2107.   return new;
  2108. }
  2109.  
  2110.  
  2111. /* Emit insns to move operands[1] into operands[0].  */
  2112.  
  2113. void
  2114. emit_pic_move (operands, mode)
  2115.      rtx *operands;
  2116.      enum machine_mode mode;
  2117. {
  2118.   rtx temp = reload_in_progress ? operands[0] : gen_reg_rtx (Pmode);
  2119.  
  2120. #ifdef MACHO_PIC
  2121.   if (MACHOPIC_PURE)
  2122.     {
  2123.       operands[1] = machopic_indirect_data_reference (operands[1], temp);
  2124.       operands[1] = machopic_legitimize_pic_address (operands[1], mode, 
  2125.                          temp == operands[1] ? 0 : temp);
  2126.     }
  2127.   else if (MACHOPIC_INDIRECT)
  2128.     {
  2129.       operands[1] = machopic_indirect_data_reference (operands[1], 0);
  2130.     }
  2131. #else
  2132.   if (GET_CODE (operands[0]) == MEM && SYMBOLIC_CONST (operands[1]))
  2133.     operands[1] = (rtx) force_reg (SImode, operands[1]);
  2134.   else
  2135.     operands[1] = legitimize_pic_address (operands[1], temp);
  2136. #endif
  2137. }
  2138.  
  2139.  
  2140. /* Try machine-dependent ways of modifying an illegitimate address
  2141.    to be legitimate.  If we find one, return the new, valid address.
  2142.    This macro is used in only one place: `memory_address' in explow.c.
  2143.  
  2144.    OLDX is the address as it was before break_out_memory_refs was called.
  2145.    In some cases it is useful to look at this to decide what needs to be done.
  2146.  
  2147.    MODE and WIN are passed so that this macro can use
  2148.    GO_IF_LEGITIMATE_ADDRESS.
  2149.  
  2150.    It is always safe for this macro to do nothing.  It exists to recognize
  2151.    opportunities to optimize the output.
  2152.  
  2153.    For the 80386, we handle X+REG by loading X into a register R and
  2154.    using R+REG.  R will go in a general reg and indexing will be used.
  2155.    However, if REG is a broken-out memory address or multiplication,
  2156.    nothing needs to be done because REG can certainly go in a general reg.
  2157.  
  2158.    When -fpic is used, special handling is needed for symbolic references.
  2159.    See comments by legitimize_pic_address in i386.c for details.  */
  2160.  
  2161. rtx
  2162. legitimize_address (x, oldx, mode)
  2163.      register rtx x;
  2164.      register rtx oldx;
  2165.      enum machine_mode mode;
  2166. {
  2167.   int changed = 0;
  2168.   unsigned log;
  2169.  
  2170.   if (TARGET_DEBUG_ADDR)
  2171.     {
  2172.       fprintf (stderr, "\n==========\nLEGITIMIZE_ADDRESS, mode = %s\n", GET_MODE_NAME (mode));
  2173.       debug_rtx (x);
  2174.     }
  2175.  
  2176.   if (flag_pic && SYMBOLIC_CONST (x))
  2177.     return legitimize_pic_address (x, 0);
  2178.  
  2179.   /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
  2180.   if (GET_CODE (x) == ASHIFT
  2181.       && GET_CODE (XEXP (x, 1)) == CONST_INT
  2182.       && (log = (unsigned)exact_log2 (INTVAL (XEXP (x, 1)))) < 4)
  2183.     {
  2184.       changed = 1;
  2185.       x = gen_rtx (MULT, Pmode,
  2186.            force_reg (Pmode, XEXP (x, 0)),
  2187.            GEN_INT (1 << log));
  2188.     }
  2189.  
  2190.   if (GET_CODE (x) == PLUS)
  2191.     {
  2192.       /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
  2193.       if (GET_CODE (XEXP (x, 0)) == ASHIFT
  2194.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  2195.       && (log = (unsigned)exact_log2 (INTVAL (XEXP (XEXP (x, 0), 1)))) < 4)
  2196.     {
  2197.       changed = 1;
  2198.       XEXP (x, 0) = gen_rtx (MULT, Pmode,
  2199.                  force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
  2200.                  GEN_INT (1 << log));
  2201.     }
  2202.  
  2203.       if (GET_CODE (XEXP (x, 1)) == ASHIFT
  2204.       && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT
  2205.       && (log = (unsigned)exact_log2 (INTVAL (XEXP (XEXP (x, 1), 1)))) < 4)
  2206.     {
  2207.       changed = 1;
  2208.       XEXP (x, 1) = gen_rtx (MULT, Pmode,
  2209.                  force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
  2210.                  GEN_INT (1 << log));
  2211.     }
  2212.  
  2213.       /* Put multiply first if it isn't already */
  2214.       if (GET_CODE (XEXP (x, 1)) == MULT)
  2215.     {
  2216.       rtx tmp = XEXP (x, 0);
  2217.       XEXP (x, 0) = XEXP (x, 1);
  2218.       XEXP (x, 1) = tmp;
  2219.       changed = 1;
  2220.     }
  2221.  
  2222.       /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
  2223.      into (plus (plus (mult (reg) (const)) (reg)) (const)).  This can be
  2224.      created by virtual register instantiation, register elimination, and
  2225.      similar optimizations.  */
  2226.       if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS)
  2227.     {
  2228.       changed = 1;
  2229.       x = gen_rtx (PLUS, Pmode,
  2230.                gen_rtx (PLUS, Pmode, XEXP (x, 0), XEXP (XEXP (x, 1), 0)),
  2231.                XEXP (XEXP (x, 1), 1));
  2232.     }
  2233.  
  2234.       /* Canonicalize (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
  2235.      into (plus (plus (mult (reg) (const)) (reg)) (const)).  */
  2236.       else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
  2237.            && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
  2238.            && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
  2239.            && CONSTANT_P (XEXP (x, 1)))
  2240.     {
  2241.       rtx constant, other;
  2242.  
  2243.       if (GET_CODE (XEXP (x, 1)) == CONST_INT)
  2244.         {
  2245.           constant = XEXP (x, 1);
  2246.           other = XEXP (XEXP (XEXP (x, 0), 1), 1);
  2247.         }
  2248.       else if (GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 1)) == CONST_INT)
  2249.         {
  2250.           constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
  2251.           other = XEXP (x, 1);
  2252.         }
  2253.       else
  2254.         constant = 0;
  2255.  
  2256.       if (constant)
  2257.         {
  2258.           changed = 1;
  2259.           x = gen_rtx (PLUS, Pmode,
  2260.                gen_rtx (PLUS, Pmode, XEXP (XEXP (x, 0), 0),
  2261.                     XEXP (XEXP (XEXP (x, 0), 1), 0)),
  2262.                plus_constant (other, INTVAL (constant)));
  2263.         }
  2264.     }
  2265.  
  2266.       if (changed && legitimate_address_p (mode, x, FALSE))
  2267.     return x;
  2268.  
  2269.       if (GET_CODE (XEXP (x, 0)) == MULT)
  2270.     {
  2271.       changed = 1;
  2272.       XEXP (x, 0) = force_operand (XEXP (x, 0), 0);
  2273.     }
  2274.  
  2275.       if (GET_CODE (XEXP (x, 1)) == MULT)
  2276.     {
  2277.       changed = 1;
  2278.       XEXP (x, 1) = force_operand (XEXP (x, 1), 0);
  2279.     }
  2280.  
  2281.       if (changed
  2282.       && GET_CODE (XEXP (x, 1)) == REG
  2283.       && GET_CODE (XEXP (x, 0)) == REG)
  2284.     return x;
  2285.  
  2286.       if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1)))
  2287.     {
  2288.       changed = 1;
  2289.       x = legitimize_pic_address (x, 0);
  2290.     }
  2291.  
  2292.       if (changed && legitimate_address_p (mode, x, FALSE))
  2293.     return x;
  2294.  
  2295.       if (GET_CODE (XEXP (x, 0)) == REG)
  2296.     {
  2297.       register rtx temp = gen_reg_rtx (Pmode);
  2298.       register rtx val  = force_operand (XEXP (x, 1), temp);
  2299.       if (val != temp)
  2300.         emit_move_insn (temp, val);
  2301.  
  2302.       XEXP (x, 1) = temp;
  2303.       return x;
  2304.     }
  2305.  
  2306.       else if (GET_CODE (XEXP (x, 1)) == REG)
  2307.     {
  2308.       register rtx temp = gen_reg_rtx (Pmode);
  2309.       register rtx val  = force_operand (XEXP (x, 0), temp);
  2310.       if (val != temp)
  2311.         emit_move_insn (temp, val);
  2312.  
  2313.       XEXP (x, 0) = temp;
  2314.       return x;
  2315.     }
  2316.     }
  2317.  
  2318.   return x;
  2319. }
  2320.  
  2321.  
  2322. /* Print an integer constant expression in assembler syntax.  Addition
  2323.    and subtraction are the only arithmetic that may appear in these
  2324.    expressions.  FILE is the stdio stream to write to, X is the rtx, and
  2325.    CODE is the operand print code from the output string.  */
  2326.  
  2327. static void
  2328. output_pic_addr_const (file, x, code)
  2329.      FILE *file;
  2330.      rtx x;
  2331.      int code;
  2332. {
  2333.   char buf[256];
  2334.  
  2335.   switch (GET_CODE (x))
  2336.     {
  2337.     case PC:
  2338.       if (flag_pic)
  2339.     putc ('.', file);
  2340.       else
  2341.     abort ();
  2342.       break;
  2343.  
  2344.     case SYMBOL_REF:
  2345.     case LABEL_REF:
  2346.       if (GET_CODE (x) == SYMBOL_REF)
  2347.     assemble_name (file, XSTR (x, 0));
  2348.       else
  2349.     {
  2350.       ASM_GENERATE_INTERNAL_LABEL (buf, "L",
  2351.                        CODE_LABEL_NUMBER (XEXP (x, 0)));
  2352.       assemble_name (asm_out_file, buf);
  2353.     }
  2354.  
  2355. #ifndef MACHO_PIC
  2356.       if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x))
  2357.     fprintf (file, "@GOTOFF(%%ebx)");
  2358.       else if (code == 'P')
  2359.     fprintf (file, "@PLT");
  2360.       else if (GET_CODE (x) == LABEL_REF)
  2361.     fprintf (file, "@GOTOFF");
  2362.       else if (! SYMBOL_REF_FLAG (x))
  2363.     fprintf (file, "@GOT");
  2364.       else
  2365.     fprintf (file, "@GOTOFF");
  2366. #endif
  2367.  
  2368.       break;
  2369.  
  2370.     case CODE_LABEL:
  2371.       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
  2372.       assemble_name (asm_out_file, buf);
  2373.       break;
  2374.  
  2375.     case CONST_INT:
  2376.       fprintf (file, "%d", INTVAL (x));
  2377.       break;
  2378.  
  2379.     case CONST:
  2380.       /* This used to output parentheses around the expression,
  2381.      but that does not work on the 386 (either ATT or BSD assembler).  */
  2382.       output_pic_addr_const (file, XEXP (x, 0), code);
  2383.       break;
  2384.  
  2385.     case CONST_DOUBLE:
  2386.       if (GET_MODE (x) == VOIDmode)
  2387.     {
  2388.       /* We can use %d if the number is <32 bits and positive.  */
  2389.       if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
  2390.         fprintf (file, "0x%x%08x",
  2391.              CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
  2392.       else
  2393.         fprintf (file, "%d", CONST_DOUBLE_LOW (x));
  2394.     }
  2395.       else
  2396.     /* We can't handle floating point constants;
  2397.        PRINT_OPERAND must handle them.  */
  2398.     output_operand_lossage ("floating constant misused");
  2399.       break;
  2400.  
  2401.     case PLUS:
  2402.       /* Some assemblers need integer constants to appear last (eg masm).  */
  2403.       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
  2404.     {
  2405.       output_pic_addr_const (file, XEXP (x, 1), code);
  2406.       if (INTVAL (XEXP (x, 0)) >= 0)
  2407.         fprintf (file, "+");
  2408.       output_pic_addr_const (file, XEXP (x, 0), code);
  2409.     }
  2410.       else
  2411.     {
  2412.       output_pic_addr_const (file, XEXP (x, 0), code);
  2413.       if (INTVAL (XEXP (x, 1)) >= 0)
  2414.         fprintf (file, "+");
  2415.       output_pic_addr_const (file, XEXP (x, 1), code);
  2416.     }
  2417.       break;
  2418.  
  2419.     case MINUS:
  2420.       output_pic_addr_const (file, XEXP (x, 0), code);
  2421.       fprintf (file, "-");
  2422.       output_pic_addr_const (file, XEXP (x, 1), code);
  2423.       break;
  2424.  
  2425.     default:
  2426.       output_operand_lossage ("invalid expression as operand");
  2427.     }
  2428. }
  2429.  
  2430. /* Meaning of CODE:
  2431.    f -- float insn (print a CONST_DOUBLE as a float rather than in hex).
  2432.    D,L,W,B,Q,S -- print the opcode suffix for specified size of operand.
  2433.    R -- print the prefix for register names.
  2434.    z -- print the opcode suffix for the size of the current operand.
  2435.    * -- print a star (in certain assembler syntax)
  2436.    w -- print the operand as if it's a "word" (HImode) even if it isn't.
  2437.    c -- don't print special prefixes before constant operands.
  2438.    J -- print the appropriate jump operand.
  2439. */
  2440.  
  2441. void
  2442. print_operand (file, x, code)
  2443.      FILE *file;
  2444.      rtx x;
  2445.      int code;
  2446. {
  2447.   if (code)
  2448.     {
  2449.       switch (code)
  2450.     {
  2451.     case '*':
  2452.       if (USE_STAR)
  2453.         putc ('*', file);
  2454.       return;
  2455.  
  2456.     case 'L':
  2457.       PUT_OP_SIZE (code, 'l', file);
  2458.       return;
  2459.  
  2460.     case 'W':
  2461.       PUT_OP_SIZE (code, 'w', file);
  2462.       return;
  2463.  
  2464.     case 'B':
  2465.       PUT_OP_SIZE (code, 'b', file);
  2466.       return;
  2467.  
  2468.     case 'Q':
  2469.       PUT_OP_SIZE (code, 'l', file);
  2470.       return;
  2471.  
  2472.     case 'S':
  2473.       PUT_OP_SIZE (code, 's', file);
  2474.       return;
  2475.  
  2476.     case 'T':
  2477.       PUT_OP_SIZE (code, 't', file);
  2478.       return;
  2479.  
  2480.     case 'z':
  2481.       /* 387 opcodes don't get size suffixes if the operands are
  2482.          registers. */
  2483.  
  2484.       if (STACK_REG_P (x))
  2485.         return;
  2486.  
  2487.       /* this is the size of op from size of operand */
  2488.       switch (GET_MODE_SIZE (GET_MODE (x)))
  2489.         {
  2490.         case 1:
  2491.           PUT_OP_SIZE ('B', 'b', file);
  2492.           return;
  2493.  
  2494.         case 2:
  2495.           PUT_OP_SIZE ('W', 'w', file);
  2496.           return;
  2497.  
  2498.         case 4:
  2499.           if (GET_MODE (x) == SFmode)
  2500.         {
  2501.           PUT_OP_SIZE ('S', 's', file);
  2502.           return;
  2503.         }
  2504.           else
  2505.         PUT_OP_SIZE ('L', 'l', file);
  2506.           return;
  2507.  
  2508.         case 12:
  2509.           PUT_OP_SIZE ('T', 't', file);
  2510.           return;
  2511.  
  2512.         case 8:
  2513.           if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
  2514.         {
  2515. #ifdef GAS_MNEMONICS
  2516.           PUT_OP_SIZE ('Q', 'q', file);
  2517.           return;
  2518. #else
  2519.           PUT_OP_SIZE ('Q', 'l', file);    /* Fall through */
  2520. #endif
  2521.         }
  2522.  
  2523.           PUT_OP_SIZE ('Q', 'l', file);
  2524.           return;
  2525.         }
  2526.  
  2527.     case 'b':
  2528.     case 'w':
  2529.     case 'k':
  2530.     case 'h':
  2531.     case 'y':
  2532.     case 'P':
  2533.       break;
  2534.  
  2535.     case 'J':
  2536.       switch (GET_CODE (x))
  2537.         {
  2538.           /* These conditions are appropriate for testing the result
  2539.          of an arithmetic operation, not for a compare operation.
  2540.              Cases GE, LT assume CC_NO_OVERFLOW true. All cases assume
  2541.          CC_Z_IN_NOT_C false and not floating point.  */
  2542.         case NE:  fputs ("jne", file); return;
  2543.         case EQ:  fputs ("je",  file); return;
  2544.         case GE:  fputs ("jns", file); return;
  2545.         case LT:  fputs ("js",  file); return;
  2546.         case GEU: fputs ("jmp", file); return;
  2547.         case GTU: fputs ("jne",  file); return;
  2548.         case LEU: fputs ("je", file); return;
  2549.         case LTU: fputs ("#branch never",  file); return;
  2550.  
  2551.         /* no matching branches for GT nor LE */
  2552.         }
  2553.       abort ();
  2554.  
  2555.     default:
  2556.       {
  2557.         char str[50];
  2558.  
  2559.         sprintf (str, "invalid operand code `%c'", code);
  2560.         output_operand_lossage (str);
  2561.       }
  2562.     }
  2563.     }
  2564.   if (GET_CODE (x) == REG)
  2565.     {
  2566.       PRINT_REG (x, code, file);
  2567.     }
  2568.   else if (GET_CODE (x) == MEM)
  2569.     {
  2570.       PRINT_PTR (x, file);
  2571.       if (CONSTANT_ADDRESS_P (XEXP (x, 0)))
  2572.     {
  2573.       if (flag_pic)
  2574.         output_pic_addr_const (file, XEXP (x, 0), code);
  2575.       else
  2576.         output_addr_const (file, XEXP (x, 0));
  2577.     }
  2578.       else
  2579.     output_address (XEXP (x, 0));
  2580.     }
  2581.   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
  2582.     {
  2583.       REAL_VALUE_TYPE r; long l;
  2584.       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  2585.       REAL_VALUE_TO_TARGET_SINGLE (r, l);
  2586.       PRINT_IMMED_PREFIX (file);
  2587.       fprintf (file, "0x%x", l);
  2588.     }
  2589.  /* These float cases don't actually occur as immediate operands. */
  2590.  else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
  2591.     {
  2592.       REAL_VALUE_TYPE r; char dstr[30];
  2593.       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  2594.       REAL_VALUE_TO_DECIMAL (r, "%.22e", dstr);
  2595.       fprintf (file, "%s", dstr);
  2596.     }
  2597.   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == XFmode)
  2598.     {
  2599.       REAL_VALUE_TYPE r; char dstr[30];
  2600.       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  2601.       REAL_VALUE_TO_DECIMAL (r, "%.22e", dstr);
  2602.       fprintf (file, "%s", dstr);
  2603.     }
  2604.   else 
  2605.     {
  2606.       if (code != 'P')
  2607.     {
  2608.       if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
  2609.         PRINT_IMMED_PREFIX (file);
  2610.       else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF
  2611.            || GET_CODE (x) == LABEL_REF)
  2612.         PRINT_OFFSET_PREFIX (file);
  2613.     }
  2614.       if (flag_pic)
  2615.     output_pic_addr_const (file, x, code);
  2616.       else
  2617.     output_addr_const (file, x);
  2618.     }
  2619. }
  2620.  
  2621. /* Print a memory operand whose address is ADDR.  */
  2622.  
  2623. void
  2624. print_operand_address (file, addr)
  2625.      FILE *file;
  2626.      register rtx addr;
  2627. {
  2628.   register rtx reg1, reg2, breg, ireg;
  2629.   rtx offset;
  2630.  
  2631.   switch (GET_CODE (addr))
  2632.     {
  2633.     case REG:
  2634.       ADDR_BEG (file);
  2635.       fprintf (file, "%se", RP);
  2636.       fputs (hi_reg_name[REGNO (addr)], file);
  2637.       ADDR_END (file);
  2638.       break;
  2639.  
  2640.     case PLUS:
  2641.       reg1 = 0;
  2642.       reg2 = 0;
  2643.       ireg = 0;
  2644.       breg = 0;
  2645.       offset = 0;
  2646.       if (CONSTANT_ADDRESS_P (XEXP (addr, 0)))
  2647.     {
  2648.       offset = XEXP (addr, 0);
  2649.       addr = XEXP (addr, 1);
  2650.     }
  2651.       else if (CONSTANT_ADDRESS_P (XEXP (addr, 1)))
  2652.     {
  2653.       offset = XEXP (addr, 1);
  2654.       addr = XEXP (addr, 0);
  2655.     }
  2656.       if (GET_CODE (addr) != PLUS) ;
  2657.       else if (GET_CODE (XEXP (addr, 0)) == MULT)
  2658.     {
  2659.       reg1 = XEXP (addr, 0);
  2660.       addr = XEXP (addr, 1);
  2661.     }
  2662.       else if (GET_CODE (XEXP (addr, 1)) == MULT)
  2663.     {
  2664.       reg1 = XEXP (addr, 1);
  2665.       addr = XEXP (addr, 0);
  2666.     }
  2667.       else if (GET_CODE (XEXP (addr, 0)) == REG)
  2668.     {
  2669.       reg1 = XEXP (addr, 0);
  2670.       addr = XEXP (addr, 1);
  2671.     }
  2672.       else if (GET_CODE (XEXP (addr, 1)) == REG)
  2673.     {
  2674.       reg1 = XEXP (addr, 1);
  2675.       addr = XEXP (addr, 0);
  2676.     }
  2677.       if (GET_CODE (addr) == REG || GET_CODE (addr) == MULT)
  2678.     {
  2679.       if (reg1 == 0) reg1 = addr;
  2680.       else reg2 = addr;
  2681.       addr = 0;
  2682.     }
  2683.       if (offset != 0)
  2684.     {
  2685.       if (addr != 0) abort ();
  2686.       addr = offset;
  2687.     }
  2688.       if ((reg1 && GET_CODE (reg1) == MULT)
  2689.       || (reg2 != 0 && REGNO_OK_FOR_BASE_P (REGNO (reg2))))
  2690.     {
  2691.       breg = reg2;
  2692.       ireg = reg1;
  2693.     }
  2694.       else if (reg1 != 0 && REGNO_OK_FOR_BASE_P (REGNO (reg1)))
  2695.     {
  2696.       breg = reg1;
  2697.       ireg = reg2;
  2698.     }
  2699.  
  2700.       if (ireg != 0 || breg != 0)
  2701.     {
  2702.       int scale = 1;
  2703.  
  2704.       if (addr != 0)
  2705.         {
  2706.           if (flag_pic)
  2707.         output_pic_addr_const (file, addr, 0);
  2708.  
  2709.           else if (GET_CODE (addr) == LABEL_REF)
  2710.         output_asm_label (addr);
  2711.  
  2712.           else
  2713.         output_addr_const (file, addr);
  2714.         }
  2715.  
  2716.         if (ireg != 0 && GET_CODE (ireg) == MULT)
  2717.         {
  2718.           scale = INTVAL (XEXP (ireg, 1));
  2719.           ireg = XEXP (ireg, 0);
  2720.         }
  2721.  
  2722.       /* The stack pointer can only appear as a base register,
  2723.          never an index register, so exchange the regs if it is wrong. */
  2724.  
  2725.       if (scale == 1 && ireg && REGNO (ireg) == STACK_POINTER_REGNUM)
  2726.         {
  2727.           rtx tmp;
  2728.  
  2729.           tmp = breg;
  2730.           breg = ireg;
  2731.           ireg = tmp;
  2732.         }
  2733.  
  2734.       /* output breg+ireg*scale */
  2735.       PRINT_B_I_S (breg, ireg, scale, file);
  2736.       break;
  2737.     }
  2738.  
  2739.     case MULT:
  2740.       {
  2741.     int scale;
  2742.     if (GET_CODE (XEXP (addr, 0)) == CONST_INT)
  2743.       {
  2744.         scale = INTVAL (XEXP (addr, 0));
  2745.         ireg = XEXP (addr, 1);
  2746.       }
  2747.     else
  2748.       {
  2749.         scale = INTVAL (XEXP (addr, 1));
  2750.         ireg = XEXP (addr, 0);
  2751.       }
  2752.     output_addr_const (file, const0_rtx);
  2753.     PRINT_B_I_S ((rtx) 0, ireg, scale, file);
  2754.       }
  2755.       break;
  2756.  
  2757.     default:
  2758.       if (GET_CODE (addr) == CONST_INT
  2759.       && INTVAL (addr) < 0x8000
  2760.       && INTVAL (addr) >= -0x8000)
  2761.     fprintf (file, "%d", INTVAL (addr));
  2762.       else
  2763.     {
  2764.       if (flag_pic)
  2765.         output_pic_addr_const (file, addr, 0);
  2766.       else
  2767.         output_addr_const (file, addr);
  2768.     }
  2769.     }
  2770. }
  2771.  
  2772. /* Set the cc_status for the results of an insn whose pattern is EXP.
  2773.    On the 80386, we assume that only test and compare insns, as well
  2774.    as SI, HI, & DI mode ADD, SUB, NEG, AND, IOR, XOR, ASHIFT,
  2775.    ASHIFTRT, and LSHIFTRT instructions set the condition codes usefully.
  2776.    Also, we assume that jumps, moves and sCOND don't affect the condition
  2777.    codes.  All else clobbers the condition codes, by assumption.
  2778.  
  2779.    We assume that ALL integer add, minus, etc. instructions effect the
  2780.    condition codes.  This MUST be consistent with i386.md.
  2781.  
  2782.    We don't record any float test or compare - the redundant test &
  2783.    compare check in final.c does not handle stack-like regs correctly. */
  2784.  
  2785. void
  2786. notice_update_cc (exp)
  2787.      rtx exp;
  2788. {
  2789.   if (GET_CODE (exp) == SET)
  2790.     {
  2791.       /* Jumps do not alter the cc's.  */
  2792.       if (SET_DEST (exp) == pc_rtx)
  2793.     return;
  2794.       /* Moving register or memory into a register:
  2795.      it doesn't alter the cc's, but it might invalidate
  2796.      the RTX's which we remember the cc's came from.
  2797.      (Note that moving a constant 0 or 1 MAY set the cc's).  */
  2798.       if (REG_P (SET_DEST (exp))
  2799.       && (REG_P (SET_SRC (exp)) || GET_CODE (SET_SRC (exp)) == MEM
  2800.           || GET_RTX_CLASS (GET_CODE (SET_SRC (exp))) == '<'))
  2801.     {
  2802.       if (cc_status.value1
  2803.           && reg_overlap_mentioned_p (SET_DEST (exp), cc_status.value1))
  2804.         cc_status.value1 = 0;
  2805.       if (cc_status.value2
  2806.           && reg_overlap_mentioned_p (SET_DEST (exp), cc_status.value2))
  2807.         cc_status.value2 = 0;
  2808.       return;
  2809.     }
  2810.       /* Moving register into memory doesn't alter the cc's.
  2811.      It may invalidate the RTX's which we remember the cc's came from.  */
  2812.       if (GET_CODE (SET_DEST (exp)) == MEM
  2813.       && (REG_P (SET_SRC (exp))
  2814.           || GET_RTX_CLASS (GET_CODE (SET_SRC (exp))) == '<'))
  2815.     {
  2816.       if (cc_status.value1 && GET_CODE (cc_status.value1) == MEM)
  2817.         cc_status.value1 = 0;
  2818.       if (cc_status.value2 && GET_CODE (cc_status.value2) == MEM)
  2819.         cc_status.value2 = 0;
  2820.       return;
  2821.     }
  2822.       /* Function calls clobber the cc's.  */
  2823.       else if (GET_CODE (SET_SRC (exp)) == CALL)
  2824.     {
  2825.       CC_STATUS_INIT;
  2826.       return;
  2827.     }
  2828.       /* Tests and compares set the cc's in predictable ways.  */
  2829.       else if (SET_DEST (exp) == cc0_rtx)
  2830.     {
  2831.       CC_STATUS_INIT;
  2832.       cc_status.value1 = SET_SRC (exp);
  2833.       return;
  2834.     }
  2835.       /* Certain instructions effect the condition codes. */
  2836.       else if (GET_MODE (SET_SRC (exp)) == SImode
  2837.            || GET_MODE (SET_SRC (exp)) == HImode
  2838.            || GET_MODE (SET_SRC (exp)) == QImode)
  2839.     switch (GET_CODE (SET_SRC (exp)))
  2840.       {
  2841.       case ASHIFTRT: case LSHIFTRT:
  2842.       case ASHIFT:
  2843.         /* Shifts on the 386 don't set the condition codes if the
  2844.            shift count is zero. */
  2845.         if (GET_CODE (XEXP (SET_SRC (exp), 1)) != CONST_INT)
  2846.           {
  2847.         CC_STATUS_INIT;
  2848.         break;
  2849.           }
  2850.         /* We assume that the CONST_INT is non-zero (this rtx would
  2851.            have been deleted if it were zero. */
  2852.  
  2853.       case PLUS: case MINUS: case NEG:
  2854.       case AND: case IOR: case XOR:
  2855.         cc_status.flags = CC_NO_OVERFLOW;
  2856.         cc_status.value1 = SET_SRC (exp);
  2857.         cc_status.value2 = SET_DEST (exp);
  2858.         break;
  2859.  
  2860.       default:
  2861.         CC_STATUS_INIT;
  2862.       }
  2863.       else
  2864.     {
  2865.       CC_STATUS_INIT;
  2866.     }
  2867.     }
  2868.   else if (GET_CODE (exp) == PARALLEL
  2869.        && GET_CODE (XVECEXP (exp, 0, 0)) == SET)
  2870.     {
  2871.       if (SET_DEST (XVECEXP (exp, 0, 0)) == pc_rtx)
  2872.     return;
  2873.       if (SET_DEST (XVECEXP (exp, 0, 0)) == cc0_rtx)
  2874.     {
  2875.       CC_STATUS_INIT;
  2876.       if (stack_regs_mentioned_p (SET_SRC (XVECEXP (exp, 0, 0))))
  2877.         cc_status.flags |= CC_IN_80387;
  2878.       else
  2879.         cc_status.value1 = SET_SRC (XVECEXP (exp, 0, 0));
  2880.       return;
  2881.     }
  2882.       CC_STATUS_INIT;
  2883.     }
  2884.   else
  2885.     {
  2886.       CC_STATUS_INIT;
  2887.     }
  2888. }
  2889.  
  2890. /* Split one or more DImode RTL references into pairs of SImode
  2891.    references.  The RTL can be REG, offsettable MEM, integer constant, or
  2892.    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
  2893.    split and "num" is its length.  lo_half and hi_half are output arrays
  2894.    that parallel "operands". */
  2895.  
  2896. void
  2897. split_di (operands, num, lo_half, hi_half)
  2898.      rtx operands[];
  2899.      int num;
  2900.      rtx lo_half[], hi_half[];
  2901. {
  2902.   while (num--)
  2903.     {
  2904.       if (GET_CODE (operands[num]) == REG)
  2905.     {
  2906.       lo_half[num] = gen_rtx (REG, SImode, REGNO (operands[num]));
  2907.       hi_half[num] = gen_rtx (REG, SImode, REGNO (operands[num]) + 1);
  2908.     }
  2909.       else if (CONSTANT_P (operands[num]))
  2910.     {
  2911.       split_double (operands[num], &lo_half[num], &hi_half[num]);
  2912.     }
  2913.       else if (offsettable_memref_p (operands[num]))
  2914.     {
  2915.       lo_half[num] = operands[num];
  2916.       hi_half[num] = adj_offsettable_operand (operands[num], 4);
  2917.     }
  2918.       else
  2919.     abort();
  2920.     }
  2921. }
  2922.  
  2923. /* Return 1 if this is a valid binary operation on a 387.
  2924.    OP is the expression matched, and MODE is its mode. */
  2925.  
  2926. int
  2927. binary_387_op (op, mode)
  2928.     register rtx op;
  2929.     enum machine_mode mode;
  2930. {
  2931.   if (mode != VOIDmode && mode != GET_MODE (op))
  2932.     return 0;
  2933.  
  2934.   switch (GET_CODE (op))
  2935.     {
  2936.     case PLUS:
  2937.     case MINUS:
  2938.     case MULT:
  2939.     case DIV:
  2940.       return GET_MODE_CLASS (GET_MODE (op)) == MODE_FLOAT;
  2941.  
  2942.     default:
  2943.       return 0;
  2944.     }
  2945. }
  2946.  
  2947.  
  2948. /* Return 1 if this is a valid shift or rotate operation on a 386.
  2949.    OP is the expression matched, and MODE is its mode. */
  2950.  
  2951. int
  2952. shift_op (op, mode)
  2953.     register rtx op;
  2954.     enum machine_mode mode;
  2955. {
  2956.   rtx operand = XEXP (op, 0);
  2957.  
  2958.   if (mode != VOIDmode && mode != GET_MODE (op))
  2959.     return 0;
  2960.  
  2961.   if (GET_MODE (operand) != GET_MODE (op)
  2962.       || GET_MODE_CLASS (GET_MODE (op)) != MODE_INT)
  2963.     return 0;
  2964.  
  2965.   return (GET_CODE (op) == ASHIFT
  2966.       || GET_CODE (op) == ASHIFTRT
  2967.       || GET_CODE (op) == LSHIFTRT
  2968.       || GET_CODE (op) == ROTATE
  2969.       || GET_CODE (op) == ROTATERT);
  2970. }
  2971.  
  2972. /* Return 1 if OP is COMPARE rtx with mode VOIDmode.
  2973.    MODE is not used.  */
  2974.  
  2975. int
  2976. VOIDmode_compare_op (op, mode)
  2977.     register rtx op;
  2978.     enum machine_mode mode;
  2979. {
  2980.   return GET_CODE (op) == COMPARE && GET_MODE (op) == VOIDmode;
  2981. }
  2982.  
  2983. /* Output code to perform a 387 binary operation in INSN, one of PLUS,
  2984.    MINUS, MULT or DIV.  OPERANDS are the insn operands, where operands[3]
  2985.    is the expression of the binary operation.  The output may either be
  2986.    emitted here, or returned to the caller, like all output_* functions.
  2987.  
  2988.    There is no guarantee that the operands are the same mode, as they
  2989.    might be within FLOAT or FLOAT_EXTEND expressions. */
  2990.  
  2991. char *
  2992. output_387_binary_op (insn, operands)
  2993.      rtx insn;
  2994.      rtx *operands;
  2995. {
  2996.   rtx temp;
  2997.   char *base_op;
  2998.   static char buf[100];
  2999.  
  3000.   switch (GET_CODE (operands[3]))
  3001.     {
  3002.     case PLUS:
  3003.       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
  3004.       || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
  3005.     base_op = "fiadd";
  3006.       else
  3007.     base_op = "fadd";
  3008.       break;
  3009.  
  3010.     case MINUS:
  3011.       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
  3012.       || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
  3013.     base_op = "fisub";
  3014.       else
  3015.     base_op = "fsub";
  3016.       break;
  3017.  
  3018.     case MULT:
  3019.       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
  3020.       || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
  3021.     base_op = "fimul";
  3022.       else
  3023.     base_op = "fmul";
  3024.       break;
  3025.  
  3026.     case DIV:
  3027.       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
  3028.       || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
  3029.     base_op = "fidiv";
  3030.       else
  3031.     base_op = "fdiv";
  3032.       break;
  3033.  
  3034.     default:
  3035.       abort ();
  3036.     }
  3037.  
  3038.   strcpy (buf, base_op);
  3039.  
  3040.   switch (GET_CODE (operands[3]))
  3041.     {
  3042.     case MULT:
  3043.     case PLUS:
  3044.       if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2]))
  3045.     {
  3046.       temp = operands[2];
  3047.       operands[2] = operands[1];
  3048.       operands[1] = temp;
  3049.     }
  3050.  
  3051.       if (GET_CODE (operands[2]) == MEM)
  3052.     return strcat (buf, AS1 (%z2,%2));
  3053.  
  3054.       if (NON_STACK_REG_P (operands[1]))
  3055.     {
  3056.       output_op_from_reg (operands[1], strcat (buf, AS1 (%z0,%1)));
  3057.       RET;
  3058.     }
  3059.       else if (NON_STACK_REG_P (operands[2]))
  3060.     {
  3061.       output_op_from_reg (operands[2], strcat (buf, AS1 (%z0,%1)));
  3062.       RET;
  3063.     }
  3064.  
  3065.       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
  3066.     return strcat (buf, AS2 (p,%2,%0));
  3067.  
  3068.       if (STACK_TOP_P (operands[0]))
  3069.     return strcat (buf, AS2C (%y2,%0));
  3070.       else
  3071.     return strcat (buf, AS2C (%2,%0));
  3072.  
  3073.     case MINUS:
  3074.     case DIV:
  3075.       if (GET_CODE (operands[1]) == MEM)
  3076.     return strcat (buf, AS1 (r%z1,%1));
  3077.  
  3078.       if (GET_CODE (operands[2]) == MEM)
  3079.     return strcat (buf, AS1 (%z2,%2));
  3080.  
  3081.       if (NON_STACK_REG_P (operands[1]))
  3082.     {
  3083.       output_op_from_reg (operands[1], strcat (buf, AS1 (r%z0,%1)));
  3084.       RET;
  3085.     }
  3086.       else if (NON_STACK_REG_P (operands[2]))
  3087.     {
  3088.       output_op_from_reg (operands[2], strcat (buf, AS1 (%z0,%1)));
  3089.       RET;
  3090.     }
  3091.  
  3092.       if (! STACK_REG_P (operands[1]) || ! STACK_REG_P (operands[2]))
  3093.     abort ();
  3094.  
  3095.       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
  3096.     return strcat (buf, AS2 (rp,%2,%0));
  3097.  
  3098.       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
  3099.     return strcat (buf, AS2 (p,%1,%0));
  3100.  
  3101.       if (STACK_TOP_P (operands[0]))
  3102.     {
  3103.       if (STACK_TOP_P (operands[1]))
  3104.         return strcat (buf, AS2C (%y2,%0));
  3105.       else
  3106.         return strcat (buf, AS2 (r,%y1,%0));
  3107.     }
  3108.       else if (STACK_TOP_P (operands[1]))
  3109.     return strcat (buf, AS2C (%1,%0));
  3110.       else
  3111.     return strcat (buf, AS2 (r,%2,%0));
  3112.  
  3113.     default:
  3114.       abort ();
  3115.     }
  3116. }
  3117.  
  3118. /* Output code for INSN to convert a float to a signed int.  OPERANDS
  3119.    are the insn operands.  The output may be SFmode or DFmode and the
  3120.    input operand may be SImode or DImode.  As a special case, make sure
  3121.    that the 387 stack top dies if the output mode is DImode, because the
  3122.    hardware requires this.  */
  3123.  
  3124. char *
  3125. output_fix_trunc (insn, operands)
  3126.      rtx insn;
  3127.      rtx *operands;
  3128. {
  3129.   int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
  3130.   rtx xops[2];
  3131.  
  3132.   if (! STACK_TOP_P (operands[1]) ||
  3133.       (GET_MODE (operands[0]) == DImode && ! stack_top_dies))
  3134.     abort ();
  3135.  
  3136.   xops[0] = GEN_INT (12);
  3137.   xops[1] = operands[4];
  3138.  
  3139.   output_asm_insn (AS1 (fnstc%W2,%2), operands);
  3140.   output_asm_insn (AS2 (mov%L2,%2,%4), operands);
  3141.   output_asm_insn (AS2 (mov%B1,%0,%h1), xops);
  3142.   output_asm_insn (AS2 (mov%L4,%4,%3), operands);
  3143.   output_asm_insn (AS1 (fldc%W3,%3), operands);
  3144.  
  3145.   if (NON_STACK_REG_P (operands[0]))
  3146.     output_to_reg (operands[0], stack_top_dies);
  3147.   else if (GET_CODE (operands[0]) == MEM)
  3148.     {
  3149.       if (stack_top_dies)
  3150.     output_asm_insn (AS1 (fistp%z0,%0), operands);
  3151.       else
  3152.     output_asm_insn (AS1 (fist%z0,%0), operands);
  3153.     }
  3154.   else
  3155.     abort ();
  3156.  
  3157.   return AS1 (fldc%W2,%2);
  3158. }
  3159.  
  3160. /* Output code for INSN to compare OPERANDS.  The two operands might
  3161.    not have the same mode: one might be within a FLOAT or FLOAT_EXTEND
  3162.    expression.  If the compare is in mode CCFPEQmode, use an opcode that
  3163.    will not fault if a qNaN is present. */
  3164.  
  3165. char *
  3166. output_float_compare (insn, operands)
  3167.      rtx insn;
  3168.      rtx *operands;
  3169. {
  3170.   int stack_top_dies;
  3171.   rtx body = XVECEXP (PATTERN (insn), 0, 0);
  3172.   int unordered_compare = GET_MODE (SET_SRC (body)) == CCFPEQmode;
  3173.  
  3174.   if (! STACK_TOP_P (operands[0]))
  3175.     abort ();
  3176.  
  3177.   stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
  3178.  
  3179.   if (STACK_REG_P (operands[1])
  3180.       && stack_top_dies
  3181.       && find_regno_note (insn, REG_DEAD, REGNO (operands[1]))
  3182.       && REGNO (operands[1]) != FIRST_STACK_REG)
  3183.     {
  3184.       /* If both the top of the 387 stack dies, and the other operand
  3185.      is also a stack register that dies, then this must be a
  3186.      `fcompp' float compare */
  3187.  
  3188.       if (unordered_compare)
  3189.     output_asm_insn ("fucompp", operands);
  3190.       else
  3191.     output_asm_insn ("fcompp", operands);
  3192.     }
  3193.   else
  3194.     {
  3195.       static char buf[100];
  3196.  
  3197.       /* Decide if this is the integer or float compare opcode, or the
  3198.      unordered float compare. */
  3199.  
  3200.       if (unordered_compare)
  3201.     strcpy (buf, "fucom");
  3202.       else if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_FLOAT)
  3203.     strcpy (buf, "fcom");
  3204.       else
  3205.     strcpy (buf, "ficom");
  3206.  
  3207.       /* Modify the opcode if the 387 stack is to be popped. */
  3208.  
  3209.       if (stack_top_dies)
  3210.     strcat (buf, "p");
  3211.  
  3212.       if (NON_STACK_REG_P (operands[1]))
  3213.     output_op_from_reg (operands[1], strcat (buf, AS1 (%z0,%1)));
  3214.       else
  3215.         output_asm_insn (strcat (buf, AS1 (%z1,%y1)), operands);
  3216.     }
  3217.  
  3218.   /* Now retrieve the condition code. */
  3219.  
  3220.   return output_fp_cc0_set (insn);
  3221. }
  3222.  
  3223. /* Output opcodes to transfer the results of FP compare or test INSN
  3224.    from the FPU to the CPU flags.  If TARGET_IEEE_FP, ensure that if the
  3225.    result of the compare or test is unordered, no comparison operator
  3226.    succeeds except NE.  Return an output template, if any.  */
  3227.  
  3228. char *
  3229. output_fp_cc0_set (insn)
  3230.      rtx insn;
  3231. {
  3232.   rtx xops[3];
  3233.   rtx unordered_label;
  3234.   rtx next;
  3235.   enum rtx_code code;
  3236.  
  3237. #ifdef NEXT_SEMANTICS
  3238.   next = next_cc0_user (insn);
  3239.  
  3240.   /* a fpcc_switch instruction may have been inserted 
  3241.      here.  In that case, we need to actually output that 
  3242.      insn before we do the comparison below. */
  3243.   if (next == NULL_RTX && flag_fppc)
  3244.     {
  3245.       next = next_nonnote_insn (insn);
  3246.       
  3247.       if (next && GET_CODE (next) == INSN
  3248.       && INSN_CODE (next) == CODE_FOR_fppc_switch)
  3249.     {
  3250.       /* output the fppc_switch insn in `next' here! */
  3251.       /*
  3252.       xops[0] = XVECEXP (PATTERN (next), 0, 0);
  3253.       if (insn_template [CODE_FOR_fppc_switch])
  3254.         {
  3255.           output_asm_insn (insn_template[CODE_FOR_fppc_switch], xops);
  3256.         }
  3257.       else
  3258.         abort ();
  3259.         */
  3260.       next = next_cc0_user (next);
  3261.     }
  3262.     }
  3263. #endif
  3264.  
  3265.   xops[0] = gen_rtx (REG, HImode, 0);
  3266.   output_asm_insn (AS1 (fnsts%W0,%0), xops);
  3267.  
  3268.   if (! TARGET_IEEE_FP)
  3269.     return "sahf";
  3270.  
  3271. #ifndef NEXT_SEMANTICS
  3272.   next = next_cc0_user (insn);
  3273. #endif
  3274.   if (next == NULL_RTX)
  3275.     abort ();
  3276.  
  3277.   if (GET_CODE (next) == JUMP_INSN
  3278.       && GET_CODE (PATTERN (next)) == SET
  3279.       && SET_DEST (PATTERN (next)) == pc_rtx
  3280.       && GET_CODE (SET_SRC (PATTERN (next))) == IF_THEN_ELSE)
  3281.     {
  3282.       code = GET_CODE (XEXP (SET_SRC (PATTERN (next)), 0));
  3283.     }
  3284.   else if (GET_CODE (PATTERN (next)) == SET)
  3285.     {
  3286.       code = GET_CODE (SET_SRC (PATTERN (next)));
  3287.     }
  3288.   else
  3289.     abort ();
  3290.  
  3291.   xops[0] = gen_rtx (REG, QImode, 0);
  3292.  
  3293.   switch (code)
  3294.     {
  3295.     case GT:
  3296.       xops[1] = GEN_INT (0x45);
  3297.       output_asm_insn (AS2 (and%B0,%1,%h0), xops);
  3298.       /* je label */
  3299.       break;
  3300.  
  3301.     case LT:
  3302.       xops[1] = GEN_INT (0x45);
  3303.       xops[2] = GEN_INT (0x01);
  3304.       output_asm_insn (AS2 (and%B0,%1,%h0), xops);
  3305.       output_asm_insn (AS2 (cmp%B0,%2,%h0), xops);
  3306.       /* je label */
  3307.       break;
  3308.  
  3309.     case GE:
  3310.       xops[1] = GEN_INT (0x05);
  3311.       output_asm_insn (AS2 (and%B0,%1,%h0), xops);
  3312.       /* je label */
  3313.       break;
  3314.  
  3315.     case LE:
  3316.       xops[1] = GEN_INT (0x45);
  3317.       xops[2] = GEN_INT (0x40);
  3318.       output_asm_insn (AS2 (and%B0,%1,%h0), xops);
  3319.       output_asm_insn (AS1 (dec%B0,%h0), xops);
  3320.       output_asm_insn (AS2 (cmp%B0,%2,%h0), xops);
  3321.       /* jb label */
  3322.       break;
  3323.  
  3324.     case EQ:
  3325.       xops[1] = GEN_INT (0x45);
  3326.       xops[2] = GEN_INT (0x40);
  3327.       output_asm_insn (AS2 (and%B0,%1,%h0), xops);
  3328.       output_asm_insn (AS2 (cmp%B0,%2,%h0), xops);
  3329.       /* je label */
  3330.       break;
  3331.  
  3332.     case NE:
  3333.       xops[1] = GEN_INT (0x44);
  3334.       xops[2] = GEN_INT (0x40);
  3335.       output_asm_insn (AS2 (and%B0,%1,%h0), xops);
  3336.       output_asm_insn (AS2 (xor%B0,%2,%h0), xops);
  3337.       /* jne label */
  3338.       break;
  3339.  
  3340.     case GTU:
  3341.     case LTU:
  3342.     case GEU:
  3343.     case LEU:
  3344.     default:
  3345.       abort ();
  3346.     }
  3347.   RET;
  3348. }
  3349.  
  3350. #ifdef MACHO_PIC
  3351. #define MAX_386_STACK_LOCALS 3
  3352. #else
  3353. #define MAX_386_STACK_LOCALS 2
  3354. #endif
  3355.  
  3356. static rtx i386_stack_locals[(int) MAX_MACHINE_MODE][MAX_386_STACK_LOCALS];
  3357.  
  3358. /* Define the structure for the machine field in struct function.  */
  3359. struct machine_function
  3360. {
  3361.   rtx i386_stack_locals[(int) MAX_MACHINE_MODE][MAX_386_STACK_LOCALS];
  3362. };
  3363.  
  3364. /* Functions to save and restore i386_stack_locals.
  3365.    These will be called, via pointer variables,
  3366.    from push_function_context and pop_function_context.  */
  3367.  
  3368. void
  3369. save_386_machine_status (p)
  3370.      struct function *p;
  3371. {
  3372.   p->machine = (struct machine_function *) xmalloc (sizeof i386_stack_locals);
  3373.   bcopy ((char *) i386_stack_locals, (char *) p->machine->i386_stack_locals,
  3374.      sizeof i386_stack_locals);
  3375. }
  3376.  
  3377. void
  3378. restore_386_machine_status (p)
  3379.      struct function *p;
  3380. {
  3381.   bcopy ((char *) p->machine->i386_stack_locals, (char *) i386_stack_locals,
  3382.      sizeof i386_stack_locals);
  3383.   free (p->machine);
  3384. }
  3385.  
  3386. /* Clear stack slot assignments remembered from previous functions.
  3387.    This is called from INIT_EXPANDERS once before RTL is emitted for each
  3388.    function.  */
  3389.  
  3390. void
  3391. clear_386_stack_locals ()
  3392. {
  3393.   enum machine_mode mode;
  3394.   int n;
  3395.  
  3396.   for (mode = VOIDmode; (int) mode < (int) MAX_MACHINE_MODE;
  3397.        mode = (enum machine_mode) ((int) mode + 1))
  3398.     for (n = 0; n < MAX_386_STACK_LOCALS; n++)
  3399.       i386_stack_locals[(int) mode][n] = NULL_RTX;
  3400.  
  3401.   /* Arrange to save and restore i386_stack_locals around nested functions.  */
  3402.   save_machine_status = save_386_machine_status;
  3403.   restore_machine_status = restore_386_machine_status;
  3404. }
  3405.  
  3406. /* Return a MEM corresponding to a stack slot with mode MODE.
  3407.    Allocate a new slot if necessary.
  3408.  
  3409.    The RTL for a function can have several slots available: N is
  3410.    which slot to use.  */
  3411.  
  3412. rtx
  3413. assign_386_stack_local (mode, n)
  3414.      enum machine_mode mode;
  3415.      int n;
  3416. {
  3417.   if (n < 0 || n >= MAX_386_STACK_LOCALS)
  3418.     abort ();
  3419.  
  3420.   if (i386_stack_locals[(int) mode][n] == NULL_RTX)
  3421.     i386_stack_locals[(int) mode][n]
  3422.       = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
  3423.  
  3424.   return i386_stack_locals[(int) mode][n];
  3425. }
  3426.  
  3427. #ifdef NEXT_SEMANTICS
  3428. static rtx
  3429. lookup_i386_stack_local (mode, n)
  3430.   enum machine_mode mode;
  3431.   int n;
  3432. {
  3433.     if (n < 0 || n >= MAX_386_STACK_LOCALS)
  3434.       abort ();
  3435.  
  3436.     return  i386_stack_locals[(int) mode][n];
  3437. }
  3438. #endif
  3439.