tcg: Improve tcg_gen_muli_i32/i64

Convert multiplication by power of two to left shift.

Backports commit b2e3ae9452fa55eb036739ec39c33f0782a97504 from qemu
This commit is contained in:
Richard Henderson 2018-03-17 19:52:38 -04:00 committed by Lioncash
parent 36d902cd0e
commit e9eee21efd
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -277,9 +277,15 @@ void tcg_gen_setcondi_i32(TCGContext *s, TCGCond cond, TCGv_i32 ret,
void tcg_gen_muli_i32(TCGContext *s, TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
TCGv_i32 t0 = tcg_const_i32(s, arg2);
tcg_gen_mul_i32(s, ret, arg1, t0);
tcg_temp_free_i32(s, t0);
if (arg2 == 0) {
tcg_gen_movi_i32(s, ret, 0);
} else if (is_power_of_2(arg2)) {
tcg_gen_shli_i32(s, ret, arg1, ctz32(arg2));
} else {
TCGv_i32 t0 = tcg_const_i32(s, arg2);
tcg_gen_mul_i32(s, ret, arg1, t0);
tcg_temp_free_i32(s, t0);
}
}
void tcg_gen_div_i32(TCGContext *s, TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
@ -1437,9 +1443,15 @@ void tcg_gen_setcondi_i64(TCGContext *s, TCGCond cond, TCGv_i64 ret,
void tcg_gen_muli_i64(TCGContext *s, TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
{
TCGv_i64 t0 = tcg_const_i64(s, arg2);
tcg_gen_mul_i64(s, ret, arg1, t0);
tcg_temp_free_i64(s, t0);
if (arg2 == 0) {
tcg_gen_movi_i64(s, ret, 0);
} else if (is_power_of_2(arg2)) {
tcg_gen_shli_i64(s, ret, arg1, ctz64(arg2));
} else {
TCGv_i64 t0 = tcg_const_i64(s, arg2);
tcg_gen_mul_i64(s, ret, arg1, t0);
tcg_temp_free_i64(s, t0);
}
}
void tcg_gen_div_i64(TCGContext *s, TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)