diff mbox

[SH] PR 53568 - Add support for bswap built-ins

Message ID 1339573702.2198.11.camel@yam-132-YW-E178-FTW
State New
Headers show

Commit Message

Oleg Endo June 13, 2012, 7:48 a.m. UTC
Hello,

The attached patch adds support for the bswap32 built-in on SH.

Tested with 
make -k -j8 check RUNTESTFLAGS="--target_board=sh-sim
\{-m2/-ml,-m2/-mb,-m2a/-mb,-m2a-single/-mb,-m4/-ml,
-m4/-mb,-m4-single/-ml,-m4-single/-mb,-m4a-single/-ml,
-m4a-single/-mb}"

and no new failures.


Cheers,
Oleg


ChangeLog:

	PR target/53568
	* config/sh/sh.md (bswapsi2): New expander.
	(swapbsi2): New insn.

Comments

Kaz Kojima June 13, 2012, 11:31 a.m. UTC | #1
Oleg Endo <oleg.endo@t-online.de> wrote:
> The attached patch adds support for the bswap32 built-in on SH.
> 
> Tested with 
> make -k -j8 check RUNTESTFLAGS="--target_board=sh-sim
> \{-m2/-ml,-m2/-mb,-m2a/-mb,-m2a-single/-mb,-m4/-ml,
> -m4/-mb,-m4-single/-ml,-m4-single/-mb,-m4a-single/-ml,
> -m4a-single/-mb}"
> 
> and no new failures.

OK.

Regards,
	kaz
diff mbox

Patch

Index: gcc/config/sh/sh.md
===================================================================
--- gcc/config/sh/sh.md	(revision 188425)
+++ gcc/config/sh/sh.md	(working copy)
@@ -4529,6 +4529,38 @@ 
   emit_label_after (skip_neg_label, emit_insn (gen_negc (high_dst, high_src)));
   DONE;
 })
+
+(define_expand "bswapsi2"
+  [(set (match_operand:SI 0 "arith_reg_dest" "")
+	(bswap:SI (match_operand:SI 1 "arith_reg_operand" "")))]
+  "TARGET_SH1"
+{
+  if (! can_create_pseudo_p ())
+    FAIL;
+  else
+    {
+      rtx tmp0 = gen_reg_rtx (SImode);
+      rtx tmp1 = gen_reg_rtx (SImode);
+
+      emit_insn (gen_swapbsi2 (tmp0, operands[1]));
+      emit_insn (gen_rotlsi3_16 (tmp1, tmp0));
+      emit_insn (gen_swapbsi2 (operands[0], tmp1));
+      DONE;
+    }
+})
+
+(define_insn "swapbsi2"
+  [(set (match_operand:SI 0 "arith_reg_dest" "=r")
+	(ior:SI (and:SI (match_operand:SI 1 "arith_reg_operand" "r")
+			(const_int 4294901760))
+		(ior:SI (and:SI (ashift:SI (match_dup 1) (const_int 8))
+				(const_int 65280))
+			(and:SI (ashiftrt:SI (match_dup 1) (const_int 8))
+				(const_int 255)))))]
+  "TARGET_SH1"
+  "swap.b	%1,%0"
+  [(set_attr "type" "arith")])
+
 
 ;; -------------------------------------------------------------------------
 ;; Zero extension instructions