Skip to contentSkip to conversation

target/s390x: Use mutable temporary value for op_ts

PATCH Superseded Ilya Leoshkevich 3 participants 4 messages Mar 18, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 target/s390x: Use mutable temporary value for op_ts

From: Ido Plat <[email protected]>

Otherwise TCG would assume the register that holds t1 would be constant and reuse whenever it needs the value within it.

[iii: Adjust a newline and capitalization]
---
 target/s390x/tcg/translate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/s390x/tcg/translate.c +2 -1
index 0d0c672c959..3fdddac7684 100644
@@ -4781,8 +4781,9 @@ static DisasJumpType op_trXX(DisasContext *s, DisasOps *o)
 
 static DisasJumpType op_ts(DisasContext *s, DisasOps *o)
 {
-    TCGv_i32 t1 = tcg_constant_i32(0xff);
+    TCGv_i32 t1 = tcg_temp_new_i32();
 
+    tcg_gen_movi_i32(t1, 0xff);
     tcg_gen_atomic_xchg_i32(t1, o->in2, t1, get_mem_index(s), MO_UB);
     tcg_gen_extract_i32(cc_op, t1, 7, 1);
     set_cc_static(s);
Signature · 1 line
2.44.0
#1 lore raw

PATCH 2/2 tests/tcg/s390x: Test TEST AND SET

Add a small test to prevent regressions.

---
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/ts.c            | 35 +++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
 create mode 100644 tests/tcg/s390x/ts.c
tests/tcg/s390x/Makefile.target +1 -0
index e2aba2ec274..a8f86c94498 100644
@@ -47,6 +47,7 @@ TESTS+=add-logical-with-carry
 TESTS+=lae
 TESTS+=cvd
 TESTS+=cvb
+TESTS+=ts
 
 cdsg: CFLAGS+=-pthread
 cdsg: LDFLAGS+=-pthread
tests/tcg/s390x/ts.c new file +35 -0
new file mode 100644
index 00000000000..441faf30d98
@@ -0,0 +1,35 @@
+/*
+ * Test the TEST AND SET instruction.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include <assert.h>
+#include <stdlib.h>
+
+static int ts(char *p)
+{
+    int cc;
+
+    asm("ts %[p]\n"
+        "ipm %[cc]"
+        : [cc] "=r" (cc)
+        , [p] "+Q" (*p)
+        : : "cc");
+
+    return (cc >> 28) & 3;
+}
+
+int main(void)
+{
+    char c;
+
+    c = 0x80;
+    assert(ts(&c) == 1);
+    assert(c == 0xff);
+
+    c = 0x7f;
+    assert(ts(&c) == 0);
+    assert(c == 0xff);
+
+    return EXIT_SUCCESS;
+}
Signature · 1 line
2.44.0
Reviewed-by on v1 1/2
#3 lore raw
In reply to Ilya Leoshkevich
Quoted 17 lines · Ilya Leoshkevich

From: Ido Plat <[email protected]>

Otherwise TCG would assume the register that holds t1 would be constant and reuse whenever it needs the value within it.

[iii: Adjust a newline and capitalization]
---
  target/s390x/tcg/translate.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
target/s390x/tcg/translate.c +0 -0
index 0d0c672c959..3fdddac7684 100644

target/s390x/tcg/translate.c static DisasJumpType op_trXX(DisasContext *s, DisasOps *o) · line 4787

Quoted 8 lines
target/s390x/tcg/translate.c +2 -1
@@ -4781,8 +4781,9 @@ static DisasJumpType op_trXX(DisasContext *s, DisasOps *o)
 
  static DisasJumpType op_ts(DisasContext *s, DisasOps *o)
  {
-    TCGv_i32 t1 = tcg_constant_i32(0xff);
+    TCGv_i32 t1 = tcg_temp_new_i32();
 
+    tcg_gen_movi_i32(t1, 0xff);
      tcg_gen_atomic_xchg_i32(t1, o->in2, t1, get_mem_index(s), MO_UB);

Better as

    TCGv_i32 ff = tcg_constant_i32(0xff);
    TCGv_i32 t1 = tcg_temp_new_i32();

    tcg_gen_atomic_xchg_i32(t1, o->in2, ff, get_mem_index(s), MO_UB);

With that,

r~