From f76e26645afbf7422f01d4a0fafb36ec476d16ab Mon Sep 17 00:00:00 2001
From: kazu <kazu@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 12 Feb 2002 15:31:54 +0000
Subject: [PATCH] 	* config/h8300/h8300.c (shift_alg_hi): Improve the
 15-bit 	logical shifts on H8/300. 	(shift_alg_si): Improve
 several shifts on H8/300. 	(get_shift_alg): Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@49708 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog            |   7 +++
 gcc/config/h8300/h8300.c | 112 +++++++++++++++++++++++++++++++--------
 2 files changed, 96 insertions(+), 23 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 4720c619c045..03b4b9e31bd4 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2002-02-12  Kazu Hirata  <kazu@hxi.com>
+
+	* config/h8300/h8300.c (shift_alg_hi): Improve the 15-bit
+	logical shifts on H8/300.
+	(shift_alg_si): Improve several shifts on H8/300.
+	(get_shift_alg): Likewise.
+
 2002-02-12  Graham Stott  <grahams@redhat.com>
 
 	* config/pa/pa.c (compute_movstrsi_length): Fix typos.
diff --git a/gcc/config/h8300/h8300.c b/gcc/config/h8300/h8300.c
index 6a47d0a5a059..dae7defb6f56 100644
--- a/gcc/config/h8300/h8300.c
+++ b/gcc/config/h8300/h8300.c
@@ -2012,9 +2012,9 @@ static const enum shift_alg shift_alg_hi[3][3][16] = {
     /*  0    1    2    3    4    5    6    7  */
     /*  8    9   10   11   12   13   14   15  */
     { INL, INL, INL, INL, INL, LOP, LOP, SPC,
-      SPC, SPC, SPC, SPC, SPC, LOP, LOP, ROT }, /* SHIFT_ASHIFT   */
+      SPC, SPC, SPC, SPC, SPC, LOP, LOP, SPC }, /* SHIFT_ASHIFT   */
     { INL, INL, INL, INL, INL, LOP, LOP, SPC,
-      SPC, SPC, SPC, SPC, SPC, LOP, LOP, ROT }, /* SHIFT_LSHIFTRT */
+      SPC, SPC, SPC, SPC, SPC, LOP, LOP, SPC }, /* SHIFT_LSHIFTRT */
     { INL, INL, INL, INL, INL, LOP, LOP, SPC,
       SPC, SPC, SPC, SPC, SPC, LOP, LOP, SPC }, /* SHIFT_ASHIFTRT */
   },
@@ -2051,16 +2051,16 @@ static const enum shift_alg shift_alg_si[3][3][32] = {
     /* 24   25   26   27   28   29   30   31  */
     { INL, INL, INL, LOP, LOP, LOP, LOP, LOP,
       SPC, LOP, LOP, LOP, LOP, LOP, LOP, LOP,
-      SPC, LOP, LOP, LOP, LOP, LOP, LOP, LOP,
-      LOP, LOP, LOP, LOP, LOP, LOP, LOP, SPC }, /* SHIFT_ASHIFT   */
+      SPC, SPC, SPC, SPC, SPC, LOP, LOP, LOP,
+      SPC, SPC, SPC, SPC, LOP, LOP, LOP, SPC }, /* SHIFT_ASHIFT   */
     { INL, INL, INL, LOP, LOP, LOP, LOP, LOP,
-      SPC, LOP, LOP, LOP, LOP, LOP, LOP, LOP,
-      SPC, LOP, LOP, LOP, LOP, LOP, LOP, LOP,
-      LOP, LOP, LOP, LOP, LOP, LOP, LOP, SPC }, /* SHIFT_LSHIFTRT */
+      SPC, SPC, LOP, LOP, LOP, LOP, LOP, SPC,
+      SPC, SPC, SPC, LOP, LOP, LOP, LOP, LOP,
+      SPC, SPC, SPC, SPC, SPC, LOP, LOP, SPC }, /* SHIFT_LSHIFTRT */
     { INL, INL, INL, LOP, LOP, LOP, LOP, LOP,
-      SPC, LOP, LOP, LOP, LOP, LOP, LOP, LOP,
-      SPC, LOP, LOP, LOP, LOP, LOP, LOP, LOP,
-      LOP, LOP, LOP, LOP, LOP, LOP, LOP, SPC }, /* SHIFT_ASHIFTRT */
+      SPC, LOP, LOP, LOP, LOP, LOP, LOP, SPC,
+      SPC, SPC, LOP, LOP, LOP, LOP, LOP, LOP,
+      SPC, SPC, SPC, LOP, LOP, LOP, LOP, SPC }, /* SHIFT_ASHIFTRT */
   },
   {
     /* TARGET_H8300H  */
@@ -2282,16 +2282,28 @@ get_shift_alg (shift_type, shift_mode, count, info)
 	      goto end;
 	    }
 	}
