Skip to contentSkip to conversation

tcg/i386: convert add/sub of 128 to sub/add of -128

PATCH Superseded Paolo Bonzini 2 participants 2 messages Dec 21, 2023 – Dec 27, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

---
 tcg/i386/tcg-target.c.inc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tcg/i386/tcg-target.c.inc +5 -1
index a83f8aab304..4e9f372d4fd 100644
@@ -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);
Signature · 1 line
2.43.0
#1 lore raw
Quoted 12 lines · Paolo Bonzini
---
  tcg/i386/tcg-target.c.inc | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
tcg/i386/tcg-target.c.inc +0 -0
index a83f8aab304..4e9f372d4fd 100644
@@ -1332,7 +1332,11 @@ static void tgen_arithi(TCGContext *s, int c, int r0,
          return;
      }

tcg/i386/tcg-target.c.inc static void tgen_arithi(TCGContext *s, int c, int r0, · line 1342

Quoted 10 lines
tcg/i386/tcg-target.c.inc +5 -1
 
-    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~