Skip to contentSkip to conversation

target-arm: Handle UNDEF cases for Neon load/stores

PATCH In review Peter Maydell 2 participants 4 messages Apr 18, 2011 – Apr 25, 2011

lore
Share & tools
lore
#0 lore raw

cover target-arm: Handle UNDEF cases for Neon load/stores

These two simple patches make qemu correctly UNDEF where required in the Neon load/store space. We also catch and UNDEF on an UNPREDICTABLE rather than indexing off the end of the register file.

Tested in the usual way with random instruction sequences.

Peter Maydell (2):
target-arm: Handle UNDEFs for Neon single element load/stores
target-arm: Handle UNDEF cases for Neon VLD/VST multiple-structures

 target-arm/translate.c |   49 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)
#1 lore raw

PATCH 1/2 target-arm: Handle UNDEFs for Neon single element load/stores

Handle the UNDEF and UNPREDICTABLE cases for Neon "single element to one lane" VLD and "single element from one lane" VST.

---
 target-arm/translate.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)
target-arm/translate.c +34 -0
index 6190028..5820add 100644
@@ -3975,6 +3975,7 @@ static int disas_neon_ls_insn(CPUState * env, DisasContext *s, uint32_t insn)
             stride = (1 << size) * nregs;
         } else {
             /* Single element.  */
+            int idx = (insn >> 4) & 0xf;
             pass = (insn >> 7) & 1;
             switch (size) {
             case 0:
@@ -3993,6 +3994,39 @@ static int disas_neon_ls_insn(CPUState * env, DisasContext *s, uint32_t insn)
                 abort();
             }
             nregs = ((insn >> 8) & 3) + 1;
+            /* Catch the UNDEF cases. This is unavoidably a bit messy. */
+            switch (nregs) {
+            case 1:
+                if (((idx & (1 << size)) != 0) ||
+                    (size == 2 && ((idx & 3) == 1 || (idx & 3) == 2))) {
+                    return 1;
+                }
+                break;
+            case 3:
+                if ((idx & 1) != 0) {
+                    return 1;
+                }
+                /* fall through */
+            case 2:
+                if (size == 2 && (idx & 2) != 0) {
+                    return 1;
+                }
+                break;
+            case 4:
+                if ((size == 2) && ((idx & 3) == 3)) {
+                    return 1;
+                }
+                break;
+            default:
+                abort();
+            }
+            if ((rd + stride * (nregs - 1)) > 31) {
+                /* Attempts to write off the end of the register file
+                 * are UNPREDICTABLE; we choose to UNDEF because otherwise
+                 * the neon_load_reg() would write off the end of the array.
+                 */
+                return 1;
+            }
             addr = tcg_temp_new_i32();
             load_reg_var(s, addr, rn);
             for (reg = 0; reg < nregs; reg++) {
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/2 target-arm: Handle UNDEF cases for Neon VLD/VST multiple-structures

In reply to Peter Maydell

Correctly UNDEF for Neon VLD/VST "multiple structures" forms where the align field is not valid.

---
 target-arm/translate.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
target-arm/translate.c +15 -0
index 5820add..30ca7df 100644
@@ -3830,6 +3830,21 @@ static int disas_neon_ls_insn(CPUState * env, DisasContext *s, uint32_t insn)
         size = (insn >> 6) & 3;
         if (op > 10)
             return 1;
+        /* Catch UNDEF cases for bad values of align field */
+        switch (op & 0xc) {
+        case 4:
+            if (((insn >> 5) & 1) == 1) {
+                return 1;
+            }
+            break;
+        case 8:
+            if (((insn >> 4) & 3) == 3) {
+                return 1;
+            }
+            break;
+        default:
+            break;
+        }
         nregs = neon_ls_element_type[op].nregs;
         interleave = neon_ls_element_type[op].interleave;
         spacing = neon_ls_element_type[op].spacing;
Signature · 1 line
1.7.1
#3 lore raw
In reply to Peter Maydell
Quoted 4 lines · Peter Maydell

These two simple patches make qemu correctly UNDEF where required in the Neon load/store space. We also catch and UNDEF on an UNPREDICTABLE rather than indexing off the end of the register file.

Quoted 9 lines

Tested in the usual way with random instruction sequences.

Peter Maydell (2):
target-arm: Handle UNDEFs for Neon single element load/stores
target-arm: Handle UNDEF cases for Neon VLD/VST multiple-structures

 target-arm/translate.c |   49 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)

Thanks, both applied.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net