home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Compilers⁄Interps / GCC-2.3.3r12 / Sources-Targets / m68k.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-24  |  104.0 KB  |  3,975 lines  |  [TEXT/MPS ]

  1. /* Subroutines for insn-output.c for Motorola 68000 family.
  2.    Copyright (C) 1987 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, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* Some output-actions in m68k.md need these.  */
  22. #include <stdio.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 "c-tree.h"
  36. #include "c-parse.h"
  37. #include "obstack.h"
  38.  
  39. extern flag_gen_trace_calls;
  40.  
  41. /* Needed for use_return_insn.  */
  42. #include "flags.h"
  43.  
  44. #ifdef SUPPORT_SUN_FPA
  45.  
  46. /* Index into this array by (register number >> 3) to find the
  47.    smallest class which contains that register.  */
  48. enum reg_class regno_reg_class[]
  49.   = { DATA_REGS, ADDR_REGS, FP_REGS,
  50.       LO_FPA_REGS, LO_FPA_REGS, FPA_REGS, FPA_REGS };
  51.  
  52. #endif /* defined SUPPORT_SUN_FPA */
  53.  
  54. /* This flag is used to communicate between movhi and ASM_OUTPUT_CASE_END,
  55.    if SGS_SWITCH_TABLE.  */
  56. int switch_table_difference_label_flag;
  57.  
  58.  rtx find_addr_reg ();
  59. rtx legitimize_pic_address ();
  60.  
  61. int globalize_this;
  62.  
  63. /* Nonzero if the current function was declared as a pascal function. */
  64.  
  65. extern int current_function_is_pascal;
  66.  
  67. /* Size varies according to cmd option. */
  68.  
  69. int long_double_type_size;
  70.  
  71. /* Index into this array by (register number >> 3) to find the
  72.    smallest class which contains that register.  */
  73. enum reg_class regno_reg_class[]
  74.   = { DATA_REGS, ADDR_REGS, FP_REGS };
  75.  
  76.  rtx find_addr_reg ();
  77.  
  78.  
  79.  
  80. /* Emit a (use pic_offset_table_rtx) if we used PIC relocation in the 
  81.    function at any time during the compilation process.  In the future 
  82.    we should try and eliminate the USE if we can easily determine that 
  83.    all PIC references were deleted from the current function.  That would 
  84.    save an address register */
  85.    
  86. finalize_pic ()
  87. {
  88.   if (flag_pic && current_function_uses_pic_offset_table)
  89.     emit_insn (gen_rtx (USE, VOIDmode, pic_offset_table_rtx));
  90. }
  91.  
  92.  
  93. /* This function generates the assembly code for function entry.
  94.    STREAM is a stdio stream to output the code to.
  95.    SIZE is an int: how many units of temporary storage to allocate.
  96.    Refer to the array `regs_ever_live' to determine which registers
  97.    to save; `regs_ever_live[I]' is nonzero if register number I
  98.    is ever used in the function.  This function is responsible for
  99.    knowing which registers should not be saved even if used.  */
  100.  
  101.  
  102. /* Note that the order of the bit mask for fmovem is the opposite
  103.    of the order for movem!  */
  104.  
  105. void
  106. output_function_prologue (stream, size)
  107.      FILE *stream;
  108.      int size;
  109. {
  110.   register int regno;
  111.   register int mask = 0;
  112.   int num_saved_regs = 0;
  113.   extern char call_used_regs[];
  114.   int fsize = (size + 3) & -4;
  115.   char maskstr[100];
  116.   
  117.  
  118.   if (TARGET_FX30)
  119.     asm_fprintf (stream, "m#start:\n");
  120.   if (frame_pointer_needed)
  121.     {
  122.       /* Adding negative number is faster on the 68040.  */
  123.       if (fsize < 0x8000 && !TARGET_68040)
  124.     {
  125. #ifdef MOTOROLA
  126.       asm_fprintf (stream, "\tlink.w %s,%0I%d\n",
  127.                reg_names[FRAME_POINTER_REGNUM], -fsize);
  128. #else
  129.       asm_fprintf (stream, "\tlink %s,%0I%d\n",
  130.                reg_names[FRAME_POINTER_REGNUM], -fsize);
  131. #endif
  132.     }
  133.       else if (TARGET_68020)
  134.     {
  135. #ifdef MOTOROLA
  136.       asm_fprintf (stream, "\tlink.l %s,%0I%d\n",
  137.                reg_names[FRAME_POINTER_REGNUM], -fsize);
  138. #else
  139.       asm_fprintf (stream, "\tlink %s,%0I%d\n",
  140.                reg_names[FRAME_POINTER_REGNUM], -fsize);
  141. #endif
  142.     }
  143.       else
  144.     {
  145. #ifdef MOTOROLA
  146.       asm_fprintf (stream, "\tlink.w %s,%0I0\n\tadd.l %0I%d,%Rsp\n",
  147.                reg_names[FRAME_POINTER_REGNUM], -fsize);
  148. #else
  149.       asm_fprintf (stream, "\tlink %s,%0I0\n\taddl %0I%d,%Rsp\n",
  150.                reg_names[FRAME_POINTER_REGNUM], -fsize);
  151. #endif
  152.     }
  153.     }
  154.   else if (fsize)
  155.     {
  156.       /* Adding negative number is faster on the 68040.  */
  157.       if (fsize + 4 < 0x8000)
  158.     {
  159. #ifdef MOTOROLA
  160.       asm_fprintf (stream, "\tadd.w %0I%d,%Rsp\n", - (fsize + 4));
  161. #else
  162.       asm_fprintf (stream, "\taddw %0I%d,%Rsp\n", - (fsize + 4));
  163. #endif
  164.     }
  165.       else
  166.     {
  167. #ifdef MOTOROLA
  168.       asm_fprintf (stream, "\tadd.l %0I%d,%Rsp\n", - (fsize + 4));
  169. #else
  170.       asm_fprintf (stream, "\taddl %0I%d,%Rsp\n", - (fsize + 4));
  171. #endif
  172.     }
  173.     }
  174. #ifdef SUPPORT_SUN_FPA
  175.   for (regno = 24; regno < 56; regno++)
  176.     if (regs_ever_live[regno] && ! call_used_regs[regno])
  177.       {
  178. #ifdef MOTOROLA
  179.     asm_fprintf (stream, "\tfpmovd %s,-(%Rsp)\n",
  180.              reg_names[regno]);
  181. #else
  182.     asm_fprintf (stream, "\tfpmoved %s,%Rsp@-\n",
  183.              reg_names[regno]);
  184. #endif
  185.       }
  186. #endif
  187.   maskstr[0] = '\0';
  188.   for (regno = 16; regno < 24; regno++)
  189.     if (regs_ever_live[regno] && ! call_used_regs[regno])
  190.       {
  191.     mask |= 1 << (regno - 16);
  192.     /* Add the name of the register to the mask string. */
  193.     strcat(maskstr, reg_names[regno]);
  194.     strcat(maskstr, "/");
  195.       }
  196.   if ((mask & 0xff) != 0)
  197.     {
  198. #ifdef MOTOROLA
  199. #ifdef MPW_ASM
  200.       maskstr[strlen(maskstr)-1] = '\0';
  201.       asm_fprintf (stream, "\tfmovem %s,-(sp)\n", maskstr);
  202. #else
  203.       asm_fprintf (stream, "\tfmovm %0I0x%x,-(%Rsp)\n", mask & 0xff);
  204. #endif
  205. #else
  206.       asm_fprintf (stream, "\tfmovem %0I0x%x,%Rsp@-\n", mask & 0xff);
  207. #endif
  208.     }
  209.   mask = 0;  maskstr[0] = '\0';
  210.   for (regno = 0; regno < 16; regno++)
  211.     if (regs_ever_live[regno] && ! call_used_regs[regno])
  212.       {
  213.         mask |= 1 << (15 - regno);
  214.     /* Add the name of the register to the mask string, but
  215.        not if it's the frame pointer.  (Easier to avoid adding
  216.        than to do the flag removal as done for the numeric mask.) */
  217.     if (! (frame_pointer_needed && regno == FRAME_POINTER_REGNUM))
  218.       {
  219.         strcat(maskstr, reg_names[regno]);
  220.         strcat(maskstr, "/");
  221.       }
  222.         num_saved_regs++;
  223.     }
  224.   if (frame_pointer_needed)
  225.     {
  226.       mask &= ~ (1 << (15 - FRAME_POINTER_REGNUM));
  227.       num_saved_regs--;
  228.     }
  229.  
  230. #if NEED_PROBE
  231.   fprintf (stream, "\ttstl sp@(%d)\n", NEED_PROBE - num_saved_regs * 4);
  232. #endif
  233.  
  234.   if (num_saved_regs <= 2)
  235.     {
  236.       /* Store each separately in the same order moveml uses.
  237.          Using two movel instructions instead of a single moveml
  238.          is about 15% faster for the 68020 and 68030 at no expense
  239.          in code size */
  240.  
  241.       int i;
  242.  
  243.       /* Undo the work from above. */
  244.       for (i = 0; i< 16; i++)
  245.         if (mask & (1 << i))
  246.           asm_fprintf (stream,
  247. #ifdef MOTOROLA
  248.                "\t%Omove.l %s,-(%Rsp)\n",
  249. #else
  250.                "\tmovel %s,%Rsp@-\n",
  251. #endif
  252.                reg_names[15 - i]);
  253.     }
  254.   else if (mask)
  255.     {
  256. #ifdef MOTOROLA
  257. #ifdef MPW_ASM
  258.       /* Peel off the trailing slash. */
  259.       maskstr[strlen(maskstr)-1] = '\0';
  260.       asm_fprintf (stream, "\tmovem.l %s,-(sp)\n", maskstr);
  261. #else
  262.       asm_fprintf (stream, "\tmovm.l %0I0x%x,-(%Rsp)\n", mask);
  263. #endif
  264. #else
  265.       asm_fprintf (stream, "\tmoveml %0I0x%x,%Rsp@-\n", mask);
  266. #endif
  267.     }
  268. #ifdef TARGET_FX30
  269.   if (TARGET_FX30)
  270.     {
  271.       asm_fprintf (stream, "\tDC.L $4bfb0170 ; lea -> a5\n");
  272.       asm_fprintf (stream, "\tDC.L _StaticDataArea-m#start-*+2\n");
  273.     }
  274. #endif /* TARGET_FX30 */
  275.   if (flag_pic && current_function_uses_pic_offset_table)
  276.     {
  277. #ifdef MOTOROLA
  278.       asm_fprintf (stream, "\t%Omove.l %0I__GLOBAL_OFFSET_TABLE_, %s\n",
  279.            reg_names[PIC_OFFSET_TABLE_REGNUM]);
  280.       asm_fprintf (stream, "\tlea.l (%Rpc,%s.l),%s\n",
  281.            reg_names[PIC_OFFSET_TABLE_REGNUM],
  282.            reg_names[PIC_OFFSET_TABLE_REGNUM]);
  283. #else
  284.       asm_fprintf (stream, "\tmovel %0I__GLOBAL_OFFSET_TABLE_, %s\n",
  285.            reg_names[PIC_OFFSET_TABLE_REGNUM]);
  286.       asm_fprintf (stream, "\tlea %Rpc@(0,%s:l),%s\n",
  287.            reg_names[PIC_OFFSET_TABLE_REGNUM],
  288.            reg_names[PIC_OFFSET_TABLE_REGNUM]);
  289. #endif
  290.     }
  291.   /* Hook for tracing has to be called after everything else is set up. */
  292.   if (flag_gen_trace_calls)
  293.     {
  294.       asm_fprintf (stream, "\tIMPORT %%_BP:CODE\n");
  295.       asm_fprintf (stream, "\tjsr %%_BP\n");
  296.     }
  297. }
  298.  
  299. /* Return true if this function's epilogue can be output as RTL.  */
  300.  
  301. int
  302. use_return_insn ()
  303. {
  304.   int regno;
  305.  
  306.   if (!reload_completed || frame_pointer_needed || get_frame_size () != 0)
  307.     return 0;
  308.   
  309.   /* Copied from output_function_epilogue ().  We should probably create a
  310.      separate layout routine to perform the common work.  */
  311.   
  312.   for (regno = 0 ; regno < FIRST_PSEUDO_REGISTER ; regno++)
  313.     if (regs_ever_live[regno] && ! call_used_regs[regno])
  314.       return 0;
  315.   
  316.   return 1;
  317. }
  318.  
  319. /* This function generates the assembly code for function exit,
  320.    on machines that need it.  Args are same as for FUNCTION_PROLOGUE.
  321.  
  322.    The function epilogue should not depend on the current stack pointer!
  323.    It should use the frame pointer only, if there is a frame pointer.
  324.    This is mandatory because of alloca; we also take advantage of it to
  325.    omit stack adjustments before returning.  */
  326.  
  327. /* Function epilogue code restores any saved regs and then returns.  There
  328.    are a number of obscure details and different options that can come up.
  329.    
  330.    Note the Macsbug symbol output at the end (see Appendix G of Macsbug
  331.    reference for details).  Also note that the pascal function return
  332.    sequence is cribbed from MPW, for no particularly deep reason. */
  333.  
  334. void
  335. output_function_epilogue (stream, size)
  336.      FILE *stream;
  337.      int size;
  338. {
  339.   register int regno;
  340.   register int mask, fmask;
  341.   register int nregs;
  342.   int offset, foffset, fpoffset;
  343.   extern char call_used_regs[];
  344.   int fsize = (size + 3) & -4;
  345.   int big = 0;
  346.   rtx insn = get_last_insn ();
  347.   char maskstr[100], fmaskstr[100];
  348.   
  349.   /* If the last insn was a BARRIER, we don't have to write any code.  */
  350.   if (GET_CODE (insn) == NOTE)
  351.     insn = prev_nonnote_insn (insn);
  352.   if (insn && GET_CODE (insn) == BARRIER)
  353.     {
  354.       /* Output just a no-op so that debuggers don't get confused
  355.      about which function the pc is in at this address.  */
  356.       asm_fprintf (stream, "\tnop\n");
  357.       goto trailer;
  358.     }
  359.  
  360.   /* Have to generate the trace calls after the return result is set up
  361.      (by function body), but before any state restoration happens. */
  362.   if (flag_gen_trace_calls)
  363.     {
  364.       asm_fprintf (stream, "\tmove.l d0,-(a7)\n");
  365.       asm_fprintf (stream, "\tIMPORT %%_EP\n");
  366.       asm_fprintf (stream, "\tjsr %%_EP\n");
  367.       asm_fprintf (stream, "\tmove.l (a7)+,d0\n");
  368.     }
  369.  
  370. #ifdef FUNCTION_EXTRA_EPILOGUE
  371.   FUNCTION_EXTRA_EPILOGUE (stream, size);
  372. #endif
  373.   nregs = 0;  fmask = 0; fpoffset = 0;
  374. #ifdef SUPPORT_SUN_FPA
  375.   for (regno = 24 ; regno < 56 ; regno++)
  376.     if (regs_ever_live[regno] && ! call_used_regs[regno])
  377.       nregs++;
  378.   fpoffset = nregs * 8;
  379. #endif
  380.   nregs = 0;  fmaskstr[0] = '\0';
  381.   for (regno = 16; regno < 24; regno++)
  382.     if (regs_ever_live[regno] && ! call_used_regs[regno])
  383.       {
  384.         nregs++;
  385.     fmask |= 1 << (23 - regno);
  386.     strcat(fmaskstr, reg_names[regno]);  strcat(fmaskstr, "/");
  387.       }
  388.   foffset = fpoffset + nregs * 12;
  389.   nregs = 0;  mask = 0;  maskstr[0] = '\0';
  390.   if (frame_pointer_needed)
  391.     regs_ever_live[FRAME_POINTER_REGNUM] = 0;
  392.   for (regno = 0; regno < 16; regno++)
  393.     if (regs_ever_live[regno] && ! call_used_regs[regno])
  394.       {
  395.         nregs++;
  396.     mask |= 1 << regno;
  397.     strcat(maskstr, reg_names[regno]);  strcat(maskstr, "/");
  398.       }
  399.   if (TARGET_FX30)
  400.     {
  401.       nregs++;
  402.       strcat(mask, reg_names[13]);  strcat(mask, "/");
  403.     }
  404.   offset = foffset + nregs * 4;
  405.   if (offset + fsize >= 0x8000
  406.       && frame_pointer_needed
  407.       && (mask || fmask || fpoffset))
  408.     {
  409. #ifdef MOTOROLA
  410.       asm_fprintf (stream, "\t%Omove.l %0I%d,%Ra0\n", -fsize);
  411. #else
  412.       asm_fprintf (stream, "\tmovel %0I%d,%Ra0\n", -fsize);
  413. #endif
  414.       fsize = 0, big = 1;
  415.     }
  416.   if (nregs <= 2)
  417.     {
  418.       /* Restore each separately in the same order moveml does.
  419.          Using two movel instructions instead of a single moveml
  420.          is about 15% faster for the 68020 and 68030 at no expense
  421.          in code size. */
  422.  
  423.       int i;
  424.  
  425.       /* Undo the work from above. */
  426.       for (i = 0; i< 16; i++)
  427.         if (mask & (1 << i))
  428.           {
  429.             if (big)
  430.           {
  431. #ifdef MOTOROLA
  432. #ifdef MPW_ASM
  433.         asm_fprintf (stream, "\t%Omove.l (-%d,%s,%Ra0:l),%s\n",
  434.                  offset + fsize,
  435.                  reg_names[FRAME_POINTER_REGNUM],
  436.                  reg_names[i]);
  437. #else
  438.         asm_fprintf (stream, "\t%Omove.l -%d(%s,%Ra0.l),%s\n",
  439.                  offset + fsize,
  440.                  reg_names[FRAME_POINTER_REGNUM],
  441.                  reg_names[i]);
  442. #endif /* MPW_ASM */
  443. #else
  444.         asm_fprintf (stream, "\tmovel %s@(-%d,%Ra0:l),%s\n",
  445.                  reg_names[FRAME_POINTER_REGNUM],
  446.                  offset + fsize, reg_names[i]);
  447. #endif
  448.           }
  449.             else if (! frame_pointer_needed)
  450.           {
  451. #ifdef MOTOROLA
  452.         asm_fprintf (stream, "\t%Omove.l (%Rsp)+,%s\n",
  453.                  reg_names[i]);
  454. #else
  455.         asm_fprintf (stream, "\tmovel %Rsp@+,%s\n",
  456.                  reg_names[i]);
  457. #endif
  458.           }
  459.             else
  460.           {
  461. #ifdef MOTOROLA
  462.         asm_fprintf (stream, "\t%Omove.l -%d(%s),%s\n",
  463.                  offset + fsize,
  464.                  reg_names[FRAME_POINTER_REGNUM],
  465.                  reg_names[i]);
  466. #else
  467.         asm_fprintf (stream, "\tmovel %s@(-%d),%s\n",
  468.                  reg_names[FRAME_POINTER_REGNUM],
  469.                  offset + fsize, reg_names[i]);
  470. #endif
  471.           }
  472.             offset = offset - 4;
  473.           }
  474.     }
  475.   else if (mask)
  476.     {
  477.       /* Peel off the trailing slash. */
  478.       maskstr[strlen(maskstr)-1] = '\0';
  479.       if (big)
  480.     {
  481. #ifdef MOTOROLA
  482. #ifdef MPW_ASM
  483.       asm_fprintf (stream, "\tmovem.l (-%d,%s,%Ra0.l),%s\n",
  484.                offset + fsize,
  485.                reg_names[FRAME_POINTER_REGNUM],
  486.                maskstr);
  487. #else
  488.       asm_fprintf (stream, "\tmovm.l -%d(%s,%Ra0.l),%0I0x%x\n",
  489.                offset + fsize,
  490.                reg_names[FRAME_POINTER_REGNUM],
  491.                mask);
  492. #endif /* MPW_ASM */
  493. #else
  494.       asm_fprintf (stream, "\tmoveml %s@(-%d,%Ra0:l),%0I0x%x\n",
  495.                reg_names[FRAME_POINTER_REGNUM],
  496.                offset + fsize, mask);
  497. #endif
  498.     }
  499.       else if (! frame_pointer_needed)
  500.     {
  501. #ifdef MOTOROLA
  502. #ifdef MPW_ASM
  503.       asm_fprintf (stream, "\tmovem.l (%Rsp)+,%s\n", maskstr);
  504. #else
  505.       asm_fprintf (stream, "\tmovm.l (%Rsp)+,%0I0x%x\n", mask);
  506. #endif /* MPW_ASM */
  507. #else
  508.       asm_fprintf (stream, "\tmoveml %Rsp@+,%0I0x%x\n", mask);
  509. #endif
  510.     }
  511.       else
  512.     {
  513. #ifdef MOTOROLA
  514. #ifdef MPW_ASM
  515.       asm_fprintf (stream, "\tmovem.l -%d(%s),%s\n",
  516.                offset + fsize,
  517.                reg_names[FRAME_POINTER_REGNUM],
  518.                maskstr);
  519. #else
  520.       asm_fprintf (stream, "\tmovm.l -%d(%s),%0I0x%x\n",
  521.                offset + fsize,
  522.                reg_names[FRAME_POINTER_REGNUM],
  523.                mask);
  524. #endif /* MPW_ASM */
  525. #else
  526.       asm_fprintf (stream, "\tmoveml %s@(-%d),%0I0x%x\n",
  527.                reg_names[FRAME_POINTER_REGNUM],
  528.                offset + fsize, mask);
  529. #endif
  530.     }
  531.     }
  532.   if (fmask)
  533.     {
  534.       fmaskstr[strlen(fmaskstr)-1] = '\0';
  535.       if (big)
  536.     {
  537. #ifdef MOTOROLA
  538. #ifdef MPW_ASM
  539.       asm_fprintf (stream, "\tfmovem (-%d,%s,%Ra0:l),%s\n",
  540.                foffset + fsize,
  541.                reg_names[FRAME_POINTER_REGNUM],
  542.                fmaskstr);
  543. #else
  544.       asm_fprintf (stream, "\tfmovm -%d(%s,%Ra0.l),%0I0x%x\n",
  545.                foffset + fsize,
  546.                reg_names[FRAME_POINTER_REGNUM],
  547.                fmask);
  548. #endif /* MPW_ASM */
  549. #else
  550.       asm_fprintf (stream, "\tfmovem %s@(-%d,%Ra0:l),%0I0x%x\n",
  551.                reg_names[FRAME_POINTER_REGNUM],
  552.                foffset + fsize, fmask);
  553. #endif
  554.     }
  555.       else if (! frame_pointer_needed)
  556.     {
  557. #ifdef MOTOROLA
  558. #ifdef MPW_ASM
  559.       asm_fprintf (stream, "\tfmovem (%Rsp)+,%s\n", fmaskstr);
  560. #else
  561.       asm_fprintf (stream, "\tfmovm (%Rsp)+,%0I0x%x\n", fmask);
  562. #endif /* MPW_ASM */
  563. #else
  564.       asm_fprintf (stream, "\tfmovem %Rsp@+,%0I0x%x\n", fmask);
  565. #endif
  566.     }
  567.       else
  568.     {
  569. #ifdef MOTOROLA
  570. #ifdef MPW_ASM
  571.       asm_fprintf (stream, "\tfmovem -%d(%s),%s\n",
  572.                foffset + fsize,
  573.                reg_names[FRAME_POINTER_REGNUM],
  574.                fmaskstr);
  575. #else
  576.       asm_fprintf (stream, "\tfmovm -%d(%s),%0I0x%x\n",
  577.                foffset + fsize,
  578.                reg_names[FRAME_POINTER_REGNUM],
  579.                fmask);
  580. #endif
  581. #else
  582.       asm_fprintf (stream, "\tfmovem %s@(-%d),%0I0x%x\n",
  583.                reg_names[FRAME_POINTER_REGNUM],
  584.                foffset + fsize, fmask);
  585. #endif
  586.     }
  587.     }
  588. #ifdef SUPPORT_SUN_FPA
  589.   if (fpoffset != 0)
  590.     for (regno = 55; regno >= 24; regno--)
  591.       if (regs_ever_live[regno] && ! call_used_regs[regno])
  592.         {
  593.       if (big)
  594.         {
  595. #ifdef MOTOROLA
  596.           asm_fprintf (stream, "\tfpmovd -%d(%s,%Ra0.l), %s\n",
  597.                fpoffset + fsize,
  598.                reg_names[FRAME_POINTER_REGNUM],
  599.                reg_names[regno]);
  600. #else
  601.           asm_fprintf (stream, "\tfpmoved %s@(-%d,%Ra0:l), %s\n",
  602.                reg_names[FRAME_POINTER_REGNUM],
  603.                fpoffset + fsize, reg_names[regno]);
  604. #endif
  605.         }
  606.       else if (! frame_pointer_needed)
  607.         {
  608. #ifdef MOTOROLA
  609.           asm_fprintf (stream, "\tfpmovd (%Rsp)+,%s\n",
  610.                reg_names[regno]);
  611. #else
  612.           asm_fprintf (stream, "\tfpmoved %Rsp@+, %s\n",
  613.                reg_names[regno]);
  614. #endif
  615.         }
  616.       else
  617.         {
  618. #ifdef MOTOROLA
  619.           asm_fprintf (stream, "\tfpmovd -%d(%s), %s\n",
  620.                fpoffset + fsize,
  621.                reg_names[FRAME_POINTER_REGNUM],
  622.                reg_names[regno]);
  623. #else
  624.           asm_fprintf (stream, "\tfpmoved %s@(-%d), %s\n",
  625.                reg_names[FRAME_POINTER_REGNUM],
  626.                fpoffset + fsize, reg_names[regno]);
  627. #endif
  628.         }
  629.       fpoffset -= 8;
  630.     }
  631. #endif
  632.   if (frame_pointer_needed)
  633.     fprintf (stream, "\tunlk %s\n",
  634.          reg_names[FRAME_POINTER_REGNUM]);
  635.   else if (fsize)
  636.     {
  637.       if (fsize + 4 < 0x8000)
  638.     {
  639. #ifdef MOTOROLA
  640.       asm_fprintf (stream, "\tadd.w %0I%d,%Rsp\n", fsize + 4);
  641. #else
  642.       asm_fprintf (stream, "\taddw %0I%d,%Rsp\n", fsize + 4);
  643. #endif
  644.     }
  645.       else
  646.     {
  647. #ifdef MOTOROLA
  648.       asm_fprintf (stream, "\tadd.l %0I%d,%Rsp\n", fsize + 4);
  649. #else
  650.       asm_fprintf (stream, "\taddl %0I%d,%Rsp\n", fsize + 4);
  651. #endif
  652.     }
  653.     }
  654.   /* Pascal-declared functions use a0 as a tmp var for the return address,
  655.      pop all the arguments, and jump through a0. */
  656.   if (current_function_is_pascal && current_function_args_size > 0)
  657.     asm_fprintf (stream, "\tmovea.l (sp)+,a0\n\tadd.w #%d,sp\n\tjmp (a0)\n",
  658.          current_function_args_size);
  659.   else if (current_function_pops_args)
  660.     asm_fprintf (stream, "\trtd %0I%d\n", current_function_pops_args);
  661.   else
  662.     fprintf (stream, "\trts\n");
  663.  /* If we do a tail-recursive call, still need to issue any static data needed at the
  664.     end of the function. */
  665.  trailer:
  666. #ifdef MPW_ASM
  667. #ifdef TARGET_MACSBUG
  668.   if (TARGET_MACSBUG)
  669.     {
  670.       extern char *current_function_name;
  671.       int len = strlen(current_function_name);
  672.  
  673.       if (len < 32)
  674.     asm_fprintf (stream, "\tDC.B $%x, '", 0x80 + len);
  675.       else
  676.     asm_fprintf (stream, "\tDC.B $80, %d, '", len);
  677.       asm_fprintf (stream, "%s", current_function_name);
  678.       asm_fprintf (stream, "'%s\n", ((len < 32) ? ((len+1) & 1 ? ", 0" : "")
  679.                   : ((len+2) & 1 ? ", 0" : "")));
  680.     }
  681. #endif /* TARGET_MACSBUG */
  682.   /* Unconditional, so the "local data length" gets written properly. */
  683.   dump_local_strings (stream);
  684.   /* Flag the end of the module. */
  685.   asm_fprintf (stream, "\tENDP\n");
  686. #endif /* MPW_ASM */
  687. }
  688.  
  689. /* Similar to general_operand, but exclude stack_pointer_rtx.  */
  690.  
  691. int
  692. not_sp_operand (op, mode)
  693.      register rtx op;
  694.      enum machine_mode mode;
  695. {
  696.   return op != stack_pointer_rtx && general_operand (op, mode);
  697. }
  698.  
  699. /* Return TRUE if X is a valid comparison operator for the dbcc 
  700.    instruction.  
  701.  
  702.    Note it rejects floating point comparison operators.
  703.   (In the future we could use Fdbcc).
  704.  
  705.    It also rejects some comparisons when CC_NO_OVERFLOW is set.  */
  706.    
  707. int
  708. valid_dbcc_comparison_p (x, mode)
  709.      rtx x;
  710.      enum machine_mode mode;
  711. {
  712.   /* We could add support for these in the future */
  713.   if (cc_prev_status.flags & CC_IN_68881)
  714.     return 0;
  715.  
  716.   switch (GET_CODE (x))
  717.     {
  718.  
  719.       case EQ: case NE: case GTU: case LTU:
  720.       case GEU: case LEU:
  721.         return 1;
  722.  
  723.       /* Reject some when CC_NO_OVERFLOW is set.  This may be over
  724.          conservative */
  725.       case GT: case LT: case GE: case LE:
  726.         return ! (cc_prev_status.flags & CC_NO_OVERFLOW);
  727.       default:
  728.         return 0;
  729.     }
  730. }
  731.  
  732. /* Output a dbCC; jCC sequence.  Note we do not handle the 
  733.    floating point version of this sequence (Fdbcc).  We also
  734.    do not handle alternative conditions when CC_NO_OVERFLOW is
  735.    set.  It is assumed that valid_dbcc_comparison_p will kick
  736.    those out before we get here.  */
  737.  
  738. output_dbcc_and_branch (operands)
  739.      rtx *operands;
  740. {
  741.  
  742.   switch (GET_CODE (operands[3]))
  743.     {
  744.       case EQ:
  745. #ifdef MOTOROLA
  746.         output_asm_insn ("dbeq %0,%l1\n\tbeq %l2", operands);
  747. #else
  748.         output_asm_insn ("dbeq %0,%l1\n\tjeq %l2", operands);
  749. #endif
  750.         break;
  751.  
  752.       case NE:
  753. #ifdef MOTOROLA
  754.         output_asm_insn ("dbne %0,%l1\n\tbne %l2", operands);
  755. #else
  756.         output_asm_insn ("dbne %0,%l1\n\tjne %l2", operands);
  757. #endif
  758.         break;
  759.  
  760.       case GT:
  761. #ifdef MOTOROLA
  762.         output_asm_insn ("dbgt %0,%l1\n\tbgt %l2", operands);
  763. #else
  764.         output_asm_insn ("dbgt %0,%l1\n\tjgt %l2", operands);
  765. #endif
  766.         break;
  767.  
  768.       case GTU:
  769. #ifdef MOTOROLA
  770.         output_asm_insn ("dbhi %0,%l1\n\tbhi %l2", operands);
  771. #else
  772.         output_asm_insn ("dbhi %0,%l1\n\tjhi %l2", operands);
  773. #endif
  774.         break;
  775.  
  776.       case LT:
  777. #ifdef MOTOROLA
  778.         output_asm_insn ("dblt %0,%l1\n\tblt %l2", operands);
  779. #else
  780.         output_asm_insn ("dblt %0,%l1\n\tjlt %l2", operands);
  781. #endif
  782.         break;
  783.  
  784.       case LTU:
  785. #ifdef MOTOROLA
  786.         output_asm_insn ("dbcs %0,%l1\n\tbcs %l2", operands);
  787. #else
  788.         output_asm_insn ("dbcs %0,%l1\n\tjcs %l2", operands);
  789. #endif
  790.         break;
  791.  
  792.       case GE:
  793. #ifdef MOTOROLA
  794.         output_asm_insn ("dbge %0,%l1\n\tbge %l2", operands);
  795. #else
  796.         output_asm_insn ("dbge %0,%l1\n\tjge %l2", operands);
  797. #endif
  798.         break;
  799.  
  800.       case GEU:
  801. #ifdef MOTOROLA
  802.         output_asm_insn ("dbcc %0,%l1\n\tbcc %l2", operands);
  803. #else
  804.         output_asm_insn ("dbcc %0,%l1\n\tjcc %l2", operands);
  805. #endif
  806.         break;
  807.  
  808.       case LE:
  809. #ifdef MOTOROLA
  810.         output_asm_insn ("dble %0,%l1\n\tble %l2", operands);
  811. #else
  812.         output_asm_insn ("dble %0,%l1\n\tjle %l2", operands);
  813. #endif
  814.         break;
  815.  
  816.       case LEU:
  817. #ifdef MOTOROLA
  818.         output_asm_insn ("dbls %0,%l1\n\tbls %l2", operands);
  819. #else
  820.         output_asm_insn ("dbls %0,%l1\n\tjls %l2", operands);
  821. #endif
  822.         break;
  823.  
  824.       default:
  825.     abort ();
  826.     }
  827.  
  828.   /* If the decrement is to be done in SImode, then we have
  829.      to compensate for the fact that dbcc decrements in HImode. */
  830.   switch (GET_MODE (operands[0]))
  831.     {
  832.       case SImode:
  833. #ifdef MOTOROLA
  834.         output_asm_insn ("clr%.w %0\n\tsubq%.l %#1,%0\n\tjbpl %l1", operands);
  835. #else
  836.         output_asm_insn ("clr%.w %0\n\tsubq%.l %#1,%0\n\tjpl %l1", operands);
  837. #endif
  838.         break;
  839.  
  840.       case HImode:
  841.         break;
  842.  
  843.       default:
  844.         abort ();
  845.     }
  846. }
  847.  
  848. char *
  849. output_btst (operands, countop, dataop, insn, signpos)
  850.      rtx *operands;
  851.      rtx countop, dataop;
  852.      rtx insn;
  853.      int signpos;
  854. {
  855.   operands[0] = countop;
  856.   operands[1] = dataop;
  857.  
  858.   if (GET_CODE (countop) == CONST_INT)
  859.     {
  860.       register int count = INTVAL (countop);
  861.       /* If COUNT is bigger than size of storage unit in use,
  862.      advance to the containing unit of same size.  */
  863.       if (count > signpos)
  864.     {
  865.       int offset = (count & ~signpos) / 8;
  866.       count = count & signpos;
  867.       operands[1] = dataop = adj_offsettable_operand (dataop, offset);
  868.     }
  869.       if (count == signpos)
  870.     cc_status.flags = CC_NOT_POSITIVE | CC_Z_IN_NOT_N;
  871.       else
  872.     cc_status.flags = CC_NOT_NEGATIVE | CC_Z_IN_NOT_N;
  873.  
  874.       /* These three statements used to use next_insns_test_no...
  875.      but it appears that this should do the same job.  */
  876.       if (count == 31
  877.       && next_insn_tests_no_inequality (insn))
  878.     return "tst%.l %1";
  879.       if (count == 15
  880.       && next_insn_tests_no_inequality (insn))
  881.     return "tst%.w %1";
  882.       if (count == 7
  883.       && next_insn_tests_no_inequality (insn))
  884.     return "tst%.b %1";
  885.  
  886.       cc_status.flags = CC_NOT_NEGATIVE;
  887.     }
  888.   return "btst %0,%1";
  889. }
  890.  
  891. /* Returns 1 if OP is either a symbol reference or a sum of a symbol
  892.    reference and a constant.  */
  893.  
  894. int
  895. symbolic_operand (op, mode)
  896.      register rtx op;
  897.      enum machine_mode mode;
  898. {
  899.   switch (GET_CODE (op))
  900.     {
  901.     case SYMBOL_REF:
  902.     case LABEL_REF:
  903.       return 1;
  904.  
  905.     case CONST:
  906.       op = XEXP (op, 0);
  907.       return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
  908.            || GET_CODE (XEXP (op, 0)) == LABEL_REF)
  909.           && GET_CODE (XEXP (op, 1)) == CONST_INT);
  910.  
  911. #if 0 /* Deleted, with corresponding change in m68k.h,
  912.      so as to fit the specs.  No CONST_DOUBLE is ever symbolic.  */
  913.     case CONST_DOUBLE:
  914.       return GET_MODE (op) == mode;
  915. #endif
  916.  
  917.     default:
  918.       return 0;
  919.     }
  920. }
  921.  
  922.  
  923. /* Legitimize PIC addresses.  If the address is already
  924.    position-independent, we return ORIG.  Newly generated
  925.    position-independent addresses go to REG.  If we need more
  926.    than one register, we lose.  
  927.  
  928.    An address is legitimized by making an indirect reference
  929.    through the Global Offset Table with the name of the symbol
  930.    used as an offset.  
  931.  
  932.    The assembler and linker are responsible for placing the 
  933.    address of the symbol in the GOT.  The function prologue
  934.    is responsible for initializing a5 to the starting address
  935.    of the GOT.
  936.  
  937.    The assembler is also responsible for translating a symbol name
  938.    into a constant displacement from the start of the GOT.  
  939.  
  940.    A quick example may make things a little clearer:
  941.  
  942.    When not generating PIC code to store the value 12345 into _foo
  943.    we would generate the following code:
  944.  
  945.     movel #12345, _foo
  946.  
  947.    When generating PIC two transformations are made.  First, the compiler
  948.    loads the address of foo into a register.  So the first transformation makes:
  949.  
  950.     lea    _foo, a0
  951.     movel   #12345, a0@
  952.  
  953.    The code in movsi will intercept the lea instruction and call this
  954.    routine which will transform the instructions into:
  955.  
  956.     movel   a5@(_foo:w), a0
  957.     movel   #12345, a0@
  958.    
  959.  
  960.    That (in a nutshell) is how *all* symbol and label references are 
  961.    handled.  */
  962.  
  963. rtx
  964. legitimize_pic_address (orig, mode, reg)
  965.      rtx orig, reg;
  966.      enum machine_mode mode;
  967. {
  968.   rtx pic_ref = orig;
  969.  
  970.   /* First handle a simple SYMBOL_REF or LABEL_REF */
  971.   if (GET_CODE (orig) == SYMBOL_REF || GET_CODE (orig) == LABEL_REF)
  972.     {
  973.       if (reg == 0)
  974.     abort ();
  975.  
  976.       pic_ref = gen_rtx (MEM, Pmode,
  977.              gen_rtx (PLUS, Pmode,
  978.                   pic_offset_table_rtx, orig));
  979.       current_function_uses_pic_offset_table = 1;
  980.       RTX_UNCHANGING_P (pic_ref) = 1;
  981.       emit_move_insn (reg, pic_ref);
  982.       return reg;
  983.     }
  984.   else if (GET_CODE (orig) == CONST)
  985.     {
  986.       rtx base, offset;
  987.  
  988.       /* Make sure this is CONST has not already been legitimized */
  989.       if (GET_CODE (XEXP (orig, 0)) == PLUS
  990.       && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
  991.     return orig;
  992.  
  993.       if (reg == 0)
  994.     abort ();
  995.  
  996.       /* legitimize both operands of the PLUS */
  997.       if (GET_CODE (XEXP (orig, 0)) == PLUS)
  998.     {
  999.       base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
  1000.       orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
  1001.                      base == reg ? 0 : reg);
  1002.     }
  1003.       else abort ();
  1004.  
  1005.       if (GET_CODE (orig) == CONST_INT)
  1006.     return plus_constant_for_output (base, INTVAL (orig));
  1007.       pic_ref = gen_rtx (PLUS, Pmode, base, orig);
  1008.       /* Likewise, should we set special REG_NOTEs here?  */
  1009.     }
  1010.   return pic_ref;
  1011. }
  1012.  
  1013.  
  1014. /* Return the best assembler insn template
  1015.    for moving operands[1] into operands[0] as a fullword.  */
  1016.  
  1017.  char *
  1018. singlemove_string (operands)
  1019.      rtx *operands;
  1020. {
  1021. #ifdef SUPPORT_SUN_FPA
  1022.   if (FPA_REG_P (operands[0]) || FPA_REG_P (operands[1]))
  1023.     return "fpmoves %1,%0";
  1024. #endif
  1025.   if (DATA_REG_P (operands[0])
  1026.       && GET_CODE (operands[1]) == CONST_INT
  1027.       && INTVAL (operands[1]) < 128
  1028.       && INTVAL (operands[1]) >= -128)
  1029.     {
  1030. #if defined (MOTOROLA) && !defined (CRDS)
  1031.       return "moveq%.l %1,%0";
  1032. #else
  1033.       return "moveq %1,%0";
  1034. #endif
  1035.     }
  1036.   if (operands[1] != const0_rtx)
  1037.     return "move%.l %1,%0";
  1038.   if (! ADDRESS_REG_P (operands[0]))
  1039.     return "clr%.l %0";
  1040.   return "sub%.l %0,%0";
  1041. }
  1042.  
  1043. /* Output assembler code to perform a doubleword move insn
  1044.    with operands OPERANDS.  */
  1045.  
  1046. char *
  1047. output_move_double (operands)
  1048.      rtx *operands;
  1049. {
  1050.   enum { REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP } optype0, optype1;
  1051.   rtx latehalf[2];
  1052.   rtx addreg0 = 0, addreg1 = 0;
  1053.  
  1054.   /* First classify both operands.  */
  1055.  
  1056.   if (REG_P (operands[0]))
  1057.     optype0 = REGOP;
  1058.   else if (offsettable_memref_p (operands[0]))
  1059.     optype0 = OFFSOP;
  1060.   else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
  1061.     optype0 = POPOP;
  1062.   else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
  1063.     optype0 = PUSHOP;
  1064.   else if (GET_CODE (operands[0]) == MEM)
  1065.     optype0 = MEMOP;
  1066.   else
  1067.     optype0 = RNDOP;
  1068.  
  1069.   if (REG_P (operands[1]))
  1070.     optype1 = REGOP;
  1071.   else if (CONSTANT_P (operands[1]))
  1072.     optype1 = CNSTOP;
  1073.   else if (offsettable_memref_p (operands[1]) || GET_CODE(XEXP (operands[1], 0)) == SYMBOL_REF)
  1074.     optype1 = OFFSOP;
  1075.   else if (GET_CODE (XEXP (operands[1], 0)) == POST_INC)
  1076.     optype1 = POPOP;
  1077.   else if (GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)
  1078.     optype1 = PUSHOP;
  1079.   else if (GET_CODE (operands[1]) == MEM)
  1080.     optype1 = MEMOP;
  1081.   else
  1082.     optype1 = RNDOP;
  1083.  
  1084.   /* Check for the cases that the operand constraints are not
  1085.      supposed to allow to happen.  Abort if we get one,
  1086.      because generating code for these cases is painful.  */
  1087.  
  1088.   if (optype0 == RNDOP || optype1 == RNDOP)
  1089.     abort ();
  1090.  
  1091.   /* If one operand is decrementing and one is incrementing
  1092.      decrement the former register explicitly
  1093.      and change that operand into ordinary indexing.  */
  1094.  
  1095.   if (optype0 == PUSHOP && optype1 == POPOP)
  1096.     {
  1097.       operands[0] = XEXP (XEXP (operands[0], 0), 0);
  1098.       output_asm_insn ("subq%.l %#8,%0", operands);
  1099.       operands[0] = gen_rtx (MEM, DImode, operands[0]);
  1100.       optype0 = OFFSOP;
  1101.     }
  1102.   if (optype0 == POPOP && optype1 == PUSHOP)
  1103.     {
  1104.       operands[1] = XEXP (XEXP (operands[1], 0), 0);
  1105.       output_asm_insn ("subq%.l %#8,%1", operands);
  1106.       operands[1] = gen_rtx (MEM, DImode, operands[1]);
  1107.       optype1 = OFFSOP;
  1108.     }
  1109.  
  1110.   /* If an operand is an unoffsettable memory ref, find a register
  1111.      we can increment temporarily to make it refer to the second word.  */
  1112.  
  1113.   if (optype0 == MEMOP)
  1114.     addreg0 = find_addr_reg (XEXP (operands[0], 0));
  1115.  
  1116.   if (optype1 == MEMOP)
  1117.     addreg1 = find_addr_reg (XEXP (operands[1], 0));
  1118.  
  1119.   /* Ok, we can do one word at a time.
  1120.      Normally we do the low-numbered word first,
  1121.      but if either operand is autodecrementing then we
  1122.      do the high-numbered word first.
  1123.  
  1124.      In either case, set up in LATEHALF the operands to use
  1125.      for the high-numbered word and in some cases alter the
  1126.      operands in OPERANDS to be suitable for the low-numbered word.  */
  1127.  
  1128.   if (optype0 == REGOP)
  1129.     latehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 1);
  1130.   else if (optype0 == OFFSOP)
  1131.     latehalf[0] = adj_offsettable_operand (operands[0], 4);
  1132.   else
  1133.     latehalf[0] = operands[0];
  1134.  
  1135.   if (optype1 == REGOP)
  1136.     latehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
  1137.   else if (optype1 == OFFSOP)
  1138.     latehalf[1] = adj_offsettable_operand (operands[1], 4);
  1139.   else if (optype1 == CNSTOP)
  1140.     split_double (operands[1], &operands[1], &latehalf[1]);
  1141.   else
  1142.     latehalf[1] = operands[1];
  1143.  
  1144.   /* If insn is effectively movd N(sp),-(sp) then we will do the
  1145.      high word first.  We should use the adjusted operand 1 (which is N+4(sp))
  1146.      for the low word as well, to compensate for the first decrement of sp.  */
  1147.   if (optype0 == PUSHOP
  1148.       && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM
  1149.       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
  1150.     operands[1] = latehalf[1];
  1151.  
  1152.   /* If one or both operands autodecrementing,
  1153.      do the two words, high-numbered first.  */
  1154.  
  1155.   /* Likewise,  the first move would clobber the source of the second one,
  1156.      do them in the other order.  This happens only for registers;
  1157.      such overlap can't happen in memory unless the user explicitly
  1158.      sets it up, and that is an undefined circumstance.  */
  1159.  
  1160.   if (optype0 == PUSHOP || optype1 == PUSHOP
  1161.       || (optype0 == REGOP && optype1 == REGOP
  1162.       && REGNO (operands[0]) == REGNO (latehalf[1])))
  1163.     {
  1164.       /* Make any unoffsettable addresses point at high-numbered word.  */
  1165.       if (addreg0)
  1166.     output_asm_insn ("addql %#4,%0", &addreg0);
  1167.       if (addreg1)
  1168.     output_asm_insn ("addql %#4,%0", &addreg1);
  1169.  
  1170.       /* Do that word.  */
  1171.       output_asm_insn (singlemove_string (latehalf), latehalf);
  1172.  
  1173.       /* Undo the adds we just did.  */
  1174.       if (addreg0)
  1175.     output_asm_insn ("subql %#4,%0", &addreg0);
  1176.       if (addreg1)
  1177.     output_asm_insn ("subql %#4,%0", &addreg1);
  1178.  
  1179.       /* Do low-numbered word.  */
  1180.       return singlemove_string (operands);
  1181.     }
  1182.  
  1183.   /* Normal case: do the two words, low-numbered first.  */
  1184.  
  1185.   output_asm_insn (singlemove_string (operands), operands);
  1186.  
  1187.   /* Make any unoffsettable addresses point at high-numbered word.  */
  1188.   if (addreg0)
  1189.     output_asm_insn ("addql %#4,%0", &addreg0);
  1190.   if (addreg1)
  1191.     output_asm_insn ("addql %#4,%0", &addreg1);
  1192.  
  1193.   /* Do that word.  */
  1194.   output_asm_insn (singlemove_string (latehalf), latehalf);
  1195.  
  1196.   /* Undo the adds we just did.  */
  1197.   if (addreg0)
  1198.     output_asm_insn ("subql %#4,%0", &addreg0);
  1199.   if (addreg1)
  1200.     output_asm_insn ("subql %#4,%0", &addreg1);
  1201.  
  1202.   return "";
  1203. }
  1204.  
  1205. /* Return a REG that occurs in ADDR with coefficient 1.
  1206.    ADDR can be effectively incremented by incrementing REG.  */
  1207.  
  1208.  rtx
  1209. find_addr_reg (addr)
  1210.      rtx addr;
  1211. {
  1212.   while (GET_CODE (addr) == PLUS)
  1213.     {
  1214.       if (GET_CODE (XEXP (addr, 0)) == REG)
  1215.     addr = XEXP (addr, 0);
  1216.       else if (GET_CODE (XEXP (addr, 1)) == REG)
  1217.     addr = XEXP (addr, 1);
  1218.       else if (CONSTANT_P (XEXP (addr, 0)))
  1219.     addr = XEXP (addr, 1);
  1220.       else if (CONSTANT_P (XEXP (addr, 1)))
  1221.     addr = XEXP (addr, 0);
  1222.       else
  1223.     abort ();
  1224.     }
  1225.   if (GET_CODE (addr) == REG)
  1226.     return addr;
  1227.   debug_rtx(addr);
  1228.   abort ();
  1229. }
  1230.  
  1231. /* Store in cc_status the expressions that the condition codes will
  1232.    describe after execution of an instruction whose pattern is EXP.
  1233.    Do not alter them if the instruction would not alter the cc's.  */
  1234.  
  1235. /* On the 68000, all the insns to store in an address register fail to
  1236.    set the cc's.  However, in some cases these instructions can make it
  1237.    possibly invalid to use the saved cc's.  In those cases we clear out
  1238.    some or all of the saved cc's so they won't be used.  */
  1239.  
  1240. notice_update_cc (exp, insn)
  1241.      rtx exp;
  1242.      rtx insn;
  1243. {
  1244.   /* If the cc is being set from the fpa and the expression is not an
  1245.      explicit floating point test instruction (which has code to deal with
  1246.      this), reinit the CC.  */
  1247.   if (((cc_status.value1 && FPA_REG_P (cc_status.value1))
  1248.        || (cc_status.value2 && FPA_REG_P (cc_status.value2)))
  1249.       && !(GET_CODE (exp) == PARALLEL
  1250.        && GET_CODE (XVECEXP (exp, 0, 0)) == SET
  1251.        && XEXP (XVECEXP (exp, 0, 0), 0) == cc0_rtx))
  1252.     {
  1253.       CC_STATUS_INIT; 
  1254.     }
  1255.   else if (GET_CODE (exp) == SET)
  1256.     {
  1257.       if (GET_CODE (SET_SRC (exp)) == CALL)
  1258.     {
  1259.       CC_STATUS_INIT; 
  1260.     }
  1261.       else if (ADDRESS_REG_P (SET_DEST (exp)))
  1262.     {
  1263.       if (cc_status.value1
  1264.           && reg_overlap_mentioned_p (SET_DEST (exp), cc_status.value1))
  1265.         cc_status.value1 = 0;
  1266.       if (cc_status.value2
  1267.           && reg_overlap_mentioned_p (SET_DEST (exp), cc_status.value2))
  1268.         cc_status.value2 = 0; 
  1269.     }
  1270.       else if (!FP_REG_P (SET_DEST (exp))
  1271.            && SET_DEST (exp) != cc0_rtx
  1272.            && (FP_REG_P (SET_SRC (exp))
  1273.            || GET_CODE (SET_SRC (exp)) == FIX
  1274.            || GET_CODE (SET_SRC (exp)) == FLOAT_TRUNCATE
  1275.            || GET_CODE (SET_SRC (exp)) == FLOAT_EXTEND))
  1276.     {
  1277.       CC_STATUS_INIT; 
  1278.     }
  1279.       /* A pair of move insns doesn't produce a useful overall cc.  */
  1280.       else if (!FP_REG_P (SET_DEST (exp))
  1281.            && !FP_REG_P (SET_SRC (exp))
  1282.            && GET_MODE_SIZE (GET_MODE (SET_SRC (exp))) > 4
  1283.            && (GET_CODE (SET_SRC (exp)) == REG
  1284.            || GET_CODE (SET_SRC (exp)) == MEM
  1285.            || GET_CODE (SET_SRC (exp)) == CONST_DOUBLE))
  1286.     {
  1287.       CC_STATUS_INIT; 
  1288.     }
  1289.       else if (GET_CODE (SET_SRC (exp)) == CALL)
  1290.     {
  1291.       CC_STATUS_INIT; 
  1292.     }
  1293.       else if (XEXP (exp, 0) != pc_rtx)
  1294.     {
  1295.       cc_status.flags = 0;
  1296.       cc_status.value1 = XEXP (exp, 0);
  1297.       cc_status.value2 = XEXP (exp, 1);
  1298.     }
  1299.     }
  1300.   else if (GET_CODE (exp) == PARALLEL
  1301.        && GET_CODE (XVECEXP (exp, 0, 0)) == SET)
  1302.     {
  1303.       if (ADDRESS_REG_P (XEXP (XVECEXP (exp, 0, 0), 0)))
  1304.     CC_STATUS_INIT;
  1305.       else if (XEXP (XVECEXP (exp, 0, 0), 0) != pc_rtx)
  1306.     {
  1307.       cc_status.flags = 0;
  1308.       cc_status.value1 = XEXP (XVECEXP (exp, 0, 0), 0);
  1309.       cc_status.value2 = XEXP (XVECEXP (exp, 0, 0), 1);
  1310.     }
  1311.     }
  1312.   else
  1313.     CC_STATUS_INIT;
  1314.   if (cc_status.value2 != 0
  1315.       && ADDRESS_REG_P (cc_status.value2)
  1316.       && GET_MODE (cc_status.value2) == QImode)
  1317.     CC_STATUS_INIT;
  1318.   if (cc_status.value2 != 0
  1319.       && !(cc_status.value1 && FPA_REG_P (cc_status.value1)))
  1320.     switch (GET_CODE (cc_status.value2))
  1321.       {
  1322.       case PLUS: case MINUS: case MULT:
  1323.       case DIV: case UDIV: case MOD: case UMOD: case NEG:
  1324.       case ASHIFT: case LSHIFT: case ASHIFTRT: case LSHIFTRT:
  1325.       case ROTATE: case ROTATERT:
  1326.     if (GET_MODE (cc_status.value2) != VOIDmode)
  1327.       cc_status.flags |= CC_NO_OVERFLOW;
  1328.     break;
  1329.       case ZERO_EXTEND:
  1330.     /* (SET r1 (ZERO_EXTEND r2)) on this machine
  1331.        ends with a move insn moving r2 in r2's mode.
  1332.        Thus, the cc's are set for r2.
  1333.        This can set N bit spuriously. */
  1334.     cc_status.flags |= CC_NOT_NEGATIVE; 
  1335.       }
  1336.   if (cc_status.value1 && GET_CODE (cc_status.value1) == REG
  1337.       && cc_status.value2
  1338.       && reg_overlap_mentioned_p (cc_status.value1, cc_status.value2))
  1339.     cc_status.value2 = 0;
  1340.   if (((cc_status.value1 && FP_REG_P (cc_status.value1))
  1341.        || (cc_status.value2 && FP_REG_P (cc_status.value2)))
  1342.       && !((cc_status.value1 && FPA_REG_P (cc_status.value1))
  1343.        || (cc_status.value2 && FPA_REG_P (cc_status.value2))))
  1344.     cc_status.flags = CC_IN_68881;
  1345. }
  1346.  
  1347. char *
  1348. output_move_const_double (operands)
  1349.      rtx *operands;
  1350. {
  1351. #ifdef SUPPORT_SUN_FPA
  1352.   if (TARGET_FPA && FPA_REG_P (operands[0]))
  1353.     {
  1354.       int code = standard_sun_fpa_constant_p (operands[1]);
  1355.  
  1356.       if (code != 0)
  1357.     {
  1358.       static char buf[40];
  1359.  
  1360.       sprintf (buf, "fpmove%%.d %%%%%d,%%0", code & 0x1ff);
  1361.       return buf;
  1362.     }
  1363.       return "fpmove%.d %1,%0";
  1364.     }
  1365.   else
  1366. #endif
  1367.     {
  1368.       int code = standard_68881_constant_p (operands[1]);
  1369.  
  1370.       if (code != 0)
  1371.     {
  1372.       static char buf[40];
  1373.  
  1374. #ifdef MPW_ASM
  1375.       sprintf (buf, "fmovecr #$%x,%%0", code & 0xff);
  1376. #else
  1377.       sprintf (buf, "fmovecr %%#0x%x,%%0", code & 0xff);
  1378. #endif
  1379.       return buf;
  1380.     }
  1381.       return "fmove%.d %1,%0";
  1382.     }
  1383. }
  1384.  
  1385. char *
  1386. output_move_const_single (operands)
  1387.      rtx *operands;
  1388. {
  1389. #ifdef SUPPORT_SUN_FPA
  1390.   if (TARGET_FPA)
  1391.     {
  1392.       int code = standard_sun_fpa_constant_p (operands[1]);
  1393.  
  1394.       if (code != 0)
  1395.     {
  1396.       static char buf[40];
  1397.  
  1398.       sprintf (buf, "fpmove%%.s %%%%%d,%%0", code & 0x1ff);
  1399.       return buf;
  1400.     }
  1401.       return "fpmove%.s %1,%0";
  1402.     }
  1403.   else
  1404. #endif /* defined SUPPORT_SUN_FPA */
  1405.     {
  1406.       int code = standard_68881_constant_p (operands[1]);
  1407.  
  1408.       if (code != 0)
  1409.     {
  1410.       static char buf[40];
  1411.  
  1412. #ifdef MPW_ASM
  1413.       sprintf (buf, "fmovecr #$%x,%%0", code & 0xff);
  1414. #else
  1415.       sprintf (buf, "fmovecr %%#0x%x,%%0", code & 0xff);
  1416. #endif
  1417.       return buf;
  1418.     }
  1419.       return "fmove%.s %f1,%0";
  1420.     }
  1421. }
  1422.  
  1423. /* Return nonzero if X, a CONST_DOUBLE, has a value that we can get
  1424.    from the "fmovecr" instruction.
  1425.    The value, anded with 0xff, gives the code to use in fmovecr
  1426.    to get the desired constant.  */
  1427.  
  1428. /* ??? This code should be fixed for cross-compilation. */
  1429.  
  1430. int
  1431. standard_68881_constant_p (x)
  1432.      rtx x;
  1433. {
  1434.   register double d;
  1435.  
  1436.   /* fmovecr must be emulated on the 68040, so it shouldn't be used at all. */
  1437.   if (TARGET_68040)
  1438.     return 0;
  1439.  
  1440. #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
  1441.   if (! flag_pretend_float)
  1442.     return 0;
  1443. #endif
  1444.  
  1445.   REAL_VALUE_FROM_CONST_DOUBLE (d, x);
  1446.  
  1447.   if (d == 0)
  1448.     return 0x0f;
  1449.   /* Note: there are various other constants available
  1450.      but it is a nuisance to put in their values here.  */
  1451.   if (d == 1)
  1452.     return 0x32;
  1453.   if (d == 10)
  1454.     return 0x33;
  1455.   if (d == 100)
  1456.     return 0x34;
  1457.   if (d == 10000)
  1458.     return 0x35;
  1459.   if (d == 1e8)
  1460.     return 0x36;
  1461.   if (GET_MODE (x) == SFmode)
  1462.     return 0;
  1463.   if (d == 1e16)
  1464.     return 0x37;
  1465.   /* larger powers of ten in the constants ram are not used
  1466.      because they are not equal to a `double' C constant.  */
  1467.   return 0;
  1468. }
  1469.  
  1470. /* If X is a floating-point constant, return the logarithm of X base 2,
  1471.    or 0 if X is not a power of 2.  */
  1472.  
  1473. int
  1474. floating_exact_log2 (x)
  1475.      rtx x;
  1476. {
  1477.   register double d, d1;
  1478.   int i;
  1479.  
  1480. #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
  1481.   if (! flag_pretend_float)
  1482.     return 0;
  1483. #endif
  1484.  
  1485.   REAL_VALUE_FROM_CONST_DOUBLE (d, x);
  1486.  
  1487.   if (! (d > 0))
  1488.     return 0;
  1489.  
  1490.   for (d1 = 1.0, i = 0; d1 < d; d1 *= 2.0, i++)
  1491.     ;
  1492.  
  1493.   if (d == d1)
  1494.     return i;
  1495.  
  1496.   return 0;
  1497. }
  1498.  
  1499. #ifdef SUPPORT_SUN_FPA
  1500. /* Return nonzero if X, a CONST_DOUBLE, has a value that we can get
  1501.    from the Sun FPA's constant RAM.
  1502.    The value returned, anded with 0x1ff, gives the code to use in fpmove
  1503.    to get the desired constant. */
  1504. #define S_E (2.718281745910644531)
  1505. #define D_E (2.718281828459045091)
  1506. #define S_PI (3.141592741012573242)
  1507. #define D_PI (3.141592653589793116)
  1508. #define S_SQRT2 (1.414213538169860840)
  1509. #define D_SQRT2 (1.414213562373095145)
  1510. #define S_LOG2ofE (1.442695021629333496)
  1511. #define D_LOG2ofE (1.442695040888963387)
  1512. #define S_LOG2of10 (3.321928024291992188)
  1513. #define D_LOG2of10 (3.321928024887362182)
  1514. #define S_LOGEof2 (0.6931471824645996094)
  1515. #define D_LOGEof2 (0.6931471805599452862)
  1516. #define S_LOGEof10 (2.302585124969482442)
  1517. #define D_LOGEof10 (2.302585092994045901)
  1518. #define S_LOG10of2 (0.3010300099849700928)
  1519. #define D_LOG10of2 (0.3010299956639811980)
  1520. #define S_LOG10ofE (0.4342944920063018799)
  1521. #define D_LOG10ofE (0.4342944819032518167)
  1522.  
  1523. /* This code should be fixed for cross-compilation. */
  1524.  
  1525. int
  1526. standard_sun_fpa_constant_p (x)
  1527.      rtx x;
  1528. {
  1529.   register double d;
  1530.  
  1531. #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
  1532.   if (! flag_pretend_float)
  1533.     return 0;
  1534. #endif
  1535.  
  1536.   REAL_VALUE_FROM_CONST_DOUBLE (d, x);
  1537.  
  1538.   if (d == 0.0)
  1539.     return 0x200;        /* 0 once 0x1ff is anded with it */
  1540.   if (d == 1.0)
  1541.     return 0xe;
  1542.   if (d == 0.5)
  1543.     return 0xf;
  1544.   if (d == -1.0)
  1545.     return 0x10;
  1546.   if (d == 2.0)
  1547.     return 0x11;
  1548.   if (d == 3.0)
  1549.     return 0xB1;
  1550.   if (d == 4.0)
  1551.     return 0x12;
  1552.   if (d == 8.0)
  1553.     return 0x13;
  1554.   if (d == 0.25)
  1555.     return 0x15;
  1556.   if (d == 0.125)
  1557.     return 0x16;
  1558.   if (d == 10.0)
  1559.     return 0x17;
  1560.   if (d == -(1.0/2.0))
  1561.     return 0x2E;
  1562.  
  1563. /*
  1564.  * Stuff that looks different if it's single or double
  1565.  */
  1566.   if (GET_MODE (x) == SFmode)
  1567.     {
  1568.       if (d == S_E)
  1569.     return 0x8;
  1570.       if (d == (2*S_PI))
  1571.     return 0x9;
  1572.       if (d == S_PI)
  1573.     return 0xA;
  1574.       if (d == (S_PI / 2.0))
  1575.     return 0xB;
  1576.       if (d == S_SQRT2)
  1577.     return 0xC;
  1578.       if (d == (1.0 / S_SQRT2))
  1579.     return 0xD;
  1580.       /* Large powers of 10 in the constant 
  1581.      ram are not used because they are
  1582.      not equal to a C double constant  */
  1583.       if (d == -(S_PI / 2.0))
  1584.     return 0x27;
  1585.       if (d == S_LOG2ofE)
  1586.     return 0x28;
  1587.       if (d == S_LOG2of10)
  1588.     return 0x29;
  1589.       if (d == S_LOGEof2)
  1590.     return 0x2A;
  1591.       if (d == S_LOGEof10)
  1592.     return 0x2B;
  1593.       if (d == S_LOG10of2)
  1594.     return 0x2C;
  1595.       if (d == S_LOG10ofE)
  1596.     return 0x2D;
  1597.     }
  1598.   else
  1599.     {
  1600.       if (d == D_E)
  1601.     return 0x8;
  1602.       if (d == (2*D_PI))
  1603.     return 0x9;
  1604.       if (d == D_PI)
  1605.     return 0xA;
  1606.       if (d == (D_PI / 2.0))
  1607.     return 0xB;
  1608.       if (d == D_SQRT2)
  1609.     return 0xC;
  1610.       if (d == (1.0 / D_SQRT2))
  1611.     return 0xD;
  1612.       /* Large powers of 10 in the constant 
  1613.      ram are not used because they are
  1614.      not equal to a C double constant  */
  1615.       if (d == -(D_PI / 2.0))
  1616.     return 0x27;
  1617.       if (d == D_LOG2ofE)
  1618.     return 0x28;
  1619.       if (d == D_LOG2of10)
  1620.     return 0x29;
  1621.       if (d == D_LOGEof2)
  1622.     return 0x2A;
  1623.       if (d == D_LOGEof10)
  1624.     return 0x2B;
  1625.       if (d == D_LOG10of2)
  1626.     return 0x2C;
  1627.       if (d == D_LOG10ofE)
  1628.     return 0x2D;
  1629.     }
  1630.   return 0x0;
  1631. }
  1632. #endif /* define SUPPORT_SUN_FPA */
  1633.  
  1634. /* A C compound statement to output to stdio stream STREAM the
  1635.    assembler syntax for an instruction operand X.  X is an RTL
  1636.    expression.
  1637.  
  1638.    CODE is a value that can be used to specify one of several ways
  1639.    of printing the operand.  It is used when identical operands
  1640.    must be printed differently depending on the context.  CODE
  1641.    comes from the `%' specification that was used to request
  1642.    printing of the operand.  If the specification was just `%DIGIT'
  1643.    then CODE is 0; if the specification was `%LTR DIGIT' then CODE
  1644.    is the ASCII code for LTR.
  1645.  
  1646.    If X is a register, this macro should print the register's name.
  1647.    The names can be found in an array `reg_names' whose type is
  1648.    `char *[]'.  `reg_names' is initialized from `REGISTER_NAMES'.
  1649.  
  1650.    When the machine description has a specification `%PUNCT' (a `%'
  1651.    followed by a punctuation character), this macro is called with
  1652.    a null pointer for X and the punctuation character for CODE.
  1653.  
  1654.    The m68k specific codes are:
  1655.  
  1656.    '.' for dot needed in Motorola-style opcode names.
  1657.    '-' for an operand pushing on the stack:
  1658.        sp@-, -(sp) or -(%sp) depending on the style of syntax.
  1659.    '+' for an operand pushing on the stack:
  1660.        sp@+, (sp)+ or (%sp)+ depending on the style of syntax.
  1661.    '@' for a reference to the top word on the stack:
  1662.        sp@, (sp) or (%sp) depending on the style of syntax.
  1663.    '#' for an immediate operand prefix (# in MIT and Motorola syntax
  1664.        but & in SGS syntax).
  1665.    '!' for the cc register (used in an `and to cc' insn).
  1666.    '$' for the letter `s' in an op code, but only on the 68040.
  1667.    '&' for the letter `d' in an op code, but only on the 68040.
  1668.  
  1669.    'b' for byte insn (no effect, on the Sun; this is for the ISI).
  1670.    'd' to force memory addressing to be absolute, not relative.
  1671.    'f' for float insn (print a CONST_DOUBLE as a float rather than in hex)
  1672.    'w' for FPA insn (print a CONST_DOUBLE as a SunFPA constant rather
  1673.        than directly).  Second part of 'y' below.
  1674.    'x' for float insn (print a CONST_DOUBLE as a float rather than in hex),
  1675.        or print pair of registers as rx:ry.
  1676.    'y' for a FPA insn (print pair of registers as rx:ry).  This also outputs
  1677.        CONST_DOUBLE's as SunFPA constant RAM registers if
  1678.        possible, so it should not be used except for the SunFPA.
  1679.  
  1680.    */
  1681. void
  1682. print_operand (file, op, letter)
  1683.      FILE *file;        /* file to write to */
  1684.      rtx op;            /* operand to print */
  1685.      int letter;        /* %<letter> or 0 */
  1686. {
  1687.   int i;
  1688.  
  1689.   if (letter == '.')
  1690.     {
  1691. #ifdef MOTOROLA
  1692.       asm_fprintf (file, ".");
  1693. #endif
  1694.     }
  1695.   else if (letter == '#')
  1696.     {
  1697.       asm_fprintf (file, "%0I");
  1698.     }
  1699.   else if (letter == '-')
  1700.     {
  1701. #ifdef MOTOROLA
  1702.       asm_fprintf (file, "-(%Rsp)");
  1703. #else
  1704.       asm_fprintf (file, "%Rsp@-");
  1705. #endif
  1706.     }
  1707.   else if (letter == '+')
  1708.     {
  1709. #ifdef MOTOROLA
  1710.       asm_fprintf (file, "(%Rsp)+");
  1711. #else
  1712.       asm_fprintf (file, "%Rsp@+");
  1713. #endif
  1714.     }
  1715.   else if (letter == '@')
  1716.     {
  1717. #ifdef MOTOROLA
  1718.       asm_fprintf (file, "(%Rsp)");
  1719. #else
  1720.       asm_fprintf (file, "%Rsp@");
  1721. #endif
  1722.     }
  1723.   else if (letter == '!')
  1724.     {
  1725.       asm_fprintf (file, "%Rfpcr");
  1726.     }
  1727.   else if (letter == '$')
  1728.     {
  1729.       if (TARGET_68040_ONLY)
  1730.     {
  1731.       fprintf (file, "s");
  1732.     }
  1733.     }
  1734.   else if (letter == '&')
  1735.     {
  1736.       if (TARGET_68040_ONLY)
  1737.     {
  1738.       fprintf (file, "d");
  1739.     }
  1740.     }
  1741.   else if (GET_CODE (op) == REG)
  1742.     {
  1743.       if (REGNO (op) < 16
  1744.       && (letter == 'y' || letter == 'x')
  1745.       && GET_MODE (op) == DFmode)
  1746.     {
  1747.       fprintf (file, "%s:%s", reg_names[REGNO (op)],
  1748.            reg_names[REGNO (op)+1]);
  1749.     }
  1750.       else
  1751.     {
  1752.       fprintf (file, "%s", reg_names[REGNO (op)]);
  1753.     }
  1754.     }
  1755. #ifdef MPW_ASM
  1756.   else if (letter == 'b')
  1757.     {
  1758.       output_addr_const (file, op);
  1759.     }
  1760. #endif
  1761.   else if (GET_CODE (op) == MEM)
  1762.     {
  1763.       output_address (XEXP (op, 0));
  1764. #ifndef MPW_ASM
  1765.       /* This is a special case for 68000 cmp instructions that can have an absolute
  1766.          long address.  Without this, the MPW Asm will try to do something, probably
  1767.      the wrong thing unfortunately. */
  1768.       if (letter == 'd' && ! TARGET_68020
  1769.       && CONSTANT_ADDRESS_P (XEXP (op, 0))
  1770.       && !(GET_CODE (XEXP (op, 0)) == CONST_INT
  1771.            && INTVAL (XEXP (op, 0)) < 0x8000
  1772.            && INTVAL (XEXP (op, 0)) >= -0x8000))
  1773.     {
  1774.       fprintf (file, ":l");
  1775.     }
  1776. #endif /* n MPW_ASM */
  1777.     }
  1778. #ifdef SUPPORT_SUN_FPA
  1779.   else if ((letter == 'y' || letter == 'w')
  1780.        && GET_CODE (op) == CONST_DOUBLE
  1781.        && (i = standard_sun_fpa_constant_p (op)))
  1782.     {
  1783.       fprintf (file, "%%%d", i & 0x1ff);
  1784.     }
  1785. #endif
  1786. #ifdef MPW_ASM
  1787.   /* Override the later cases for printing of doubles. (not sure why) */
  1788.   else if (GET_CODE (op) == CONST_DOUBLE)
  1789.     {
  1790.       putc ('#', file);
  1791.       if (GET_MODE(op) == SFmode && letter != 'f')
  1792.     output_mpw_float_as_int (file, op);
  1793.       else
  1794.     output_mpw_float (file, op);
  1795.     }
  1796. #else
  1797.   else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == SFmode)
  1798.     {
  1799.       double d;
  1800.       union { float f; int i; } u1;
  1801.       REAL_VALUE_FROM_CONST_DOUBLE (d, op);
  1802.       u1.f = d;
  1803.       PRINT_OPERAND_PRINT_FLOAT (letter, file);
  1804.     }
  1805.   else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) != DImode)
  1806.     {
  1807.       double d;
  1808.       REAL_VALUE_FROM_CONST_DOUBLE (d, op);
  1809.       ASM_OUTPUT_DOUBLE_OPERAND (file, d);
  1810.     }
  1811. #endif /* MPW_ASM */
  1812.   else
  1813.     {
  1814.       asm_fprintf (file, "%0I");
  1815.       output_addr_const (file, op);
  1816.     }
  1817. }
  1818.  
  1819. /* A C compound statement to output to stdio stream STREAM the
  1820.    assembler syntax for an instruction operand that is a memory
  1821.    reference whose address is ADDR.  ADDR is an RTL expression.
  1822.  
  1823.    Note that this contains a kludge that knows that the only reason
  1824.    we have an address (plus (label_ref...) (reg...)) when not generating
  1825.    PIC code is in the insn before a tablejump, and we know that m68k.md
  1826.    generates a label LInnn: on such an insn.
  1827.  
  1828.    It is possible for PIC to generate a (plus (label_ref...) (reg...))
  1829.    and we handle that just like we would a (plus (symbol_ref...) (reg...)).
  1830.  
  1831.    Some SGS assemblers have a bug such that "Lnnn-LInnn-2.b(pc,d0.l*2)"
  1832.    fails to assemble.  Luckily "Lnnn(pc,d0.l*2)" produces the results
  1833.    we want.  This difference can be accommodated by using an assembler
  1834.    define such "LDnnn" to be either "Lnnn-LInnn-2.b", "Lnnn", or any other
  1835.    string, as necessary.  This is accomplished via the ASM_OUTPUT_CASE_END
  1836.    macro.  See m68ksgs.h for an example; for versions without the bug.
  1837.  
  1838.    They also do not like things like "pea 1.w", so we simple leave off
  1839.    the .w on small constants. 
  1840.  
  1841.    This routine is responsible for distinguishing between -fpic and -fPIC 
  1842.    style relocations in an address.  When generating -fpic code the
  1843.    offset is output in word mode (eg movel a5@(_foo:w), a0).  When generating
  1844.    -fPIC code the offset is output in long mode (eg movel a5@(_foo:l), a0) */
  1845.  
  1846. void
  1847. print_operand_address (file, addr)
  1848.      FILE *file;
  1849.      rtx addr;
  1850. {
  1851.   register rtx reg1, reg2, breg, ireg;
  1852.   rtx offset;
  1853.  
  1854.   switch (GET_CODE (addr))
  1855.     {
  1856.       case REG:
  1857. #ifdef MOTOROLA
  1858.     fprintf (file, "(%s)", reg_names[REGNO (addr)]);
  1859. #else
  1860.     fprintf (file, "%s@", reg_names[REGNO (addr)]);
  1861. #endif
  1862.     break;
  1863.       case PRE_DEC:
  1864. #ifdef MOTOROLA
  1865.     fprintf (file, "-(%s)", reg_names[REGNO (XEXP (addr, 0))]);
  1866. #else
  1867.     fprintf (file, "%s@-", reg_names[REGNO (XEXP (addr, 0))]);
  1868. #endif
  1869.     break;
  1870.       case POST_INC:
  1871. #ifdef MOTOROLA
  1872.     fprintf (file, "(%s)+", reg_names[REGNO (XEXP (addr, 0))]);
  1873. #else
  1874.     fprintf (file, "%s@+", reg_names[REGNO (XEXP (addr, 0))]);
  1875. #endif
  1876.     break;
  1877.       case PLUS:
  1878.     reg1 = reg2 = ireg = breg = offset = 0;
  1879.     if (CONSTANT_ADDRESS_P (XEXP (addr, 0)))
  1880.       {
  1881.         offset = XEXP (addr, 0);
  1882.         addr = XEXP (addr, 1);
  1883.       }
  1884.     else if (CONSTANT_ADDRESS_P (XEXP (addr, 1)))
  1885.       {
  1886.         offset = XEXP (addr, 1);
  1887.         addr = XEXP (addr, 0);
  1888.       }
  1889.     if (GET_CODE (addr) != PLUS)
  1890.       {
  1891.         ;
  1892.       }
  1893.     else if (GET_CODE (XEXP (addr, 0)) == SIGN_EXTEND)
  1894.       {
  1895.         reg1 = XEXP (addr, 0);
  1896.         addr = XEXP (addr, 1);
  1897.       }
  1898.     else if (GET_CODE (XEXP (addr, 1)) == SIGN_EXTEND)
  1899.       {
  1900.         reg1 = XEXP (addr, 1);
  1901.         addr = XEXP (addr, 0);
  1902.       }
  1903.     else if (GET_CODE (XEXP (addr, 0)) == MULT)
  1904.       {
  1905.         reg1 = XEXP (addr, 0);
  1906.         addr = XEXP (addr, 1);
  1907.       }
  1908.     else if (GET_CODE (XEXP (addr, 1)) == MULT)
  1909.       {
  1910.         reg1 = XEXP (addr, 1);
  1911.         addr = XEXP (addr, 0);
  1912.       }
  1913.     else if (GET_CODE (XEXP (addr, 0)) == REG)
  1914.       {
  1915.         reg1 = XEXP (addr, 0);
  1916.         addr = XEXP (addr, 1);
  1917.       }
  1918.     else if (GET_CODE (XEXP (addr, 1)) == REG)
  1919.       {
  1920.         reg1 = XEXP (addr, 1);
  1921.         addr = XEXP (addr, 0);
  1922.       }
  1923.     if (GET_CODE (addr) == REG || GET_CODE (addr) == MULT
  1924.         || GET_CODE (addr) == SIGN_EXTEND)
  1925.       {
  1926.         if (reg1 == 0)
  1927.           {
  1928.         reg1 = addr;
  1929.           }
  1930.         else
  1931.           {
  1932.         reg2 = addr;
  1933.           }
  1934.         addr = 0;
  1935.       }
  1936. #if 0    /* for OLD_INDEXING */
  1937.     else if (GET_CODE (addr) == PLUS)
  1938.       {
  1939.         if (GET_CODE (XEXP (addr, 0)) == REG)
  1940.           {
  1941.         reg2 = XEXP (addr, 0);
  1942.         addr = XEXP (addr, 1);
  1943.           }
  1944.         else if (GET_CODE (XEXP (addr, 1)) == REG)
  1945.           {
  1946.         reg2 = XEXP (addr, 1);
  1947.         addr = XEXP (addr, 0);
  1948.           }
  1949.       }
  1950. #endif
  1951.     if (offset != 0)
  1952.       {
  1953.         if (addr != 0)
  1954.           {
  1955. #ifdef MPW_ASM
  1956.         output_addr_const(file, addr);
  1957.         return;
  1958. #else
  1959.         abort ();
  1960. #endif
  1961.           }
  1962.         addr = offset;
  1963.       }
  1964.     if ((reg1 && (GET_CODE (reg1) == SIGN_EXTEND
  1965.               || GET_CODE (reg1) == MULT))
  1966.         || (reg2 != 0 && REGNO_OK_FOR_BASE_P (REGNO (reg2))))
  1967.       {
  1968.         breg = reg2;
  1969.         ireg = reg1;
  1970.       }
  1971.     else if (reg1 != 0 && REGNO_OK_FOR_BASE_P (REGNO (reg1)))
  1972.       {
  1973.         breg = reg1;
  1974.         ireg = reg2;
  1975.       }
  1976.     if (ireg != 0 && breg == 0 && GET_CODE (addr) == LABEL_REF
  1977.         && ! (flag_pic && ireg == pic_offset_table_rtx))
  1978.       {
  1979.         int scale = 1;
  1980.         if (GET_CODE (ireg) == MULT)
  1981.           {
  1982.         scale = INTVAL (XEXP (ireg, 1));
  1983.         ireg = XEXP (ireg, 0);
  1984.           }
  1985.         if (GET_CODE (ireg) == SIGN_EXTEND)
  1986.           {
  1987. #ifdef MOTOROLA
  1988. #ifdef SGS
  1989.         asm_fprintf (file, "%LLD%d(%Rpc,%s.w",
  1990.                  CODE_LABEL_NUMBER (XEXP (addr, 0)),
  1991.                  reg_names[REGNO (XEXP (ireg, 0))]);
  1992. #else
  1993. #ifdef MPW_ASM
  1994.         asm_fprintf (file, "%LL#%d(%Rpc,%s.w",
  1995.                  CODE_LABEL_NUMBER (XEXP (addr, 0)),
  1996.                  reg_names[REGNO (XEXP (ireg, 0))]);
  1997. #else
  1998.         asm_fprintf (file, "%LL%d-%LLI%d.b(%Rpc,%s.w",
  1999.                  CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2000.                  CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2001.                  reg_names[REGNO (XEXP (ireg, 0))]);
  2002. #endif /* MPW_ASM */
  2003. #endif
  2004. #else
  2005.         asm_fprintf (file, "%Rpc@(%LL%d-%LLI%d-2:b,%s:w",
  2006.                  CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2007.                  CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2008.                  reg_names[REGNO (XEXP (ireg, 0))]);
  2009. #endif
  2010.           }
  2011.         else
  2012.           {
  2013. #ifdef MOTOROLA
  2014. #ifdef SGS
  2015.         asm_fprintf (file, "%LLD%d(%Rpc,%s.l",
  2016.                  CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2017.                  reg_names[REGNO (ireg)]);
  2018. #else
  2019. #ifdef MPW_ASM
  2020.         asm_fprintf (file, "%LL#%d(%Rpc,%s.l",
  2021.                  CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2022.                  reg_names[REGNO (ireg)]);
  2023. #else
  2024.         asm_fprintf (file, "%LL%d-%LLI%d.b(%Rpc,%s.l",
  2025.                  CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2026.                  CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2027.                  reg_names[REGNO (ireg)]);
  2028. #endif /* MPW_ASM */
  2029. #endif
  2030. #else
  2031.         asm_fprintf (file, "%Rpc@(%LL%d-%LLI%d-2:b,%s:l",
  2032.                  CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2033.                  CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2034.                  reg_names[REGNO (ireg)]);
  2035. #endif
  2036.           }
  2037.         if (scale != 1)
  2038.           {
  2039. #ifdef MOTOROLA
  2040.         fprintf (file, "*%d", scale);
  2041. #else
  2042.         fprintf (file, ":%d", scale);
  2043. #endif
  2044.           }
  2045.         putc (')', file);
  2046.         break;
  2047.       }
  2048.     if (breg != 0 && ireg == 0 && GET_CODE (addr) == LABEL_REF
  2049.         && ! (flag_pic && breg == pic_offset_table_rtx))
  2050.       {
  2051. #ifdef MOTOROLA
  2052. #ifdef SGS
  2053.         asm_fprintf (file, "%LLD%d(%Rpc,%s.l",
  2054.              CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2055.              reg_names[REGNO (breg)]);
  2056. #else
  2057. #ifdef MPW_ASM
  2058.         asm_fprintf (file, "%LL#%d(%Rpc,%s.l",
  2059.              CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2060.              reg_names[REGNO (breg)]);
  2061. #else
  2062.         asm_fprintf (file, "%LL%d-%LLI%d.b(%Rpc,%s.l",
  2063.              CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2064.              CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2065.              reg_names[REGNO (breg)]);
  2066. #endif /* MPW_ASM */
  2067. #endif
  2068. #else
  2069.         asm_fprintf (file, "%Rpc@(%LL%d-%LLI%d-2:b,%s:l",
  2070.              CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2071.              CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2072.              reg_names[REGNO (breg)]);
  2073. #endif
  2074.         putc (')', file);
  2075.         break;
  2076.       }
  2077.     if (ireg != 0 || breg != 0)
  2078.       {
  2079.         int scale = 1;
  2080.         if (breg == 0)
  2081.           {
  2082.         abort ();
  2083.           }
  2084.         if (! flag_pic && addr && GET_CODE (addr) == LABEL_REF)
  2085.           {
  2086.         abort ();
  2087.           }
  2088. #ifdef MOTOROLA
  2089.         if (addr != 0)
  2090.           {
  2091.         output_addr_const (file, addr);
  2092.             if ((flag_pic == 1) && (breg == pic_offset_table_rtx))
  2093.               fprintf (file, ".w");
  2094.             if ((flag_pic == 2) && (breg == pic_offset_table_rtx))
  2095.               fprintf (file, ".l");
  2096.           }
  2097.         fprintf (file, "(%s", reg_names[REGNO (breg)]);
  2098.         if (ireg != 0)
  2099.           {
  2100.         putc (',', file);
  2101.           }
  2102. #else
  2103.         fprintf (file, "%s@(", reg_names[REGNO (breg)]);
  2104.         if (addr != 0)
  2105.           {
  2106.         output_addr_const (file, addr);
  2107.             if ((flag_pic == 1) && (breg == pic_offset_table_rtx))
  2108.               fprintf (file, ":w");
  2109.             if ((flag_pic == 2) && (breg == pic_offset_table_rtx))
  2110.               fprintf (file, ":l");
  2111.           }
  2112.         if (addr != 0 && ireg != 0)
  2113.           {
  2114.         putc (',', file);
  2115.           }
  2116. #endif
  2117.         if (ireg != 0 && GET_CODE (ireg) == MULT)
  2118.           {
  2119.         scale = INTVAL (XEXP (ireg, 1));
  2120.         ireg = XEXP (ireg, 0);
  2121.           }
  2122.         if (ireg != 0 && GET_CODE (ireg) == SIGN_EXTEND)
  2123.           {
  2124. #ifdef MOTOROLA
  2125.         fprintf (file, "%s.w", reg_names[REGNO (XEXP (ireg, 0))]);
  2126. #else
  2127.         fprintf (file, "%s:w", reg_names[REGNO (XEXP (ireg, 0))]);
  2128. #endif
  2129.           }
  2130.         else if (ireg != 0)
  2131.           {
  2132. #ifdef MOTOROLA
  2133.         fprintf (file, "%s.l", reg_names[REGNO (ireg)]);
  2134. #else
  2135.         fprintf (file, "%s:l", reg_names[REGNO (ireg)]);
  2136. #endif
  2137.           }
  2138.         if (scale != 1)
  2139.           {
  2140. #ifdef MOTOROLA
  2141.         fprintf (file, "*%d", scale);
  2142. #else
  2143.         fprintf (file, ":%d", scale);
  2144. #endif
  2145.           }
  2146.         putc (')', file);
  2147.         break;
  2148.       }
  2149.     else if (reg1 != 0 && GET_CODE (addr) == LABEL_REF
  2150.          && ! (flag_pic && reg1 == pic_offset_table_rtx))    
  2151.       {
  2152. #ifdef MOTOROLA
  2153. #ifdef SGS
  2154.         asm_fprintf (file, "%LLD%d(%Rpc,%s.l)",
  2155.              CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2156.              reg_names[REGNO (reg1)]);
  2157. #else
  2158. #ifdef MPW_ASM
  2159.         asm_fprintf (file, "%LL#%d(%Rpc,%s.l)",
  2160.              CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2161.              reg_names[REGNO (reg1)]);
  2162. #else
  2163.         asm_fprintf (file, "%LL%d-%LLI%d.b(%Rpc,%s.l)",
  2164.              CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2165.              CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2166.              reg_names[REGNO (reg1)]);
  2167. #endif
  2168. #endif
  2169. #else
  2170.         asm_fprintf (file, "%Rpc@(%LL%d-%LLI%d-2:b,%s:l)",
  2171.              CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2172.              CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2173.              reg_names[REGNO (reg1)]);
  2174. #endif
  2175.         break;
  2176.       }
  2177.     /* FALL-THROUGH (is this really what we want? */
  2178.       default:
  2179.         if (GET_CODE (addr) == CONST_INT
  2180.         && INTVAL (addr) < 0x8000
  2181.         && INTVAL (addr) >= -0x8000)
  2182.       {
  2183. #ifdef MOTOROLA
  2184. #ifdef MPW_ASM
  2185.         fprintf (file, "%d", INTVAL (addr)); /* no .w needed for size */
  2186. #else
  2187. #ifdef SGS
  2188.         /* Many SGS assemblers croak on size specifiers for constants. */
  2189.         fprintf (file, "%d", INTVAL (addr));
  2190. #else
  2191.         fprintf (file, "%d.w", INTVAL (addr));
  2192. #endif
  2193. #endif /* MPW_ASM */
  2194. #else
  2195.         fprintf (file, "%d:w", INTVAL (addr));
  2196. #endif
  2197.       }
  2198. #ifdef MPW_ASM
  2199.       /* What is this all about?? */
  2200.       else if (TARGET_32BITDATA && global_data_ref_p (addr)) 
  2201.     { 
  2202.       fprintf (file, "("); 
  2203.       output_addr_const (file, addr);
  2204.       fprintf (file, ",a5)"); 
  2205.     }  
  2206. #endif
  2207.     else
  2208.       {
  2209.         output_addr_const (file, addr);
  2210.       }
  2211.     break;
  2212.     }
  2213. }
  2214.  
  2215. #if 0
  2216. /* Output assembler code to perform a doubleword move insn
  2217.    with operands OPERANDS.  */
  2218.  
  2219. char *
  2220. output_move_double (operands)
  2221.      rtx *operands;
  2222. {
  2223.   enum { REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP } optype0, optype1;
  2224.   rtx latehalf[2];
  2225.   rtx addreg0 = 0, addreg1 = 0;
  2226.  
  2227.   /* First classify both operands.  */
  2228.  
  2229.   if (REG_P (operands[0]))
  2230.     optype0 = REGOP;
  2231.   else if (offsettable_memref_p (operands[0]))
  2232.     optype0 = OFFSOP;
  2233.   else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
  2234.     optype0 = POPOP;
  2235.   else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
  2236.     optype0 = PUSHOP;
  2237.   else if (GET_CODE (operands[0]) == MEM)
  2238.     optype0 = MEMOP;
  2239.   else
  2240.     optype0 = RNDOP;
  2241.  
  2242.   if (REG_P (operands[1]))
  2243.     optype1 = REGOP;
  2244.   else if (CONSTANT_P (operands[1])
  2245.        || GET_CODE (operands[1]) == CONST_DOUBLE)
  2246.     optype1 = CNSTOP;
  2247.   else if (offsettable_memref_p (operands[1]))
  2248.     optype1 = OFFSOP;
  2249.   else if (GET_CODE (XEXP (operands[1], 0)) == POST_INC)
  2250.     optype1 = POPOP;
  2251.   else if (GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)
  2252.     optype1 = PUSHOP;
  2253.   else if (GET_CODE (operands[1]) == MEM)
  2254.     optype1 = MEMOP;
  2255.   else
  2256.     optype1 = RNDOP;
  2257.  
  2258.   /* Check for the cases that the operand constraints are not
  2259.      supposed to allow to happen.  Abort if we get one,
  2260.      because generating code for these cases is painful.  */
  2261.  
  2262.   if (optype0 == RNDOP || optype1 == RNDOP)
  2263.     abort ();
  2264.  
  2265.   /* If one operand is decrementing and one is incrementing
  2266.      decrement the former register explicitly
  2267.      and change that operand into ordinary indexing.  */
  2268.  
  2269.   if (optype0 == PUSHOP && optype1 == POPOP)
  2270.     {
  2271.       operands[0] = XEXP (XEXP (operands[0], 0), 0);
  2272.       output_asm_insn ("subq.l #8,%0", operands);
  2273.       operands[0] = gen_rtx (MEM, DImode, operands[0]);
  2274.       optype0 = OFFSOP;
  2275.     }
  2276.   if (optype0 == POPOP && optype1 == PUSHOP)
  2277.     {
  2278.       operands[1] = XEXP (XEXP (operands[1], 0), 0);
  2279.       output_asm_insn ("subq.l #8,%1", operands);
  2280.       operands[1] = gen_rtx (MEM, DImode, operands[1]);
  2281.       optype1 = OFFSOP;
  2282.     }
  2283.  
  2284.   /* If an operand is an unoffsettable memory ref, find a register
  2285.      we can increment temporarily to make it refer to the second word.  */
  2286.  
  2287.   if (optype0 == MEMOP)
  2288.     addreg0 = find_addr_reg (XEXP (operands[0], 0));
  2289.  
  2290.   if (optype1 == MEMOP)
  2291.     addreg1 = find_addr_reg (XEXP (operands[1], 0));
  2292.  
  2293.   /* Ok, we can do one word at a time.
  2294.      Normally we do the low-numbered word first,
  2295.      but if either operand is autodecrementing then we
  2296.      do the high-numbered word first.
  2297.  
  2298.      In either case, set up in LATEHALF the operands to use
  2299.      for the high-numbered word and in some cases alter the
  2300.      operands in OPERANDS to be suitable for the low-numbered word.  */
  2301.  
  2302.   if (optype0 == REGOP)
  2303.     latehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 1);
  2304.   else if (optype0 == OFFSOP)
  2305.     latehalf[0] = adj_offsettable_operand (operands[0], 4);
  2306.   else
  2307.     latehalf[0] = operands[0];
  2308.  
  2309.   if (optype1 == REGOP)
  2310.     latehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
  2311.   else if (optype1 == OFFSOP)
  2312.     latehalf[1] = adj_offsettable_operand (operands[1], 4);
  2313.   else if (optype1 == CNSTOP)
  2314.     {
  2315.       if (CONSTANT_P (operands[1]))
  2316.     latehalf[1] = const0_rtx;
  2317.       else if (GET_CODE (operands[1]) == CONST_DOUBLE)
  2318.     {
  2319.       union { REAL_VALUE_TYPE e; int i[3]; } ue;
  2320.       union { double d; int i[2]; } ud;
  2321.  
  2322.       ue.i[0] = CONST_DOUBLE_LOW (operands[1]);
  2323.       ue.i[1] = CONST_DOUBLE_HIGH (operands[1]);
  2324.       ue.i[2] = CONST_DOUBLE_TOP (operands[1]);
  2325.  
  2326.       ud.d = ue.e;
  2327.  
  2328.       latehalf[1] = gen_rtx (CONST_INT, VOIDmode, ud.i[1]);
  2329.       operands[1] = gen_rtx (CONST_INT, VOIDmode, ud.i[0]);
  2330.     }
  2331.     }
  2332.   else
  2333.     latehalf[1] = operands[1];
  2334.  
  2335.   /* If insn is effectively movd N(sp),-(sp) then we will do the
  2336.      high word first.  We should use the adjusted operand 1 (which is N+4(sp))
  2337.      for the low word as well, to compensate for the first decrement of sp.  */
  2338.   if (optype0 == PUSHOP
  2339.       && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM
  2340.       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
  2341.     operands[1] = latehalf[1];
  2342.  
  2343.   /* If one or both operands autodecrementing,
  2344.      do the two words, high-numbered first.  */
  2345.  
  2346.   /* Likewise,  the first move would clobber the source of the second one,
  2347.      do them in the other order.  This happens only for registers;
  2348.      such overlap can't happen in memory unless the user explicitly
  2349.      sets it up, and that is an undefined circumstance.  */
  2350.  
  2351.   if (optype0 == PUSHOP || optype1 == PUSHOP
  2352.       || (optype0 == REGOP && optype1 == REGOP
  2353.       && REGNO (operands[0]) == REGNO (latehalf[1])))
  2354.     {
  2355.       /* Make any unoffsettable addresses point at high-numbered word.  */
  2356.       if (addreg0)
  2357.     output_asm_insn ("addql #4,%0", &addreg0);
  2358.       if (addreg1)
  2359.     output_asm_insn ("addql #4,%0", &addreg1);
  2360.  
  2361.       /* Do that word.  */
  2362.       output_asm_insn (singlemove_string (latehalf), latehalf);
  2363.  
  2364.       /* Undo the adds we just did.  */
  2365.       if (addreg0)
  2366.     output_asm_insn ("subql #4,%0", &addreg0);
  2367.       if (addreg1)
  2368.     output_asm_insn ("subql #4,%0", &addreg1);
  2369.  
  2370.       /* Do low-numbered word.  */
  2371.       output_asm_insn (singlemove_string (operands), operands);
  2372.  
  2373.       return "";
  2374.     }
  2375.  
  2376.   /* Normal case: do the two words, low-numbered first.  */
  2377.  
  2378.   output_asm_insn (singlemove_string (operands), operands);
  2379.  
  2380.   /* Make any unoffsettable addresses point at high-numbered word.  */
  2381.   if (addreg0)
  2382.     output_asm_insn ("addql #4,%0", &addreg0);
  2383.   if (addreg1)
  2384.     output_asm_insn ("addql #4,%0", &addreg1);
  2385.  
  2386.   /* Do that word.  */
  2387.   output_asm_insn (singlemove_string (latehalf), latehalf);
  2388.  
  2389.   /* Undo the adds we just did.  */
  2390.   if (addreg0)
  2391.     output_asm_insn ("subql #4,%0", &addreg0);
  2392.   if (addreg1)
  2393.     output_asm_insn ("subql #4,%0", &addreg1);
  2394.  
  2395.   return "";
  2396. }
  2397. #endif
  2398.  
  2399. /* Output assembler code to perform a long double move insn
  2400.    with operands OPERANDS.  */
  2401.  
  2402. char *
  2403. output_move_extended (operands)
  2404.      rtx *operands;
  2405. {
  2406.   enum { REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP } optype0, optype1;
  2407.   rtx latehalf[2], thirdhalf[2];
  2408.   rtx addreg0 = 0, addreg1 = 0;
  2409.  
  2410.   /* First classify both operands.  */
  2411.  
  2412.   if (REG_P (operands[0]))
  2413.     optype0 = REGOP;
  2414.   else if (offsettable_memref_p (operands[0]))
  2415.     optype0 = OFFSOP;
  2416.   else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
  2417.     optype0 = POPOP;
  2418.   else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
  2419.     optype0 = PUSHOP;
  2420.   else if (GET_CODE (operands[0]) == MEM)
  2421.     optype0 = MEMOP;
  2422.   else
  2423.     optype0 = RNDOP;
  2424.  
  2425.   if (REG_P (operands[1]))
  2426.     optype1 = REGOP;
  2427.   else if (CONSTANT_P (operands[1])
  2428.        || GET_CODE (operands[1]) == CONST_DOUBLE)
  2429.     optype1 = CNSTOP;
  2430.   else if (offsettable_memref_p (operands[1]))
  2431.     optype1 = OFFSOP;
  2432.   else if (GET_CODE (XEXP (operands[1], 0)) == POST_INC)
  2433.     optype1 = POPOP;
  2434.   else if (GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)
  2435.     optype1 = PUSHOP;
  2436.   else if (GET_CODE (operands[1]) == MEM)
  2437.     optype1 = MEMOP;
  2438.   else
  2439.     optype1 = RNDOP;
  2440.  
  2441.   /* Check for the cases that the operand constraints are not
  2442.      supposed to allow to happen.  Abort if we get one,
  2443.      because generating code for these cases is painful.  */
  2444.  
  2445.   if (optype0 == RNDOP || optype1 == RNDOP || optype0 == MEMOP || optype1 == MEMOP)
  2446.     abort ();
  2447.  
  2448.   /* If one operand is decrementing and one is incrementing
  2449.      decrement the former register explicitly
  2450.      and change that operand into ordinary indexing.  */
  2451.  
  2452.   if (optype0 == PUSHOP && optype1 == POPOP)
  2453.     {
  2454.       operands[0] = XEXP (XEXP (operands[0], 0), 0);
  2455.       output_asm_insn ("subq.l #12345,%0", operands);
  2456.       operands[0] = gen_rtx (MEM, DImode, operands[0]);
  2457.       optype0 = OFFSOP;
  2458.     }
  2459.   if (optype0 == POPOP && optype1 == PUSHOP)
  2460.     {
  2461.       operands[1] = XEXP (XEXP (operands[1], 0), 0);
  2462.       output_asm_insn ("subq.l #12345,%1", operands);
  2463.       operands[1] = gen_rtx (MEM, DImode, operands[1]);
  2464.       optype1 = OFFSOP;
  2465.     }
  2466.  
  2467.   /* Ok, we can do one word at a time.
  2468.      Normally we do the low-numbered word first,
  2469.      but if either operand is autodecrementing then we
  2470.      do the high-numbered word first.
  2471.  
  2472.      In either case, set up in LATEHALF the operands to use
  2473.      for the high-numbered word and in some cases alter the
  2474.      operands in OPERANDS to be suitable for the low-numbered word.  */
  2475.  
  2476.   if (optype0 == REGOP)
  2477.     latehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 1);
  2478.   else if (optype0 == OFFSOP)
  2479.     latehalf[0] = adj_offsettable_operand (operands[0], (TARGET_68881 ? 4 :2));
  2480.   else
  2481.     latehalf[0] = operands[0];
  2482.  
  2483.   if (optype1 == REGOP)
  2484.     latehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
  2485.   else if (optype1 == OFFSOP)
  2486.     latehalf[1] = adj_offsettable_operand (operands[1], (TARGET_68881 ? 4 :2));
  2487.   else if (optype1 == CNSTOP)
  2488.     {
  2489.       if (GET_CODE (operands[1]) == CONST_DOUBLE)
  2490.     {
  2491.       latehalf[1] = gen_rtx (CONST_INT, VOIDmode,
  2492.                  CONST_DOUBLE_HIGH (operands[1]));
  2493.     }
  2494.       else if (CONSTANT_P (operands[1]))
  2495.     latehalf[1] = const0_rtx;
  2496.     }
  2497.   else
  2498.     latehalf[1] = operands[1];
  2499.  
  2500.   if (optype0 == REGOP)
  2501.     thirdhalf[0] = gen_rtx (REG, SImode,
  2502.                ((!TARGET_68881 && REGNO (operands[0]) == 0) ?
  2503.                  8 :
  2504.                  REGNO (operands[0]) + 2));
  2505.   else if (optype0 == OFFSOP)
  2506.     thirdhalf[0] = adj_offsettable_operand (operands[0], (TARGET_68881 ? 8:6));
  2507.   else
  2508.     thirdhalf[0] = operands[0];
  2509.  
  2510.   if (optype1 == REGOP)
  2511.     thirdhalf[1] = gen_rtx (REG, SImode,
  2512.                ((!TARGET_68881 && REGNO (operands[1]) == 0) ?
  2513.                  8 :
  2514.                  REGNO (operands[1]) + 2));
  2515.   else if (optype1 == OFFSOP)
  2516.     thirdhalf[1] = adj_offsettable_operand (operands[1], (TARGET_68881 ? 8:6));
  2517.   else if (optype1 == CNSTOP)
  2518.     {
  2519.       if (GET_CODE (operands[1]) == CONST_DOUBLE)
  2520.     {
  2521.       thirdhalf[1] = gen_rtx (CONST_INT, VOIDmode,
  2522.                  CONST_DOUBLE_TOP (operands[1]));
  2523.       operands[1] = gen_rtx (CONST_INT, VOIDmode,
  2524.                  (TARGET_68881 ? CONST_DOUBLE_LOW (operands[1])
  2525.                                                  : ((unsigned int) CONST_DOUBLE_LOW (operands[1])) >> 16));
  2526.     }
  2527.       else if (CONSTANT_P (operands[1]))
  2528.     thirdhalf[1] = const0_rtx;
  2529.     }
  2530.   else
  2531.     thirdhalf[1] = operands[1];
  2532.  
  2533.   /* If insn is effectively movd N(sp),-(sp) then we will do the
  2534.      high word first.  We should use the adjusted operand 1 (which is N+4(sp))
  2535.      for the low word as well, to compensate for the first decrement of sp.  */
  2536.   if (optype0 == PUSHOP
  2537.       && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM
  2538.       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
  2539.     operands[1] = latehalf[1];
  2540.  
  2541.   /* If one or both operands autodecrementing,
  2542.      do the two words, high-numbered first.  */
  2543.  
  2544.     
  2545.   /* Likewise,  the first move would clobber the source of the second one,
  2546.      do them in the other order.  This happens only for registers;
  2547.      such overlap can't happen in memory unless the user explicitly
  2548.      sets it up, and that is an undefined circumstance.  */
  2549.  
  2550.   if (optype0 == PUSHOP || optype1 == PUSHOP
  2551.       || (optype0 == REGOP && optype1 == REGOP
  2552.       && REGNO (operands[0]) == REGNO (latehalf[1])))
  2553.     {
  2554.       output_asm_insn (singlemove_string (thirdhalf), thirdhalf);
  2555.  
  2556.       output_asm_insn (singlemove_string (latehalf), latehalf);
  2557.  
  2558.       if (TARGET_68881)
  2559.         /*extendeds are 96 bits here so we have 32 left*/
  2560.     output_asm_insn (singlemove_string (operands), operands);
  2561.       else
  2562.         /*extendeds are 80 bits here so we have 16 left*/
  2563.     output_asm_insn ("move.w %1,%0", operands);
  2564.  
  2565.       return "";
  2566.     }
  2567.  
  2568.   /* Normal case: do the three words, low-numbered first.  */
  2569.  
  2570.   if (TARGET_68881) 
  2571.     /*extendeds are 96 bits here so we have 32 left*/
  2572.     output_asm_insn (singlemove_string (operands), operands);
  2573.   else
  2574.     /*extendeds are 80 bits here so we have 16 left*/
  2575.     output_asm_insn ("move.w %1,%0", operands);
  2576.  
  2577.   output_asm_insn (singlemove_string (latehalf), latehalf);
  2578.  
  2579.   output_asm_insn (singlemove_string (thirdhalf), thirdhalf);
  2580.  
  2581.   return "";
  2582. }
  2583.  
  2584. /* Generate code for one of the extended-to-integer lib calls.  The context
  2585.    is such that we can't make call rtxes, and have to do it all manually. */
  2586.  
  2587. char *
  2588. output_lib_convert (operands, name)
  2589.      rtx *operands;
  2590.      char *name;
  2591. {
  2592.   rtx aoperands[2];
  2593.   char tmpbuf[1000];
  2594.   int pushed = 0;
  2595.  
  2596.   /* What regs need to be saved/restored? probably several... */
  2597.   /* Set up a new operand array. */
  2598.   aoperands[1] = operands[1];
  2599.   aoperands[0] = gen_rtx (MEM, GET_MODE (aoperands[1]),
  2600.               gen_rtx (PRE_DEC, Pmode, stack_pointer_rtx));
  2601.   /* We need a pointer to the float; try different ways to get one. */
  2602.   if (GET_CODE (aoperands[1]) == MEM)
  2603.     {
  2604.       output_asm_insn ("pea %1", aoperands);
  2605.     }
  2606.   else if (FP_REG_P (aoperands[1]))
  2607.     {
  2608.       output_asm_insn ("fmove.x %1,%0", aoperands);
  2609.       output_asm_insn ("pea 0(sp)", NULL);
  2610.       pushed = 1;
  2611.     }
  2612.   else
  2613.     {
  2614.       output_move_extended (aoperands);
  2615.       output_asm_insn ("pea 0(sp)", NULL);
  2616.       pushed = 1;
  2617.     }
  2618.   /* Do an on-the-spot importation of the libcall name. */
  2619.   sprintf (tmpbuf, "IMPORT %s", name);
  2620.   output_asm_insn (tmpbuf, NULL);
  2621.   /* Now go and do it. */
  2622.   if (TARGET_FX30)
  2623.     sprintf (tmpbuf, "DC.W $61ff ; bsr.l\\;DC.L %s-m#start-*", name);
  2624.   else
  2625.     sprintf (tmpbuf, "jsr %s", name);
  2626.   output_asm_insn (tmpbuf, NULL);
  2627.   /* If intended result place is not d0, move it there. */
  2628.   if (! (REG_P (operands[0]) && REGNO (operands[0]) == 0))
  2629.     {
  2630.       aoperands[0] = operands[0];
  2631.       aoperands[1] = gen_rtx (REG, SImode, 0);
  2632.       output_asm_insn (singlemove_string (aoperands), aoperands);
  2633.     }
  2634.   /* Fix up the stack (we pushed a pointer and maybe an extended float
  2635.      for it to point to). */
  2636.   sprintf (tmpbuf, "add.w #%d,sp",
  2637.        4 + (pushed ? mode_size[(int) XFmode] : 0));
  2638.   output_asm_insn(tmpbuf, NULL);
  2639.   return "";
  2640. }
  2641.  
  2642. /* The int library call convention is to use D0 and D1 with output to D0.
  2643.    The complication here is that regalloc is already complete, so we have
  2644.    to be very careful not to step on any important values.  From md we
  2645.    *are* guaranteed that output is a Dn, while input is either Dn or a
  2646.    constant, which simplifies things considerably. */
  2647.  
  2648. /*  (I'm not 100% convinced that this code is correct...) */
  2649. char *
  2650. output_int_lib_call (operands, name)
  2651.      rtx *operands;
  2652.      char *name;
  2653. {
  2654.   char tmpbuf[1000];
  2655.   int o0d0 = 0, o2d0 = 0, o0d1 = 0, o2d1 = 0, o0d2 = 0;
  2656.  
  2657.   /* Int lib routines may step on a0. */
  2658.   output_asm_insn ("movem.l a0/a1,-(sp)", NULL);
  2659.  
  2660.   if (GET_CODE (operands[0]) == REG && REGNO (operands[0]) == 0) o0d0 = 1;
  2661.   if (GET_CODE (operands[0]) == REG && REGNO (operands[0]) == 1) o0d1 = 1;
  2662.   if (GET_CODE (operands[0]) == REG && REGNO (operands[0]) == 2) o0d2 = 1;
  2663.   if (GET_CODE (operands[2]) == REG && REGNO (operands[2]) == 0) o2d0 = 1;
  2664.   if (GET_CODE (operands[2]) == REG && REGNO (operands[2]) == 1) o2d1 = 1;
  2665.  
  2666.     if (!o0d1)
  2667.         output_asm_insn ("move.l d1,-(sp)", NULL);
  2668.  
  2669.     if (!o0d2)
  2670.         output_asm_insn ("move.l d2,-(sp)", NULL);
  2671.  
  2672.     if (o0d0)
  2673.     {
  2674.         if (o2d1)
  2675.         {
  2676.             /* everything is exactly where we want it */
  2677.         } 
  2678.         else
  2679.         {
  2680.             /* move operand 2 into d1. */
  2681.             output_asm_insn ("move.l %2,d1", operands);
  2682.         }
  2683.     }
  2684.     else
  2685.     {
  2686.         /* operand 0 is not in d0, so we need to save d0 on the stack before
  2687.            copying the operand to d0. */
  2688.         output_asm_insn ("move.l d0,-(sp)", NULL);
  2689.         if (o0d1) 
  2690.         {
  2691.             output_asm_insn ("move.l d1,d0", NULL);
  2692.             if (o2d0) 
  2693.             {
  2694.                 /* Input and output are in exactly the opposite of where we want. */
  2695.                 /* d0 just got saved on the stack, so we can copy it from the stack
  2696.                    to d1.  Note that we are copying the value not popping it off, so
  2697.                    that we can restore d0 later. */
  2698.                 output_asm_insn ("move.l (sp),d1", NULL);
  2699.             } 
  2700.             else 
  2701.             {
  2702.                 /* move the input to d1. */
  2703.                 output_asm_insn ("move.l %2,d1", operands);
  2704.             }
  2705.         } 
  2706.         else 
  2707.         {
  2708.             if (!o2d1)
  2709.             {
  2710.                 /* operand 2 is not in d1, so we gotta move it to d1 */
  2711.                 output_asm_insn ("move.l %2,d1", operands);
  2712.             }
  2713.             /* operand 0 is not in either d0 or d1, so we gotta move it to d0 */
  2714.             output_asm_insn ("move.l %0,d0", operands);
  2715.         }
  2716.     }
  2717.  
  2718.   /* Do the int lib call proper now. */
  2719.   sprintf (tmpbuf, "IMPORT %s", name);
  2720.   output_asm_insn (tmpbuf, NULL);
  2721.   if (TARGET_FX30)
  2722.     sprintf (tmpbuf, "DC.W $61ff ; bsr.l\\;DC.L %s-m#start-*", name);
  2723.   else
  2724.     sprintf (tmpbuf, "jsr %s", name);
  2725.   output_asm_insn (tmpbuf, NULL);
  2726.  
  2727.   /* Now clean up any mess we might have made on the stack, plus move the
  2728.      result from d0 to wherever it was supposed to go. */
  2729.  
  2730.   /* If operand 0 was not in d0, move the output to the correct place and then
  2731.        restore d0 */
  2732.   if (!o0d0)
  2733.     {
  2734.     output_asm_insn ("move.l d0,%0", operands);
  2735.     output_asm_insn ("move.l (sp)+,d0", NULL);
  2736.     }
  2737.  
  2738.   if (!o0d2)
  2739.     output_asm_insn ("move.l (sp)+,d2", NULL);
  2740.  
  2741.   if (!o0d1)
  2742.     output_asm_insn ("move.l (sp)+,d1", NULL);
  2743.     
  2744.   /* restore a0, a1, d1, and d2 */
  2745.   output_asm_insn ("movem.l (sp)+,a0/a1", NULL);
  2746.  
  2747.   return "";
  2748. }
  2749.  
  2750. /* Helper stuff for SANE output routines. */
  2751.  
  2752. #define STKOFF(MODE,OFF)  \
  2753.   gen_rtx (MEM, (MODE), gen_rtx (PLUS, Pmode, stack_pointer_rtx,  \
  2754.                    gen_rtx (CONST_INT, VOIDmode, (OFF))))
  2755.  
  2756. /* This takes a stack reference and changes it into a stack reference
  2757.    4 bytes deeper.  This is needed after a push on the stack. */
  2758.  
  2759. rtx deepen (x)
  2760.      rtx x;
  2761. {
  2762.   if (GET_CODE (x) == MEM
  2763.       && GET_CODE (XEXP (x, 0)) == PLUS
  2764.       && XEXP (XEXP (x, 0), 0) == stack_pointer_rtx)
  2765.     {
  2766.       return STKOFF (GET_MODE (x), 4 + INTVAL (XEXP (XEXP (x, 0), 1)));
  2767.     }
  2768.   else
  2769.     return x;
  2770. }
  2771.  
  2772. /* Output a 2(1)-address operation that uses SANE. */
  2773.  
  2774. char *
  2775. output_sane_2 (opnds, op, name)
  2776.      rtx *opnds;
  2777.      int op;
  2778.      char *name;
  2779. {
  2780.   char tmpbuf[100], *cname;
  2781.   enum machine_mode mode0 = GET_MODE (opnds[0]);
  2782.   int space0 = 0, spacetmp = 0, space;
  2783.   int cop;
  2784.   rtx operands[2], moperands[2], coperands[2], tmprtx;
  2785.  
  2786.   if (mode0 != XFmode)
  2787.     spacetmp = GET_MODE_SIZE (XFmode);
  2788.   if (REG_P (opnds[0]) || GET_CODE (opnds[0]) == CONST_DOUBLE)
  2789.     space0 = GET_MODE_SIZE (GET_MODE (opnds[0]));
  2790.   space = spacetmp + space0;
  2791.   /* Reserve needed space for all our tmps and operands. */
  2792.   if (spacetmp > 0)
  2793.     {
  2794.       sprintf(tmpbuf, "sub.w #%d,sp", spacetmp);
  2795.       output_asm_insn(tmpbuf, NULL);
  2796.       tmprtx = STKOFF (XFmode, space0);
  2797.     }
  2798.   if (space0 > 0)
  2799.     {
  2800.       output_sane_push(opnds[0]);
  2801.       operands[0] = STKOFF (GET_MODE (opnds[0]), 0);
  2802.     }
  2803.   else
  2804.     {
  2805.       operands[0] = opnds[0];
  2806.     }
  2807.   /* Now everything is a pointer to memlocs where the numbers reside. */
  2808.   /* First order of business is to make sure the input-output operand
  2809.      is of extended type.  If not, then we convert into a reserved place
  2810.      and if so, we maybe put it on the stack anyway. */
  2811.   if (mode0 != XFmode)
  2812.     {
  2813.       cop = (mode0 == HImode ? 0x200e :
  2814.         (mode0 == SImode ? 0x280e :
  2815.          (mode0 == SFmode ? 0x100e :
  2816.            0x080e)));
  2817.       cname = (mode0 == HImode ? "FI2X" :
  2818.           (mode0 == SImode ? "FL2X" :
  2819.         (mode0 == SFmode ? "FS2X" :
  2820.          "FD2X")));
  2821.       coperands[1] = operands[0];
  2822.       coperands[0] = deepen (tmprtx);
  2823.       output_sane_op (coperands, 2, cop, cname);
  2824.       moperands[0] = tmprtx;
  2825.     }
  2826.   else
  2827.     {
  2828.       moperands[0] = operands[0];
  2829.     }
  2830.   /* Now we're all set to do the operation proper. */
  2831.   output_sane_op (moperands, 1, op, name);
  2832.   /* The result of the operation is still extended, so we may need to
  2833.      do another conversion.  Fortunately, the extended result is already in
  2834.      memory, so we don't need to allocate, but the final result may need
  2835.      to be sent back to regs. */
  2836.   if (mode0 != XFmode)
  2837.     {
  2838.       cop = (mode0 == HImode ? 0x2010 :
  2839.         (mode0 == SImode ? 0x2810 :
  2840.          (mode0 == SFmode ? 0x1010 :
  2841.            0x0810)));
  2842.       cname = (mode0 == HImode ? "FX2I" :
  2843.           (mode0 == SImode ? "FX2L" :
  2844.         (mode0 == SFmode ? "FX2S" :
  2845.          "FX2D")));
  2846.       coperands[0] = deepen (operands[0]);
  2847.       coperands[1] = moperands[0];
  2848.       output_sane_op (coperands, 2, cop, cname);
  2849.     }
  2850.   /* SANE calls all done, now clean up. */
  2851.   /* Pop the result if it had to be pushed originally. */
  2852.   if (REG_P (opnds[0]) || GET_CODE (opnds[0]) == CONST_DOUBLE)
  2853.     {
  2854.       output_sane_pop (opnds[0]);
  2855.     }
  2856.   /* Deallocate everything else. */
  2857.   if (spacetmp > 0)
  2858.     {
  2859.       sprintf (tmpbuf, "add.w #%d,sp", spacetmp);
  2860.       output_asm_insn(tmpbuf, NULL);
  2861.     }
  2862.   /* All the code has already been dumped out. */
  2863.   return "";
  2864. }
  2865.  
  2866. /* Output a compare operation that uses SANE (two float operands, integer
  2867.    result). */
  2868.  
  2869. char *
  2870. output_sane_cmp (opnds, op, name)
  2871.      rtx *opnds;
  2872.      int op;
  2873.      char *name;
  2874. {
  2875.   char tmpbuf[100], *cname;
  2876.   enum machine_mode mode0 = GET_MODE (opnds[0]);
  2877.   enum machine_mode mode1 = GET_MODE (opnds[1]);
  2878.   int space0 = 0, space1 = 0, spacetmp = 0, space;
  2879.   int cop;
  2880.   rtx operands[3], moperands[3], coperands[2], tmprtx, tmpop;
  2881.  
  2882.   if (mode0 != XFmode)
  2883.     spacetmp = GET_MODE_SIZE (XFmode);
  2884.   if (REG_P (opnds[0])  || GET_CODE (opnds[0]) == CONST_DOUBLE)
  2885.     space0 = GET_MODE_SIZE (GET_MODE (opnds[0]));
  2886.   if (REG_P (opnds[1]) || GET_CODE (opnds[1]) == CONST_DOUBLE)
  2887.     space1 = GET_MODE_SIZE (GET_MODE (opnds[1]));
  2888.   space = spacetmp + space1 + space0;
  2889.   /* Reserve needed space for all our tmps and operands. */
  2890.   if (spacetmp > 0)
  2891.     {
  2892.       sprintf(tmpbuf, "sub.w #%d,sp", spacetmp);
  2893.       output_asm_insn(tmpbuf, NULL);
  2894.       tmprtx = STKOFF (XFmode, space0 + space1);
  2895.     }
  2896.   if (space1 > 0)
  2897.     {
  2898.       output_sane_push(opnds[1]);
  2899.       operands[1] = STKOFF (GET_MODE (opnds[1]), space0);
  2900.     }
  2901.   else
  2902.     {
  2903.       operands[1] = opnds[1];
  2904.     }
  2905.   if (space0 > 0)
  2906.     {
  2907.       output_sane_push(opnds[0]);
  2908.       operands[0] = STKOFF (GET_MODE (opnds[0]), 0);
  2909.     }
  2910.   else
  2911.     {
  2912.       operands[0] = opnds[0];
  2913.     }
  2914.   /* Now everything is a pointer to memlocs where the numbers reside. */
  2915.   /* First order of business is to make sure the first operand
  2916.      is of extended type.  If not, then we convert into a reserved place
  2917.      and if so, we maybe put it on the stack anyway. */
  2918.   if (mode0 != XFmode)
  2919.     {
  2920.       cop = (mode0 == HImode ? 0x200e :
  2921.         (mode0 == SImode ? 0x280e :
  2922.          (mode0 == SFmode ? 0x100e :
  2923.            0x080e)));
  2924.       cname = (mode0 == HImode ? "FI2X" :
  2925.           (mode0 == SImode ? "FL2X" :
  2926.         (mode0 == SFmode ? "FS2X" :
  2927.          "FD2X")));
  2928.       coperands[1] = operands[0];
  2929.       coperands[0] = deepen (tmprtx);
  2930.       output_sane_op (coperands, 2, cop, cname);
  2931.       moperands[0] = tmprtx;
  2932.     }
  2933.   else
  2934.     {
  2935.       moperands[0] = operands[0];
  2936.     }
  2937.   tmpop = moperands[0];
  2938.   moperands[0] = deepen (moperands[0]);
  2939.   moperands[1] = operands[1];
  2940.   /* Now we're all set to do the comparison proper. */
  2941.   output_sane_op (moperands, 2, op, name);
  2942.   /* Deallocate everything else.  Note that this add is really adda,
  2943.      so condition codes coming back from SANE op are still valid. */
  2944.   if (spacetmp + space1 + space0 > 0)
  2945.     {
  2946.       sprintf (tmpbuf, "add.w #%d,sp", spacetmp + space1 + space0);
  2947.       output_asm_insn(tmpbuf, NULL);
  2948.     }
  2949.   /* All the code has already been dumped out. */
  2950.   return "";
  2951. }
  2952.  
  2953. /* Output a compare against 0 by synthesizing the zero and calling cmp. */
  2954.  
  2955. char *
  2956. output_sane_tst (opnds, op, name)
  2957.      rtx *opnds;
  2958.      int op;
  2959.      char *name;
  2960. {
  2961.   enum machine_mode mode0 = GET_MODE (opnds[0]);
  2962.   rtx operands[2];
  2963.  
  2964.   operands[0] = opnds[0];
  2965.   operands[1] = CONST0_RTX (mode0);
  2966.   return output_sane_cmp (operands, op, name);
  2967. }
  2968.  
  2969. /* Output a conversion operation that uses SANE.  This is sort of like
  2970.    a two-address operation, except that conversions aren't needed... */
  2971.  
  2972. char *
  2973. output_sane_convert (opnds)
  2974.      rtx *opnds;
  2975. {
  2976.   char tmpbuf[100], *cname;
  2977.   enum machine_mode frommode = GET_MODE (opnds[1]);
  2978.   enum machine_mode tomode   = GET_MODE (opnds[0]);
  2979.   int space0 = 0, space1 = 0, spacetmp = 0, space;
  2980.   int cop;
  2981.   rtx operands[3], moperands[3], coperands[2], tmprtx, tmpop;
  2982.  
  2983.   if (frommode == tomode) abort();  /* should never happen? */
  2984.  
  2985.   if (frommode != XFmode && tomode != XFmode)
  2986.     spacetmp = GET_MODE_SIZE (XFmode);
  2987.   if (REG_P (opnds[0]) || GET_CODE (opnds[0]) == CONST_DOUBLE)
  2988.     space0 = GET_MODE_SIZE (GET_MODE (opnds[0]));
  2989.   if (REG_P (opnds[1]) || GET_CODE (opnds[1]) == CONST_DOUBLE)
  2990.     space1 = GET_MODE_SIZE (GET_MODE (opnds[1]));
  2991.   space = spacetmp + space1 + space0;
  2992.   /* Reserve needed space for all our tmps and operands. */
  2993.   if (spacetmp > 0)
  2994.     {
  2995.       sprintf(tmpbuf, "sub.w #%d,sp", spacetmp);
  2996.       output_asm_insn(tmpbuf, NULL);
  2997.       tmprtx = STKOFF (XFmode, space0 + space1);
  2998.     }
  2999.   if (space1 > 0)
  3000.     {
  3001.       output_sane_push(opnds[1]);
  3002.       operands[1] = STKOFF (GET_MODE (opnds[1]), space0);
  3003.     }
  3004.   else
  3005.     {
  3006.       operands[1] = opnds[1];
  3007.     }
  3008.   if (space0 > 0)
  3009.     {
  3010.       output_sane_push(opnds[0]);
  3011.       operands[0] = STKOFF (GET_MODE (opnds[0]), 0);
  3012.     }
  3013.   else
  3014.     {
  3015.       operands[0] = opnds[0];
  3016.     }
  3017.   if (frommode != XFmode)
  3018.     {
  3019.       cop = (frommode == HImode ? 0x200e :
  3020.         (frommode == SImode ? 0x280e :
  3021.          (frommode == SFmode ? 0x100e :
  3022.            0x080e)));
  3023.       cname = (frommode == HImode ? "FI2X" :
  3024.           (frommode == SImode ? "FL2X" :
  3025.         (frommode == SFmode ? "FS2X" :
  3026.          "FD2X")));
  3027.       coperands[1] = operands[1];
  3028.       coperands[0] = deepen (tomode == XFmode ? operands[0] : tmprtx);
  3029.       output_sane_op (coperands, 2, cop, cname);
  3030.     }
  3031.   /* If necessary, do the second conversion. */
  3032.   if (tomode != XFmode)
  3033.     {
  3034.       cop = (tomode == HImode ? 0x2010 :
  3035.         (tomode == SImode ? 0x2810 :
  3036.          (tomode == SFmode ? 0x1010 :
  3037.            0x0810)));
  3038.       cname = (tomode == HImode ? "FX2I" :
  3039.           (tomode == SImode ? "FX2L" :
  3040.         (tomode == SFmode ? "FX2S" :
  3041.          "FX2D")));
  3042.       coperands[1] = (frommode == XFmode ? operands[1] : tmprtx);
  3043.       coperands[0] = deepen (operands[0]);
  3044.       output_sane_op (coperands, 2, cop, cname);
  3045.     }
  3046.   /* Pop the result if it wasn't memory-resident */
  3047.   if (REG_P (opnds[0]) || GET_CODE (opnds[0]) == CONST_DOUBLE)
  3048.     {
  3049.       output_sane_pop (opnds[0]);
  3050.     }
  3051.   /* Finish cleaning up the stack. */
  3052.   if (spacetmp + space1 > 0)
  3053.     {
  3054.       sprintf (tmpbuf, "add.w #%d,sp", spacetmp + space1);
  3055.       output_asm_insn(tmpbuf, NULL);
  3056.     }
  3057.   return "";
  3058. }
  3059.  
  3060. /* Output a 3(2)-address operation that uses SANE.  This routine will do
  3061.    everything including type conversions, since this helps it use the
  3062.    stack somewhat more efficiently. */
  3063.  
  3064. char *
  3065. output_sane_3 (opnds, op, name)
  3066.      rtx *opnds;
  3067.      int op;
  3068.      char *name;
  3069. {
  3070.     char tmpbuf[100], *cname;
  3071.     enum machine_mode mode0 = GET_MODE (opnds[0]);
  3072.     enum machine_mode mode2 = GET_MODE (opnds[2]);
  3073.     int space0 = 0, space2 = 0, spacetmp = 0, space;
  3074.     int cop;
  3075.     rtx operands[3], moperands[3], coperands[2], tmprtx, tmpop;
  3076.  
  3077.     if (mode0 != XFmode)
  3078.       spacetmp = GET_MODE_SIZE (XFmode);
  3079.     if (REG_P (opnds[0]) || GET_CODE (opnds[0]) == CONST_DOUBLE)
  3080.       space0 = GET_MODE_SIZE (GET_MODE (opnds[0]));
  3081.     if (REG_P (opnds[2]) || GET_CODE (opnds[2]) == CONST_DOUBLE)
  3082.       space2 = GET_MODE_SIZE (GET_MODE (opnds[2]));
  3083.     space = spacetmp + space2 + space0;
  3084.     /* Reserve needed space for all our tmps and operands. */
  3085.     if (spacetmp > 0)
  3086.       {
  3087.     sprintf(tmpbuf, "sub.w #%d,sp", spacetmp);
  3088.     output_asm_insn(tmpbuf, NULL);
  3089.     tmprtx = STKOFF (XFmode, space0 + space2);
  3090.       }
  3091.     if (space2 > 0)
  3092.       {
  3093.     output_sane_push(opnds[2]);
  3094.     operands[2] = STKOFF (GET_MODE (opnds[2]), space0);
  3095.       }
  3096.     else
  3097.       {
  3098.     operands[2] = opnds[2];
  3099.       }
  3100.     if (space0 > 0)
  3101.       {
  3102.     output_sane_push(opnds[0]);
  3103.     operands[0] = STKOFF (GET_MODE (opnds[0]), 0);
  3104.       }
  3105.     else
  3106.       {
  3107.     operands[0] = opnds[0];
  3108.       }
  3109.     /* Now everything is a pointer to memlocs where the numbers reside. */
  3110.     /* First order of business is to make sure the input-output operand
  3111.        is of extended type.  If not, then we convert into a reserved place
  3112.        and if so, we maybe put it on the stack anyway. */
  3113.     if (mode0 != XFmode)
  3114.       {
  3115.       cop = (mode0 == HImode ? 0x200e :
  3116.          (mode0 == SImode ? 0x280e :
  3117.          (mode0 == SFmode ? 0x100e :
  3118.            0x080e)));
  3119.       cname = (mode0 == HImode ? "FI2X" :
  3120.           (mode0 == SImode ? "FL2X" :
  3121.            (mode0 == SFmode ? "FS2X" :
  3122.              "FD2X")));
  3123.     coperands[1] = operands[0];
  3124.     coperands[0] = deepen (tmprtx);
  3125.     output_sane_op (coperands, 2, cop, cname);
  3126.     moperands[0] = tmprtx;
  3127.       }
  3128.     else
  3129.       {
  3130.     moperands[0] = operands[0];
  3131.       }
  3132.     tmpop = moperands[0];
  3133.     moperands[0] = deepen (moperands[0]);
  3134.     moperands[1] = operands[2];
  3135.     /* Now we're all set to do the operation proper. */
  3136.     output_sane_op (moperands, 2, op, name);
  3137.     /* The result of the operation is still extended, so we may need to
  3138.        do another conversion.  Fortunately, the extended result is already in
  3139.        memory, so we don't need to allocate, but the final result may need
  3140.        to be sent back to regs. */
  3141.     if (mode0 != XFmode)
  3142.       {
  3143.       cop = (mode0 == HImode ? 0x2010 :
  3144.          (mode0 == SImode ? 0x2810 :
  3145.          (mode0 == SFmode ? 0x1010 :
  3146.            0x0810)));
  3147.       cname = (mode0 == HImode ? "FX2I" :
  3148.           (mode0 == SImode ? "FX2L" :
  3149.            (mode0 == SFmode ? "FX2S" :
  3150.              "FX2D")));
  3151.       coperands[0] = deepen (operands[0]);
  3152.       coperands[1] = tmpop;
  3153.       output_sane_op (coperands, 2, cop, cname);
  3154.       }
  3155.     /* SANE calls all done, now clean up. */
  3156.     /* Pop the result if it had to be pushed originally. */
  3157.     if (REG_P (opnds[0]) || GET_CODE (opnds[0]) == CONST_DOUBLE)
  3158.       {
  3159.     output_sane_pop (opnds[0]);
  3160.       }
  3161.     /* Deallocate everything else. */
  3162.     if (spacetmp + space2 > 0)
  3163.       {
  3164.     sprintf (tmpbuf, "add.w #%d,sp", spacetmp + space2);
  3165.     output_asm_insn(tmpbuf, NULL);
  3166.       }
  3167.     /* All the code has already been dumped out. */
  3168.     return "";
  3169. }
  3170.  
  3171. /* Push a SANE number onto the stack (usually from a reg). */
  3172.  
  3173. output_sane_push (x)
  3174.      rtx x;
  3175. {
  3176.   rtx pusherands[2];
  3177.  
  3178.   pusherands[0] = gen_rtx (MEM, GET_MODE (x),
  3179.                  gen_rtx (PRE_DEC, Pmode, stack_pointer_rtx));
  3180.   pusherands[1] = x;
  3181.   switch (GET_MODE (x))
  3182.     {
  3183.     case HImode:
  3184.       output_asm_insn ("move.w %1,%0", pusherands);
  3185.       break;
  3186.     case SImode:
  3187.     case SFmode:
  3188.       output_asm_insn ("move.l %f1,%0", pusherands);
  3189.       break;
  3190.     case DFmode:
  3191.       output_move_double (pusherands);
  3192.       break;
  3193.     case XFmode:
  3194.       output_move_extended (pusherands);
  3195.       break;
  3196.     default:
  3197.       abort();
  3198.     }
  3199. }
  3200.  
  3201. /* Pop a SANE number off the stack into a given place (most likely a reg). */
  3202.  
  3203. output_sane_pop (x)
  3204.      rtx x;
  3205. {
  3206.   rtx poperands[2];
  3207.  
  3208.   poperands[0] = x;
  3209.   poperands[1] = gen_rtx (MEM, GET_MODE (x),
  3210.               gen_rtx (POST_INC, Pmode, stack_pointer_rtx));
  3211.   switch (GET_MODE (x))
  3212.     {
  3213.     case HImode:
  3214.       output_asm_insn ("move.w %1,%0", poperands);
  3215.       break;
  3216.     case SImode:
  3217.     case SFmode:
  3218.       output_asm_insn ("move.l %1,%0", poperands);
  3219.       break;
  3220.     case DFmode:
  3221.       output_move_double (poperands);
  3222.       break;
  3223.     case XFmode:
  3224.       output_move_extended (poperands);
  3225.       break;
  3226.     default:
  3227.       abort();
  3228.     }
  3229. }
  3230.  
  3231. /* Issue the basic SANE calling sequence; push addresses of operands (which
  3232.    must already be in memory), push the op code, then trap.  The trap
  3233.    will pop everything itself, so no cleanup needed. */
  3234.  
  3235. output_sane_op (moperands, numopnds, op, name)
  3236.      rtx *moperands;
  3237.      int numopnds, op;
  3238.      char *name;
  3239. {
  3240.   char tmpbuf[100];
  3241.  
  3242.   if (numopnds > 1) 
  3243.     output_asm_insn ("pea %1", moperands);
  3244.   if (numopnds > 0)
  3245.     output_asm_insn ("pea %0", moperands);
  3246.   sprintf (tmpbuf, "move.w #$%x,-(sp)  ; %s", op, name);
  3247.   output_asm_insn (tmpbuf, NULL);
  3248.   output_asm_insn ("dc.w   $a9eb         ; FP68K", NULL);
  3249. }
  3250.  
  3251. char *
  3252. output_move_const_long_double (operands)
  3253.      rtx *operands;
  3254. {
  3255.     {
  3256.       int code = standard_68881_constant_p (operands[1]);
  3257.  
  3258.       if (code != 0)
  3259.     {
  3260.       static char buf[40];
  3261.  
  3262.       sprintf (buf, "fmovecr #$%x,%%0", code & 0xff);
  3263.       return buf;
  3264.     }
  3265.       return "fmove.x %1,%0";
  3266.     }
  3267. }
  3268.  
  3269. int mpw_real_arithmetic(REAL_VALUE_TYPE *value, int code, REAL_VALUE_TYPE x, REAL_VALUE_TYPE y)
  3270. {
  3271.   switch (code) {
  3272.     case PLUS_EXPR:
  3273.       *value = x + y;
  3274.       break;
  3275.     case MINUS_EXPR:
  3276.       *value = x - y;
  3277.       break;
  3278.     case MULT_EXPR:
  3279.       *value = x * y;
  3280.       break;
  3281.     case RDIV_EXPR:
  3282. #ifndef REAL_INFINITY
  3283.       if (y == 0)
  3284.         return 0;
  3285. #endif
  3286.       *value = x / y;
  3287.       break;
  3288.     case MIN_EXPR:
  3289.       *value = MIN (x, y);
  3290.       break;
  3291.     case MAX_EXPR:
  3292.       *value = MAX (x, y);
  3293.       break;
  3294.     default:
  3295.       fprintf(stderr, "code = %s\n", tree_code_name[code]);
  3296.       abort ();
  3297.   }
  3298. }
  3299.  
  3300. int mpw_real_to_int(int *low, int *high, REAL_VALUE_TYPE d)
  3301. {
  3302.   HOST_WIDE_INT half_word
  3303.     = (HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2);
  3304.  
  3305.   if (d < 0)
  3306.     d = -d;
  3307.  
  3308.   *high = (HOST_WIDE_INT) (d / half_word / half_word);
  3309.   d -= (REAL_VALUE_TYPE) *high * half_word * half_word;
  3310.   if (d >= (REAL_VALUE_TYPE) half_word * half_word / 2)
  3311.     {
  3312.       *low = d - (REAL_VALUE_TYPE) half_word * half_word / 2;
  3313.       *low |= (HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT - 1);
  3314.     }
  3315.   else
  3316.    *low = (HOST_WIDE_INT) d;
  3317.   if (d < 0)
  3318.   neg_double (*low, *high, low, high);
  3319. }
  3320.  
  3321.  
  3322. /* Print out a string in MPW Asm-approved syntax.  Main trickiness is
  3323.    to recognize non-printing characters and put them out as raw bytes,
  3324.    while keeping as many printable characters in a string as possible
  3325.   (saves space in asm code and makes it more readable too). */
  3326.  
  3327. /* newline/cr character mapping was handled at lex time... */
  3328.  
  3329. output_mpw_string(fp, str, size)
  3330. FILE *fp;
  3331. char *str;
  3332. int size;
  3333. {
  3334.   int instring = 0;
  3335.   char ch;
  3336.   int i;
  3337.  
  3338.   for (i = 0; i < size; ++i)
  3339.     {
  3340.       ch = str[i];
  3341.       if ((ch >= '\0' && ch < ' ') || (ch > '~'))
  3342.     {
  3343.       if (instring) fprintf(fp, "'\n");
  3344.       instring = 0;
  3345.       fprintf(fp, "\tDC.B %d\n", ch);
  3346.     }
  3347.       else
  3348.     {
  3349.       if (!instring) fprintf(fp, "\tDC.B '");
  3350.       instring = 1;
  3351.       if (ch == '\'')
  3352.         {
  3353.           fprintf(fp, "''");
  3354.         }
  3355.       else if (i > 0 && i % 60 == 0)
  3356.         {
  3357.           fprintf (fp, "%c'\n\tDC.B '", ch);
  3358.         }
  3359.       else
  3360.         {
  3361.           fprintf(fp, "%c", ch);
  3362.         }
  3363.     }
  3364.     }
  3365.   if (instring) fprintf(fp, "'\n");
  3366.   /* Ending NUL char is part of the string's "size",
  3367.      so doesn't need to be added. */
  3368. }
  3369.  
  3370. /* Print out a floating rtx in some useful way. */
  3371.  
  3372. #include "real.h"
  3373.  
  3374. output_mpw_float (fp, x)
  3375. FILE *fp;
  3376. rtx x;
  3377. {
  3378.   union { REAL_VALUE_TYPE f; int i[3]; } u;
  3379.   double d;
  3380.   float f;
  3381.  
  3382.   u.i[0] = CONST_DOUBLE_LOW (x);
  3383.   u.i[1] = CONST_DOUBLE_HIGH (x);
  3384.   u.i[2] = CONST_DOUBLE_TOP (x);
  3385.  
  3386.   switch (GET_MODE (x))
  3387.     {
  3388.     case SFmode:
  3389.       f = u.f;
  3390.       fprintf (fp, "\"%.9g\"", f);
  3391.       break;
  3392.     case DFmode:
  3393.       d = u.f;
  3394.       fprintf (fp, "\"%.20g\"", d);
  3395.       break;
  3396.     case XFmode:
  3397.       fprintf (fp, "\"%.30g\"", u.f);
  3398.       break;
  3399.     default:
  3400.       abort ();
  3401.     }
  3402. }
  3403.  
  3404. output_mpw_float_as_int (fp, x)
  3405. FILE *fp;
  3406. rtx x;
  3407. {
  3408.   union { REAL_VALUE_TYPE f; int i[3]; } u;
  3409.   union { float f; int i[1]; } u2;
  3410.  
  3411.   u.i[0] = CONST_DOUBLE_LOW (x);
  3412.   u.i[1] = CONST_DOUBLE_HIGH (x);
  3413.   u.i[2] = CONST_DOUBLE_TOP (x);
  3414.  
  3415.   u2.f = u.f;
  3416.  
  3417.   switch (GET_MODE (x))
  3418.     {
  3419.     case SFmode:
  3420.       fprintf (fp, "%d", u2.i[0]);
  3421.       break;
  3422.     case DFmode:
  3423.     case XFmode:
  3424.       fprintf (stderr, "Can't integerize a double or extended const!\n");
  3425.     default:
  3426.       abort ();
  3427.     }
  3428. }
  3429.  
  3430. /* Printing extended floats is a little tricky, since both the compiler and
  3431.    the target machines care about the 10/12-byte size. */
  3432.  
  3433. output_mpw_long_double (fp, x)
  3434. FILE *fp;
  3435. REAL_VALUE_TYPE x;
  3436. {
  3437.   union { REAL_VALUE_TYPE f; short s[6]; } u;
  3438.   int a = 0;
  3439.  
  3440.   u.f = x;
  3441.  
  3442.   fprintf (fp, "\tDC.W %d,", u.s[0]);
  3443.   if (TARGET_68881)
  3444.     {
  3445. #ifdef mc68881
  3446.       fprintf (fp, "%d,", u.s[1]);
  3447.       a = 1;
  3448. #else
  3449.       fprintf (fp, "0,");
  3450.       a = 0;
  3451. #endif
  3452.     }
  3453.   fprintf (fp, "%d,%d,%d,%d  ; %.30g\n",
  3454.        u.s[a+1], u.s[a+2], u.s[a+3], u.s[a+4], x);
  3455. }
  3456.  
  3457. /* We need to recognize all possible references to global data.  */
  3458.  
  3459. global_data_ref_p (addr)
  3460.     rtx addr;
  3461. {
  3462.   switch (GET_CODE (addr))
  3463.     {
  3464.     case SYMBOL_REF:
  3465.       {
  3466.     char *name = XSTR (addr, 0);
  3467.     tree ident = get_identifier(name);
  3468.     return ((int)IDENTIFIER_GLOBAL_VALUE (ident) != 0 && TREE_CODE(IDENTIFIER_GLOBAL_VALUE (ident)) == VAR_DECL);
  3469.       }
  3470.     case PLUS:
  3471.       return (global_data_ref_p (XEXP (addr, 0))
  3472.           || global_data_ref_p (XEXP (addr, 1)));
  3473.     case CONST:
  3474.       return global_data_ref_p (XEXP (addr, 0));
  3475.     default:
  3476.       return 0;
  3477.     }
  3478.   return 0;
  3479. }
  3480.  
  3481. /* Test a string to see if it matches any register names.  A few extra
  3482.    tests on individual chars to optimize - a more serious approach would
  3483.    involve a binary search tree or something.  Don't bother unless this
  3484.    can be proved to take significant time!  */
  3485.  
  3486. /* Names not in the regular reg_names list that the assembler knows about
  3487.    and will choke on if you attempt to use them as labels.  */
  3488.  
  3489. char *obscure_reg_names[] = {
  3490.   "sp",
  3491.   "a7",
  3492.   "za7",
  3493.   "pc",
  3494.   "zpc",
  3495.   "ccr",
  3496.   "sr",
  3497.   "usp",
  3498.   "sfc",
  3499.   "dfc",
  3500.   "cacr",
  3501.   "vbr",
  3502.   "caar",
  3503.   "msp",
  3504.   "isp",
  3505.   NULL };
  3506.   
  3507. mpw_register_name (str)
  3508. char *str;
  3509. {
  3510.   int i;
  3511.   extern char* reg_names[];
  3512.  
  3513.   if (str[0] == 'd' || str[0] == 'a' || str[0] == 'f')
  3514.     {
  3515.       for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
  3516.     if (strcmp (str, reg_names[i]) == 0)
  3517.       return 1;
  3518.     }
  3519.   if (str[0] == 'z' && (str[1] == 'd' || str[1] == 'a'))
  3520.     {
  3521.       for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
  3522.     if (strcmp (str, reg_names[i]+1) == 0)
  3523.       return 1;
  3524.     }
  3525.   /* There are other more obscure register names to test as well. */
  3526.   for (i = 0; obscure_reg_names[i]; ++i)
  3527.     if (strcmp (str, obscure_reg_names[i]) == 0)
  3528.       return 1;
  3529.   return 0;
  3530. }
  3531.  
  3532. char *
  3533. avoid_mpw_register_name (name)
  3534.      char *name;
  3535. {
  3536.   int typechar = ('0' <= name[0] && name[0] <= '9');
  3537.   char *newname = name;
  3538.  
  3539.   if (mpw_register_name (name + typechar))
  3540.     {
  3541.       /* should warn that name is being changed. */
  3542.       newname = (char *) xmalloc (strlen (name) + 2);
  3543.       strcpy (newname, name);
  3544.       strcat (newname, "_");
  3545.       warning ("`%s' is a register name; changing to `%s'",
  3546.            name + typechar, newname + typechar);
  3547.     }
  3548.   return newname;
  3549. }
  3550.  
  3551. /* Implementing -b requires saving up strings somewhere. */
  3552.  
  3553. char *lbls[1000];
  3554. char *strs[1000];
  3555. int lsix = 0;
  3556. int totlen = 0;
  3557.  
  3558. record_a_string(lbl, str)
  3559. char *lbl, *str;
  3560. {
  3561.   if (lsix >= 999) abort ();
  3562.   lbls[lsix] = lbl;
  3563.   strs[lsix] = str;
  3564.   totlen += strlen(str) + 1;
  3565.   totlen += (totlen & 1);   /* keeps it aligned */
  3566.   lsix++;
  3567.   fprintf(asm_out_file, "\tENTRY %s:CODE\n", lbl);
  3568. }
  3569.  
  3570. /* Functions compiled with -b have all their strings at the end of the
  3571.    function, preceded by a length field. */
  3572.  
  3573. /* Should scan a linked list of strings saved up for this function,
  3574.    not a fixed-size array. */
  3575.  
  3576. dump_local_strings (fp)
  3577. FILE *fp;
  3578. {
  3579.   int i;
  3580.  
  3581.   /* Only need the length word for debugging, otherwise skip it.
  3582.      We need it even if there are no local strings to dump. */ 
  3583.   if (TARGET_MACSBUG)
  3584.     fprintf (fp, "\tDC.W %d\n", totlen);
  3585.   for (i = 0; i < lsix; ++i)
  3586.     {
  3587.     /* String might be referred to from elsewhere within this file. */
  3588.     fprintf (fp, "\tENTRY ");
  3589.     assemble_name (fp, lbls[i]);
  3590.     fprintf (fp, ":CODE\n");
  3591.     assemble_name (fp, lbls[i]);
  3592.     output_mpw_string (fp, strs[i], strlen(strs[i]));
  3593.     fprintf(fp, "\tDC.B 0\n");
  3594.     fprintf (fp, "\tALIGN\n");
  3595.     }
  3596.   lsix = totlen = 0;
  3597.   /* Don't try to share these strings with anybody else. */
  3598.   clear_const_hash_table ();
  3599. }
  3600.  
  3601. /* This is all part of the scheme to produce the appropriate import
  3602.    and export declarations. */
  3603.  
  3604. struct impsym {
  3605.   char *name;
  3606.   int iscode;
  3607.   char *modulename;
  3608.   tree decl;
  3609.   struct impsym *next;
  3610. };
  3611.  
  3612. static struct impsym *implist = NULL;
  3613. static struct impsym *freeimps = NULL;
  3614.  
  3615. char *mnames[10];
  3616.  
  3617. int mtop = -1;
  3618.  
  3619. /* Do the allocations for this file. */
  3620.  
  3621. struct impsym *GetImpSym() {
  3622.   struct impsym *imp;
  3623.   
  3624.   if (freeimps) {
  3625.     imp = freeimps;
  3626.     freeimps = freeimps->next;
  3627.     return imp;
  3628.   } else {
  3629.     return (struct impsym *) xmalloc (sizeof (struct impsym));
  3630.   }
  3631. }
  3632.  
  3633. FreeImps() {
  3634.   struct impsym *imp = freeimps;
  3635.   if (imp) {
  3636.     while(imp->next) imp = imp->next;
  3637.     imp->next = implist;
  3638.   } else {
  3639.     freeimps = implist;
  3640.   }
  3641.   
  3642.   implist = NULL;
  3643. }
  3644.  
  3645. init_import_for_file()
  3646. {
  3647.   implist = NULL;
  3648.   mtop = 0;
  3649.   mnames[mtop] = "*";
  3650. }
  3651.  
  3652. char *copy_string();
  3653.  
  3654. start_module (name)
  3655. char *name;
  3656. {
  3657.   if (mtop >= 9)
  3658.     abort ();
  3659.   mnames[++mtop] = copy_string (name);
  3660.   if (TARGET_BSTR)
  3661.     clear_const_hash_table ();
  3662. }
  3663.  
  3664. finish_module (name)
  3665. char *name;
  3666. {
  3667.   if (name == NULL)
  3668.     abort ();
  3669.   if (strcmp(mnames[mtop], name) == 0)
  3670.     --mtop;
  3671.   if (mtop < 0)
  3672.     abort ();
  3673. }
  3674.  
  3675. match_name (name, impentry)
  3676. char *name;
  3677. struct impsym *impentry;
  3678. {  
  3679.   return ((strcmp (name, impentry->name) == 0)
  3680.       && (*(impentry->modulename) == '*'
  3681.           || strcmp (mnames[mtop], impentry->modulename) == 0));
  3682. }
  3683.  
  3684.  
  3685. import_decl (decl)
  3686. tree decl;
  3687. {
  3688.   rtx rtl;
  3689.  
  3690.   /*debug_tree(decl);*/
  3691.   switch (TREE_CODE (decl))
  3692.     {
  3693.     case FUNCTION_DECL:
  3694.       rtl = DECL_RTL (decl);
  3695.       if (rtl != 0
  3696.       && mtop >= 0
  3697.       && GET_CODE (rtl) == MEM
  3698.       && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF)
  3699.     {
  3700.       char *name = XSTR (XEXP (rtl, 0), 0);
  3701.       
  3702.       SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
  3703.       import_a_function (name, decl);
  3704.     }
  3705.       break;
  3706.     case VAR_DECL:
  3707.       rtl = DECL_RTL (decl);
  3708.       if (rtl != 0
  3709.       && mtop >= 0
  3710.       && GET_CODE (rtl) == MEM
  3711.       && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF)
  3712.     {
  3713.       char *name = XSTR (XEXP (rtl, 0), 0);
  3714.       
  3715.       SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 0;
  3716.       import_a_variable (name, decl);
  3717.     }
  3718.       break;
  3719.     default:
  3720.       break;
  3721.     }
  3722. }
  3723.  
  3724. /* Import a data name.  This just records, actual output doesn't occur
  3725.    until all the names in a module have been seen.  If the name is defined
  3726.    in this module, no import will be issued.  If it has already been seen
  3727.    at all, don't even bother to record it. */
  3728.  
  3729. import_a_variable(name, decl)
  3730. char *name;
  3731. tree decl;
  3732. {
  3733.   struct impsym *tmp;
  3734.  
  3735.   if (name == NULL) return;
  3736.   
  3737.   tmp = implist;
  3738.   while(tmp) {
  3739.     if (!strcmp(name, tmp->name)) return;
  3740.     tmp = tmp->next;
  3741.   }
  3742.   
  3743.   /* Don't import direct function definitions */
  3744.   if (name[0] == ';') return;
  3745.   if (name[1] == ';') return;
  3746.   for (tmp = implist; tmp != NULL; tmp = tmp->next)
  3747.     if (match_name (name, tmp))
  3748.       return;
  3749.   tmp = GetImpSym();
  3750.   tmp->name = copy_string(name);
  3751.   tmp->iscode = 0;
  3752.   tmp->modulename = mnames[mtop];
  3753.   tmp->decl = decl;
  3754.   tmp->next = implist;
  3755.   implist = tmp;
  3756. }
  3757.  
  3758. /* Import a code name, but ignore if it's already occurred. */
  3759.  
  3760. import_a_function(name, decl)
  3761. char *name;
  3762. tree decl;
  3763. {
  3764.   struct impsym *tmp;
  3765.  
  3766.   if (name == NULL) return;
  3767.   
  3768.   tmp = implist;
  3769.   while(tmp) {
  3770.     if (!strcmp(name, tmp->name)) return;
  3771.     tmp = tmp->next;
  3772.   }
  3773.  
  3774.   /* Don't import direct function definitions */
  3775.   if (name[0] == ';') return;
  3776.   if (name[1] == ';') return;
  3777.   for (tmp = implist; tmp != NULL; tmp = tmp->next)
  3778.     if (match_name (name, tmp))
  3779.       return;
  3780.   tmp = GetImpSym();
  3781.   tmp->name = copy_string(name);
  3782.   tmp->iscode = 1;
  3783.   tmp->modulename = mnames[mtop];
  3784.   tmp->next = implist;
  3785.   tmp->decl = decl;
  3786.   implist = tmp;
  3787. }
  3788.  
  3789. /* Define or export a data name, or more accurately erase its importation. */
  3790.  
  3791. void
  3792. define_a_variable (name)
  3793. char *name;
  3794. {
  3795.   struct impsym *tmp;
  3796.  
  3797.   for (tmp = implist; tmp; tmp = tmp->next)
  3798.     if (match_name (name, tmp))
  3799.       {
  3800.     /*tmp->name = "";*/ /*Why do we do this?*/
  3801.     return;
  3802.       }
  3803. }
  3804.  
  3805. void
  3806. define_a_function (name)
  3807. char *name;
  3808. {
  3809.   struct impsym *tmp;
  3810.  
  3811.   for (tmp = implist; tmp; tmp = tmp->next)
  3812.     if (match_name (name, tmp))
  3813.       {
  3814.     tmp->name = "";
  3815.     return;
  3816.       }
  3817. }
  3818. #if 0
  3819. /* Import every symbol in the named module into the current module. */
  3820.  
  3821. void
  3822. add_inline_imports (inlined)
  3823. char *inlined;
  3824. {
  3825.   struct impsym *tmp;
  3826.  
  3827.   for (tmp = implist; tmp; tmp = tmp->next)
  3828.     if (strcmp(inlined, tmp->modulename) == 0)
  3829.       {
  3830.     import_a_function (tmp->name);
  3831.       }
  3832. }
  3833. #endif 
  3834. /* Any symbol undefined by a function must be imported (this makes for lots
  3835.    of imports sometimes).  Must be careful about code vs data symbols.
  3836.    To save some asm instructions, all the data symbols are dumped first.
  3837.   (Note that the loops are written such that the output is correct even
  3838.    if the repn changes.)  */
  3839.  
  3840. void
  3841. import_undefined(file)
  3842. FILE *file;
  3843. {
  3844.   struct impsym *tmp;
  3845.  
  3846.  /* data_section ();*/
  3847.   for (tmp = implist; tmp; tmp = tmp->next)
  3848.     {
  3849.       if (strlen (tmp->name) > 0
  3850.       && (1 /* strcmp (mnames[mtop], tmp->modulename) == 0
  3851.           || (*(tmp->modulename) == '*' && (tmp->name)[0] == 'L') */)
  3852.       && tmp->iscode == 0)
  3853.     {
  3854.       ASM_IMPORT_NAME (file, tmp->name, 1);
  3855.       /*debug_tree(tmp->decl);*/
  3856.     }
  3857.     }
  3858.  /* text_section ();*/
  3859.   for (tmp = implist; tmp; tmp = tmp->next)
  3860.     {
  3861.       if (strlen (tmp->name) > 0
  3862.       && (1 /* strcmp (mnames[mtop], tmp->modulename) == 0
  3863.           || (*(tmp->modulename) == '*' && (tmp->name)[0] == 'L') */)
  3864.       && tmp->iscode == 1)
  3865.     {
  3866.      /* if (TREE_USED(tmp->decl))*/ ASM_IMPORT_NAME (file, tmp->name, 0);
  3867.       /*if (!strcmp(tmp->name, "read_rtx"))
  3868.         debug_tree(tmp->decl);*/
  3869.     }
  3870.     }
  3871. }
  3872.  
  3873. void
  3874. debug_implist()
  3875. {
  3876.   struct impsym *tmp;
  3877.  
  3878.   for (tmp = implist; tmp; tmp = tmp->next)
  3879.     fprintf (stderr, "\"%s\" in module \"%s\"\n", tmp->name, tmp->modulename);
  3880. }
  3881.  
  3882. rtx
  3883. function_arg (cum, mode, named)
  3884.      CUMULATIVE_ARGS *cum;
  3885.      enum machine_mode mode;
  3886.      int named;
  3887. {
  3888.   if (cum->p == NULL || cum->p->parameter_regno[cum->count] < 0)
  3889.     return 0;
  3890.  
  3891.   return gen_rtx (REG, mode, cum->p->parameter_regno[cum->count]);
  3892. }
  3893.  
  3894.       /* Normal functions return their result in d0 or fp0. */
  3895.       
  3896. rtx
  3897. function_value (amode, decl)
  3898.      tree amode, decl;
  3899. {
  3900.   /* See if this function returns its result in a specific register. */
  3901.   if (decl != NULL &&
  3902.       TYPE_CALL_CONVENTION (TREE_TYPE (decl)) != NULL &&
  3903.       TYPE_CALL_CONVENTION (TREE_TYPE (decl))->return_regno >= 0)
  3904.       /* Create and return an rtx for that register. */
  3905.       return (gen_rtx (REG, TYPE_MODE (amode),
  3906.                 TYPE_CALL_CONVENTION (TREE_TYPE (decl))->return_regno));
  3907.   else if (TARGET_68881 && (GET_MODE_CLASS (TYPE_MODE (amode)) == MODE_FLOAT))
  3908.     return gen_rtx (REG, TYPE_MODE (amode), 16);
  3909.   else
  3910.     return gen_rtx (REG, TYPE_MODE (amode), 0);
  3911. }
  3912.  
  3913. rtx
  3914. function_outgoing_value (tree amode, tree decl)
  3915. {
  3916.   int i;
  3917.  
  3918.   /* See if this is a pascal-declared function. */
  3919.   if (decl != NULL && TREE_PASCAL (decl))
  3920.     /* Return an rtx that will be patched with a correct frame
  3921.        location later. */
  3922.     return gen_rtx (MEM, TYPE_MODE (amode),
  3923.             gen_rtx (PLUS, Pmode, frame_pointer_rtx,
  3924.                  gen_rtx (CONST_INT, VOIDmode, 12345)));
  3925.   /* Otherwise do it in the same way as the caller does. */
  3926.   return function_value (amode, decl);
  3927. }
  3928.  
  3929.  
  3930. static struct obstack thestack;
  3931. static struct obstack *paramob;
  3932.  
  3933. static int c;
  3934.  
  3935. static struct call_convention *thelast = NULL;
  3936.  
  3937. /* Isn't this defined elsewhere too? */
  3938.  
  3939. /* Recognize exactly those registers that are allowed in parameter pragmas. */
  3940.  
  3941. parsereg(str)
  3942. char *str;
  3943. {
  3944.   char c;
  3945.  
  3946.   if ((c = *str++) != '_') return -1;
  3947.   if ((c = *str++) != '_') return -1;
  3948.   c = *str++;
  3949.   if (c == 'a' || c == 'A') {
  3950.     c = *str++;
  3951.     switch (c) {
  3952.     case '0':
  3953.       return 8;
  3954.     case '1':
  3955.       return 9;
  3956.     default:
  3957.       return -1;
  3958.     }
  3959.   }
  3960.   if (c == 'd' || c == 'D') {
  3961.     c = *str++;
  3962.     switch (c) {
  3963.     case '0':
  3964.       return (0);
  3965.     case '1':
  3966.       return (1);
  3967.     case '2':
  3968.       return (2);
  3969.     default:
  3970.       return -1;
  3971.     }
  3972.   }
  3973. }
  3974.  
  3975.