Skip to contentSkip to conversation

target/s390x: Use a 16-bit immediate in VREP

PATCH In review Ilya Leoshkevich 3 participants 7 messages Aug 7, 2023 – Aug 8, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 target/s390x: Use a 16-bit immediate in VREP

Unlike most other instructions that contain an immediate element index, VREP's one is 16-bit, and not 4-bit. The code uses only 8 bits, so using, e.g., 0x101 does not lead to a specification exception.

Fix by checking all 16 bits.

Fixes 28d08731b1d8 ("s390x/tcg: Implement VECTOR REPLICATE")
---
 target/s390x/tcg/translate_vx.c.inc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/s390x/tcg/translate_vx.c.inc +2 -2
index f8df121d3d3..a6d840d4065 100644
@@ -57,7 +57,7 @@
 #define FPF_LONG        3
 #define FPF_EXT         4
 
-static inline bool valid_vec_element(uint8_t enr, MemOp es)
+static inline bool valid_vec_element(uint16_t enr, MemOp es)
 {
     return !(enr & ~(NUM_VEC_ELEMENTS(es) - 1));
 }
@@ -964,7 +964,7 @@ static DisasJumpType op_vpdi(DisasContext *s, DisasOps *o)
 
 static DisasJumpType op_vrep(DisasContext *s, DisasOps *o)
 {
-    const uint8_t enr = get_field(s, i2);
+    const uint16_t enr = get_field(s, i2);
     const uint8_t es = get_field(s, m4);
 
     if (es > ES_64 || !valid_vec_element(enr, es)) {
Signature · 1 line
2.41.0
#1 lore raw

PATCH 2/2 tests/tcg/s390x: Test VREP

Add a small test to prevent regressions.

---
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/vrep.c          | 81 +++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)
 create mode 100644 tests/tcg/s390x/vrep.c
tests/tcg/s390x/Makefile.target +1 -0
index 1fc98099070..9548b6d4f51 100644
@@ -59,6 +59,7 @@ Z13_TESTS=vistr
 Z13_TESTS+=lcbb
 Z13_TESTS+=locfhr
 Z13_TESTS+=vcksm
+Z13_TESTS+=vrep
 $(Z13_TESTS): CFLAGS+=-march=z13 -O2
 TESTS+=$(Z13_TESTS)
 
tests/tcg/s390x/vrep.c new file +81 -0

81 lines not on this page · raw message

Signature · 1 line
2.41.0
Reviewed-by on v1 1/2
#2 lore raw
In reply to Ilya Leoshkevich
Quoted 7 lines · Ilya Leoshkevich

Unlike most other instructions that contain an immediate element index, VREP's one is 16-bit, and not 4-bit. The code uses only 8 bits, so using, e.g., 0x101 does not lead to a specification exception.

Fix by checking all 16 bits.

Just curious, why stable? Are there valid programs that set invalid element size and they are fixed by this?

LGTM

Quoted 28 lines
Fixes 28d08731b1d8 ("s390x/tcg: Implement VECTOR REPLICATE")
---
  target/s390x/tcg/translate_vx.c.inc | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
target/s390x/tcg/translate_vx.c.inc +2 -2
index f8df121d3d3..a6d840d4065 100644
@@ -57,7 +57,7 @@
  #define FPF_LONG        3
  #define FPF_EXT         4
 
-static inline bool valid_vec_element(uint8_t enr, MemOp es)
+static inline bool valid_vec_element(uint16_t enr, MemOp es)
  {
      return !(enr & ~(NUM_VEC_ELEMENTS(es) - 1));
  }
@@ -964,7 +964,7 @@ static DisasJumpType op_vpdi(DisasContext *s, DisasOps *o)
 
  static DisasJumpType op_vrep(DisasContext *s, DisasOps *o)
  {
-    const uint8_t enr = get_field(s, i2);
+    const uint16_t enr = get_field(s, i2);
      const uint8_t es = get_field(s, m4);
 
      if (es > ES_64 || !valid_vec_element(enr, es)) {
Signature · 3 lines
Cheers,

David / dhildenb
#3 lore raw
Quoted 6 lines · David Hildenbrand
Quoted 5 lines · Ilya Leoshkevich

Unlike most other instructions that contain an immediate element index,
VREP's one is 16-bit, and not 4-bit. The code uses only 8 bits, so using, e.g., 0x101 does not lead to a specification exception.

Quoted 6 lines
Quoted 3 lines

Fix by checking all 16 bits.

Just curious, why stable? Are there valid programs that set invalid element size and they are fixed by this?

None that I know of, but I thought this was still nice to have, and at the same time small enough to not cause any trouble.

Quoted 3 lines

LGTM

[...]

Quoted 1 line
#4 lore raw
Quoted 9 lines · Ilya Leoshkevich
Quoted 8 lines · David Hildenbrand
Quoted 7 lines · Ilya Leoshkevich

Unlike most other instructions that contain an immediate element index,
VREP's one is 16-bit, and not 4-bit. The code uses only 8 bits, so using, e.g., 0x101 does not lead to a specification exception.

Fix by checking all 16 bits.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Just curious, why stable? Are there valid programs that set invalid element size and they are fixed by this?

None that I know of, but I thought this was still nice to have, and at the same time small enough to not cause any trouble.

Yes, I was just curious. From my recollection, we didn't backport all specification exception checks.

Signature · 3 lines
Cheers,

David / dhildenb
#5 lore raw
Quoted 1 line · Ilya Leoshkevich

..>> None that I know of, but I thought this was still nice to have, and at

Quoted 1 line
Quoted 1 line

the same time small enough to not cause any trouble.

Ilya, do you have an idea why your messages don't reach qemu-stable@?

I see e.g. David's replies to yuor messages in qemu-stable@ - this way I know you sent something, and copy that message from qemu-devel@.

For example, this thread is shown in the archive with your messages unavailable:

https://mail.gnu.org/archive/html/qemu-stable/2023-08/threads.html#00118

#6 lore raw
Quoted 7 lines · Michael Tokarev
Quoted 1 line · Ilya Leoshkevich

..>> None that I know of, but I thought this was still nice to have, and at

Quoted 1 line
Quoted 1 line

the same time small enough to not cause any trouble.

Ilya, do you have an idea why your messages don't reach qemu-stable@?

Quoted 8 lines

I see e.g. David's replies to yuor messages in qemu-stable@ - this way
I know you sent something, and copy that message from qemu-devel@.

For example, this thread is shown in the archive with your messages unavailable:

https://mail.gnu.org/archive/html/qemu-stable/2023-08/threads.html#00118

No, unfortunately I don't know. Everything looks normal on my end, qemu-stable@ is properly Cc:ed and I don't see any typos. I've sent a question about this to the mailing list owner.