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

  1. /* Subroutines for insn-output.c for Motorola 68000 family.
  2.    Copyright (C) 1987, 1993, 1994 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 "config.h"
  24. #include "rtl.h"
  25. #include "regs.h"
  26. #include "hard-reg-set.h"
  27. #include "real.h"
  28. #include "insn-config.h"
  29. #include "conditions.h"
  30. #include "insn-flags.h"
  31. #include "output.h"
  32. #include "insn-attr.h"
  33.  
  34. /* Needed for use_return_insn.  */
  35. #include "flags.h"
  36.  
  37. #ifdef SUPPORT_SUN_FPA
  38.  
  39. /* Index into this array by (register number >> 3) to find the
  40.    smallest class which contains that register.  */
  41. enum reg_class regno_reg_class[]
  42.   = { DATA_REGS, ADDR_REGS, FP_REGS,
  43.       LO_FPA_REGS, LO_FPA_REGS, FPA_REGS, FPA_REGS };
  44.  
  45. #endif /* defined SUPPORT_SUN_FPA */
  46.  
  47. /* This flag is used to communicate between movhi and ASM_OUTPUT_CASE_END,
  48.    if SGS_SWITCH_TABLE.  */
  49. int switch_table_difference_label_flag;
  50.  
  51. static rtx find_addr_reg ();
  52. rtx legitimize_pic_address ();
  53.  
  54.  
  55. /* Emit a (use pic_offset_table_rtx) if we used PIC relocation in the 
  56.    function at any time during the compilation process.  In the future 
  57.    we should try and eliminate the USE if we can easily determine that 
  58.    all PIC references were deleted from the current function.  That would 
  59.    save an address register */
  60.    
  61. void
  62. finalize_pic ()
  63. {
  64.   if (flag_pic && (flag_pic < 3) && current_function_uses_pic_offset_table)
  65.     emit_insn (gen_rtx (USE, VOIDmode, pic_offset_table_rtx));
  66. }
  67.  
  68.  
  69. /* This function generates the assembly code for function entry.
  70.    STREAM is a stdio stream to output the code to.
  71.    SIZE is an int: how many units of temporary storage to allocate.
  72.    Refer to the array `regs_ever_live' to determine which registers
  73.    to save; `regs_ever_live[I]' is nonzero if register number I
  74.    is ever used in the function.  This function is responsible for
  75.    knowing which registers should not be saved even if used.  */
  76.  
  77.  
  78. /* Note that the order of the bit mask for fmovem is the opposite
  79.    of the order for movem!  */
  80.  
  81.  
  82. void
  83. output_function_prologue (stream, size)
  84.      FILE *stream;
  85.      int size;
  86. {
  87.   register int regno;
  88.   register int mask = 0;
  89.   int num_saved_regs = 0;
  90.   extern char call_used_regs[];
  91.   int fsize = (size + 3) & -4;
  92.   
  93.  
  94.   if (frame_pointer_needed)
  95.     {
  96.       if (fsize == 0 && TARGET_68040)
  97.     {
  98.     /* on the 68040, pea + move is faster than link.w 0 */
  99. #ifdef MOTOROLA
  100.       asm_fprintf (stream, "\tpea (%s)\n\tmove.l %s,%s\n",
  101.            reg_names[FRAME_POINTER_REGNUM], reg_names[STACK_POINTER_REGNUM],
  102.            reg_names[FRAME_POINTER_REGNUM]);
  103. #else
  104.       asm_fprintf (stream, "\tpea %s@\n\tmovel %s,%s\n",
  105.            reg_names[FRAME_POINTER_REGNUM], reg_names[STACK_POINTER_REGNUM],
  106.            reg_names[FRAME_POINTER_REGNUM]);
  107. #endif
  108.     }
  109.       else if (fsize < 0x8000)
  110.     {
  111. #ifdef MOTOROLA
  112.       asm_fprintf (stream, "\tlink.w %s,%0I%d\n",
  113.                reg_names[FRAME_POINTER_REGNUM], -fsize);
  114. #else
  115.       asm_fprintf (stream, "\tlink %s,%0I%d\n",
  116.                reg_names[FRAME_POINTER_REGNUM], -fsize);
  117. #endif
  118.     }
  119.       else if (TARGET_68020)
  120.     {
  121. #ifdef MOTOROLA
  122.       asm_fprintf (stream, "\tlink.l %s,%0I%d\n",
  123.                reg_names[FRAME_POINTER_REGNUM], -fsize);
  124. #else
  125.       asm_fprintf (stream, "\tlink %s,%0I%d\n",
  126.                reg_names[FRAME_POINTER_REGNUM], -fsize);
  127. #endif
  128.     }
  129.       else
  130.     {
  131.       /* Adding negative number is faster on the 68040.  */
  132. #ifdef MOTOROLA
  133.       asm_fprintf (stream, "\tlink.w %s,%0I0\n\tadd.l %0I%d,%Rsp\n",
  134.                reg_names[FRAME_POINTER_REGNUM], -fsize);
  135. #else
  136.       asm_fprintf (stream, "\tlink %s,%0I0\n\taddl %0I%d,%Rsp\n",
  137.                reg_names[FRAME_POINTER_REGNUM], -fsize);
  138. #endif
  139.     }
  140.     }
  141.   else if (fsize)
  142.     {
  143.       /* Adding negative number is faster on the 68040.  */
  144.  
  145.         if (fsize + 4 < 0x8000)
  146.     {
  147.     /* asm_fprintf() cannot handle %. */
  148. #ifdef MOTOROLA
  149.       asm_fprintf (stream, "\tadd.w %0I%d,%Rsp\n", - (fsize + 4));
  150. #else
  151.       asm_fprintf (stream, "\taddw %0I%d,%Rsp\n", - (fsize + 4));
  152. #endif
  153.     }
  154.       else
  155.     {
  156.     /* asm_fprintf() cannot handle %. */
  157. #ifdef MOTOROLA
  158.       asm_fprintf (stream, "\tadd.l %0I%d,%Rsp\n", - (fsize + 4));
  159. #else
  160.       asm_fprintf (stream, "\taddl %0I%d,%Rsp\n", - (fsize + 4));
  161. #endif
  162.     }
  163.     }
  164. #ifdef SUPPORT_SUN_FPA
  165.   for (regno = 24; regno < 56; regno++)
  166.     if (regs_ever_live[regno] && ! call_used_regs[regno])
  167.       {
  168. #ifdef MOTOROLA
  169.     asm_fprintf (stream, "\tfpmovd %s,-(%Rsp)\n",
  170.              reg_names[regno]);
  171. #else
  172.     asm_fprintf (stream, "\tfpmoved %s,%Rsp@-\n",
  173.              reg_names[regno]);
  174. #endif
  175.       }
  176. #endif
  177.   for (regno = 16; regno < 24; regno++)
  178.     if (regs_ever_live[regno] && ! call_used_regs[regno])
  179.        mask |= 1 << (regno - 16);
  180.   if ((mask & 0xff) != 0)
  181.     {
  182. #ifdef MOTOROLA
  183.       asm_fprintf (stream, "\tfmovm %0I0x%x,-(%Rsp)\n", mask & 0xff);
  184. #else
  185.       asm_fprintf (stream, "\tfmovem %0I0x%x,%Rsp@-\n", mask & 0xff);
  186. #endif
  187.     }
  188.   mask = 0;
  189.   for (regno = 0; regno < 16; regno++)
  190.     if (regs_ever_live[regno] && ! call_used_regs[regno])
  191.       {
  192.         mask |= 1 << (15 - regno);
  193.         num_saved_regs++;
  194.       }
  195.   if (frame_pointer_needed)
  196.     {
  197.       mask &= ~ (1 << (15 - FRAME_POINTER_REGNUM));
  198.       num_saved_regs--;
  199.     }
  200. #ifdef PROLOGUE_EXTRA_SAVE
  201.   PROLOGUE_EXTRA_SAVE (mask);
  202. #endif
  203.  
  204. #if NEED_PROBE
  205.   fprintf (stream, "\ttstl sp@(%d)\n", NEED_PROBE - num_saved_regs * 4);
  206. #endif
  207.  
  208.   if (num_saved_regs <= 2)
  209.     {
  210.       /* Store each separately in the same order moveml uses.
  211.          Using two movel instructions instead of a single moveml
  212.          is about 15% faster for the 68020 and 68030 at no expense
  213.          in code size */
  214.  
  215.       int i;
  216.  
  217.       /* Undo the work from above. */
  218.       for (i = 0; i< 16; i++)
  219.         if (mask & (1 << i))
  220.           asm_fprintf (stream,
  221. #ifdef MOTOROLA
  222.                "\t%Omove.l %s,-(%Rsp)\n",
  223. #else
  224.                "\tmovel %s,%Rsp@-\n",
  225. #endif
  226.                reg_names[15 - i]);
  227.     }
  228.   else if (mask)
  229.     {
  230. #ifdef MOTOROLA
  231.       asm_fprintf (stream, "\tmovm.l %0I0x%x,-(%Rsp)\n", mask);
  232. #else
  233.       asm_fprintf (stream, "\tmoveml %0I0x%x,%Rsp@-\n", mask);
  234. #endif
  235.     }
  236.   if (flag_pic && (flag_pic < 3) && current_function_uses_pic_offset_table)
  237.     {
  238. #ifdef MOTOROLA
  239.       asm_fprintf (stream, "\t%Olea (%Rpc, %U_GLOBAL_OFFSET_TABLE_@GOTPC), %s\n",
  240.            reg_names[PIC_OFFSET_TABLE_REGNUM]);
  241. #else
  242.       asm_fprintf (stream, "\tmovel %0I__GLOBAL_OFFSET_TABLE_, %s\n",
  243.            reg_names[PIC_OFFSET_TABLE_REGNUM]);
  244.       asm_fprintf (stream, "\tlea %Rpc@(0,%s:l),%s\n",
  245.            reg_names[PIC_OFFSET_TABLE_REGNUM],
  246.            reg_names[PIC_OFFSET_TABLE_REGNUM]);
  247. #endif
  248.     }
  249. }
  250.  
  251. /* Return true if this function's epilogue can be output as RTL.  */
  252.  
  253. int
  254. use_return_insn ()
  255. {
  256.   int regno;
  257.  
  258.   if (!reload_completed || frame_pointer_needed || get_frame_size () != 0)
  259.     return 0;
  260.   
  261.   /* Copied from output_function_epilogue ().  We should probably create a
  262.      separate layout routine to perform the common work.  */
  263.   
  264.   for (regno = 0 ; regno < FIRST_PSEUDO_REGISTER ; regno++)
  265.     if (regs_ever_live[regno] && ! call_used_regs[regno])
  266.       return 0;
  267.   
  268.   return 1;
  269. }
  270.  
  271. /* This function generates the assembly code for function exit,
  272.    on machines that need it.  Args are same as for FUNCTION_PROLOGUE.
  273.  
  274.    The function epilogue should not depend on the current stack pointer!
  275.    It should use the frame pointer only, if there is a frame pointer.
  276.    This is mandatory because of alloca; we also take advantage of it to
  277.    omit stack adjustments before returning.  */
  278.  
  279. void
  280. output_function_epilogue (stream, size)
  281.      FILE *stream;
  282.      int size;
  283. {
  284.   register int regno;
  285.   register int mask, fmask;
  286.   register int nregs;
  287.   int offset, foffset, fpoffset;
  288.   extern char call_used_regs[];
  289.   int fsize = (size + 3) & -4;
  290.   int big = 0;
  291.   rtx insn = get_last_insn ();
  292.   
  293.   /* If the last insn was a BARRIER, we don't have to write any code.  */
  294.   if (GET_CODE (insn) == NOTE)
  295.     insn = prev_nonnote_insn (insn);
  296.   if (insn && GET_CODE (insn) == BARRIER)
  297.     {
  298.       /* Output just a no-op so that debuggers don't get confused
  299.      about which function the pc is in at this address.  */
  300.       asm_fprintf (stream, "\tnop\n");
  301. #ifdef EPILOGUE_EXTRA_BARRIER_KLUDGE
  302.       EPILOGUE_EXTRA_BARRIER_KLUDGE(stream);
  303. #endif
  304.       return;
  305.     }
  306.  
  307. #ifdef FUNCTION_EXTRA_EPILOGUE
  308.   FUNCTION_EXTRA_EPILOGUE (stream, size);
  309. #endif
  310.   nregs = 0;  fmask = 0; fpoffset = 0;
  311. #ifdef SUPPORT_SUN_FPA
  312.   for (regno = 24 ; regno < 56 ; regno++)
  313.     if (regs_ever_live[regno] && ! call_used_regs[regno])
  314.       nregs++;
  315.   fpoffset = nregs * 8;
  316. #endif
  317.   nregs = 0;
  318.   for (regno = 16; regno < 24; regno++)
  319.     if (regs_ever_live[regno] && ! call_used_regs[regno])
  320.       {
  321.         nregs++;
  322.     fmask |= 1 << (23 - regno);
  323.       }
  324.   foffset = fpoffset + nregs * 12;
  325.   nregs = 0;  mask = 0;
  326.   if (frame_pointer_needed)
  327.     regs_ever_live[FRAME_POINTER_REGNUM] = 0;
  328.   for (regno = 0; regno < 16; regno++)
  329.     if (regs_ever_live[regno] && ! call_used_regs[regno])
  330.       {
  331.         nregs++;
  332.     mask |= 1 << regno;
  333.       }
  334. #ifdef EPILOGUE_EXTRA_RESTORE
  335.   EPILOGUE_EXTRA_RESTORE(mask, nregs);
  336. #endif
  337.   offset = foffset + nregs * 4;
  338.   if (offset + fsize >= 0x8000
  339.       && frame_pointer_needed
  340.       && (mask || fmask || fpoffset))
  341.     {
  342. #ifdef MOTOROLA
  343.       asm_fprintf (stream, "\t%Omove.l %0I%d,%Ra0\n", -fsize);
  344. #else
  345.       asm_fprintf (stream, "\tmovel %0I%d,%Ra0\n", -fsize);
  346. #endif
  347.       fsize = 0, big = 1;
  348.     }
  349.   if (nregs <= 2)
  350.     {
  351.       /* Restore each separately in the same order moveml does.
  352.          Using two movel instructions instead of a single moveml
  353.          is about 15% faster for the 68020 and 68030 at no expense
  354.          in code size. */
  355.  
  356.       int i;
  357.  
  358.       /* Undo the work from above. */
  359.       for (i = 0; i< 16; i++)
  360.         if (mask & (1 << i))
  361.           {
  362.             if (big)
  363.           {
  364. #ifdef MOTOROLA
  365.         asm_fprintf (stream, "\t%Omove.l -%d(%s,%Ra0.l),%s\n",
  366.                  offset + fsize,
  367.                  reg_names[FRAME_POINTER_REGNUM],
  368.                  reg_names[i]);
  369. #else
  370.         asm_fprintf (stream, "\tmovel %s@(-%d,%Ra0:l),%s\n",
  371.                  reg_names[FRAME_POINTER_REGNUM],
  372.                  offset + fsize, reg_names[i]);
  373. #endif
  374.           }
  375.             else if (! frame_pointer_needed)
  376.           {
  377. #ifdef MOTOROLA
  378.         asm_fprintf (stream, "\t%Omove.l (%Rsp)+,%s\n",
  379.                  reg_names[i]);
  380. #else
  381.         asm_fprintf (stream, "\tmovel %Rsp@+,%s\n",
  382.                  reg_names[i]);
  383. #endif
  384.           }
  385.             else
  386.           {
  387. #ifdef MOTOROLA
  388.         asm_fprintf (stream, "\t%Omove.l -%d(%s),%s\n",
  389.                  offset + fsize,
  390.                  reg_names[FRAME_POINTER_REGNUM],
  391.                  reg_names[i]);
  392. #else
  393.         asm_fprintf (stream, "\tmovel %s@(-%d),%s\n",
  394.                  reg_names[FRAME_POINTER_REGNUM],
  395.                  offset + fsize, reg_names[i]);
  396. #endif
  397.           }
  398.             offset = offset - 4;
  399.           }
  400.     }
  401.   else if (mask)
  402.     {
  403.       if (big)
  404.     {
  405. #ifdef MOTOROLA
  406.       asm_fprintf (stream, "\tmovm.l -%d(%s,%Ra0.l),%0I0x%x\n",
  407.                offset + fsize,
  408.                reg_names[FRAME_POINTER_REGNUM],
  409.                mask);
  410. #else
  411.       asm_fprintf (stream, "\tmoveml %s@(-%d,%Ra0:l),%0I0x%x\n",
  412.                reg_names[FRAME_POINTER_REGNUM],
  413.                offset + fsize, mask);
  414. #endif
  415.     }
  416.       else if (! frame_pointer_needed)
  417.     {
  418. #ifdef MOTOROLA
  419.       asm_fprintf (stream, "\tmovm.l (%Rsp)+,%0I0x%x\n", mask);
  420. #else
  421.       asm_fprintf (stream, "\tmoveml %Rsp@+,%0I0x%x\n", mask);
  422. #endif
  423.     }
  424.       else
  425.     {
  426. #ifdef MOTOROLA
  427.       asm_fprintf (stream, "\tmovm.l -%d(%s),%0I0x%x\n",
  428.                offset + fsize,
  429.                reg_names[FRAME_POINTER_REGNUM],
  430.                mask);
  431. #else
  432.       asm_fprintf (stream, "\tmoveml %s@(-%d),%0I0x%x\n",
  433.                reg_names[FRAME_POINTER_REGNUM],
  434.                offset + fsize, mask);
  435. #endif
  436.     }
  437.     }
  438.   if (fmask)
  439.     {
  440.       if (big)
  441.     {
  442. #ifdef MOTOROLA
  443.       asm_fprintf (stream, "\tfmovm -%d(%s,%Ra0.l),%0I0x%x\n",
  444.                foffset + fsize,
  445.                reg_names[FRAME_POINTER_REGNUM],
  446.                fmask);
  447. #else
  448.       asm_fprintf (stream, "\tfmovem %s@(-%d,%Ra0:l),%0I0x%x\n",
  449.                reg_names[FRAME_POINTER_REGNUM],
  450.                foffset + fsize, fmask);
  451. #endif
  452.     }
  453.       else if (! frame_pointer_needed)
  454.     {
  455. #ifdef MOTOROLA
  456.       asm_fprintf (stream, "\tfmovm (%Rsp)+,%0I0x%x\n", fmask);
  457. #else
  458.       asm_fprintf (stream, "\tfmovem %Rsp@+,%0I0x%x\n", fmask);
  459. #endif
  460.     }
  461.       else
  462.     {
  463. #ifdef MOTOROLA
  464.       asm_fprintf (stream, "\tfmovm -%d(%s),%0I0x%x\n",
  465.                foffset + fsize,
  466.                reg_names[FRAME_POINTER_REGNUM],
  467.                fmask);
  468. #else
  469.       asm_fprintf (stream, "\tfmovem %s@(-%d),%0I0x%x\n",
  470.                reg_names[FRAME_POINTER_REGNUM],
  471.                foffset + fsize, fmask);
  472. #endif
  473.     }
  474.     }
  475.   if (fpoffset != 0)
  476.     for (regno = 55; regno >= 24; regno--)
  477.       if (regs_ever_live[regno] && ! call_used_regs[regno])
  478.         {
  479.       if (big)
  480.         {
  481. #ifdef MOTOROLA
  482.           asm_fprintf (stream, "\tfpmovd -%d(%s,%Ra0.l), %s\n",
  483.                fpoffset + fsize,
  484.                reg_names[FRAME_POINTER_REGNUM],
  485.                reg_names[regno]);
  486. #else
  487.           asm_fprintf (stream, "\tfpmoved %s@(-%d,%Ra0:l), %s\n",
  488.                reg_names[FRAME_POINTER_REGNUM],
  489.                fpoffset + fsize, reg_names[regno]);
  490. #endif
  491.         }
  492.       else if (! frame_pointer_needed)
  493.         {
  494. #ifdef MOTOROLA
  495.           asm_fprintf (stream, "\tfpmovd (%Rsp)+,%s\n",
  496.                reg_names[regno]);
  497. #else
  498.           asm_fprintf (stream, "\tfpmoved %Rsp@+, %s\n",
  499.                reg_names[regno]);
  500. #endif
  501.         }
  502.       else
  503.         {
  504. #ifdef MOTOROLA
  505.           asm_fprintf (stream, "\tfpmovd -%d(%s), %s\n",
  506.                fpoffset + fsize,
  507.                reg_names[FRAME_POINTER_REGNUM],
  508.                reg_names[regno]);
  509. #else
  510.           asm_fprintf (stream, "\tfpmoved %s@(-%d), %s\n",
  511.                reg_names[FRAME_POINTER_REGNUM],
  512.                fpoffset + fsize, reg_names[regno]);
  513. #endif
  514.         }
  515.       fpoffset -= 8;
  516.     }
  517.   if (frame_pointer_needed)
  518.     fprintf (stream, "\tunlk %s\n",
  519.          reg_names[FRAME_POINTER_REGNUM]);
  520.   else if (fsize)
  521.     {
  522.       if (fsize + 4 < 0x8000)
  523.     {
  524.     /* asm_fprintf() cannot handle %. */
  525. #ifdef MOTOROLA
  526.       asm_fprintf (stream, "\tadd.w %0I%d,%Rsp\n", fsize + 4);
  527. #else
  528.       asm_fprintf (stream, "\taddw %0I%d,%Rsp\n", fsize + 4);
  529. #endif
  530.     }
  531.       else
  532.     {
  533.     /* asm_fprintf() cannot handle %. */
  534. #ifdef MOTOROLA
  535.       asm_fprintf (stream, "\tadd.l %0I%d,%Rsp\n", fsize + 4);
  536. #else
  537.       asm_fprintf (stream, "\taddl %0I%d,%Rsp\n", fsize + 4);
  538. #endif
  539.     }
  540.     }
  541. #ifdef EPILOGUE_EXTRA_TEST
  542.   EPILOGUE_EXTRA_TEST(stream);
  543. #endif
  544.   if (current_function_pops_args)
  545.     asm_fprintf (stream, "\trtd %0I%d\n", current_function_pops_args);
  546.   else
  547.     fprintf (stream, "\trts\n");
  548. }
  549.  
  550. /* Similar to general_operand, but exclude stack_pointer_rtx.  */
  551.  
  552. int
  553. not_sp_operand (op, mode)
  554.      register rtx op;
  555.      enum machine_mode mode;
  556. {
  557.   return op != stack_pointer_rtx && general_operand (op, mode);
  558. }
  559.  
  560. /* Return TRUE if X is a valid comparison operator for the dbcc 
  561.    instruction.  
  562.  
  563.    Note it rejects floating point comparison operators.
  564.    (In the future we could use Fdbcc).
  565.  
  566.    It also rejects some comparisons when CC_NO_OVERFLOW is set.  */
  567.    
  568. int
  569. valid_dbcc_comparison_p (x, mode)
  570.      rtx x;
  571.      enum machine_mode mode;
  572. {
  573.   /* We could add support for these in the future */
  574.   if (cc_prev_status.flags & CC_IN_68881)
  575.     return 0;
  576.  
  577.   switch (GET_CODE (x))
  578.     {
  579.  
  580.       case EQ: case NE: case GTU: case LTU:
  581.       case GEU: case LEU:
  582.         return 1;
  583.  
  584.       /* Reject some when CC_NO_OVERFLOW is set.  This may be over
  585.          conservative */
  586.       case GT: case LT: case GE: case LE:
  587.         return ! (cc_prev_status.flags & CC_NO_OVERFLOW);
  588.       default:
  589.         return 0;
  590.     }
  591. }
  592.  
  593. /* Output a dbCC; jCC sequence.  Note we do not handle the 
  594.    floating point version of this sequence (Fdbcc).  We also
  595.    do not handle alternative conditions when CC_NO_OVERFLOW is
  596.    set.  It is assumed that valid_dbcc_comparison_p will kick
  597.    those out before we get here.  */
  598.  
  599. output_dbcc_and_branch (operands)
  600.      rtx *operands;
  601. {
  602.  
  603.   switch (GET_CODE (operands[3]))
  604.     {
  605.       case EQ:
  606. #ifdef MOTOROLA
  607.         output_asm_insn ("dbeq %0,%l1\n\tjbeq %l2", operands);
  608. #else
  609.         output_asm_insn ("dbeq %0,%l1\n\tjeq %l2", operands);
  610. #endif
  611.         break;
  612.  
  613.       case NE:
  614. #ifdef MOTOROLA
  615.         output_asm_insn ("dbne %0,%l1\n\tjbne %l2", operands);
  616. #else
  617.         output_asm_insn ("dbne %0,%l1\n\tjne %l2", operands);
  618. #endif
  619.         break;
  620.  
  621.       case GT:
  622. #ifdef MOTOROLA
  623.         output_asm_insn ("dbgt %0,%l1\n\tjbgt %l2", operands);
  624. #else
  625.         output_asm_insn ("dbgt %0,%l1\n\tjgt %l2", operands);
  626. #endif
  627.         break;
  628.  
  629.       case GTU:
  630. #ifdef MOTOROLA
  631.         output_asm_insn ("dbhi %0,%l1\n\tjbhi %l2", operands);
  632. #else
  633.         output_asm_insn ("dbhi %0,%l1\n\tjhi %l2", operands);
  634. #endif
  635.         break;
  636.  
  637.       case LT:
  638. #ifdef MOTOROLA
  639.         output_asm_insn ("dblt %0,%l1\n\tjblt %l2", operands);
  640. #else
  641.         output_asm_insn ("dblt %0,%l1\n\tjlt %l2", operands);
  642. #endif
  643.         break;
  644.  
  645.       case LTU:
  646. #ifdef MOTOROLA
  647.         output_asm_insn ("dbcs %0,%l1\n\tjbcs %l2", operands);
  648. #else
  649.         output_asm_insn ("dbcs %0,%l1\n\tjcs %l2", operands);
  650. #endif
  651.         break;
  652.  
  653.       case GE:
  654. #ifdef MOTOROLA
  655.         output_asm_insn ("dbge %0,%l1\n\tjbge %l2", operands);
  656. #else
  657.         output_asm_insn ("dbge %0,%l1\n\tjge %l2", operands);
  658. #endif
  659.         break;
  660.  
  661.       case GEU:
  662. #ifdef MOTOROLA
  663.         output_asm_insn ("dbcc %0,%l1\n\tjbcc %l2", operands);
  664. #else
  665.         output_asm_insn ("dbcc %0,%l1\n\tjcc %l2", operands);
  666. #endif
  667.         break;
  668.  
  669.       case LE:
  670. #ifdef MOTOROLA
  671.         output_asm_insn ("dble %0,%l1\n\tjble %l2", operands);
  672. #else
  673.         output_asm_insn ("dble %0,%l1\n\tjle %l2", operands);
  674. #endif
  675.         break;
  676.  
  677.       case LEU:
  678. #ifdef MOTOROLA
  679.         output_asm_insn ("dbls %0,%l1\n\tjbls %l2", operands);
  680. #else
  681.         output_asm_insn ("dbls %0,%l1\n\tjls %l2", operands);
  682. #endif
  683.         break;
  684.  
  685.       default:
  686.     abort ();
  687.     }
  688.  
  689.   /* If the decrement is to be done in SImode, then we have
  690.      to compensate for the fact that dbcc decrements in HImode. */
  691.   switch (GET_MODE (operands[0]))
  692.     {
  693.       case SImode:
  694. #ifdef MOTOROLA
  695.         output_asm_insn ("clr%.w %0\n\tsubq%.l %#1,%0\n\tjbpl %l1", operands);
  696. #else
  697.         output_asm_insn ("clr%.w %0\n\tsubq%.l %#1,%0\n\tjpl %l1", operands);
  698. #endif
  699.         break;
  700.  
  701.       case HImode:
  702.         break;
  703.  
  704.       default:
  705.         abort ();
  706.     }
  707. }
  708.  
  709. char *
  710. output_btst (operands, countop, dataop, insn, signpos)
  711.      rtx *operands;
  712.      rtx countop, dataop;
  713.      rtx insn;
  714.      int signpos;
  715. {
  716.   operands[0] = countop;
  717.   operands[1] = dataop;
  718.  
  719.   if (GET_CODE (countop) == CONST_INT)
  720.     {
  721.       register int count = INTVAL (countop);
  722.       /* If COUNT is bigger than size of storage unit in use,
  723.      advance to the containing unit of same size.  */
  724.       if (count > signpos)
  725.     {
  726.       int offset = (count & ~signpos) / 8;
  727.       count = count & signpos;
  728.       operands[1] = dataop = adj_offsettable_operand (dataop, offset);
  729.     }
  730.       if (count == signpos)
  731.     cc_status.flags = CC_NOT_POSITIVE | CC_Z_IN_NOT_N;
  732.       else
  733.     cc_status.flags = CC_NOT_NEGATIVE | CC_Z_IN_NOT_N;
  734.  
  735.       /* These three statements used to use next_insns_test_no...
  736.      but it appears that this should do the same job.  */
  737.       if (count == 31
  738.       && next_insn_tests_no_inequality (insn))
  739.     return "tst%.l %1";
  740.       if (count == 15
  741.       && next_insn_tests_no_inequality (insn))
  742.     return "tst%.w %1";
  743.       if (count == 7
  744.       && next_insn_tests_no_inequality (insn))
  745.     return "tst%.b %1";
  746.  
  747.       cc_status.flags = CC_NOT_NEGATIVE;
  748.     }
  749.   return "btst %0,%1";
  750. }
  751.  
  752. /* Returns 1 if OP is either a symbol reference or a sum of a symbol
  753.    reference and a constant.  */
  754.  
  755. int
  756. symbolic_operand (op, mode)
  757.      register rtx op;
  758.      enum machine_mode mode;
  759. {
  760.   switch (GET_CODE (op))
  761.     {
  762.     case SYMBOL_REF:
  763.     case LABEL_REF:
  764.       return 1;
  765.  
  766.     case CONST:
  767.       op = XEXP (op, 0);
  768.       return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
  769.            || GET_CODE (XEXP (op, 0)) == LABEL_REF)
  770.           && GET_CODE (XEXP (op, 1)) == CONST_INT);
  771.  
  772. #if 0 /* Deleted, with corresponding change in m68k.h,
  773.      so as to fit the specs.  No CONST_DOUBLE is ever symbolic.  */
  774.     case CONST_DOUBLE:
  775.       return GET_MODE (op) == mode;
  776. #endif
  777.  
  778.     default:
  779.       return 0;
  780.     }
  781. }
  782.  
  783.  
  784. /* Legitimize PIC addresses.  If the address is already
  785.    position-independent, we return ORIG.  Newly generated
  786.    position-independent addresses go to REG.  If we need more
  787.    than one register, we lose.  
  788.  
  789.    An address is legitimized by making an indirect reference
  790.    through the Global Offset Table with the name of the symbol
  791.    used as an offset.  
  792.  
  793.    The assembler and linker are responsible for placing the 
  794.    address of the symbol in the GOT.  The function prologue
  795.    is responsible for initializing a5 to the starting address
  796.    of the GOT.
  797.  
  798.    The assembler is also responsible for translating a symbol name
  799.    into a constant displacement from the start of the GOT.  
  800.  
  801.    A quick example may make things a little clearer:
  802.  
  803.    When not generating PIC code to store the value 12345 into _foo
  804.    we would generate the following code:
  805.  
  806.     movel #12345, _foo
  807.  
  808.    When generating PIC two transformations are made.  First, the compiler
  809.    loads the address of foo into a register.  So the first transformation makes:
  810.  
  811.     lea    _foo, a0
  812.     movel   #12345, a0@
  813.  
  814.    The code in movsi will intercept the lea instruction and call this
  815.    routine which will transform the instructions into:
  816.  
  817.     movel   a5@(_foo:w), a0
  818.     movel   #12345, a0@
  819.    
  820.  
  821.    That (in a nutshell) is how *all* symbol and label references are 
  822.    handled.  */
  823.  
  824. rtx
  825. legitimize_pic_address (orig, mode, reg)
  826.      rtx orig, reg;
  827.      enum machine_mode mode;
  828. {
  829.   rtx pic_ref = orig;
  830.  
  831.   /* First handle a simple SYMBOL_REF or LABEL_REF */
  832.   if (GET_CODE (orig) == SYMBOL_REF || GET_CODE (orig) == LABEL_REF)
  833.     {
  834. #ifdef LEGITIMATE_BASEREL_OPERAND_P
  835.   if (LEGITIMATE_BASEREL_OPERAND_P (orig))
  836.     return orig;
  837. #endif
  838.  
  839.       if (reg == 0)
  840.     abort ();
  841.  
  842.       if (flag_pic >= 3)
  843.     pic_ref = gen_rtx (PLUS, Pmode, pic_offset_table_rtx, orig);
  844.       else
  845.         pic_ref = gen_rtx (MEM, Pmode,
  846.                gen_rtx (PLUS, Pmode,
  847.                     pic_offset_table_rtx, orig));
  848.  
  849.       current_function_uses_pic_offset_table = 1;
  850.       RTX_UNCHANGING_P (pic_ref) = 1;
  851.       emit_move_insn (reg, pic_ref);
  852.  
  853.       return reg;
  854.     }
  855.   else if (GET_CODE (orig) == CONST)
  856.     {
  857.       rtx base, offset;
  858.  
  859.       /* Make sure this is CONST has not already been legitimized */
  860.       if (GET_CODE (XEXP (orig, 0)) == PLUS
  861.       && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
  862.     return orig;
  863.  
  864.       if (reg == 0)
  865.     abort ();
  866.  
  867.       /* legitimize both operands of the PLUS */
  868.       if (GET_CODE (XEXP (orig, 0)) == PLUS)
  869.     {
  870.       base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
  871.       orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
  872.                      base == reg ? 0 : reg);
  873.     }
  874.       else abort ();
  875.  
  876.       if (GET_CODE (orig) == CONST_INT)
  877.     return plus_constant_for_output (base, INTVAL (orig));
  878.       pic_ref = gen_rtx (PLUS, Pmode, base, orig);
  879.       /* Likewise, should we set special REG_NOTEs here?  */
  880.     }
  881.  
  882.   return pic_ref;
  883. }
  884.  
  885.  
  886. /* Return the best assembler insn template
  887.    for moving operands[1] into operands[0] as a fullword.  */
  888.  
  889. static char *
  890. singlemove_string (operands)
  891.      rtx *operands;
  892. {
  893. #ifdef SUPPORT_SUN_FPA
  894.   if (FPA_REG_P (operands[0]) || FPA_REG_P (operands[1]))
  895.     return "fpmoves %1,%0";
  896. #endif
  897.   if (DATA_REG_P (operands[0])
  898.       && GET_CODE (operands[1]) == CONST_INT
  899.       && INTVAL (operands[1]) < 128
  900.       && INTVAL (operands[1]) >= -128)
  901.     {
  902. #if defined (MOTOROLA) && !defined (CRDS)
  903.       return "moveq%.l %1,%0";
  904. #else
  905.       return "moveq %1,%0";
  906. #endif
  907.     }
  908.   if (operands[1] != const0_rtx)
  909.     return "move%.l %1,%0";
  910.   if (! ADDRESS_REG_P (operands[0]))
  911.     return "clr%.l %0";
  912.   return "sub%.l %0,%0";
  913. }
  914.  
  915.  
  916. /* Output assembler code to perform a doubleword move insn
  917.    with operands OPERANDS.  */
  918.  
  919. char *
  920. output_move_double (operands)
  921.      rtx *operands;
  922. {
  923.   enum
  924.     {
  925.       REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP
  926.     } optype0, optype1;
  927.   rtx latehalf[2];
  928.   rtx middlehalf[2];
  929.   rtx xops[2];
  930.   rtx addreg0 = 0, addreg1 = 0;
  931.   int dest_overlapped_low = 0;
  932.   int size = GET_MODE_SIZE (GET_MODE (operands[0]));
  933.  
  934.   middlehalf[0] = 0;
  935.   middlehalf[1] = 0;
  936.  
  937.   /* First classify both operands.  */
  938.  
  939.   if (REG_P (operands[0]))
  940.     optype0 = REGOP;
  941.   else if (offsettable_memref_p (operands[0]))
  942.     optype0 = OFFSOP;
  943.   else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
  944.     optype0 = POPOP;
  945.   else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
  946.     optype0 = PUSHOP;
  947.   else if (GET_CODE (operands[0]) == MEM)
  948.     optype0 = MEMOP;
  949.   else
  950.     optype0 = RNDOP;
  951.  
  952.   if (REG_P (operands[1]))
  953.     optype1 = REGOP;
  954.   else if (CONSTANT_P (operands[1]))
  955.     optype1 = CNSTOP;
  956.   else if (offsettable_memref_p (operands[1]))
  957.     optype1 = OFFSOP;
  958.   else if (GET_CODE (XEXP (operands[1], 0)) == POST_INC)
  959.     optype1 = POPOP;
  960.   else if (GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)
  961.     optype1 = PUSHOP;
  962.   else if (GET_CODE (operands[1]) == MEM)
  963.     optype1 = MEMOP;
  964.   else
  965.     optype1 = RNDOP;
  966.  
  967.   /* Check for the cases that the operand constraints are not
  968.      supposed to allow to happen.  Abort if we get one,
  969.      because generating code for these cases is painful.  */
  970.  
  971.   if (optype0 == RNDOP || optype1 == RNDOP)
  972.     abort ();
  973.  
  974.   /* If one operand is decrementing and one is incrementing
  975.      decrement the former register explicitly
  976.      and change that operand into ordinary indexing.  */
  977.  
  978.   if (optype0 == PUSHOP && optype1 == POPOP)
  979.     {
  980.       operands[0] = XEXP (XEXP (operands[0], 0), 0);
  981.       if (size == 12)
  982.         output_asm_insn ("sub%.l %#12,%0", operands);
  983.       else
  984.         output_asm_insn ("subq%.l %#8,%0", operands);
  985.       if (GET_MODE (operands[1]) == XFmode)
  986.     operands[0] = gen_rtx (MEM, XFmode, operands[0]);
  987.       else if (GET_MODE (operands[0]) == DFmode)
  988.     operands[0] = gen_rtx (MEM, DFmode, operands[0]);
  989.       else
  990.     operands[0] = gen_rtx (MEM, DImode, operands[0]);
  991.       optype0 = OFFSOP;
  992.     }
  993.   if (optype0 == POPOP && optype1 == PUSHOP)
  994.     {
  995.       operands[1] = XEXP (XEXP (operands[1], 0), 0);
  996.       if (size == 12)
  997.         output_asm_insn ("sub%.l %#12,%1", operands);
  998.       else
  999.         output_asm_insn ("subq%.l %#8,%1", operands);
  1000.       if (GET_MODE (operands[1]) == XFmode)
  1001.     operands[1] = gen_rtx (MEM, XFmode, operands[1]);
  1002.       else if (GET_MODE (operands[1]) == DFmode)
  1003.     operands[1] = gen_rtx (MEM, DFmode, operands[1]);
  1004.       else
  1005.     operands[1] = gen_rtx (MEM, DImode, operands[1]);
  1006.       optype1 = OFFSOP;
  1007.     }
  1008.  
  1009.   /* If an operand is an unoffsettable memory ref, find a register
  1010.      we can increment temporarily to make it refer to the second word.  */
  1011.  
  1012.   if (optype0 == MEMOP)
  1013.     addreg0 = find_addr_reg (XEXP (operands[0], 0));
  1014.  
  1015.   if (optype1 == MEMOP)
  1016.     addreg1 = find_addr_reg (XEXP (operands[1], 0));
  1017.  
  1018.   /* Ok, we can do one word at a time.
  1019.      Normally we do the low-numbered word first,
  1020.      but if either operand is autodecrementing then we
  1021.      do the high-numbered word first.
  1022.  
  1023.      In either case, set up in LATEHALF the operands to use
  1024.      for the high-numbered word and in some cases alter the
  1025.      operands in OPERANDS to be suitable for the low-numbered word.  */
  1026.  
  1027.   if (size == 12)
  1028.     {
  1029.       if (optype0 == REGOP)
  1030.     {
  1031.       latehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 2);
  1032.       middlehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 1);
  1033.     }
  1034.       else if (optype0 == OFFSOP)
  1035.     {
  1036.       middlehalf[0] = adj_offsettable_operand (operands[0], 4);
  1037.       latehalf[0] = adj_offsettable_operand (operands[0], size - 4);
  1038.     }
  1039.       else
  1040.     {
  1041.       middlehalf[0] = operands[0];
  1042.       latehalf[0] = operands[0];
  1043.     }
  1044.  
  1045.       if (optype1 == REGOP)
  1046.     {
  1047.       latehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 2);
  1048.       middlehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
  1049.     }
  1050.       else if (optype1 == OFFSOP)
  1051.     {
  1052.       middlehalf[1] = adj_offsettable_operand (operands[1], 4);
  1053.       latehalf[1] = adj_offsettable_operand (operands[1], size - 4);
  1054.     }
  1055.       else if (optype1 == CNSTOP)
  1056.     {
  1057.       if (GET_CODE (operands[1]) == CONST_DOUBLE)
  1058.         {
  1059.           REAL_VALUE_TYPE r;
  1060.           long l[3];
  1061.  
  1062.           REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
  1063.           REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
  1064.           operands[1] = GEN_INT (l[0]);
  1065.           middlehalf[1] = GEN_INT (l[1]);
  1066.           latehalf[1] = GEN_INT (l[2]);
  1067.         }
  1068.       else if (CONSTANT_P (operands[1]))
  1069.         {
  1070.           /* actually, no non-CONST_DOUBLE constant should ever
  1071.          appear here.  */
  1072.           abort ();
  1073.           if (GET_CODE (operands[1]) == CONST_INT && INTVAL (operands[1]) < 0)
  1074.         latehalf[1] = constm1_rtx;
  1075.           else
  1076.         latehalf[1] = const0_rtx;
  1077.         }
  1078.     }
  1079.       else
  1080.     {
  1081.       middlehalf[1] = operands[1];
  1082.       latehalf[1] = operands[1];
  1083.     }
  1084.     }
  1085.   else
  1086.     /* size is not 12: */
  1087.     {
  1088.       if (optype0 == REGOP)
  1089.     latehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 1);
  1090.       else if (optype0 == OFFSOP)
  1091.     latehalf[0] = adj_offsettable_operand (operands[0], size - 4);
  1092.       else
  1093.     latehalf[0] = operands[0];
  1094.  
  1095.       if (optype1 == REGOP)
  1096.     latehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
  1097.       else if (optype1 == OFFSOP)
  1098.     latehalf[1] = adj_offsettable_operand (operands[1], size - 4);
  1099.       else if (optype1 == CNSTOP)
  1100.     split_double (operands[1], &operands[1], &latehalf[1]);
  1101.       else
  1102.     latehalf[1] = operands[1];
  1103.     }
  1104.  
  1105.   /* If insn is effectively movd N(sp),-(sp) then we will do the
  1106.      high word first.  We should use the adjusted operand 1 (which is N+4(sp))
  1107.      for the low word as well, to compensate for the first decrement of sp.  */
  1108.   if (optype0 == PUSHOP
  1109.       && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM
  1110.       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
  1111.     operands[1] = middlehalf[1] = latehalf[1];
  1112.  
  1113.   /* For (set (reg:DI N) (mem:DI ... (reg:SI N) ...)),
  1114.      if the upper part of reg N does not appear in the MEM, arrange to
  1115.      emit the move late-half first.  Otherwise, compute the MEM address
  1116.      into the upper part of N and use that as a pointer to the memory
  1117.      operand.  */
  1118.   if (optype0 == REGOP
  1119.       && (optype1 == OFFSOP || optype1 == MEMOP))
  1120.     {
  1121.       rtx testlow = gen_rtx (REG, SImode, REGNO (operands[0]));
  1122.  
  1123.       if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0))
  1124.       && reg_overlap_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
  1125.     {
  1126.       /* If both halves of dest are used in the src memory address,
  1127.          compute the address into latehalf of dest.
  1128.          Note that this can't happen if the dest is two data regs.  */
  1129. compadr:
  1130.       xops[0] = latehalf[0];
  1131.       xops[1] = XEXP (operands[1], 0);
  1132.       output_asm_insn ("lea %a1,%0", xops);
  1133.       if( GET_MODE (operands[1]) == XFmode )
  1134.         {
  1135.           operands[1] = gen_rtx (MEM, XFmode, latehalf[0]);
  1136.           middlehalf[1] = adj_offsettable_operand (operands[1], size-8);
  1137.           latehalf[1] = adj_offsettable_operand (operands[1], size-4);
  1138.         }
  1139.       else
  1140.         {
  1141.           operands[1] = gen_rtx (MEM, DImode, latehalf[0]);
  1142.           latehalf[1] = adj_offsettable_operand (operands[1], size-4);
  1143.         }
  1144.     }
  1145.       else if (size == 12
  1146.            && reg_overlap_mentioned_p (middlehalf[0],
  1147.                        XEXP (operands[1], 0)))
  1148.     {
  1149.       /* Check for two regs used by both source and dest.
  1150.          Note that this can't happen if the dest is all data regs.
  1151.          It can happen if the dest is d6, d7, a0.
  1152.          But in that case, latehalf is an addr reg, so
  1153.          the code at compadr does ok.  */
  1154.  
  1155.       if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0))
  1156.           || reg_overlap_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
  1157.         goto compadr;
  1158.  
  1159.       /* JRV says this can't happen: */
  1160.       if (addreg0 || addreg1)
  1161.         abort ();
  1162.  
  1163.       /* Only the middle reg conflicts; simply put it last. */
  1164.       output_asm_insn (singlemove_string (operands), operands);
  1165.       output_asm_insn (singlemove_string (latehalf), latehalf);
  1166.       output_asm_insn (singlemove_string (middlehalf), middlehalf);
  1167.       return "";
  1168.     }
  1169.       else if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0)))
  1170.     /* If the low half of dest is mentioned in the source memory
  1171.        address, the arrange to emit the move late half first.  */
  1172.     dest_overlapped_low = 1;
  1173.     }
  1174.  
  1175.   /* If one or both operands autodecrementing,
  1176.      do the two words, high-numbered first.  */
  1177.  
  1178.   /* Likewise,  the first move would clobber the source of the second one,
  1179.      do them in the other order.  This happens only for registers;
  1180.      such overlap can't happen in memory unless the user explicitly
  1181.      sets it up, and that is an undefined circumstance.  */
  1182.  
  1183.   if (optype0 == PUSHOP || optype1 == PUSHOP
  1184.       || (optype0 == REGOP && optype1 == REGOP
  1185.       && ((middlehalf[1] && REGNO (operands[0]) == REGNO (middlehalf[1]))
  1186.           || REGNO (operands[0]) == REGNO (latehalf[1])))
  1187.       || dest_overlapped_low)
  1188.     {
  1189.       /* Make any unoffsettable addresses point at high-numbered word.  */
  1190.       if (addreg0)
  1191.     {
  1192.       if (size == 12)
  1193.         output_asm_insn ("addq%.l %#8,%0", &addreg0);
  1194.       else
  1195.         output_asm_insn ("addq%.l %#4,%0", &addreg0);
  1196.     }
  1197.       if (addreg1)
  1198.     {
  1199.       if (size == 12)
  1200.         output_asm_insn ("addq%.l %#8,%0", &addreg1);
  1201.       else
  1202.         output_asm_insn ("addq%.l %#4,%0", &addreg1);
  1203.     }
  1204.  
  1205.       /* Do that word.  */
  1206.       output_asm_insn (singlemove_string (latehalf), latehalf);
  1207.  
  1208.       /* Undo the adds we just did.  */
  1209.       if (addreg0)
  1210.     output_asm_insn ("subq%.l %#4,%0", &addreg0);
  1211.       if (addreg1)
  1212.     output_asm_insn ("subq%.l %#4,%0", &addreg1);
  1213.  
  1214.       if (size == 12)
  1215.     {
  1216.       output_asm_insn (singlemove_string (middlehalf), middlehalf);
  1217.       if (addreg0)
  1218.         output_asm_insn ("subq%.l %#4,%0", &addreg0);
  1219.       if (addreg1)
  1220.         output_asm_insn ("subq%.l %#4,%0", &addreg1);
  1221.     }
  1222.  
  1223.       /* Do low-numbered word.  */
  1224.       return singlemove_string (operands);
  1225.     }
  1226.  
  1227.   /* Normal case: do the two words, low-numbered first.  */
  1228.  
  1229.   output_asm_insn (singlemove_string (operands), operands);
  1230.  
  1231.   /* Do the middle one of the three words for long double */
  1232.   if (size == 12)
  1233.     {
  1234.       if (addreg0)
  1235.     output_asm_insn ("addq%.l %#4,%0", &addreg0);
  1236.       if (addreg1)
  1237.     output_asm_insn ("addq%.l %#4,%0", &addreg1);
  1238.  
  1239.       output_asm_insn (singlemove_string (middlehalf), middlehalf);
  1240.     }
  1241.  
  1242.   /* Make any unoffsettable addresses point at high-numbered word.  */
  1243.   if (addreg0)
  1244.     output_asm_insn ("addq%.l %#4,%0", &addreg0);
  1245.   if (addreg1)
  1246.     output_asm_insn ("addq%.l %#4,%0", &addreg1);
  1247.  
  1248.   /* Do that word.  */
  1249.   output_asm_insn (singlemove_string (latehalf), latehalf);
  1250.  
  1251.   /* Undo the adds we just did.  */
  1252.   if (addreg0)
  1253.     {
  1254.       if (size == 12)
  1255.         output_asm_insn ("subq%.l %#8,%0", &addreg0);
  1256.       else
  1257.         output_asm_insn ("subq%.l %#4,%0", &addreg0);
  1258.     }
  1259.   if (addreg1)
  1260.     {
  1261.       if (size == 12)
  1262.         output_asm_insn ("subq%.l %#8,%0", &addreg1);
  1263.       else
  1264.         output_asm_insn ("subq%.l %#4,%0", &addreg1);
  1265.     }
  1266.  
  1267.   return "";
  1268. }
  1269.  
  1270. /* Return a REG that occurs in ADDR with coefficient 1.
  1271.    ADDR can be effectively incremented by incrementing REG.  */
  1272.  
  1273. static rtx
  1274. find_addr_reg (addr)
  1275.      rtx addr;
  1276. {
  1277.   while (GET_CODE (addr) == PLUS)
  1278.     {
  1279.       if (GET_CODE (XEXP (addr, 0)) == REG)
  1280.     addr = XEXP (addr, 0);
  1281.       else if (GET_CODE (XEXP (addr, 1)) == REG)
  1282.     addr = XEXP (addr, 1);
  1283.       else if (CONSTANT_P (XEXP (addr, 0)))
  1284.     addr = XEXP (addr, 1);
  1285.       else if (CONSTANT_P (XEXP (addr, 1)))
  1286.     addr = XEXP (addr, 0);
  1287.       else
  1288.     abort ();
  1289.     }
  1290.   if (GET_CODE (addr) == REG)
  1291.     return addr;
  1292.   abort ();
  1293. }
  1294.  
  1295. /* Store in cc_status the expressions that the condition codes will
  1296.    describe after execution of an instruction whose pattern is EXP.
  1297.    Do not alter them if the instruction would not alter the cc's.  */
  1298.  
  1299. /* On the 68000, all the insns to store in an address register fail to
  1300.    set the cc's.  However, in some cases these instructions can make it
  1301.    possibly invalid to use the saved cc's.  In those cases we clear out
  1302.    some or all of the saved cc's so they won't be used.  */
  1303.  
  1304. notice_update_cc (exp, insn)
  1305.      rtx exp;
  1306.      rtx insn;
  1307. {
  1308.   /* If the cc is being set from the fpa and the expression is not an
  1309.      explicit floating point test instruction (which has code to deal with
  1310.      this), reinit the CC.  */
  1311.   if (((cc_status.value1 && FPA_REG_P (cc_status.value1))
  1312.        || (cc_status.value2 && FPA_REG_P (cc_status.value2)))
  1313.       && !(GET_CODE (exp) == PARALLEL
  1314.        && GET_CODE (XVECEXP (exp, 0, 0)) == SET
  1315.        && XEXP (XVECEXP (exp, 0, 0), 0) == cc0_rtx))
  1316.     {
  1317.       CC_STATUS_INIT; 
  1318.     }
  1319.   else if (GET_CODE (exp) == SET)
  1320.     {
  1321.       if (GET_CODE (SET_SRC (exp)) == CALL)
  1322.     {
  1323.       CC_STATUS_INIT; 
  1324.     }
  1325.       else if (ADDRESS_REG_P (SET_DEST (exp)))
  1326.     {
  1327.       if (cc_status.value1
  1328.           && reg_overlap_mentioned_p (SET_DEST (exp), cc_status.value1))
  1329.         cc_status.value1 = 0;
  1330.       if (cc_status.value2
  1331.           && reg_overlap_mentioned_p (SET_DEST (exp), cc_status.value2))
  1332.         cc_status.value2 = 0; 
  1333.     }
  1334.       else if (!FP_REG_P (SET_DEST (exp))
  1335.            && SET_DEST (exp) != cc0_rtx
  1336.            && (FP_REG_P (SET_SRC (exp))
  1337.            || GET_CODE (SET_SRC (exp)) == FIX
  1338.            || GET_CODE (SET_SRC (exp)) == FLOAT_TRUNCATE
  1339.            || GET_CODE (SET_SRC (exp)) == FLOAT_EXTEND))
  1340.     {
  1341.       CC_STATUS_INIT; 
  1342.     }
  1343.       /* A pair of move insns doesn't produce a useful overall cc.  */
  1344.       else if (!FP_REG_P (SET_DEST (exp))
  1345.            && !FP_REG_P (SET_SRC (exp))
  1346.            && GET_MODE_SIZE (GET_MODE (SET_SRC (exp))) > 4
  1347.            && (GET_CODE (SET_SRC (exp)) == REG
  1348.            || GET_CODE (SET_SRC (exp)) == MEM
  1349.            || GET_CODE (SET_SRC (exp)) == CONST_DOUBLE))
  1350.     {
  1351.       CC_STATUS_INIT; 
  1352.     }
  1353.       else if (GET_CODE (SET_SRC (exp)) == CALL)
  1354.     {
  1355.       CC_STATUS_INIT; 
  1356.     }
  1357.       else if (XEXP (exp, 0) != pc_rtx)
  1358.     {
  1359.       cc_status.flags = 0;
  1360.       cc_status.value1 = XEXP (exp, 0);
  1361.       cc_status.value2 = XEXP (exp, 1);
  1362.     }
  1363.     }
  1364.   else if (GET_CODE (exp) == PARALLEL
  1365.        && GET_CODE (XVECEXP (exp, 0, 0)) == SET)
  1366.     {
  1367.       if (ADDRESS_REG_P (XEXP (XVECEXP (exp, 0, 0), 0)))
  1368.     CC_STATUS_INIT;
  1369.       else if (XEXP (XVECEXP (exp, 0, 0), 0) != pc_rtx)
  1370.     {
  1371.       cc_status.flags = 0;
  1372.       cc_status.value1 = XEXP (XVECEXP (exp, 0, 0), 0);
  1373.       cc_status.value2 = XEXP (XVECEXP (exp, 0, 0), 1);
  1374.     }
  1375.     }
  1376.   else
  1377.     CC_STATUS_INIT;
  1378.   if (cc_status.value2 != 0
  1379.       && ADDRESS_REG_P (cc_status.value2)
  1380.       && GET_MODE (cc_status.value2) == QImode)
  1381.     CC_STATUS_INIT;
  1382.   if (cc_status.value2 != 0
  1383.       && !(cc_status.value1 && FPA_REG_P (cc_status.value1)))
  1384.     switch (GET_CODE (cc_status.value2))
  1385.       {
  1386.       case PLUS: case MINUS: case MULT:
  1387.       case DIV: case UDIV: case MOD: case UMOD: case NEG:
  1388.       case ASHIFT: case ASHIFTRT: case LSHIFTRT:
  1389.       case ROTATE: case ROTATERT:
  1390.     if (GET_MODE (cc_status.value2) != VOIDmode)
  1391.       cc_status.flags |= CC_NO_OVERFLOW;
  1392.     break;
  1393.       case ZERO_EXTEND:
  1394.     /* (SET r1 (ZERO_EXTEND r2)) on this machine
  1395.        ends with a move insn moving r2 in r2's mode.
  1396.        Thus, the cc's are set for r2.
  1397.        This can set N bit spuriously. */
  1398.     cc_status.flags |= CC_NOT_NEGATIVE; 
  1399.       }
  1400.   if (cc_status.value1 && GET_CODE (cc_status.value1) == REG
  1401.       && cc_status.value2
  1402.       && reg_overlap_mentioned_p (cc_status.value1, cc_status.value2))
  1403.     cc_status.value2 = 0;
  1404.   if (((cc_status.value1 && FP_REG_P (cc_status.value1))
  1405.        || (cc_status.value2 && FP_REG_P (cc_status.value2)))
  1406.       && !((cc_status.value1 && FPA_REG_P (cc_status.value1))
  1407.        || (cc_status.value2 && FPA_REG_P (cc_status.value2))))
  1408.     cc_status.flags = CC_IN_68881;
  1409. }
  1410.  
  1411. char *
  1412. output_move_const_double (operands)
  1413.      rtx *operands;
  1414. {
  1415. #ifdef SUPPORT_SUN_FPA
  1416.   if (TARGET_FPA && FPA_REG_P (operands[0]))
  1417.     {
  1418.       int code = standard_sun_fpa_constant_p (operands[1]);
  1419.  
  1420.       if (code != 0)
  1421.     {
  1422.       static char buf[40];
  1423.  
  1424.       sprintf (buf, "fpmove%%.d %%%%%d,%%0", code & 0x1ff);
  1425.       return buf;
  1426.     }
  1427.       return "fpmove%.d %1,%0";
  1428.     }
  1429.   else
  1430. #endif
  1431.     {
  1432.       int code = standard_68881_constant_p (operands[1]);
  1433.  
  1434.       if (code != 0)
  1435.     {
  1436.       static char buf[40];
  1437.  
  1438.       sprintf (buf, "fmovecr %%#0x%x,%%0", code & 0xff);
  1439.       return buf;
  1440.     }
  1441.       return "fmove%.d %1,%0";
  1442.     }
  1443. }
  1444.  
  1445. char *
  1446. output_move_const_single (operands)
  1447.      rtx *operands;
  1448. {
  1449. #ifdef SUPPORT_SUN_FPA
  1450.   if (TARGET_FPA)
  1451.     {
  1452.       int code = standard_sun_fpa_constant_p (operands[1]);
  1453.  
  1454.       if (code != 0)
  1455.     {
  1456.       static char buf[40];
  1457.  
  1458.       sprintf (buf, "fpmove%%.s %%%%%d,%%0", code & 0x1ff);
  1459.       return buf;
  1460.     }
  1461.       return "fpmove%.s %1,%0";
  1462.     }
  1463.   else
  1464. #endif /* defined SUPPORT_SUN_FPA */
  1465.     {
  1466.       int code = standard_68881_constant_p (operands[1]);
  1467.  
  1468.       if (code != 0)
  1469.     {
  1470.       static char buf[40];
  1471.  
  1472.       sprintf (buf, "fmovecr %%#0x%x,%%0", code & 0xff);
  1473.       return buf;
  1474.     }
  1475.       return "fmove%.s %f1,%0";
  1476.     }
  1477. }
  1478.  
  1479. /* Return nonzero if X, a CONST_DOUBLE, has a value that we can get
  1480.    from the "fmovecr" instruction.
  1481.    The value, anded with 0xff, gives the code to use in fmovecr
  1482.    to get the desired constant.  */
  1483.  
  1484. /* This code has been fixed for cross-compilation. */
  1485.   
  1486. static int inited_68881_table = 0;
  1487.  
  1488. char *strings_68881[7] = {
  1489.   "0.0",
  1490.   "1.0",
  1491.   "10.0",
  1492.   "100.0",
  1493.   "10000.0",
  1494.   "1e8",
  1495.   "1e16"
  1496.   };
  1497.  
  1498. int codes_68881[7] = {
  1499.   0x0f,
  1500.   0x32,
  1501.   0x33,
  1502.   0x34,
  1503.   0x35,
  1504.   0x36,
  1505.   0x37
  1506.   };
  1507.  
  1508. REAL_VALUE_TYPE values_68881[7];
  1509.  
  1510. /* Set up values_68881 array by converting the decimal values
  1511.    strings_68881 to binary.   */
  1512.  
  1513. void
  1514. init_68881_table ()
  1515. {
  1516.   int i;
  1517.   REAL_VALUE_TYPE r;
  1518.   enum machine_mode mode;
  1519.  
  1520.   mode = DFmode;
  1521.   for (i = 0; i < 7; i++)
  1522.     {
  1523.       if (i == 6)
  1524.         mode = SFmode;
  1525.       r = REAL_VALUE_ATOF (strings_68881[i], mode);
  1526.       values_68881[i] = r;
  1527.     }
  1528.   inited_68881_table = 1;
  1529. }
  1530.  
  1531. int
  1532. standard_68881_constant_p (x)
  1533.      rtx x;
  1534. {
  1535.   REAL_VALUE_TYPE r;
  1536.   int i;
  1537.   enum machine_mode mode;
  1538.  
  1539. #ifdef NO_ASM_FMOVECR
  1540.   return 0;
  1541. #endif
  1542.  
  1543.   /* fmovecr must be emulated on the 68040, so it shouldn't be used at all. */
  1544.   if (TARGET_68040)
  1545.     return 0;
  1546.  
  1547. #ifndef REAL_ARITHMETIC
  1548. #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
  1549.   if (! flag_pretend_float)
  1550.     return 0;
  1551. #endif
  1552. #endif
  1553.  
  1554.   if (! inited_68881_table)
  1555.     init_68881_table ();
  1556.  
  1557.   REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  1558.  
  1559.   for (i = 0; i < 6; i++)
  1560.     {
  1561.       if (REAL_VALUES_EQUAL (r, values_68881[i]))
  1562.         return (codes_68881[i]);
  1563.     }
  1564.   
  1565.   if (GET_MODE (x) == SFmode)
  1566.     return 0;
  1567.  
  1568.   if (REAL_VALUES_EQUAL (r, values_68881[6]))
  1569.     return (codes_68881[6]);
  1570.  
  1571.   /* larger powers of ten in the constants ram are not used
  1572.      because they are not equal to a `double' C constant.  */
  1573.   return 0;
  1574. }
  1575.  
  1576. /* If X is a floating-point constant, return the logarithm of X base 2,
  1577.    or 0 if X is not a power of 2.  */
  1578.  
  1579. int
  1580. floating_exact_log2 (x)
  1581.      rtx x;
  1582. {
  1583.   REAL_VALUE_TYPE r, r1;
  1584.   int i;
  1585.  
  1586. #ifndef REAL_ARITHMETIC
  1587. #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
  1588.   if (! flag_pretend_float)
  1589.     return 0;
  1590. #endif
  1591. #endif
  1592.  
  1593.   REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  1594.  
  1595.   if (REAL_VALUES_LESS (r, dconst0))
  1596.     return 0;
  1597.  
  1598.   r1 = dconst1;
  1599.   i = 0;
  1600.   while (REAL_VALUES_LESS (r1, r))
  1601.     {
  1602.       r1 = REAL_VALUE_LDEXP (dconst1, i);
  1603.       if (REAL_VALUES_EQUAL (r1, r))
  1604.         return i;
  1605.       i = i + 1;
  1606.     }
  1607.   return 0;
  1608. }
  1609.  
  1610. #ifdef SUPPORT_SUN_FPA
  1611. /* Return nonzero if X, a CONST_DOUBLE, has a value that we can get
  1612.    from the Sun FPA's constant RAM.
  1613.    The value returned, anded with 0x1ff, gives the code to use in fpmove
  1614.    to get the desired constant. */
  1615.  
  1616. static int inited_FPA_table = 0;
  1617.  
  1618. char *strings_FPA[38] = {
  1619. /* small rationals */
  1620.   "0.0",
  1621.   "1.0",
  1622.   "0.5",
  1623.   "-1.0",
  1624.   "2.0",
  1625.   "3.0",
  1626.   "4.0",
  1627.   "8.0",
  1628.   "0.25",
  1629.   "0.125",
  1630.   "10.0",
  1631.   "-0.5",
  1632. /* Decimal equivalents of double precision values */
  1633.   "2.718281828459045091", /* D_E */
  1634.   "6.283185307179586477", /* 2 pi */
  1635.   "3.141592653589793116", /* D_PI */
  1636.   "1.570796326794896619", /* pi/2 */
  1637.   "1.414213562373095145", /* D_SQRT2 */
  1638.   "0.7071067811865475244", /* 1/sqrt(2) */
  1639.   "-1.570796326794896619", /* -pi/2 */
  1640.   "1.442695040888963387", /* D_LOG2ofE */
  1641.   "3.321928024887362182", /* D_LOG2of10 */
  1642.   "0.6931471805599452862", /* D_LOGEof2 */
  1643.   "2.302585092994045901", /* D_LOGEof10 */
  1644.   "0.3010299956639811980", /* D_LOG10of2 */
  1645.   "0.4342944819032518167", /* D_LOG10ofE */
  1646. /* Decimal equivalents of single precision values */
  1647.   "2.718281745910644531", /* S_E */
  1648.   "6.283185307179586477", /* 2 pi */
  1649.   "3.141592741012573242", /* S_PI */
  1650.   "1.570796326794896619", /* pi/2 */
  1651.   "1.414213538169860840", /* S_SQRT2 */
  1652.   "0.7071067811865475244", /* 1/sqrt(2) */
  1653.   "-1.570796326794896619", /* -pi/2 */
  1654.   "1.442695021629333496", /* S_LOG2ofE */
  1655.   "3.321928024291992188", /* S_LOG2of10 */
  1656.   "0.6931471824645996094", /* S_LOGEof2 */
  1657.   "2.302585124969482442", /* S_LOGEof10 */
  1658.   "0.3010300099849700928", /* S_LOG10of2 */
  1659.   "0.4342944920063018799", /* S_LOG10ofE */
  1660. };
  1661.  
  1662.  
  1663. int codes_FPA[38] = {
  1664. /* small rationals */
  1665.   0x200,
  1666.   0xe,
  1667.   0xf,
  1668.   0x10,
  1669.   0x11,
  1670.   0xb1,
  1671.   0x12,
  1672.   0x13,
  1673.   0x15,
  1674.   0x16,
  1675.   0x17,
  1676.   0x2e,
  1677. /* double precision */
  1678.   0x8,
  1679.   0x9,
  1680.   0xa,
  1681.   0xb,
  1682.   0xc,
  1683.   0xd,
  1684.   0x27,
  1685.   0x28,
  1686.   0x29,
  1687.   0x2a,
  1688.   0x2b,
  1689.   0x2c,
  1690.   0x2d,
  1691. /* single precision */
  1692.   0x8,
  1693.   0x9,
  1694.   0xa,
  1695.   0xb,
  1696.   0xc,
  1697.   0xd,
  1698.   0x27,
  1699.   0x28,
  1700.   0x29,
  1701.   0x2a,
  1702.   0x2b,
  1703.   0x2c,
  1704.   0x2d
  1705.   };
  1706.  
  1707. REAL_VALUE_TYPE values_FPA[38];
  1708.  
  1709. /* This code has been fixed for cross-compilation. */
  1710.  
  1711. void
  1712. init_FPA_table ()
  1713. {
  1714.   enum machine_mode mode;
  1715.   int i;
  1716.   REAL_VALUE_TYPE r;
  1717.  
  1718.   mode = DFmode;
  1719.   for (i = 0; i < 38; i++)
  1720.     {
  1721.       if (i == 25)
  1722.         mode = SFmode;
  1723.       r = REAL_VALUE_ATOF (strings_FPA[i], mode);
  1724.       values_FPA[i] = r;
  1725.     }
  1726.   inited_FPA_table = 1;
  1727. }
  1728.  
  1729.  
  1730. int
  1731. standard_sun_fpa_constant_p (x)
  1732.      rtx x;
  1733. {
  1734.   REAL_VALUE_TYPE r;
  1735.   int i;
  1736.  
  1737. #ifndef REAL_ARITHMETIC
  1738. #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
  1739.   if (! flag_pretend_float)
  1740.     return 0;
  1741. #endif
  1742. #endif
  1743.  
  1744.   if (! inited_FPA_table)
  1745.     init_FPA_table ();
  1746.  
  1747.   REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  1748.  
  1749.   for (i=0; i<12; i++)
  1750.     {
  1751.       if (REAL_VALUES_EQUAL (r, values_FPA[i]))
  1752.         return (codes_FPA[i]);
  1753.     }
  1754.  
  1755.   if (GET_MODE (x) == SFmode)
  1756.     {
  1757.       for (i=25; i<38; i++)
  1758.         {
  1759.           if (REAL_VALUES_EQUAL (r, values_FPA[i]))
  1760.             return (codes_FPA[i]);
  1761.         }
  1762.     }
  1763.   else
  1764.     {
  1765.       for (i=12; i<25; i++)
  1766.         {
  1767.           if (REAL_VALUES_EQUAL (r, values_FPA[i]))
  1768.             return (codes_FPA[i]);
  1769.         }
  1770.     }
  1771.   return 0x0;
  1772. }
  1773. #endif /* define SUPPORT_SUN_FPA */
  1774.  
  1775. /* A C compound statement to output to stdio stream STREAM the
  1776.    assembler syntax for an instruction operand X.  X is an RTL
  1777.    expression.
  1778.  
  1779.    CODE is a value that can be used to specify one of several ways
  1780.    of printing the operand.  It is used when identical operands
  1781.    must be printed differently depending on the context.  CODE
  1782.    comes from the `%' specification that was used to request
  1783.    printing of the operand.  If the specification was just `%DIGIT'
  1784.    then CODE is 0; if the specification was `%LTR DIGIT' then CODE
  1785.    is the ASCII code for LTR.
  1786.  
  1787.    If X is a register, this macro should print the register's name.
  1788.    The names can be found in an array `reg_names' whose type is
  1789.    `char *[]'.  `reg_names' is initialized from `REGISTER_NAMES'.
  1790.  
  1791.    When the machine description has a specification `%PUNCT' (a `%'
  1792.    followed by a punctuation character), this macro is called with
  1793.    a null pointer for X and the punctuation character for CODE.
  1794.  
  1795.    The m68k specific codes are:
  1796.  
  1797.    '.' for dot needed in Motorola-style opcode names.
  1798.    '-' for an operand pushing on the stack:
  1799.        sp@-, -(sp) or -(%sp) depending on the style of syntax.
  1800.    '+' for an operand pushing on the stack:
  1801.        sp@+, (sp)+ or (%sp)+ depending on the style of syntax.
  1802.    '@' for a reference to the top word on the stack:
  1803.        sp@, (sp) or (%sp) depending on the style of syntax.
  1804.    '#' for an immediate operand prefix (# in MIT and Motorola syntax
  1805.        but & in SGS syntax).
  1806.    '!' for the cc register (used in an `and to cc' insn).
  1807.    '$' for the letter `s' in an op code, but only on the 68040.
  1808.    '&' for the letter `d' in an op code, but only on the 68040.
  1809.    '/' for register prefix needed by longlong.h.
  1810.  
  1811.    'b' for byte insn (no effect, on the Sun; this is for the ISI).
  1812.    'd' to force memory addressing to be absolute, not relative.
  1813.    'f' for float insn (print a CONST_DOUBLE as a float rather than in hex)
  1814.    'w' for FPA insn (print a CONST_DOUBLE as a SunFPA constant rather
  1815.        than directly).  Second part of 'y' below.
  1816.    'x' for float insn (print a CONST_DOUBLE as a float rather than in hex),
  1817.        or print pair of registers as rx:ry.
  1818.    'y' for a FPA insn (print pair of registers as rx:ry).  This also outputs
  1819.        CONST_DOUBLE's as SunFPA constant RAM registers if
  1820.        possible, so it should not be used except for the SunFPA.
  1821.  
  1822.    */
  1823.  
  1824. void
  1825. print_operand (file, op, letter)
  1826.      FILE *file;        /* file to write to */
  1827.      rtx op;            /* operand to print */
  1828.      int letter;        /* %<letter> or 0 */
  1829. {
  1830.   int i;
  1831.  
  1832.   if (letter == '.')
  1833.     {
  1834. #ifdef MOTOROLA
  1835.       asm_fprintf (file, ".");
  1836. #endif
  1837.     }
  1838.   else if (letter == '#')
  1839.     {
  1840.       asm_fprintf (file, "%0I");
  1841.     }
  1842.   else if (letter == '-')
  1843.     {
  1844. #ifdef MOTOROLA
  1845.       asm_fprintf (file, "-(%Rsp)");
  1846. #else
  1847.       asm_fprintf (file, "%Rsp@-");
  1848. #endif
  1849.     }
  1850.   else if (letter == '+')
  1851.     {
  1852. #ifdef MOTOROLA
  1853.       asm_fprintf (file, "(%Rsp)+");
  1854. #else
  1855.       asm_fprintf (file, "%Rsp@+");
  1856. #endif
  1857.     }
  1858.   else if (letter == '@')
  1859.     {
  1860. #ifdef MOTOROLA
  1861.       asm_fprintf (file, "(%Rsp)");
  1862. #else
  1863.       asm_fprintf (file, "%Rsp@");
  1864. #endif
  1865.     }
  1866.   else if (letter == '!')
  1867.     {
  1868.       asm_fprintf (file, "%Rfpcr");
  1869.     }
  1870.   else if (letter == '$')
  1871.     {
  1872.       if (TARGET_68040_ONLY)
  1873.     {
  1874.       fprintf (file, "s");
  1875.     }
  1876.     }
  1877.   else if (letter == '&')
  1878.     {
  1879.       if (TARGET_68040_ONLY)
  1880.     {
  1881.       fprintf (file, "d");
  1882.     }
  1883.     }
  1884.   else if (letter == '/')
  1885.     {
  1886.       asm_fprintf (file, "%R");
  1887.     }
  1888.   else if (GET_CODE (op) == REG)
  1889.     {
  1890. #ifdef SUPPORT_SUN_FPA
  1891.       if (REGNO (op) < 16
  1892.       && (letter == 'y' || letter == 'x')
  1893.       && GET_MODE (op) == DFmode)
  1894.     {
  1895.       fprintf (file, "%s:%s", reg_names[REGNO (op)],
  1896.            reg_names[REGNO (op)+1]);
  1897.     }
  1898.       else
  1899. #endif
  1900.     {
  1901.       fprintf (file, "%s", reg_names[REGNO (op)]);
  1902.     }
  1903.     }
  1904.   else if (GET_CODE (op) == MEM)
  1905.     {
  1906.       output_address (XEXP (op, 0));
  1907.       if (letter == 'd' && ! TARGET_68020
  1908.       && CONSTANT_ADDRESS_P (XEXP (op, 0))
  1909.       && !(GET_CODE (XEXP (op, 0)) == CONST_INT
  1910.            && INTVAL (XEXP (op, 0)) < 0x8000
  1911.            && INTVAL (XEXP (op, 0)) >= -0x8000))
  1912.     {
  1913.       fprintf (file, ":l");
  1914.     }
  1915.     }
  1916. #ifdef SUPPORT_SUN_FPA
  1917.   else if ((letter == 'y' || letter == 'w')
  1918.        && GET_CODE (op) == CONST_DOUBLE
  1919.        && (i = standard_sun_fpa_constant_p (op)))
  1920.     {
  1921.       fprintf (file, "%%%d", i & 0x1ff);
  1922.     }
  1923. #endif
  1924.   else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == SFmode)
  1925.     {
  1926.       REAL_VALUE_TYPE r;
  1927.       REAL_VALUE_FROM_CONST_DOUBLE (r, op);
  1928.       ASM_OUTPUT_FLOAT_OPERAND (letter, file, r);
  1929.     }
  1930.   else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == XFmode)
  1931.     {
  1932.       REAL_VALUE_TYPE r;
  1933.       REAL_VALUE_FROM_CONST_DOUBLE (r, op);
  1934.       ASM_OUTPUT_LONG_DOUBLE_OPERAND (file, r);
  1935.     }
  1936.   else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == DFmode)
  1937.     {
  1938.       REAL_VALUE_TYPE r;
  1939.       REAL_VALUE_FROM_CONST_DOUBLE (r, op);
  1940.       ASM_OUTPUT_DOUBLE_OPERAND (file, r);
  1941.     }
  1942.   else
  1943.     {
  1944.       asm_fprintf (file, "%0I"); output_addr_const (file, op);
  1945.     }
  1946. }
  1947.  
  1948.  
  1949. /* A C compound statement to output to stdio stream STREAM the
  1950.    assembler syntax for an instruction operand that is a memory
  1951.    reference whose address is ADDR.  ADDR is an RTL expression.
  1952.  
  1953.    Note that this contains a kludge that knows that the only reason
  1954.    we have an address (plus (label_ref...) (reg...)) when not generating
  1955.    PIC code is in the insn before a tablejump, and we know that m68k.md
  1956.    generates a label LInnn: on such an insn.
  1957.  
  1958.    It is possible for PIC to generate a (plus (label_ref...) (reg...))
  1959.    and we handle that just like we would a (plus (symbol_ref...) (reg...)).
  1960.  
  1961.    Some SGS assemblers have a bug such that "Lnnn-LInnn-2.b(pc,d0.l*2)"
  1962.    fails to assemble.  Luckily "Lnnn(pc,d0.l*2)" produces the results
  1963.    we want.  This difference can be accommodated by using an assembler
  1964.    define such "LDnnn" to be either "Lnnn-LInnn-2.b", "Lnnn", or any other
  1965.    string, as necessary.  This is accomplished via the ASM_OUTPUT_CASE_END
  1966.    macro.  See m68k/sgs.h for an example; for versions without the bug.
  1967.    Some assemblers refuse all the above solutions.  The workaround is to
  1968.    emit "K(pc,d0.l*2)" with K being a small constant known to give the
  1969.    right behaviour.
  1970.  
  1971.    They also do not like things like "pea 1.w", so we simple leave off
  1972.    the .w on small constants. 
  1973.  
  1974.    This routine is responsible for distinguishing between -fpic and -fPIC 
  1975.    style relocations in an address.  When generating -fpic code the
  1976.    offset is output in word mode (eg movel a5@(_foo:w), a0).  When generating
  1977.    -fPIC code the offset is output in long mode (eg movel a5@(_foo:l), a0) */
  1978.  
  1979. #ifndef ASM_OUTPUT_CASE_FETCH
  1980. #ifdef MOTOROLA
  1981. #ifdef SGS
  1982. #define ASM_OUTPUT_CASE_FETCH(file, labelno, regname)\
  1983.     asm_fprintf (file, "%LLD%d(%Rpc,%s.", labelno, regname)
  1984. #else
  1985. #define ASM_OUTPUT_CASE_FETCH(file, labelno, regname)\
  1986.     asm_fprintf (file, "%LL%d-%LLI%d.b(%Rpc,%s.", labelno, labelno, regname)
  1987. #endif
  1988. #else
  1989. #define ASM_OUTPUT_CASE_FETCH(file, labelno, regname)\
  1990.     asm_fprintf (file, "%Rpc@(%LL%d-%LLI%d-2:b,%s:", labelno, labelno, regname)
  1991. #endif
  1992. #endif /* ASM_OUTPUT_CASE_FETCH */
  1993.  
  1994. void
  1995. print_operand_address (file, addr)
  1996.      FILE *file;
  1997.      rtx addr;
  1998. {
  1999.   register rtx reg1, reg2, breg, ireg;
  2000.   rtx offset;
  2001.  
  2002.   switch (GET_CODE (addr))
  2003.     {
  2004.       case REG:
  2005. #ifdef MOTOROLA
  2006.     fprintf (file, "(%s)", reg_names[REGNO (addr)]);
  2007. #else
  2008.     fprintf (file, "%s@", reg_names[REGNO (addr)]);
  2009. #endif
  2010.     break;
  2011.       case PRE_DEC:
  2012. #ifdef MOTOROLA
  2013.     fprintf (file, "-(%s)", reg_names[REGNO (XEXP (addr, 0))]);
  2014. #else
  2015.     fprintf (file, "%s@-", reg_names[REGNO (XEXP (addr, 0))]);
  2016. #endif
  2017.     break;
  2018.       case POST_INC:
  2019. #ifdef MOTOROLA
  2020.     fprintf (file, "(%s)+", reg_names[REGNO (XEXP (addr, 0))]);
  2021. #else
  2022.     fprintf (file, "%s@+", reg_names[REGNO (XEXP (addr, 0))]);
  2023. #endif
  2024.     break;
  2025.       case PLUS:
  2026.     reg1 = reg2 = ireg = breg = offset = 0;
  2027.     if (CONSTANT_ADDRESS_P (XEXP (addr, 0)))
  2028.       {
  2029.         offset = XEXP (addr, 0);
  2030.         addr = XEXP (addr, 1);
  2031.       }
  2032.     else if (CONSTANT_ADDRESS_P (XEXP (addr, 1)))
  2033.       {
  2034.         offset = XEXP (addr, 1);
  2035.         addr = XEXP (addr, 0);
  2036.       }
  2037.     if (GET_CODE (addr) != PLUS)
  2038.       {
  2039.         ;
  2040.       }
  2041.     else if (GET_CODE (XEXP (addr, 0)) == SIGN_EXTEND)
  2042.       {
  2043.         reg1 = XEXP (addr, 0);
  2044.         addr = XEXP (addr, 1);
  2045.       }
  2046.     else if (GET_CODE (XEXP (addr, 1)) == SIGN_EXTEND)
  2047.       {
  2048.         reg1 = XEXP (addr, 1);
  2049.         addr = XEXP (addr, 0);
  2050.       }
  2051.     else if (GET_CODE (XEXP (addr, 0)) == MULT)
  2052.       {
  2053.         reg1 = XEXP (addr, 0);
  2054.         addr = XEXP (addr, 1);
  2055.       }
  2056.     else if (GET_CODE (XEXP (addr, 1)) == MULT)
  2057.       {
  2058.         reg1 = XEXP (addr, 1);
  2059.         addr = XEXP (addr, 0);
  2060.       }
  2061.     else if (GET_CODE (XEXP (addr, 0)) == REG)
  2062.       {
  2063.         reg1 = XEXP (addr, 0);
  2064.         addr = XEXP (addr, 1);
  2065.       }
  2066.     else if (GET_CODE (XEXP (addr, 1)) == REG)
  2067.       {
  2068.         reg1 = XEXP (addr, 1);
  2069.         addr = XEXP (addr, 0);
  2070.       }
  2071.     if (GET_CODE (addr) == REG || GET_CODE (addr) == MULT
  2072.         || GET_CODE (addr) == SIGN_EXTEND)
  2073.       {
  2074.         if (reg1 == 0)
  2075.           {
  2076.         reg1 = addr;
  2077.           }
  2078.         else
  2079.           {
  2080.         reg2 = addr;
  2081.           }
  2082.         addr = 0;
  2083.       }
  2084. #if 0    /* for OLD_INDEXING */
  2085.     else if (GET_CODE (addr) == PLUS)
  2086.       {
  2087.         if (GET_CODE (XEXP (addr, 0)) == REG)
  2088.           {
  2089.         reg2 = XEXP (addr, 0);
  2090.         addr = XEXP (addr, 1);
  2091.           }
  2092.         else if (GET_CODE (XEXP (addr, 1)) == REG)
  2093.           {
  2094.         reg2 = XEXP (addr, 1);
  2095.         addr = XEXP (addr, 0);
  2096.           }
  2097.       }
  2098. #endif
  2099.     if (offset != 0)
  2100.       {
  2101.         if (addr != 0)
  2102.           {
  2103.         abort ();
  2104.           }
  2105.         addr = offset;
  2106.       }
  2107.     if ((reg1 && (GET_CODE (reg1) == SIGN_EXTEND
  2108.               || GET_CODE (reg1) == MULT))
  2109.         || (reg2 != 0 && REGNO_OK_FOR_BASE_P (REGNO (reg2))))
  2110.       {
  2111.         breg = reg2;
  2112.         ireg = reg1;
  2113.       }
  2114.     else if (reg1 != 0 && REGNO_OK_FOR_BASE_P (REGNO (reg1)))
  2115.       {
  2116.         breg = reg1;
  2117.         ireg = reg2;
  2118.       }
  2119.     if (ireg != 0 && breg == 0 && GET_CODE (addr) == LABEL_REF
  2120.         && ! (flag_pic && ireg == pic_offset_table_rtx))
  2121.       {
  2122.         int scale = 1;
  2123.         if (GET_CODE (ireg) == MULT)
  2124.           {
  2125.         scale = INTVAL (XEXP (ireg, 1));
  2126.         ireg = XEXP (ireg, 0);
  2127.           }
  2128.         if (GET_CODE (ireg) == SIGN_EXTEND)
  2129.           {
  2130.         ASM_OUTPUT_CASE_FETCH (file,
  2131.                  CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2132.                  reg_names[REGNO (XEXP (ireg, 0))]);
  2133.         fprintf (file, "w");
  2134.           }
  2135.         else
  2136.           {
  2137.         ASM_OUTPUT_CASE_FETCH (file,
  2138.                  CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2139.                  reg_names[REGNO (ireg)]);
  2140.         fprintf (file, "l");
  2141.           }
  2142.         if (scale != 1)
  2143.           {
  2144. #ifdef MOTOROLA
  2145.         fprintf (file, "*%d", scale);
  2146. #else
  2147.         fprintf (file, ":%d", scale);
  2148. #endif
  2149.           }
  2150.         putc (')', file);
  2151.         break;
  2152.       }
  2153.     if (breg != 0 && ireg == 0 && GET_CODE (addr) == LABEL_REF
  2154.         && ! (flag_pic && breg == pic_offset_table_rtx))
  2155.       {
  2156.         ASM_OUTPUT_CASE_FETCH (file,
  2157.              CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2158.              reg_names[REGNO (breg)]);
  2159.         fprintf (file, "l)");
  2160.         break;
  2161.       }
  2162.     if (ireg != 0 || breg != 0)
  2163.       {
  2164.         int scale = 1;
  2165.         if (breg == 0)
  2166.           {
  2167.         abort ();
  2168.           }
  2169.         if (! flag_pic && addr && GET_CODE (addr) == LABEL_REF)
  2170.           {
  2171.         abort ();
  2172.           }
  2173. #ifdef MOTOROLA
  2174.         if (addr != 0)
  2175.           {
  2176.         output_addr_const (file, addr);
  2177.             if (flag_pic && (breg == pic_offset_table_rtx))
  2178.               fprintf (file, "@GOT");
  2179.           }
  2180.         fprintf (file, "(%s", reg_names[REGNO (breg)]);
  2181.         if (ireg != 0)
  2182.           {
  2183.         putc (',', file);
  2184.           }
  2185. #else
  2186.         fprintf (file, "%s@(", reg_names[REGNO (breg)]);
  2187.         if (addr != 0)
  2188.           {
  2189.         output_addr_const (file, addr);
  2190.             if ((flag_pic == 1) && (breg == pic_offset_table_rtx))
  2191.               fprintf (file, ":w");
  2192.             if ((flag_pic == 2) && (breg == pic_offset_table_rtx))
  2193.               fprintf (file, ":l");
  2194.             if ((flag_pic == 3) && (breg == pic_offset_table_rtx))
  2195.               fprintf (file, ":W");
  2196.             if ((flag_pic == 4) && (breg == pic_offset_table_rtx))
  2197.               fprintf (file, ":L");
  2198.           }
  2199.         if (addr != 0 && ireg != 0)
  2200.           {
  2201.         putc (',', file);
  2202.           }
  2203. #endif
  2204.         if (ireg != 0 && GET_CODE (ireg) == MULT)
  2205.           {
  2206.         scale = INTVAL (XEXP (ireg, 1));
  2207.         ireg = XEXP (ireg, 0);
  2208.           }
  2209.         if (ireg != 0 && GET_CODE (ireg) == SIGN_EXTEND)
  2210.           {
  2211. #ifdef MOTOROLA
  2212.         fprintf (file, "%s.w", reg_names[REGNO (XEXP (ireg, 0))]);
  2213. #else
  2214.         fprintf (file, "%s:w", reg_names[REGNO (XEXP (ireg, 0))]);
  2215. #endif
  2216.           }
  2217.         else if (ireg != 0)
  2218.           {
  2219. #ifdef MOTOROLA
  2220.         fprintf (file, "%s.l", reg_names[REGNO (ireg)]);
  2221. #else
  2222.         fprintf (file, "%s:l", reg_names[REGNO (ireg)]);
  2223. #endif
  2224.           }
  2225.         if (scale != 1)
  2226.           {
  2227. #ifdef MOTOROLA
  2228.         fprintf (file, "*%d", scale);
  2229. #else
  2230.         fprintf (file, ":%d", scale);
  2231. #endif
  2232.           }
  2233.         putc (')', file);
  2234.         break;
  2235.       }
  2236.     else if (reg1 != 0 && GET_CODE (addr) == LABEL_REF
  2237.          && ! (flag_pic && reg1 == pic_offset_table_rtx))    
  2238.       {
  2239.         ASM_OUTPUT_CASE_FETCH (file,
  2240.              CODE_LABEL_NUMBER (XEXP (addr, 0)),
  2241.              reg_names[REGNO (reg1)]);
  2242.         fprintf (file, "l)");
  2243.         break;
  2244.       }
  2245.     /* FALL-THROUGH (is this really what we want? */
  2246.       default:
  2247.         if (GET_CODE (addr) == CONST_INT
  2248.         && INTVAL (addr) < 0x8000
  2249.         && INTVAL (addr) >= -0x8000)
  2250.       {
  2251. #ifdef MOTOROLA
  2252. #ifdef SGS
  2253.         /* Many SGS assemblers croak on size specifiers for constants. */
  2254.         fprintf (file, "%d", INTVAL (addr));
  2255. #else
  2256.         fprintf (file, "%d.w", INTVAL (addr));
  2257. #endif
  2258. #else
  2259.         fprintf (file, "%d:w", INTVAL (addr));
  2260. #endif
  2261.       }
  2262.     else
  2263.       {
  2264.         output_addr_const (file, addr);
  2265.       }
  2266.     break;
  2267.     }
  2268. }
  2269.  
  2270. /* Check for cases where a clr insns can be omitted from code using
  2271.    strict_low_part sets.  For example, the second clrl here is not needed:
  2272.    clrl d0; movw a0@+,d0; use d0; clrl d0; movw a0@+; use d0; ...
  2273.  
  2274.    MODE is the mode of this STRICT_LOW_PART set.  FIRST_INSN is the clear
  2275.    insn we are checking for redundancy.  TARGET is the register set by the
  2276.    clear insn.  */
  2277.  
  2278. int
  2279. strict_low_part_peephole_ok (mode, first_insn, target)
  2280.      enum machine_mode mode;
  2281.      rtx first_insn;
  2282.      rtx target;
  2283. {
  2284.   rtx p;
  2285.  
  2286.   p = prev_nonnote_insn (first_insn);
  2287.  
  2288.   while (p)
  2289.     {
  2290.       /* If it isn't an insn, then give up.  */
  2291.       if (GET_CODE (p) != INSN)
  2292.     return 0;
  2293.  
  2294.       if (reg_set_p (target, p))
  2295.     {
  2296.       rtx set = single_set (p);
  2297.       rtx dest;
  2298.  
  2299.       /* If it isn't an easy to recognize insn, then give up.  */
  2300.       if (! set)
  2301.         return 0;
  2302.  
  2303.       dest = SET_DEST (set);
  2304.  
  2305.       /* If this sets the entire target register to zero, then our
  2306.          first_insn is redundant.  */
  2307.       if (rtx_equal_p (dest, target)
  2308.           && SET_SRC (set) == const0_rtx)
  2309.         return 1;
  2310.       else if (GET_CODE (dest) == STRICT_LOW_PART
  2311.            && GET_CODE (XEXP (dest, 0)) == REG
  2312.            && REGNO (XEXP (dest, 0)) == REGNO (target)
  2313.            && (GET_MODE_SIZE (GET_MODE (XEXP (dest, 0)))
  2314.                <= GET_MODE_SIZE (mode)))
  2315.         /* This is a strict low part set which modifies less than
  2316.            we are using, so it is safe.  */
  2317.         ;
  2318.       else
  2319.         return 0;
  2320.     }
  2321.  
  2322.       p = prev_nonnote_insn (p);
  2323.  
  2324.     }
  2325.  
  2326.   return 0;
  2327. }
  2328.