From 1bcbdc2f1b8bba91f6f05455bd3c91cf68286a33 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Tue, 18 Dec 2018 05:48:04 -0500 Subject: [PATCH] tcg: Clean up generic bswap64 Based on the only current user, Sparc: New code uses 2 constants that take 2 insns to load from constant pool, plus 13. Old code used 6 constants that took 1 or 2 insns to create, plus 21. The result is a new total of 17 vs an old total of 29. Backports commit 9e821eab0ab708add35fa0446d880086e845ee3e from qemu --- qemu/tcg/tcg-op.c | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/qemu/tcg/tcg-op.c b/qemu/tcg/tcg-op.c index ca09bf76..801b2876 100644 --- a/qemu/tcg/tcg-op.c +++ b/qemu/tcg/tcg-op.c @@ -1685,37 +1685,30 @@ void tcg_gen_bswap64_i64(TCGContext *s, TCGv_i64 ret, TCGv_i64 arg) } else { TCGv_i64 t0 = tcg_temp_new_i64(s); TCGv_i64 t1 = tcg_temp_new_i64(s); + TCGv_i64 t2 = tcg_temp_new_i64(s); - tcg_gen_shli_i64(s, t0, arg, 56); + /* arg = abcdefgh */ + tcg_gen_movi_i64(s, t2, 0x00ff00ff00ff00ffull); + tcg_gen_shri_i64(s, t0, arg, 8); /* t0 = .abcdefg */ + tcg_gen_and_i64(s, t1, arg, t2); /* t1 = .b.d.f.h */ + tcg_gen_and_i64(s, t0, t0, t2); /* t0 = .a.c.e.g */ + tcg_gen_shli_i64(s, t1, t1, 8); /* t1 = b.d.f.h. */ + tcg_gen_or_i64(s, ret, t0, t1); /* ret = badcfehg */ - tcg_gen_andi_i64(s, t1, arg, 0x0000ff00); - tcg_gen_shli_i64(s, t1, t1, 40); - tcg_gen_or_i64(s, t0, t0, t1); + tcg_gen_movi_i64(s, t2, 0x0000ffff0000ffffull); + tcg_gen_shri_i64(s, t0, ret, 16); /* t0 = ..badcfe */ + tcg_gen_and_i64(s, t1, ret, t2); /* t1 = ..dc..hg */ + tcg_gen_and_i64(s, t0, t0, t2); /* t0 = ..ba..fe */ + tcg_gen_shli_i64(s, t1, t1, 16); /* t1 = dc..hg.. */ + tcg_gen_or_i64(s, ret, t0, t1); /* ret = dcbahgfe */ - tcg_gen_andi_i64(s, t1, arg, 0x00ff0000); - tcg_gen_shli_i64(s, t1, t1, 24); - tcg_gen_or_i64(s, t0, t0, t1); + tcg_gen_shri_i64(s, t0, ret, 32); /* t0 = ....dcba */ + tcg_gen_shli_i64(s, t1, ret, 32); /* t1 = hgfe.... */ + tcg_gen_or_i64(s, ret, t0, t1); /* ret = hgfedcba */ - tcg_gen_andi_i64(s, t1, arg, 0xff000000); - tcg_gen_shli_i64(s, t1, t1, 8); - tcg_gen_or_i64(s, t0, t0, t1); - - tcg_gen_shri_i64(s, t1, arg, 8); - tcg_gen_andi_i64(s, t1, t1, 0xff000000); - tcg_gen_or_i64(s, t0, t0, t1); - - tcg_gen_shri_i64(s, t1, arg, 24); - tcg_gen_andi_i64(s, t1, t1, 0x00ff0000); - tcg_gen_or_i64(s, t0, t0, t1); - - tcg_gen_shri_i64(s, t1, arg, 40); - tcg_gen_andi_i64(s, t1, t1, 0x0000ff00); - tcg_gen_or_i64(s, t0, t0, t1); - - tcg_gen_shri_i64(s, t1, arg, 56); - tcg_gen_or_i64(s, ret, t0, t1); tcg_temp_free_i64(s, t0); tcg_temp_free_i64(s, t1); + tcg_temp_free_i64(s, t2); } }