-      else if (count == 15 && shift_type == SHIFT_ASHIFTRT)
+      else if (count == 15)
 	{
-	  info->special = "shll\t%t0\n\tsubx\t%t0,%t0\n\tmov.b\t%t0,%s0";
-	  goto end;
+	  switch (shift_type)
+	    {
+	    case SHIFT_ASHIFT:
+	      info->special = "bld\t#0,%s0\n\txor\t%s0,%s0\n\txor\t%t0,%t0\n\tbst\t#7,%t0";
+	      goto end;
+	    case SHIFT_LSHIFTRT:
+	      info->special = "bld\t#7,%t0\n\txor\t%s0,%s0\n\txor\t%t0,%t0\n\tbst\t#0,%s0";
+	      goto end;
+	    case SHIFT_ASHIFTRT:
+	      info->special = "shll\t%t0\n\tsubx\t%t0,%t0\n\tmov.b\t%t0,%s0";
+	      goto end;
+	    }
 	}
       abort ();
 
     case SIshift:
-      if (count == 8 && TARGET_H8300)
+      if (TARGET_H8300 && 8 <= count && count <= 9)
 	{
+	  info->remainder = count - 8;
+
 	  switch (shift_type)
 	    {
 	    case SHIFT_ASHIFT:
@@ -2299,6 +2311,7 @@ get_shift_alg (shift_type, shift_mode, count, info)
 	      goto end;
 	    case SHIFT_LSHIFTRT:
 	      info->special = "mov.b\t%x0,%w0\n\tmov.b\t%y0,%x0\n\tmov.b\t%z0,%y0\n\tsub.b\t%z0,%z0";
+	      info->shift1  = "shlr\t%y0\n\trotxr\t%x0\n\trotxr\t%w0";
 	      goto end;
 	    case SHIFT_ASHIFTRT:
 	      info->special = "mov.b\t%x0,%w0\n\tmov.b\t%y0,%x0\n\tmov.b\t%z0,%y0\n\tshll\t%z0\n\tsubx\t%z0,%z0";
@@ -2320,6 +2333,20 @@ get_shift_alg (shift_type, shift_mode, count, info)
 	      goto end;
 	    }
 	}
+      else if (count == 15 && TARGET_H8300)
+	{
+	  switch (shift_type)
+	    {
+	    case SHIFT_ASHIFT:
+	      abort ();
+	    case SHIFT_LSHIFTRT:
+	      info->special = "bld\t#7,%z0\n\tmov.w\t%e0,%f0\n\txor\t%y0,%y0\n\txor\t%z0,%z0\n\trotxl\t%w0,%w0\n\trotxl\t%x0,%x0\n\trotxl\t%y0,%y0";
+	      goto end;
+	    case SHIFT_ASHIFTRT:
+	      info->special = "bld\t#7,%z0\n\tmov.w\t%e0,%f0\n\trotxl\t%w0,%w0\n\trotxl\t%x0,%x0\n\tsubx\t%y0,%y0\n\tsubx\t%z0,%z0";
+	      goto end;
+	    }
+	}
       else if (count == 15 && !TARGET_H8300)
 	{
 	  switch (shift_type)
@@ -2334,7 +2361,7 @@ get_shift_alg (shift_type, shift_mode, count, info)
 	      abort ();
 	    }
 	}
