[PATCH] decodetree: Infer argument set before inferring format

Richard Henderson posted 1 patch 3 months, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20250722183343.273533-1-richard.henderson@linaro.org
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, John Snow <jsnow@redhat.com>, Cleber Rosa <crosa@redhat.com>
scripts/decodetree.py           | 7 ++++---
tests/decode/meson.build        | 1 +
tests/decode/succ_infer1.decode | 4 ++++
3 files changed, 9 insertions(+), 3 deletions(-)
create mode 100644 tests/decode/succ_infer1.decode
[PATCH] decodetree: Infer argument set before inferring format
Posted by Richard Henderson 3 months, 3 weeks ago
Failure to confirm an argument set first may result in
the selection of a format which leaves extra arguments
to be filled in by the pattern.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 scripts/decodetree.py           | 7 ++++---
 tests/decode/meson.build        | 1 +
 tests/decode/succ_infer1.decode | 4 ++++
 3 files changed, 9 insertions(+), 3 deletions(-)
 create mode 100644 tests/decode/succ_infer1.decode

diff --git a/scripts/decodetree.py b/scripts/decodetree.py
index e8b72da3a9..f992472b73 100644
--- a/scripts/decodetree.py
+++ b/scripts/decodetree.py
@@ -1016,9 +1016,12 @@ def infer_format(arg, fieldmask, flds, width):
         else:
             var_flds[n] = c
 
+    if not arg:
+        arg = infer_argument_set(flds)
+
     # Look for an existing format with the same argument set and fields
     for fmt in formats.values():
-        if arg and fmt.base != arg:
+        if fmt.base != arg:
             continue
         if fieldmask != fmt.fieldmask:
             continue
@@ -1029,8 +1032,6 @@ def infer_format(arg, fieldmask, flds, width):
         return (fmt, const_flds)
 
     name = decode_function + '_Fmt_' + str(len(formats))
-    if not arg:
-        arg = infer_argument_set(flds)
 
     fmt = Format(name, 0, arg, 0, 0, 0, fieldmask, var_flds, width)
     formats[name] = fmt
diff --git a/tests/decode/meson.build b/tests/decode/meson.build
index b13fada980..63405ca08f 100644
--- a/tests/decode/meson.build
+++ b/tests/decode/meson.build
@@ -41,6 +41,7 @@ succ_tests = [
     'succ_argset_type1.decode',
     'succ_function.decode',
     'succ_ident1.decode',
+    'succ_infer1.decode',
     'succ_named_field.decode',
     'succ_pattern_group_nest1.decode',
     'succ_pattern_group_nest2.decode',
diff --git a/tests/decode/succ_infer1.decode b/tests/decode/succ_infer1.decode
new file mode 100644
index 0000000000..6fa40bada5
--- /dev/null
+++ b/tests/decode/succ_infer1.decode
@@ -0,0 +1,4 @@
+&rprr_load      rd pg rn rm dtype nreg
+@rprr_load      .... .... ... rm:5 ... pg:3 rn:5 rd:5            &rprr_load
+
+LD1Q            1100 0100 000 rm:5 101 pg:3 rn:5 rd:5
-- 
2.43.0
Re: [PATCH] decodetree: Infer argument set before inferring format
Posted by Philippe Mathieu-Daudé 3 months, 3 weeks ago
On 22/7/25 20:33, Richard Henderson wrote:
> Failure to confirm an argument set first may result in
> the selection of a format which leaves extra arguments
> to be filled in by the pattern.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   scripts/decodetree.py           | 7 ++++---
>   tests/decode/meson.build        | 1 +
>   tests/decode/succ_infer1.decode | 4 ++++
>   3 files changed, 9 insertions(+), 3 deletions(-)
>   create mode 100644 tests/decode/succ_infer1.decode

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>


Re: [PATCH] decodetree: Infer argument set before inferring format
Posted by Peter Maydell 3 months, 3 weeks ago
On Tue, 22 Jul 2025 at 19:33, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Failure to confirm an argument set first may result in
> the selection of a format which leaves extra arguments
> to be filled in by the pattern.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  scripts/decodetree.py           | 7 ++++---
>  tests/decode/meson.build        | 1 +
>  tests/decode/succ_infer1.decode | 4 ++++
>  3 files changed, 9 insertions(+), 3 deletions(-)
>  create mode 100644 tests/decode/succ_infer1.decode

This fixes the problem I was running into with the LD1Q
fix I'm working on.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Tested-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM