[PATCH] tcg/i386: convert add/sub of 128 to sub/add of -128

Paolo Bonzini posted 1 patch 11 months, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20231221134355.35304-1-pbonzini@redhat.com
Maintainers: Richard Henderson <richard.henderson@linaro.org>
There is a newer version of this series
tcg/i386/tcg-target.c.inc | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH] tcg/i386: convert add/sub of 128 to sub/add of -128
Posted by Paolo Bonzini 11 months, 1 week ago
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tcg/i386/tcg-target.c.inc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc
index a83f8aab304..4e9f372d4fd 100644
--- a/tcg/i386/tcg-target.c.inc
+++ b/tcg/i386/tcg-target.c.inc
@@ -1332,7 +1332,11 @@ static void tgen_arithi(TCGContext *s, int c, int r0,
         return;
     }
 
-    if (c == ARITH_AND) {
+    if ((c == ARITH_ADD || c == ARITH_SUB) && val == 128) {
+        /* Facilitate using an 8-bit immediate.  */
+        c ^= ARITH_ADD ^ ARITH_SUB;
+	val = -128;
+    } else if (c == ARITH_AND) {
         if (TCG_TARGET_REG_BITS == 64) {
             if (val == 0xffffffffu) {
                 tcg_out_ext32u(s, r0, r0);
-- 
2.43.0
Re: [PATCH] tcg/i386: convert add/sub of 128 to sub/add of -128
Posted by Richard Henderson 11 months ago
On 12/22/23 00:43, Paolo Bonzini wrote:
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   tcg/i386/tcg-target.c.inc | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc
> index a83f8aab304..4e9f372d4fd 100644
> --- a/tcg/i386/tcg-target.c.inc
> +++ b/tcg/i386/tcg-target.c.inc
> @@ -1332,7 +1332,11 @@ static void tgen_arithi(TCGContext *s, int c, int r0,
>           return;
>       }
>   
> -    if (c == ARITH_AND) {
> +    if ((c == ARITH_ADD || c == ARITH_SUB) && val == 128) {
> +        /* Facilitate using an 8-bit immediate.  */
> +        c ^= ARITH_ADD ^ ARITH_SUB;
> +	val = -128;
> +    } else if (c == ARITH_AND) {
>           if (TCG_TARGET_REG_BITS == 64) {
>               if (val == 0xffffffffu) {
>                   tcg_out_ext32u(s, r0, r0);

Need to check for !cf, because this swaps the sense of carry.
Ought to merge this with the inc/dec block above to save comparisons.


r~