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]

[ColdFire 38/63] Clean up handling of integer moves


This patch makes various constant-related functions take a
HOST_WIDE_INT rather than a CONST_INT rtx.  It's partly a cleanup,
but the valid_mov3q_const part is also needed by the next patch.

Richard


gcc/
	* config/m68k/m68k-protos.h (valid_mov3q_const): Take a HOST_WIDE_INT
	and return a bool.
	(output_move_const_into_data_reg, output_move_simode_const): Delete.
	* config/m68k/m68k.c (const_method, const_int_cost): Take a
	HOST_WIDE_INT instead of an rtx.
	(m68k_rtx_costs): Update call accordingly.
	(output_move_const_into_data_reg): Likewise.  Fix formatting.
	(valid_mov3q_const): Take a HOST_WIDE_INT instead of an rtx.
	Return a bool.
	(output_move_simode_const): Update calls after above changes.
	Rework to use automatic variables and predicates like MEM_P.
	* config/m68k/m68k.md (pushexthisi_const): Update call to
	valid_mov3q_const.

Index: gcc/config/m68k/m68k-protos.h
===================================================================
--- gcc/config/m68k/m68k-protos.h	2007-01-09 15:02:15.000000000 +0000
+++ gcc/config/m68k/m68k-protos.h	2007-01-09 15:02:16.000000000 +0000
@@ -23,9 +23,7 @@ the Free Software Foundation; either ver
 #ifdef RTX_CODE
 extern bool m68k_interrupt_function_p (tree);
 extern HOST_WIDE_INT m68k_initial_elimination_offset (int from, int to);
-extern const char *output_move_const_into_data_reg (rtx *);
-extern int valid_mov3q_const (rtx);
-extern const char *output_move_simode_const (rtx *);
+extern bool valid_mov3q_const (HOST_WIDE_INT);
 extern const char *output_move_simode (rtx *);
 extern const char *output_move_himode (rtx *);
 extern const char *output_move_qimode (rtx *);
Index: gcc/config/m68k/m68k.c
===================================================================
--- gcc/config/m68k/m68k.c	2007-01-09 15:02:15.000000000 +0000
+++ gcc/config/m68k/m68k.c	2007-01-09 15:02:16.000000000 +0000
@@ -146,7 +146,6 @@ static tree m68k_handle_fndecl_attribute
 					  bool *no_add_attrs);
 static void m68k_compute_frame_layout (void);
 static bool m68k_save_reg (unsigned int regno, bool interrupt_handler);
-static int const_int_cost (rtx);
 static bool m68k_rtx_costs (rtx, int, int, int *);
 
 
