Skip to contentSkip to conversation

decodetree enhancements

PATCH Superseded Richard Henderson 2 participants 12 messages Feb 28, 2019

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover decodetree enhancements

Changes since v1:
* Move documentation to docs/devel/; fix some typos; add a description of when you might use argument sets.
* Include test cases for pattern groups.
* Add --static-decode.

r~

Bastian Koppelmann (1):
test/decode: Add tests for PatternGroups

Philippe Mathieu-Daudé (2):
MAINTAINERS: Add scripts/decodetree.py to the TCG section
decodetree: Ensure build_tree does not include values outside insnmask

Richard Henderson (5):
decodetree: Move documentation to docs/devel/decodetree.rst
decodetree: Document the usefulness of argument sets
decodetree: Do not unconditionaly return from Pattern.output_code
decodetree: Allow grouping of overlapping patterns
decodetree: Add --static-decode option

 MAINTAINERS                                  |   2 +
 docs/devel/decodetree.rst                    | 221 ++++++++++++++
 scripts/decodetree.py                        | 292 +++++++++----------
 tests/decode/check.sh                        |   6 +
 tests/decode/err_pattern_group_empty.decode  |   6 +
 tests/decode/err_pattern_group_ident1.decode |  10 +
 tests/decode/err_pattern_group_ident2.decode |  11 +
 tests/decode/err_pattern_group_nest1.decode  |  13 +
 tests/decode/succ_pattern_group_nest1.decode |  22 ++
 9 files changed, 434 insertions(+), 149 deletions(-)
 create mode 100644 docs/devel/decodetree.rst
 create mode 100644 tests/decode/err_pattern_group_empty.decode
 create mode 100644 tests/decode/err_pattern_group_ident1.decode
 create mode 100644 tests/decode/err_pattern_group_ident2.decode
 create mode 100644 tests/decode/err_pattern_group_nest1.decode
 create mode 100644 tests/decode/succ_pattern_group_nest1.decode
Signature · 1 line
2.17.2
#1 lore raw

PATCH v2 1/8 MAINTAINERS: Add scripts/decodetree.py to the TCG section

From: Philippe Mathieu-Daudé <[email protected]>

Message-Id: <[email protected]>

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 7be8c578ea..34364a77ce 100644
@@ -117,6 +117,7 @@ F: cpus.c
 F: exec.c
 F: accel/tcg/
 F: accel/stubs/tcg-stub.c
+F: scripts/decodetree.py
 F: include/exec/cpu*.h
 F: include/exec/exec-all.h
 F: include/exec/helper*.h
Signature · 1 line
2.17.2
#2 lore raw

PATCH v2 2/8 decodetree: Move documentation to docs/devel/decodetree.rst

In reply to Richard Henderson

One great big block comment isn't the best way to document the syntax of a language.

---
 MAINTAINERS               |   1 +
 docs/devel/decodetree.rst | 156 ++++++++++++++++++++++++++++++++++++++
 scripts/decodetree.py     | 134 +-------------------------------
 3 files changed, 158 insertions(+), 133 deletions(-)
 create mode 100644 docs/devel/decodetree.rst
MAINTAINERS +1 -0
index 34364a77ce..120cd7bff0 100644
@@ -118,6 +118,7 @@ F: exec.c
 F: accel/tcg/
 F: accel/stubs/tcg-stub.c
 F: scripts/decodetree.py
+F: docs/devel/decodetree.rst
 F: include/exec/cpu*.h
 F: include/exec/exec-all.h
 F: include/exec/helper*.h
docs/devel/decodetree.rst new file +156 -0

156 lines not on this page · raw message

scripts/decodetree.py +1 -133

140 lines not on this page · raw message

Signature · 1 line
2.17.2
Reviewed-by on v2 2/8
#3 lore raw

Re: [Qemu-devel] [PATCH v2 2/8] decodetree: Move documentation to docs/devel/decodetree.rst

Quoted 10 lines · Richard Henderson

One great big block comment isn't the best way to document the syntax of a language.

---
  MAINTAINERS               |   1 +
  docs/devel/decodetree.rst | 156 ++++++++++++++++++++++++++++++++++++++
  scripts/decodetree.py     | 134 +-------------------------------
  3 files changed, 158 insertions(+), 133 deletions(-)

create mode 100644 docs/devel/decodetree.rst

Cheers,

Bastian

#4 lore raw

