This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Clean up shift code generation in h8300 port (stage 5)


Hi,

Attached is a patch to remove redundant code from get_shift_alg() in
h8300.c.

The patch merges multiple occurences of similar code is in the
function into one.

Tested on h8300 port.  Committed.

Kazu Hirata

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

	* config/h8300/h8300.c (get_shift_alg): Remove redundant code.

Index: h8300.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/h8300/h8300.c,v
retrieving revision 1.75
diff -c -r1.75 h8300.c
*** h8300.c	2001/11/12 09:22:28	1.75
--- h8300.c	2001/11/12 14:56:40
***************
*** 2347,2380 ****
    else
      cpu = 2;
  
!   /* In case we end up with SHIFT_SPECIAL, initialize REMAINDER to 0.  */
!   info->remainder = 0;
! 
!   /* Assume either SHIFT_LOOP or SHIFT_INLINE.
!      It is up to the caller to know that looping clobbers cc.  */
!   info->shift1 = shift_one[cpu_type][shift_type][shift_mode].assembler;
!   info->shift2 = shift_two[shift_type][shift_mode].assembler;
!   info->cc_valid_p = shift_one[cpu_type][shift_type][shift_mode].cc_valid;
! 
!   /* Now look for cases we want to optimize.  */
    switch (shift_mode)
      {
      case QIshift:
        if (GET_MODE_BITSIZE (QImode) <= count)
! 	goto return_shift_loop;
  
!       switch (shift_alg_qi[cpu][shift_type][count])
! 	{
! 	case SHIFT_INLINE:
! 	  goto return_shift_inline;
! 	case SHIFT_LOOP:
! 	  goto return_shift_loop;
! 	case SHIFT_ROT_AND:
! 	  goto return_shift_rot_and;
! 	case SHIFT_SPECIAL:
! 	  ;
! 	}
  
        /* For ASHIFTRT by 7 bits, the sign bit is simply replicated
  	 through the entire value.  */
        if (shift_type == SHIFT_ASHIFTRT && count == 7)
--- 2347,2413 ----
    else
      cpu = 2;
  
!   /* Find the shift algorithm.  */
    switch (shift_mode)
      {
      case QIshift:
        if (GET_MODE_BITSIZE (QImode) <= count)
! 	info->alg = SHIFT_LOOP;
!       else
! 	info->alg = shift_alg_qi[cpu][shift_type][count];
!       break;
  
!     case HIshift:
!       if (GET_MODE_BITSIZE (HImode) <= count)
! 	info->alg = SHIFT_LOOP;
!       else
! 	info->alg = shift_alg_hi[cpu][shift_type][count];
!       break;
! 
!     case SIshift:
!       if (GET_MODE_BITSIZE (SImode) <= count)
! 	info->alg = SHIFT_LOOP;
!       else
! 	info->alg = shift_alg_si[cpu][shift_type][count];
!       break;
! 
!     default:
!       abort ();
!     }
! 
!   /* Fill in INFO.  Return unless we have SHIFT_SPECIAL.  */
!   switch (info->alg)
!     {
!     case SHIFT_INLINE:
!       info->remainder = count;
!       /* Fall through.  */
! 
!     case SHIFT_LOOP:
!       /* It is up to the caller to know that looping clobbers cc.  */
!       info->shift1 = shift_one[cpu_type][shift_type][shift_mode].assembler;
!       info->shift2 = shift_two[shift_type][shift_mode].assembler;
!       info->cc_valid_p = shift_one[cpu_type][shift_type][shift_mode].cc_valid;
!       goto end;
! 
!     case SHIFT_ROT_AND:
!       info->shift1 = rotate_one[cpu_type][shift_type][shift_mode];
!       info->shift2 = rotate_two[shift_type][shift_mode];
!       info->cc_valid_p = 0;
!       goto end;
! 
!     case SHIFT_SPECIAL:
!       /* REMAINDER is 0 for most cases, so initialize it to 0.  */
!       info->remainder = 0;
!       info->shift1 = shift_one[cpu_type][shift_type][shift_mode].assembler;
!       info->shift2 = shift_two[shift_type][shift_mode].assembler;
!       info->cc_valid_p = 0;
!       break;
!     }
  
+   /* Here we only deal with SHIFT_SPECIAL.  */
+   switch (shift_mode)
+     {
+     case QIshift:
        /* For ASHIFTRT by 7 bits, the sign bit is simply replicated
  	 through the entire value.  */
        if (shift_type == SHIFT_ASHIFTRT && count == 7)
***************
*** 2385,2405 ****
        abort ();
  
      case HIshift:
-       if (GET_MODE_BITSIZE (HImode) <= count)
- 	goto return_shift_loop;
- 
-       switch (shift_alg_hi[cpu][shift_type][count])
- 	{
- 	case SHIFT_INLINE:
- 	  goto return_shift_inline;
- 	case SHIFT_LOOP:
- 	  goto return_shift_loop;
- 	case SHIFT_ROT_AND:
- 	  goto return_shift_rot_and;
- 	case SHIFT_SPECIAL:
- 	  ;
- 	}
- 
        if (count == 7)
  	{
  	  if (shift_type == SHIFT_ASHIFT && TARGET_H8300)
--- 2418,2423 ----
***************
*** 2466,2487 ****
        abort ();
  
      case SIshift:
-       if (GET_MODE_BITSIZE (SImode) <= count)
- 	goto return_shift_loop;
- 
-       info->alg = shift_alg_si[cpu][shift_type][count];
-       switch (info->alg)
- 	{
- 	case SHIFT_INLINE:
- 	  goto return_shift_inline;
- 	case SHIFT_LOOP:
- 	  goto return_shift_loop;
- 	case SHIFT_ROT_AND:
- 	  goto return_shift_rot_and;
- 	case SHIFT_SPECIAL:
- 	  ;
- 	}
- 
        if (count == 8 && TARGET_H8300)
  	{
  	  switch (shift_type)
--- 2484,2489 ----
***************
*** 2583,2610 ****
        abort ();
      }
  
-  return_shift_loop:
-   /* No fancy method is available.  Just loop.  */
-   info->alg = SHIFT_LOOP;
-   goto end;
- 
-  return_shift_inline:
-   info->remainder = count;
-   info->alg = SHIFT_INLINE;
-   goto end;
- 
   return_shift_special:
-   info->cc_valid_p = 0;
-   info->alg = SHIFT_SPECIAL;
-   goto end;
- 
-  return_shift_rot_and:
-   info->shift1 = rotate_one[cpu_type][shift_type][shift_mode];
-   info->shift2 = rotate_two[shift_type][shift_mode];
-   info->cc_valid_p = 0;
-   info->alg = SHIFT_ROT_AND;
-   goto end;
- 
   end:
    if (!TARGET_H8300S)
      info->shift2 = NULL;
--- 2585,2591 ----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]