[patch] Improve shifts in h8300 port (stage 2)

Kazu Hirata kazu@hxi.com
Tue Nov 13 15:03:00 GMT 2001


Hi,

Attached is a patch to improve shifts in h8300 port.

The patch contains two improvements, both of which take advantage of
the fact that xor insn on h8300 does not clobber cc0.

1) 15-bit logical shifts

The original gcc outputs a loop for this case.  However, we can
improve it by using a special sequence of insns.  See below:

-	mov.b	#15,r3l   <- old code
-.Llt83:
-	shll.l	er2
-	add	#0xff,r3l
-	bne	.Llt83

+	shlr.w	e2        <- new code
+	mov.w	r2,e2
+	xor.w	r2,r2
+	rotxr.l	er2

2) 31-bit logical shifts

The original gcc outputs a rotation in the opposite direction followed
by an and.  However, we can improve it by using a special sequence of
insns.  See below:

-	rotr.l	er2              <- old code
-	and.l	#-2147483648,er2 <- This takes 6 bytes!

+	shlr.l	er2              <- new code
+	xor.l	er2,er2
+	rotxr.l	er2

Tested on h8300 port.  Committed.

Kazu Hirata

2001-11-12  Kazu Hirata  <kazu@hxi.com>

	* config/h8300/h8300.c (shift_alg_si): Use special code for
	15-bit logical shifts and 31-bit logical shifts.
	(get_shift_alg): Generate special code for 15-bit and 31-bit
	logical shifts.