-      else if ((TARGET_H8300 && count == 16)
+      else if ((TARGET_H8300 && 16 <= count && count <= 20)
 	       || (TARGET_H8300H && 16 <= count && count <= 19)
 	       || (TARGET_H8300S && 16 <= count && count <= 21))
 	{
@@ -2344,24 +2371,63 @@ get_shift_alg (shift_type, shift_mode, count, info)
 	    {
 	    case SHIFT_ASHIFT:
 	      info->special = "mov.w\t%f0,%e0\n\tsub.w\t%f0,%f0";
-	      info->shift1  = "shll.l\t%S0";
-	      info->shift2  = "shll.l\t#2,%S0";
+	      if (TARGET_H8300)
+		{
+		  info->shift1 = "add.w\t%e0,%e0";
+		}
+	      else
+		{
+		  info->shift1 = "shll.l\t%S0";
+		  info->shift2 = "shll.l\t#2,%S0";
+		}
 	      goto end;
 	    case SHIFT_LSHIFTRT:
 	      info->special = "mov.w\t%e0,%f0\n\tsub.w\t%e0,%e0";
-	      info->shift1  = "shlr.l\t%S0";
-	      info->shift2  = "shlr.l\t#2,%S0";
+	      if (TARGET_H8300)
+		{
+		  info->shift1 = "shlr\t%x0\n\trotxr\t%w0";
+		}
+	      else
+		{
+		  info->shift1 = "shlr.l\t%S0";
+		  info->shift2 = "shlr.l\t#2,%S0";
+		}
 	      goto end;
 	    case SHIFT_ASHIFTRT:
 	      if (TARGET_H8300)
-		info->special = "mov.w\t%e0,%f0\n\tshll\t%z0\n\tsubx\t%z0,%z0\n\tmov.b\t%z0,%y0";
+		{
+		  info->special = "mov.w\t%e0,%f0\n\tshll\t%z0\n\tsubx\t%z0,%z0\n\tmov.b\t%z0,%y0";
+		  info->shift1  = "shar\t%x0\n\trotxr\t%w0";
+		}
 	      else
-		info->special = "mov.w\t%e0,%f0\n\texts.l\t%S0";
-	      info->shift1 = "shar.l\t%S0";
-	      info->shift2 = "shar.l\t#2,%S0";
+		{
+		  info->special = "mov.w\t%e0,%f0\n\texts.l\t%S0";
+		  info->shift1  = "shar.l\t%S0";
+		  info->shift2  = "shar.l\t#2,%S0";
+		}
 	      goto end;
 	    }
 	}
+      else if (TARGET_H8300 && 24 <= count && count <= 28)
+ 	{
+ 	  info->remainder = count - 24;
+ 
+ 	  switch (shift_type)
+ 	    {
+ 	    case SHIFT_ASHIFT:
+ 	      info->special = "mov.b\t%w0,%z0\n\tsub.b\t%y0,%y0\n\tsub.w\t%f0,%f0";
+ 	      info->shift1  = "shll.b\t%z0";
+ 	      goto end;
+ 	    case SHIFT_LSHIFTRT:
+ 	      info->special = "mov.b\t%z0,%w0\n\tsub.b\t%x0,%x0\n\tsub.w\t%e0,%e0";
+ 	      info->shift1  = "shlr.b\t%w0";
+ 	      goto end;
+ 	    case SHIFT_ASHIFTRT:
+ 	      info->special = "mov.b\t%z0,%w0\n\tbld\t#7,%w0\n\tsubx\t%x0,%x0\n\tsubx\t%x0,%x0\n\tsubx\t%x0,%x0";
+ 	      info->shift1  = "shar.b\t%w0";
+  	      goto end;
+  	    }
+  	}
       else if ((TARGET_H8300H && count == 24)
 	       || (TARGET_H8300S && 24 <= count && count <= 25))
 	{
-- 
GitLab