PATCH v2 3/8 decodetree: Document the usefulness of argument sets

In reply to Richard Henderson
Cc Bastian Koppelmann <[email protected]>
---
 docs/devel/decodetree.rst | 7 +++++++
 1 file changed, 7 insertions(+)
docs/devel/decodetree.rst +7 -0
index d9be30b2db..62cb7f687c 100644
@@ -69,6 +69,13 @@ with each of the fields being one of the member arguments.
 If ``!extern`` is specified, the backing structure is assumed
 to have been already declared, typically via a second decoder.
 
+Argument sets are useful when one wants to define helper functions
+for the translator functions that can perform operations on a common
+set of arguments.  This can ensure, for instance, that the ``AND``
+pattern and the ``OR`` pattern put their operands into the same named
+structure, so that a common ``gen_logic_insn`` may be able to handle
+the operations common between the two.
+
 Argument set examples::
 
   &reg3       ra rb rc
Signature · 1 line
2.17.2
#6 lore raw

PATCH v2 4/8 decodetree: Ensure build_tree does not include values outside insnmask

In reply to Richard Henderson

From: Philippe Mathieu-Daudé <[email protected]>

Reproduced with "scripts/decodetree.py /dev/null".

---
 scripts/decodetree.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/decodetree.py +1 -1
index 33e32ee87f..e26d8253f2 100755
@@ -784,7 +784,7 @@ class Tree:
 
 def build_tree(pats, outerbits, outermask):
     # Find the intersection of all remaining fixedmask.
-    innermask = ~outermask
+    innermask = ~outermask & insnmask
     for i in pats:
         innermask &= i.fixedmask
 
Signature · 1 line
2.17.2
#7 lore raw

PATCH v2 5/8 decodetree: Do not unconditionaly return from Pattern.output_code

In reply to Richard Henderson

As a consequence, the 'return false' gets pushed up one level.

This will allow us to perform some other action when the translator returns failure.

---
 scripts/decodetree.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
scripts/decodetree.py +4 -3
index e26d8253f2..cc5fa1a8ab 100755
@@ -348,8 +348,8 @@ class Pattern(General):
             output(ind, self.base.extract_name(), '(&u.f_', arg, ', insn);\n')
         for n, f in self.fields.items():
             output(ind, 'u.f_', arg, '.', n, ' = ', f.str_extract(), ';\n')
-        output(ind, 'return ', translate_prefix, '_', self.name,
-               '(ctx, &u.f_', arg, ');\n')
+        output(ind, 'if (', translate_prefix, '_', self.name,
+               '(ctx, &u.f_', arg, ')) return true;\n')
 # end Pattern
 
 
@@ -777,8 +777,8 @@ class Tree:
             output(ind, '    /* ',
                    str_match_bits(innerbits, innermask), ' */\n')
             s.output_code(i + 4, extracted, innerbits, innermask)
+            output(ind, '    return false;\n')
         output(ind, '}\n')
-        output(ind, 'return false;\n')
 # end Tree
 
 
@@ -932,6 +932,7 @@ def main():
     output(i4, '} u;\n\n')
 
     t.output_code(4, False, 0, 0)
+    output(i4, 'return false;\n')
 
     output('}\n')
 
Signature · 1 line
2.17.2
#8 lore raw

PATCH v2 6/8 decodetree: Allow grouping of overlapping patterns

In reply to Richard Henderson
---
 docs/devel/decodetree.rst |  58 +++++++++++++++
 scripts/decodetree.py     | 144 +++++++++++++++++++++++++++++++++++---
 2 files changed, 191 insertions(+), 11 deletions(-)
docs/devel/decodetree.rst +58 -0
index 62cb7f687c..44ac621ea8 100644
@@ -161,3 +161,61 @@ which will, in part, invoke::
 and::
 
   trans_addl_i(ctx, &arg_opi, insn)