@@ -1943,17 +1942,15 @@ legitimize_pic_address (rtx orig, enum m
 
 typedef enum { MOVL, SWAP, NEGW, NOTW, NOTB, MOVQ, MVS, MVZ } CONST_METHOD;
 
-static CONST_METHOD const_method (rtx);
-
 #define USE_MOVQ(i)	((unsigned) ((i) + 128) <= 255)
 
+/* Return the type of move that should be used for integer I.  */
+
 static CONST_METHOD
-const_method (rtx constant)
+const_method (HOST_WIDE_INT i)
 {
-  int i;
   unsigned u;
 
-  i = INTVAL (constant);
   if (USE_MOVQ (i))
     return MOVQ;
 
@@ -1991,10 +1988,12 @@ const_method (rtx constant)
   return MOVL;
 }
 
+/* Return the cost of moving constant I into a data register.  */
+
 static int
-const_int_cost (rtx constant)
+const_int_cost (HOST_WIDE_INT i)
 {
-  switch (const_method (constant))
+  switch (const_method (i))
     {
     case MOVQ:
       /* Constants between -128 and 127 are cheap due to moveq.  */
@@ -2024,7 +2023,7 @@ m68k_rtx_costs (rtx x, int code, int out
       if (x == const0_rtx)
 	*total = 0;
       else
-        *total = const_int_cost (x);
+        *total = const_int_cost (INTVAL (x));
       return true;
 
     case CONST:
@@ -2149,13 +2148,16 @@ #define DIVW_COST				\
     }
 }
 
-const char *
+/* Return an instruction to move CONST_INT OPERANDS[1] into data regsiter
+   OPERANDS[0].  */
+
+static const char *
 output_move_const_into_data_reg (rtx *operands)
 {
-  int i;
+  HOST_WIDE_INT i;
 
   i = INTVAL (operands[1]);
-  switch (const_method (operands[1]))
+  switch (const_method (i))
     {
     case MVZ:
       return "mvzw %1,%0";
@@ -2182,63 +2184,55 @@ output_move_const_into_data_reg (rtx *op
 	return "moveq %1,%0\n\tswap %0";
       }
     case MOVL:
-	return "move%.l %1,%0";
+      return "move%.l %1,%0";
     default:
-	gcc_unreachable ();
+      gcc_unreachable ();
     }
 }
 
-/* Return 1 if 'constant' can be represented by
-   mov3q on a ColdFire V4 core.  */
-int
-valid_mov3q_const (rtx constant)
-{
-  int i;
+/* Return true if I can be handled by ISA B's mov3q instruction.  */
 
-  if (TARGET_ISAB && GET_CODE (constant) == CONST_INT)
-    {
-      i = INTVAL (constant);
-      if (i == -1 || (i >= 1 && i <= 7))
-	return 1;
-    }
-  return 0;
+bool
+valid_mov3q_const (HOST_WIDE_INT i)
+{
+  return TARGET_ISAB && (i == -1 || IN_RANGE (i, 1, 7));
 }
 
+/* Return an instruction to move CONST_INT OPERANDS[1] into OPERANDS[0].
+   I is the value of OPERANDS[1].  */
 
-const char *
+static const char *
 output_move_simode_const (rtx *operands)
 {
-  if (operands[1] == const0_rtx
-      && (DATA_REG_P (operands[0])
-	  || GET_CODE (operands[0]) == MEM)
+  rtx dest;
+  HOST_WIDE_INT src;
+
+  dest = operands[0];
+  src = INTVAL (operands[1]);
+  if (src == 0
+      && (DATA_REG_P (dest) || MEM_P (dest))
       /* clr insns on 68000 read before writing.  */
       && ((TARGET_68010 || TARGET_COLDFIRE)
-	  || !(GET_CODE (operands[0]) == MEM
-	       && MEM_VOLATILE_P (operands[0]))))
+	  || !(MEM_P (dest) && MEM_VOLATILE_P (dest))))
     return "clr%.l %0";
-  else if ((GET_MODE (operands[0]) == SImode)
-           && valid_mov3q_const (operands[1]))
+  else if (GET_MODE (dest) == SImode && valid_mov3q_const (src))
     return "mov3q%.l %1,%0";
-  else if (operands[1] == const0_rtx
-	   && ADDRESS_REG_P (operands[0]))
+  else if (src == 0 && ADDRESS_REG_P (dest))
     return "sub%.l %0,%0";
-  else if (DATA_REG_P (operands[0]))
+  else if (DATA_REG_P (dest))
     return output_move_const_into_data_reg (operands);
-  else if (ADDRESS_REG_P (operands[0])
-	   && INTVAL (operands[1]) < 0x8000
-	   && INTVAL (operands[1]) >= -0x8000)
+  else if (ADDRESS_REG_P (dest) && IN_RANGE (src, -0x8000, 0x7fff))
     {
-      if (valid_mov3q_const (operands[1]))
+      if (valid_mov3q_const (src))
         return "mov3q%.l %1,%0";
       return "move%.w %1,%0";
     }
-  else if (GET_CODE (operands[0]) == MEM
-	   && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
-	   && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM
-	   && INTVAL (operands[1]) < 0x8000
-	   && INTVAL (operands[1]) >= -0x8000)
+  else if (MEM_P (dest)
+	   && GET_CODE (XEXP (dest, 0)) == PRE_DEC
+	   && REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
+	   && IN_RANGE (src, -0x8000, 0x7fff))
     {
-      if (valid_mov3q_const (operands[1]))
+      if (valid_mov3q_const (src))
         return "mov3q%.l %1,%-";
       return "pea %a1";
     }
Index: gcc/config/m68k/m68k.md
===================================================================
--- gcc/config/m68k/m68k.md	2007-01-09 15:02:16.000000000 +0000
+++ gcc/config/m68k/m68k.md	2007-01-09 15:02:16.000000000 +0000
@@ -584,7 +584,7 @@ (define_insn "pushexthisi_const"
 {
   if (operands[1] == const0_rtx)
     return "clr%.l %0";
-  if (valid_mov3q_const(operands[1]))
+  if (valid_mov3q_const (INTVAL (operands[1])))
     return "mov3q%.l %1,%-";
   return "pea %a1";
 })


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