[patch] config/h8300/h8300.c: Rearrange code for conciseness.

Kazu Hirata kazu@hxi.com
Sat Aug 5 14:56:00 GMT 2000


Hi,

Attached is a patch to rearrange code in h8300.c for conciseness.
What the patch does is very similar to:

http://gcc.gnu.org/ml/gcc-patches/2000-07/msg01246.html

The patch cuts down dosize () to almost a half of the original while
preserving the functionality.  I hope this improves readability as
well.

Thanks,

Kazu Hirata

2000-08-05  Kazu Hirata  <kazu@hxi.com>

	* config/h8300/h8300.c (dosize): Rearrange code for conciseness.
	(split_adds_subs): Likewise.

============================================================

Index: h8300.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/h8300/h8300.c,v
retrieving revision 1.36
diff -c -3 -p -r1.36 h8300.c
*** h8300.c	2000/08/04 07:07:55	1.36
--- h8300.c	2000/08/05 20:55:02
*************** dosize (file, op, size)
*** 148,210 ****
       const char *op;
       unsigned int size;
  {
!   /* On the h8300h and h8300s, for sizes <= 8 bytes it is as good or
!      better to use adds/subs insns rather than add.l/sub.l
!      with an immediate value.   */
!   if (size > 4 && size <= 8 && (TARGET_H8300H || TARGET_H8300S))
!     {
!       /* Crank the size down to <= 4.  */
!       fprintf (file, "\t%ss\t#%d,sp\n", op, 4);
!       size -= 4;
!     }
! 
!   switch (size)
!     {
!     case 4:
!       if (TARGET_H8300H || TARGET_H8300S)
  	{
! 	  fprintf (file, "\t%ss\t#%d,sp\n", op, 4);
! 	  size = 0;
! 	  break;
  	}
!     case 3:
!       fprintf (file, "\t%ss\t#%d,sp\n", op, 2);
!       size -= 2;
!       /* Fall through...  */
!     case 2:
!     case 1:
!       fprintf (file, "\t%ss\t#%d,sp\n", op, size);
!       size = 0;
!       break;
!     case 0:
!       break;
!     default:
        if (TARGET_H8300)
! 	{
! 	  if (current_function_needs_context
! 	      && strcmp (op, "sub") == 0)
! 	    {
! 	      /* Egad.  We don't have a temporary to hold the
! 		 size of the frame in the prologue!  Just inline
! 		 the bastard since this shouldn't happen often.  */
! 	      while (size >= 2)
! 		{
! 		  fprintf (file, "\tsubs\t#2,sp\n");
! 		  size -= 2;
! 		}
! 
! 	      if (size)
! 		fprintf (file, "\tsubs\t#1,sp\n");
! 
! 	      size = 0;
! 	    }
! 	  else
! 	    fprintf (file, "\tmov.w\t#%d,r3\n\t%s.w\tr3,sp\n", size, op);
! 	}
        else
! 	fprintf (file, "\t%s\t#%d,sp\n", op, size);
!       size = 0;
!       break;
      }
  }
  
--- 148,182 ----
       const char *op;
       unsigned int size;
  {
!   /* On the H8/300H and H8/S, for sizes <= 8 bytes, it is as good or
!      better to use adds/subs insns rather than add.l/sub.l with an
!      immediate value.
! 
!      Also, on the H8/300, if we don't have a temporary to hold the
!      size of the frame in the prologue, we simply emit a sequence of
!      subs since this shouldn't happen often.  */
!   if ((TARGET_H8300 && size <= 4)
!       || ((TARGET_H8300H || TARGET_H8300S) && size <= 8)
!       || (TARGET_H8300 && current_function_needs_context
! 	  && strcmp (op, "sub")))
!     {
!       HOST_WIDE_INT amount;
! 
!       /* Try different amounts in descending order.  */
!       for (amount = (TARGET_H8300H || TARGET_H8300S) ? 4 : 2;
! 	   amount > 0;
! 	   amount /= 2)
  	{
! 	  for(; size >= amount; size -= amount)
! 	    fprintf (file, "\t%ss\t#%d,sp\n", op, amount);
  	}
!     }
!   else
!     {
        if (TARGET_H8300)
! 	fprintf (file, "\tmov.w\t#%d,r3\n\t%s.w\tr3,sp\n", size, op);
        else
! 	fprintf (file, "\t%s.l\t#%d,sp\n", op, size);
      }
  }
  
*************** split_adds_subs (mode, operands)
*** 640,650 ****
         amount > 0;
         amount /= 2)
      {
!       while (val >= amount)
  	{
  	  rtx tmp = gen_rtx_PLUS (mode, reg, GEN_INT (sign * amount));
  	  emit_insn (gen_rtx_SET (VOIDmode, reg, tmp));
- 	  val -= amount;
  	}
      }
  
--- 612,621 ----
         amount > 0;
         amount /= 2)
      {
!       for(; val >= amount; val -= amount)
  	{
  	  rtx tmp = gen_rtx_PLUS (mode, reg, GEN_INT (sign * amount));
  	  emit_insn (gen_rtx_SET (VOIDmode, reg, tmp));
  	}
      }
  
============================================================



More information about the Gcc-patches mailing list