mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 16:53:55 -06:00
tcg: Add support for integer absolute value
Remove a function of the same name from target/arm/. Use a branchless implementation of abs gleaned from gcc. Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: David Hildenbrand <david@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
0a8d7a3bf5
commit
ff1f11f7f8
3 changed files with 25 additions and 10 deletions
20
tcg/tcg-op.c
20
tcg/tcg-op.c
|
@ -1091,6 +1091,16 @@ void tcg_gen_umax_i32(TCGv_i32 ret, TCGv_i32 a, TCGv_i32 b)
|
|||
tcg_gen_movcond_i32(TCG_COND_LTU, ret, a, b, b, a);
|
||||
}
|
||||
|
||||
void tcg_gen_abs_i32(TCGv_i32 ret, TCGv_i32 a)
|
||||
{
|
||||
TCGv_i32 t = tcg_temp_new_i32();
|
||||
|
||||
tcg_gen_sari_i32(t, a, 31);
|
||||
tcg_gen_xor_i32(ret, a, t);
|
||||
tcg_gen_sub_i32(ret, ret, t);
|
||||
tcg_temp_free_i32(t);
|
||||
}
|
||||
|
||||
/* 64-bit ops */
|
||||
|
||||
#if TCG_TARGET_REG_BITS == 32
|
||||
|
@ -2548,6 +2558,16 @@ void tcg_gen_umax_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b)
|
|||
tcg_gen_movcond_i64(TCG_COND_LTU, ret, a, b, b, a);
|
||||
}
|
||||
|
||||
void tcg_gen_abs_i64(TCGv_i64 ret, TCGv_i64 a)
|
||||
{
|
||||
TCGv_i64 t = tcg_temp_new_i64();
|
||||
|
||||
tcg_gen_sari_i64(t, a, 63);
|
||||
tcg_gen_xor_i64(ret, a, t);
|
||||
tcg_gen_sub_i64(ret, ret, t);
|
||||
tcg_temp_free_i64(t);
|
||||
}
|
||||
|
||||
/* Size changing operations. */
|
||||
|
||||
void tcg_gen_extrl_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue