diff mbox series

[v2,23/25] target/tricore: Use min/max for saturate

Message ID 20230307183503.2512684-24-richard.henderson@linaro.org
State Superseded
Headers show
Series tcg: Remove tcg_const_* | expand

Commit Message

Richard Henderson March 7, 2023, 6:35 p.m. UTC
Use tcg_constant_i32 for the bounds.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
Cc: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
---
 target/tricore/translate.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

Comments

Philippe Mathieu-Daudé March 9, 2023, 10:09 a.m. UTC | #1
On 7/3/23 19:35, Richard Henderson wrote:
> Use tcg_constant_i32 for the bounds.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> Cc: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
> ---
>   target/tricore/translate.c | 14 +++-----------
>   1 file changed, 3 insertions(+), 11 deletions(-)

>   static void gen_saturate(TCGv ret, TCGv arg, int32_t up, int32_t low)
>   {
> -    TCGv sat_neg = tcg_const_i32(low);
> -    TCGv temp = tcg_const_i32(up);
> -
> -    /* sat_neg = (arg < low ) ? low : arg; */
> -    tcg_gen_movcond_tl(TCG_COND_LT, sat_neg, arg, sat_neg, sat_neg, arg);
> -
> -    /* ret = (sat_neg > up ) ? up  : sat_neg; */
> -    tcg_gen_movcond_tl(TCG_COND_GT, ret, sat_neg, temp, temp, sat_neg);
> +    tcg_gen_smax_tl(ret, arg, tcg_constant_i32(low));

This one is trivial when looking at tcg_gen_smax implementation.

> +    tcg_gen_smin_tl(ret, ret, tcg_constant_i32(up));

OK, when changing TCG_COND_GT -> TCG_COND_LT and inverting the args,
then this becomes obvious this is tcg_gen_smin.

>   }
>   
>   static void gen_saturate_u(TCGv ret, TCGv arg, int32_t up)
>   {
> -    TCGv temp = tcg_const_i32(up);
> -    /* sat_neg = (arg > up ) ? up : arg; */
> -    tcg_gen_movcond_tl(TCG_COND_GTU, ret, arg, temp, temp, arg);
> +    tcg_gen_umin_tl(ret, arg, tcg_constant_i32(up));

Inverting args for TCG_COND_GTU -> TCG_COND_LTU, this is indeed
tcg_gen_umin.

>   }

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
diff mbox series

Patch

diff --git a/target/tricore/translate.c b/target/tricore/translate.c
index a3a5263a5d..2646cb3eb5 100644
--- a/target/tricore/translate.c
+++ b/target/tricore/translate.c
@@ -2443,21 +2443,13 @@  gen_msubsui_64(TCGv ret_low, TCGv ret_high, TCGv r1, TCGv r2_low, TCGv r2_high,
 
 static void gen_saturate(TCGv ret, TCGv arg, int32_t up, int32_t low)
 {
-    TCGv sat_neg = tcg_const_i32(low);
-    TCGv temp = tcg_const_i32(up);
-
-    /* sat_neg = (arg < low ) ? low : arg; */
-    tcg_gen_movcond_tl(TCG_COND_LT, sat_neg, arg, sat_neg, sat_neg, arg);
-
-    /* ret = (sat_neg > up ) ? up  : sat_neg; */
-    tcg_gen_movcond_tl(TCG_COND_GT, ret, sat_neg, temp, temp, sat_neg);
+    tcg_gen_smax_tl(ret, arg, tcg_constant_i32(low));
+    tcg_gen_smin_tl(ret, ret, tcg_constant_i32(up));
 }
 
 static void gen_saturate_u(TCGv ret, TCGv arg, int32_t up)
 {
-    TCGv temp = tcg_const_i32(up);
-    /* sat_neg = (arg > up ) ? up : arg; */
-    tcg_gen_movcond_tl(TCG_COND_GTU, ret, arg, temp, temp, arg);
+    tcg_gen_umin_tl(ret, arg, tcg_constant_i32(up));
 }
 
 static void gen_shi(TCGv ret, TCGv r1, int32_t shift_count)