+
+Pattern Groups
+==============
+
+Syntax::
+
+  group    := '{' ( pat_def | group )+ '}'
+
+A *group* begins with a lone open-brace, with all subsequent lines
+indented two spaces, and ending with a lone close-brace.  Groups
+may be nested, increasing the required indentation of the lines
+within the nested group to two spaces per nesting level.
+
+Unlike ungrouped patterns, grouped patterns are allowed to overlap.
+Conflicts are resolved by selecting the patterns in order.  If all
+of the fixedbits for a pattern match, its translate function will
+be called.  If the translate function returns false, then subsequent
+patterns within the group will be matched.
+
+The following example from PA-RISC shows specialization of the *or*
+instruction::
+
+  {
+    {
+      nop   000010 ----- ----- 0000 001001 0 00000
+      copy  000010 00000 r1:5  0000 001001 0 rt:5
+    }
+    or      000010 rt2:5 r1:5  cf:4 001001 0 rt:5
+  }
+
+When the *cf* field is zero, the instruction has no side effects,
+and may be specialized.  When the *rt* field is zero, the output
+is discarded and so the instruction has no effect.  When the *rt2*
+field is zero, the operation is ``reg[rt] | 0`` and so encodes
+the canonical register copy operation.
+
+The output from the generator might look like::
+
+  switch (insn & 0xfc000fe0) {
+  case 0x08000240:
+    /* 000010.. ........ ....0010 010..... */
+    if ((insn & 0x0000f000) == 0x00000000) {
+        /* 000010.. ........ 00000010 010..... */
+        if ((insn & 0x0000001f) == 0x00000000) {
+            /* 000010.. ........ 00000010 01000000 */
+            extract_decode_Fmt_0(&u.f_decode0, insn);
+            if (trans_nop(ctx, &u.f_decode0)) return true;
+        }
+        if ((insn & 0x03e00000) == 0x00000000) {
+            /* 00001000 000..... 00000010 010..... */
+            extract_decode_Fmt_1(&u.f_decode1, insn);
+            if (trans_copy(ctx, &u.f_decode1)) return true;
+        }
+    }
+    extract_decode_Fmt_2(&u.f_decode2, insn);
+    if (trans_or(ctx, &u.f_decode2)) return true;
+    return false;
+  }
scripts/decodetree.py +133 -11

218 lines not on this page · raw message

Signature · 1 line
2.17.2
#9 lore raw

PATCH v2 7/8 test/decode: Add tests for PatternGroups

In reply to Richard Henderson

From: Bastian Koppelmann <[email protected]>

This adds one test that supposed to succeed to test deep nesting of pattern groups which is rarely exercised by targets using decode tree. The remaining tests exercise various fail conditions.

Message-Id: <[email protected]>

---
 tests/decode/check.sh                        |  6 ++++++
 tests/decode/err_pattern_group_empty.decode  |  6 ++++++
 tests/decode/err_pattern_group_ident1.decode | 10 +++++++++
 tests/decode/err_pattern_group_ident2.decode | 11 ++++++++++
 tests/decode/err_pattern_group_nest1.decode  | 13 ++++++++++++
 tests/decode/succ_pattern_group_nest1.decode | 22 ++++++++++++++++++++
 6 files changed, 68 insertions(+)
 create mode 100644 tests/decode/err_pattern_group_empty.decode
 create mode 100644 tests/decode/err_pattern_group_ident1.decode
 create mode 100644 tests/decode/err_pattern_group_ident2.decode
 create mode 100644 tests/decode/err_pattern_group_nest1.decode
 create mode 100644 tests/decode/succ_pattern_group_nest1.decode
tests/decode/check.sh +6 -0
index 79a06c37cd..95445a0115 100755
@@ -15,4 +15,10 @@ for i in err_*.decode; do
     fi
 done
 
+for i in succ_*.decode; do
+    if ! $PYTHON $DECODETREE $i > /dev/null 2> /dev/null; then
+        echo FAIL:$i 1>&2
+    fi
+done
+
 exit $E
