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
This commit is contained in:
Richard Henderson 2018-12-18 05:48:04 -05:00 committed by Lioncash
parent f68b4aa896
commit 1bcbdc2f1b
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -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);
}
}