* [Qemu-devel] [PATCH] tcg: Improve tcg_gen_muli_i32/i64
@ 2018-02-11 20:39 Richard Henderson
2018-02-12 22:43 ` Emilio G. Cota
2018-02-13 4:10 ` Philippe Mathieu-Daudé
0 siblings, 2 replies; 3+ messages in thread
From: Richard Henderson @ 2018-02-11 20:39 UTC (permalink / raw)
To: qemu-devel
Convert multiplication by power of two to left shift.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tcg/tcg-op.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 3467787323..34b96d68f3 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -277,9 +277,15 @@ void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
- TCGv_i32 t0 = tcg_const_i32(arg2);
- tcg_gen_mul_i32(ret, arg1, t0);
- tcg_temp_free_i32(t0);
+ if (arg2 == 0) {
+ tcg_gen_movi_i32(ret, 0);
+ } else if (is_power_of_2(arg2)) {
+ tcg_gen_shli_i32(ret, arg1, ctz32(arg2));
+ } else {
+ TCGv_i32 t0 = tcg_const_i32(arg2);
+ tcg_gen_mul_i32(ret, arg1, t0);
+ tcg_temp_free_i32(t0);
+ }
}
void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
@@ -1430,9 +1436,15 @@ void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
{
- TCGv_i64 t0 = tcg_const_i64(arg2);
- tcg_gen_mul_i64(ret, arg1, t0);
- tcg_temp_free_i64(t0);
+ if (arg2 == 0) {
+ tcg_gen_movi_i64(ret, 0);
+ } else if (is_power_of_2(arg2)) {
+ tcg_gen_shli_i64(ret, arg1, ctz64(arg2));
+ } else {
+ TCGv_i64 t0 = tcg_const_i64(arg2);
+ tcg_gen_mul_i64(ret, arg1, t0);
+ tcg_temp_free_i64(t0);
+ }
}
void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
--
2.14.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] tcg: Improve tcg_gen_muli_i32/i64
2018-02-11 20:39 [Qemu-devel] [PATCH] tcg: Improve tcg_gen_muli_i32/i64 Richard Henderson
@ 2018-02-12 22:43 ` Emilio G. Cota
2018-02-13 4:10 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 3+ messages in thread
From: Emilio G. Cota @ 2018-02-12 22:43 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Sun, Feb 11, 2018 at 12:39:34 -0800, Richard Henderson wrote:
> Convert multiplication by power of two to left shift.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Emilio G. Cota <cota@braap.org>
Thanks,
Emilio
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] tcg: Improve tcg_gen_muli_i32/i64
2018-02-11 20:39 [Qemu-devel] [PATCH] tcg: Improve tcg_gen_muli_i32/i64 Richard Henderson
2018-02-12 22:43 ` Emilio G. Cota
@ 2018-02-13 4:10 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-02-13 4:10 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
On 02/11/2018 05:39 PM, Richard Henderson wrote:
> Convert multiplication by power of two to left shift.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> tcg/tcg-op.c | 24 ++++++++++++++++++------
> 1 file changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
> index 3467787323..34b96d68f3 100644
> --- a/tcg/tcg-op.c
> +++ b/tcg/tcg-op.c
> @@ -277,9 +277,15 @@ void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
>
> void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
> {
> - TCGv_i32 t0 = tcg_const_i32(arg2);
> - tcg_gen_mul_i32(ret, arg1, t0);
> - tcg_temp_free_i32(t0);
> + if (arg2 == 0) {
> + tcg_gen_movi_i32(ret, 0);
> + } else if (is_power_of_2(arg2)) {
> + tcg_gen_shli_i32(ret, arg1, ctz32(arg2));
> + } else {
> + TCGv_i32 t0 = tcg_const_i32(arg2);
> + tcg_gen_mul_i32(ret, arg1, t0);
> + tcg_temp_free_i32(t0);
> + }
> }
>
> void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
> @@ -1430,9 +1436,15 @@ void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
>
> void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
> {
> - TCGv_i64 t0 = tcg_const_i64(arg2);
> - tcg_gen_mul_i64(ret, arg1, t0);
> - tcg_temp_free_i64(t0);
> + if (arg2 == 0) {
> + tcg_gen_movi_i64(ret, 0);
> + } else if (is_power_of_2(arg2)) {
> + tcg_gen_shli_i64(ret, arg1, ctz64(arg2));
> + } else {
> + TCGv_i64 t0 = tcg_const_i64(arg2);
> + tcg_gen_mul_i64(ret, arg1, t0);
> + tcg_temp_free_i64(t0);
> + }
> }
>
> void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-02-13 4:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-11 20:39 [Qemu-devel] [PATCH] tcg: Improve tcg_gen_muli_i32/i64 Richard Henderson
2018-02-12 22:43 ` Emilio G. Cota
2018-02-13 4:10 ` Philippe Mathieu-Daudé
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).