H8/300H code size issues (RTX_COSTS)

Kazu Hirata kazu@cs.umass.edu
Wed Nov 13 08:53:00 GMT 2002


Hi Toshi,

> BTW, I've been looking at code size issues on the H8/300H, and I've
> found some interesting things lately.

For at least several months, I've kept a patch for shift insn portion
of RTX_COSTS.  I just tried the patch again, and saw that about 800
lines of assembly code were cut down in newlib.

This may not reduce your code by 50% but may be a good starting point.

Would you mind sending me a preprocessed copy of your code?

Kazu Hirata

Index: h8300-protos.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/h8300/h8300-protos.h,v
retrieving revision 1.32
diff -c -r1.32 h8300-protos.h
*** h8300-protos.h	29 Oct 2002 17:55:45 -0000	1.32
--- h8300-protos.h	1 Nov 2002 21:56:04 -0000
***************
*** 32,37 ****
--- 32,38 ----
  extern const char *output_simode_bld PARAMS ((int, rtx[]));
  extern void print_operand_address PARAMS ((FILE *, rtx));
  extern int const_costs PARAMS ((rtx, enum rtx_code, enum rtx_code));
+ extern int h8300_shift_costs PARAMS ((rtx));
  extern void print_operand PARAMS ((FILE *, rtx, int));
  extern void final_prescan_insn PARAMS ((rtx, rtx *, int));
  extern int do_movsi PARAMS ((rtx[]));
Index: h8300.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/h8300/h8300.c,v
retrieving revision 1.154
diff -c -r1.154 h8300.c
*** h8300.c	30 Oct 2002 11:21:24 -0000	1.154
--- h8300.c	1 Nov 2002 21:56:08 -0000
***************
*** 1124,1129 ****
--- 1124,1147 ----
        return 4;
      }
  }
+ 
+ int
+ h8300_shift_costs (x)
+      rtx x;
+ {
+   rtx operands[4];
+ 
+   if (GET_MODE (x) != QImode
+       || GET_MODE (x) != HImode
+       || GET_MODE (x) != SImode)
+     return 20;
+ 
+   operands[0] = NULL;
+   operands[1] = NULL;
+   operands[2] = XEXP (x, 1);
+   operands[3] = x;
+   return compute_a_shift_length (NULL, operands) / 2;
+ }
  
  /* Documentation for the machine specific operand escapes:
  
Index: h8300.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/h8300/h8300.h,v
retrieving revision 1.113
diff -c -r1.113 h8300.h
*** h8300.h	1 Nov 2002 21:36:37 -0000	1.113
--- h8300.h	1 Nov 2002 21:56:09 -0000
***************
*** 1011,1028 ****
     switch on CODE.  */
  /* ??? Shifts need to have a *much* higher cost than this.  */
  
! #define RTX_COSTS(RTX, CODE, OUTER_CODE)	\
!   case MOD:					\
!   case DIV:					\
!     return 60;					\
!   case MULT:					\
!     return 20;					\
!   case ASHIFT:					\
!   case ASHIFTRT:				\
!   case LSHIFTRT:				\
!   case ROTATE:					\
!   case ROTATERT:				\
!     if (GET_MODE (RTX) == HImode) return 2;	\
      return 8;
  
  /* Tell final.c how to eliminate redundant test instructions.  */
--- 1011,1030 ----
     switch on CODE.  */
  /* ??? Shifts need to have a *much* higher cost than this.  */
  
! #define RTX_COSTS(RTX, CODE, OUTER_CODE)		\
!   case AND:						\
!   case MOD:						\
!   case DIV:						\
!     return 60;						\
!   case MULT:						\
!     return 20;						\
!   case ASHIFT:						\
!   case ASHIFTRT:					\
!   case LSHIFTRT:					\
!     return COSTS_N_INSNS (h8300_shift_costs (RTX));	\
!   case ROTATE:						\
!   case ROTATERT:					\
!     if (GET_MODE (RTX) == HImode) return 2;		\
      return 8;
  
  /* Tell final.c how to eliminate redundant test instructions.  */



More information about the Gcc-bugs mailing list