tests/decode/err_pattern_group_empty.decode new file +6 -0
new file mode 100644
index 0000000000..abbff6b528
@@ -0,0 +1,6 @@
+# This work is licensed under the terms of the GNU LGPL, version 2 or later.
+# See the COPYING.LIB file in the top-level directory.
+
+# empty groups are not allowed
+{
+}
tests/decode/err_pattern_group_ident1.decode new file +10 -0
new file mode 100644
index 0000000000..3e65fab2f9
@@ -0,0 +1,10 @@
+# This work is licensed under the terms of the GNU LGPL, version 2 or later.
+# See the COPYING.LIB file in the top-level directory.
+
+%sub1 0:8
+
+# Make sure that indentation is enforced
+{
+    top      00000000 00000000 00000000 00000000
+    sub1     00000000 00000000 00000000 ........ %sub1
+}
tests/decode/err_pattern_group_ident2.decode new file +11 -0
new file mode 100644
index 0000000000..bc859233b1
@@ -0,0 +1,11 @@
+# This work is licensed under the terms of the GNU LGPL, version 2 or later.
+# See the COPYING.LIB file in the top-level directory.
+
+%sub1 0:8
+
+# Make sure that indentation is enforced
+{
+  top      00000000 00000000 00000000 00000000
+  sub1     00000000 00000000 00000000 ........ %sub1
+# comments are suposed to be indented
+}
tests/decode/err_pattern_group_nest1.decode new file +13 -0
new file mode 100644
index 0000000000..92e971c3c5
@@ -0,0 +1,13 @@
+# This work is licensed under the terms of the GNU LGPL, version 2 or later.
+# See the COPYING.LIB file in the top-level directory.
+
+%sub1 0:8
+%sub2 8:8
+%sub3 16:8
+%sub4 24:8
+
+# Groups with no overlap are supposed to fail
+{
+  top  00000000 00000000 00000000 00000000
+  sub4 ........ ........ ........ ........ %sub1 %sub2 %sub3 %sub4
+}
tests/decode/succ_pattern_group_nest1.decode new file +22 -0
new file mode 100644
index 0000000000..77b0f48b49
@@ -0,0 +1,22 @@
+# This work is licensed under the terms of the GNU LGPL, version 2 or later.
+# See the COPYING.LIB file in the top-level directory.
+
+%sub1 0:8
+%sub2 8:8
+%sub3 16:8
+%sub4 24:7
+
+# Make sure deep netsting works, as few targets will actually exercise it
+{
+  top        00000000 00000000 00000000 00000000
+  {
+    sub1     00000000 00000000 00000000 ........ %sub1
+    {
+      sub2   00000000 00000000 ........ ........ %sub1 %sub2
+      {
+        sub3 00000000 ........ ........ ........ %sub1 %sub2 %sub3
+        sub4 0....... ........ ........ ........ %sub1 %sub2 %sub3 %sub4
+      }
+    }
+  }
+}
Signature · 1 line
2.17.2
#10 lore raw

PATCH v2 8/8 decodetree: Add --static-decode option

In reply to Richard Henderson

Like --decode, but do not drop 'static' qualifier.

---
 scripts/decodetree.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
scripts/decodetree.py +4 -1
index 4596a9da02..68979b73a0 100755
@@ -980,7 +980,8 @@ def main():
 
     decode_scope = 'static '
 
-    long_opts = ['decode=', 'translate=', 'output=', 'insnwidth=']
+    long_opts = ['decode=', 'translate=', 'output=', 'insnwidth=',
+                 'static-decode=']
     try:
         (opts, args) = getopt.getopt(sys.argv[1:], 'o:w:', long_opts)
     except getopt.GetoptError as err:
@@ -991,6 +992,8 @@ def main():
         elif o == '--decode':
             decode_function = a
             decode_scope = ''
+        elif o == '--static-decode':
+            decode_function = a
         elif o == '--translate':
             translate_prefix = a
             translate_scope = ''
Signature · 1 line
2.17.2
#11 lore raw

[Qemu-devel] [PATCH 9/8] decodetree: Produce clean output for an empty input file

In reply to Richard Henderson

This is interesting for bisection, where an output file is plumbed, but does not yet have patterns.

---

One more small fix that should have gone with the v2 patchset.

---
 scripts/decodetree.py | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
scripts/decodetree.py +8 -7
index 68979b73a0..1785769eec 100755
@@ -1050,15 +1050,16 @@ def main():
            '(DisasContext *ctx, ', insntype, ' insn)\n{\n')
 
     i4 = str_indent(4)
-    output(i4, 'union {\n')
-    for n in sorted(arguments.keys()):
-        f = arguments[n]
-        output(i4, i4, f.struct_name(), ' f_', f.name, ';\n')
-    output(i4, '} u;\n\n')
 
-    t.output_code(4, False, 0, 0)
+    if len(allpatterns) != 0:
+        output(i4, 'union {\n')
+        for n in sorted(arguments.keys()):
+            f = arguments[n]
+            output(i4, i4, f.struct_name(), ' f_', f.name, ';\n')
+        output(i4, '} u;\n\n')
+        t.output_code(4, False, 0, 0)
+
     output(i4, 'return false;\n')
-
     output('}\n')
 
     if output_file:
Signature · 1 line
2.17.2