Index: h8300.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/h8300/h8300.c,v
retrieving revision 1.78
diff -c -r1.78 h8300.c
*** h8300.c	2001/11/12 18:20:59	1.78
--- h8300.c	2001/11/12 18:37:18
***************
*** 2252,2264 ****
      /* 16   17   18   19   20   21   22   23  */
      /* 24   25   26   27   28   29   30   31  */
      { INL, INL, INL, INL, INL, LOP, LOP, LOP,
!       SPC, LOP, LOP, LOP, LOP, LOP, LOP, LOP,
        SPC, SPC, SPC, SPC, LOP, LOP, LOP, LOP,
!       SPC, LOP, LOP, LOP, ROT, ROT, ROT, ROT }, /* SHIFT_ASHIFT   */
      { INL, INL, INL, INL, INL, LOP, LOP, LOP,
!       SPC, LOP, LOP, LOP, LOP, LOP, LOP, LOP,
        SPC, SPC, SPC, SPC, LOP, LOP, LOP, LOP,
!       SPC, LOP, LOP, LOP, ROT, ROT, ROT, ROT }, /* SHIFT_LSHIFTRT */
      { INL, INL, INL, INL, INL, LOP, LOP, LOP,
        SPC, LOP, LOP, LOP, LOP, LOP, LOP, LOP,
        SPC, SPC, SPC, SPC, LOP, LOP, LOP, LOP,
--- 2252,2264 ----
      /* 16   17   18   19   20   21   22   23  */
      /* 24   25   26   27   28   29   30   31  */
      { INL, INL, INL, INL, INL, LOP, LOP, LOP,
!       SPC, LOP, LOP, LOP, LOP, LOP, LOP, SPC,
        SPC, SPC, SPC, SPC, LOP, LOP, LOP, LOP,
!       SPC, LOP, LOP, LOP, ROT, ROT, ROT, SPC }, /* SHIFT_ASHIFT   */
      { INL, INL, INL, INL, INL, LOP, LOP, LOP,
!       SPC, LOP, LOP, LOP, LOP, LOP, LOP, SPC,
        SPC, SPC, SPC, SPC, LOP, LOP, LOP, LOP,
!       SPC, LOP, LOP, LOP, ROT, ROT, ROT, SPC }, /* SHIFT_LSHIFTRT */
      { INL, INL, INL, INL, INL, LOP, LOP, LOP,
        SPC, LOP, LOP, LOP, LOP, LOP, LOP, LOP,
        SPC, SPC, SPC, SPC, LOP, LOP, LOP, LOP,
***************
*** 2271,2283 ****
      /* 16   17   18   19   20   21   22   23  */
      /* 24   25   26   27   28   29   30   31  */
      { INL, INL, INL, INL, INL, INL, INL, INL,
!       INL, INL, INL, LOP, LOP, LOP, LOP, LOP,
        SPC, SPC, SPC, SPC, SPC, SPC, LOP, LOP,
!       SPC, LOP, LOP, LOP, ROT, ROT, ROT, ROT }, /* SHIFT_ASHIFT   */
      { INL, INL, INL, INL, INL, INL, INL, INL,
!       INL, INL, INL, LOP, LOP, LOP, LOP, LOP,
        SPC, SPC, SPC, SPC, SPC, SPC, LOP, LOP,
!       SPC, LOP, LOP, LOP, ROT, ROT, ROT, ROT }, /* SHIFT_LSHIFTRT */
      { INL, INL, INL, INL, INL, INL, INL, INL,
        INL, INL, INL, LOP, LOP, LOP, LOP, LOP,
        SPC, SPC, SPC, SPC, SPC, SPC, LOP, LOP,
--- 2271,2283 ----
      /* 16   17   18   19   20   21   22   23  */
      /* 24   25   26   27   28   29   30   31  */
      { INL, INL, INL, INL, INL, INL, INL, INL,
!       INL, INL, INL, LOP, LOP, LOP, LOP, SPC,
        SPC, SPC, SPC, SPC, SPC, SPC, LOP, LOP,
!       SPC, LOP, LOP, LOP, ROT, ROT, ROT, SPC }, /* SHIFT_ASHIFT   */
      { INL, INL, INL, INL, INL, INL, INL, INL,
!       INL, INL, INL, LOP, LOP, LOP, LOP, SPC,
        SPC, SPC, SPC, SPC, SPC, SPC, LOP, LOP,
!       SPC, LOP, LOP, LOP, ROT, ROT, ROT, SPC }, /* SHIFT_LSHIFTRT */
      { INL, INL, INL, INL, INL, INL, INL, INL,
        INL, INL, INL, LOP, LOP, LOP, LOP, LOP,
        SPC, SPC, SPC, SPC, SPC, SPC, LOP, LOP,
***************
*** 2514,2519 ****
--- 2514,2531 ----
  	      goto end;
  	    }
  	}
+       else if (count == 15 && !TARGET_H8300)
+ 	{
+ 	  switch (shift_type)
+ 	    {
+ 	    case SHIFT_ASHIFT:
+ 	      info->special = "shlr.w\t%e0\n\tmov.w\t%f0,%e0\n\txor.w\t%f0,%f0\n\trotxr.l\t%S0";
+ 	      goto end;
+ 	    case SHIFT_LSHIFTRT:
+ 	      info->special = "shll.w\t%e0\n\tmov.w\t%e0,%f0\n\txor.w\t%e0,%e0\n\trotxl.l\t%S0";
+ 	      goto end;
+ 	    }
+ 	}
        else if ((TARGET_H8300 && count == 16)
  	       || (TARGET_H8300H && 16 <= count && count <= 19)
  	       || (TARGET_H8300S && 16 <= count && count <= 21))
***************
*** 2559,2580 ****
  	}
        else if (count == 31)
  	{
! 	  if (shift_type == SHIFT_ASHIFTRT)
  	    {
! 	      if (TARGET_H8300)
! 		info->special = "shll\t%z0\n\tsubx\t%w0,%w0\n\tmov.b\t%w0,%x0\n\tmov.w\t%f0,%e0";
! 	      else
! 		info->special = "shll\t%e0\n\tsubx\t%w0,%w0\n\tmov.b\t%w0,%x0\n\tmov.w\t%f0,%e0";
! 	      goto end;
  	    }
  	  else
  	    {
! 	      if (TARGET_H8300)
  		{
! 		  if (shift_type == SHIFT_ASHIFT)
! 		    info->special = "sub.w\t%e0,%e0\n\tshlr\t%w0\n\tmov.w\t%e0,%f0\n\trotxr\t%z0";
! 		  else
! 		    info->special = "sub.w\t%f0,%f0\n\tshll\t%z0\n\tmov.w\t%f0,%e0\n\trotxl\t%w0";
  		  goto end;
  		}
  	    }
--- 2571,2603 ----
  	}
        else if (count == 31)
  	{
! 	  if (TARGET_H8300)
  	    {
! 	      switch (shift_type)
! 		{
! 		case SHIFT_ASHIFT:
! 		  info->special = "sub.w\t%e0,%e0\n\tshlr\t%w0\n\tmov.w\t%e0,%f0\n\trotxr\t%z0";
! 		  goto end;
! 		case SHIFT_LSHIFTRT:
! 		  info->special = "sub.w\t%f0,%f0\n\tshll\t%z0\n\tmov.w\t%f0,%e0\n\trotxl\t%w0";
! 		  goto end;
! 		case SHIFT_ASHIFTRT:
! 		  info->special = "shll\t%z0\n\tsubx\t%w0,%w0\n\tmov.b\t%w0,%x0\n\tmov.w\t%f0,%e0";
! 		  goto end;
! 		}
  	    }
  	  else
  	    {
! 	      switch (shift_type)
  		{
! 		case SHIFT_ASHIFT:
! 		  info->special = "shlr.l\t%S0\n\txor.l\t%S0,%S0\n\trotxr.l\t%S0";
! 		  goto end;
! 		case SHIFT_LSHIFTRT:
! 		  info->special = "shll.l\t%S0\n\txor.l\t%S0,%S0\n\trotxl.l\t%S0";
! 		  goto end;
! 		case SHIFT_ASHIFTRT:
! 		  info->special = "shll\t%e0\n\tsubx\t%w0,%w0\n\tmov.b\t%w0,%x0\n\tmov.w\t%f0,%e0";
  		  goto end;
  		}
  	    }



More information about the Gcc-patches mailing list