Skip to contentSkip to conversation

tests/tcg/s390x: Fix the exrl-trt* tests with Clang

PATCH In review Thomas Huth 3 participants 3 messages Mar 1, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/tcg/s390x: Fix the exrl-trt* tests with Clang

The exrl-trt* tests use two pre-initialized variables for the results of the assembly code:

    uint64_t r1 = 0xffffffffffffffffull;
    uint64_t r2 = 0xffffffffffffffffull;

But then the assembly code copies over the full contents of the register into the output variable, without taking care of this pre-initialized values:

        "    lgr %[r1],%%r1\n"
        "    lgr %[r2],%%r2\n"

The code then finally compares the register contents to a value that apparently depends on the pre-initialized values:

    if (r2 != 0xffffffffffffffaaull) {
        write(1, "bad r2\n", 7);
        return 1;
    }

This all works with GCC, since the 0xffffffffffffffff got into the r2 register there by accident, but it fails completely with Clang.

Let's fix this by declaring the r1 and r2 variables as proper register variables instead, so the pre-initialized values get correctly passed into the inline assembly code.

---
 tests/tcg/s390x/exrl-trt.c  | 8 +++-----
 tests/tcg/s390x/exrl-trtr.c | 8 +++-----
 2 files changed, 6 insertions(+), 10 deletions(-)
