Patchwork m68k: add bswapsi2 expander

login
register
mail settings
Submitter Andreas Schwab
Date April 11, 2012, 10:03 p.m.
Message ID <m2lim2ylie.fsf@igel.home>
Download mbox | patch
Permalink /patch/151900/
State New
Headers show

Comments

Andreas Schwab - April 11, 2012, 10:03 p.m.
The default expansion of bswapsi2 (and bswapdi2) is pretty suboptimal.
Tested on m68k-linux.

Andreas.

	* config/m68k/m68k.md (rotrhi3+1): Name it rotrhi_lowpart.
	(bswapsi2): New expander.

Patch

diff --git a/gcc/config/m68k/m68k.md b/gcc/config/m68k/m68k.md
index e4b4b59..8104e75 100644
--- a/gcc/config/m68k/m68k.md
+++ b/gcc/config/m68k/m68k.md
@@ -1,6 +1,6 @@ 
 ;;- Machine description for GNU compiler, Motorola 68000 Version
 ;;  Copyright (C) 1987, 1988, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001,
-;;  2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+;;  2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012
 ;;  Free Software Foundation, Inc.
 
 ;; This file is part of GCC.
@@ -5475,7 +5475,7 @@ 
   "!TARGET_COLDFIRE"
   "ror%.w %2,%0")
 
-(define_insn ""
+(define_insn "rotrhi_lowpart"
   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+d"))
 	(rotatert:HI (match_dup 0)
 		     (match_operand:HI 1 "general_operand" "dI")))]
@@ -5495,6 +5495,19 @@ 
 		     (match_operand:QI 1 "general_operand" "dI")))]
   "!TARGET_COLDFIRE"
   "ror%.b %1,%0")
+
+(define_expand "bswapsi2"
+  [(set (match_operand:SI 0 "register_operand")
+	(bswap:SI (match_operand:SI 1 "register_operand")))]
+  "!TARGET_COLDFIRE"
+{
+  rtx x = operands[0];
+  emit_move_insn (x, operands[1]);
+  emit_insn (gen_rotrhi_lowpart (gen_lowpart (HImode, x), GEN_INT (8)));
+  emit_insn (gen_rotlsi3 (x, x, GEN_INT (16)));
+  emit_insn (gen_rotrhi_lowpart (gen_lowpart (HImode, x), GEN_INT (8)));
+  DONE;
+})
 
 
 ;; Bit set/clear in memory byte.