tests/tcg/s390x/exrl-trt.c +3 -5
index 16711a3181..451f777b9d 100644
@@ -5,8 +5,8 @@ int main(void)
 {
     char op1[] = "hello";
     char op2[256];
-    uint64_t r1 = 0xffffffffffffffffull;
-    uint64_t r2 = 0xffffffffffffffffull;
+    register uint64_t r1 asm("r1") = 0xffffffffffffffffull;
+    register uint64_t r2 asm("r2") = 0xffffffffffffffffull;
     uint64_t cc;
     int i;
 
@@ -21,8 +21,6 @@ int main(void)
         "    j 2f\n"
         "1:  trt 0(1,%[op1]),%[op2]\n"
         "2:  exrl %[op1_len],1b\n"
-        "    lgr %[r1],%%r1\n"
-        "    lgr %[r2],%%r2\n"
         "    ipm %[cc]\n"
         : [r1] "+r" (r1),
           [r2] "+r" (r2),
@@ -30,7 +28,7 @@ int main(void)
         : [op1] "a" (&op1),
           [op1_len] "a" (5),
           [op2] "Q" (op2)
-        : "r1", "r2", "cc");
+        : "cc");
     cc = (cc >> 28) & 3;
     if (cc != 2) {
         write(1, "bad cc\n", 7);
tests/tcg/s390x/exrl-trtr.c +3 -5
index 5f30cda6bd..422f7f385a 100644
@@ -5,8 +5,8 @@ int main(void)
 {
     char op1[] = {0, 1, 2, 3};
     char op2[256];
-    uint64_t r1 = 0xffffffffffffffffull;
-    uint64_t r2 = 0xffffffffffffffffull;
+    register uint64_t r1 asm("r1") = 0xffffffffffffffffull;
+    register uint64_t r2 asm("r2") = 0xffffffffffffffffull;
     uint64_t cc;
     int i;
 
@@ -21,8 +21,6 @@ int main(void)
         "    j 2f\n"
         "1:  trtr 3(1,%[op1]),%[op2]\n"
         "2:  exrl %[op1_len],1b\n"
-        "    lgr %[r1],%%r1\n"
-        "    lgr %[r2],%%r2\n"
         "    ipm %[cc]\n"
         : [r1] "+r" (r1),
           [r2] "+r" (r2),
@@ -30,7 +28,7 @@ int main(void)
         : [op1] "a" (&op1),
           [op1_len] "a" (3),
           [op2] "Q" (op2)
-        : "r1", "r2", "cc");
+        : "cc");
     cc = (cc >> 28) & 3;
     if (cc != 1) {
         write(1, "bad cc\n", 7);
Signature · 1 line
2.27.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 93 lines · Thomas Huth

The exrl-trt* tests use two pre-initialized variables for the results of the assembly code:

    uint64_t r1 = 0xffffffffffffffffull;
    uint64_t r2 = 0xffffffffffffffffull;

But then the assembly code copies over the full contents of the register into the output variable, without taking care of this pre-initialized values:

        "    lgr %[r1],%%r1\n"
        "    lgr %[r2],%%r2\n"

The code then finally compares the register contents to a value that apparently depends on the pre-initialized values:

    if (r2 != 0xffffffffffffffaaull) {
        write(1, "bad r2\n", 7);
        return 1;
    }

This all works with GCC, since the 0xffffffffffffffff got into the r2 register there by accident, but it fails completely with Clang.

Let's fix this by declaring the r1 and r2 variables as proper register variables instead, so the pre-initialized values get correctly passed into the inline assembly code.

---
 tests/tcg/s390x/exrl-trt.c  | 8 +++-----
 tests/tcg/s390x/exrl-trtr.c | 8 +++-----
 2 files changed, 6 insertions(+), 10 deletions(-)
tests/tcg/s390x/exrl-trt.c +3 -5
index 16711a3181..451f777b9d 100644
@@ -5,8 +5,8 @@ int main(void)
 {
     char op1[] = "hello";
     char op2[256];
-    uint64_t r1 = 0xffffffffffffffffull;
-    uint64_t r2 = 0xffffffffffffffffull;
+    register uint64_t r1 asm("r1") = 0xffffffffffffffffull;
+    register uint64_t r2 asm("r2") = 0xffffffffffffffffull;
     uint64_t cc;
     int i;
 
@@ -21,8 +21,6 @@ int main(void)
         "    j 2f\n"
         "1:  trt 0(1,%[op1]),%[op2]\n"
         "2:  exrl %[op1_len],1b\n"
-        "    lgr %[r1],%%r1\n"
-        "    lgr %[r2],%%r2\n"
         "    ipm %[cc]\n"
         : [r1] "+r" (r1),
           [r2] "+r" (r2),
@@ -30,7 +28,7 @@ int main(void)
         : [op1] "a" (&op1),
           [op1_len] "a" (5),
           [op2] "Q" (op2)
-        : "r1", "r2", "cc");
+        : "cc");
     cc = (cc >> 28) & 3;
     if (cc != 2) {
         write(1, "bad cc\n", 7);
tests/tcg/s390x/exrl-trtr.c +2 -4
index 5f30cda6bd..422f7f385a 100644
@@ -5,8 +5,8 @@ int main(void)
 {
     char op1[] = {0, 1, 2, 3};
     char op2[256];
-    uint64_t r1 = 0xffffffffffffffffull;
-    uint64_t r2 = 0xffffffffffffffffull;
+    register uint64_t r1 asm("r1") = 0xffffffffffffffffull;
+    register uint64_t r2 asm("r2") = 0xffffffffffffffffull;
     uint64_t cc;
     int i;
 
@@ -21,8 +21,6 @@ int main(void)
         "    j 2f\n"
         "1:  trtr 3(1,%[op1]),%[op2]\n"
         "2:  exrl %[op1_len],1b\n"
-        "    lgr %[r1],%%r1\n"
-        "    lgr %[r2],%%r2\n"
         "    ipm %[cc]\n"
         : [r1] "+r" (r1),
           [r2] "+r" (r2),

tests/tcg/s390x/exrl-trtr.c int main(void) · line 34

Quoted 8 lines
tests/tcg/s390x/exrl-trtr.c +1 -1
@@ -30,7 +28,7 @@ int main(void)
         : [op1] "a" (&op1),
           [op1_len] "a" (3),
           [op2] "Q" (op2)
-        : "r1", "r2", "cc");
+        : "cc");
     cc = (cc >> 28) & 3;
     if (cc != 1) {
         write(1, "bad cc\n", 7);
Signature · 3 lines
Thanks,

David / dhildenb
Reviewed-by on v1 1/1
#2 lore raw
In reply to Thomas Huth
Quoted 29 lines · Thomas Huth

The exrl-trt* tests use two pre-initialized variables for the results of the assembly code:

     uint64_t r1 = 0xffffffffffffffffull;
     uint64_t r2 = 0xffffffffffffffffull;

But then the assembly code copies over the full contents of the register into the output variable, without taking care of this pre-initialized values:

         "    lgr %[r1],%%r1\n"
         "    lgr %[r2],%%r2\n"

The code then finally compares the register contents to a value that apparently depends on the pre-initialized values:

     if (r2 != 0xffffffffffffffaaull) {
         write(1, "bad r2\n", 7);
         return 1;
     }

This all works with GCC, since the 0xffffffffffffffff got into the r2 register there by accident, but it fails completely with Clang.

Let's fix this by declaring the r1 and r2 variables as proper register variables instead, so the pre-initialized values get correctly passed into the inline assembly code.

Quoted 5 lines
---
  tests/tcg/s390x/exrl-trt.c  | 8 +++-----
  tests/tcg/s390x/exrl-trtr.c | 8 +++-----
  2 files changed, 6 insertions(+), 10 deletions(-)

r~