diff mbox series

[1/1] decodetree: Add support for 64-bit instructions

Message ID CP2PR80MB36688C896376D6D8601E1EB5DA759@CP2PR80MB3668.lamprd80.prod.outlook.com (mailing list archive)
State New, archived
Headers show
Series Add 64-bit instruction support to decodetree | expand

Commit Message

Luis Fernando Fujita Pires April 7, 2021, 2:59 p.m. UTC
Allow '64' to be specified for the instruction width command line params 
and use the appropriate insn/field data types, mask, extract and deposit
functions in that case.

This will be used to implement the new 64-bit Power ISA 3.1 instructions.

Signed-off-by: Luis Pires <luis.pires@eldorado.org.br>
---
 docs/devel/decodetree.rst |  3 ---
 scripts/decodetree.py     | 25 ++++++++++++++++++++-----
 2 files changed, 20 insertions(+), 8 deletions(-)

--
2.25.1

Comments

Richard Henderson April 7, 2021, 3:18 p.m. UTC | #1
On 4/7/21 7:59 AM, Luis Fernando Fujita Pires wrote:
> Allow '64' to be specified for the instruction width command line params
> and use the appropriate insn/field data types, mask, extract and deposit
> functions in that case.
> 
> This will be used to implement the new 64-bit Power ISA 3.1 instructions.
> 
> Signed-off-by: Luis Pires <luis.pires@eldorado.org.br>
> ---
>   docs/devel/decodetree.rst |  3 ---
>   scripts/decodetree.py     | 25 ++++++++++++++++++++-----
>   2 files changed, 20 insertions(+), 8 deletions(-)

Looks good.

> --- a/docs/devel/decodetree.rst
> +++ b/docs/devel/decodetree.rst
> @@ -40,9 +40,6 @@ and returns an integral value extracted from there.
> 
>   A field with no ``unnamed_fields`` and no ``!function`` is in error.
> 
> -FIXME: the fields of the structure into which this result will be stored
> -is restricted to ``int``.  Which means that we cannot expand 64-bit items.

Let's replace this FIXME with a sentence or two documenting the type used.


r~
diff mbox series

Patch

diff --git a/docs/devel/decodetree.rst b/docs/devel/decodetree.rst
index 74f66bf46e..505267234d 100644
--- a/docs/devel/decodetree.rst
+++ b/docs/devel/decodetree.rst
@@ -40,9 +40,6 @@  and returns an integral value extracted from there.

 A field with no ``unnamed_fields`` and no ``!function`` is in error.

-FIXME: the fields of the structure into which this result will be stored
-is restricted to ``int``.  Which means that we cannot expand 64-bit items.
-
 Field examples:

 +---------------------------+---------------------------------------------+
diff --git a/scripts/decodetree.py b/scripts/decodetree.py
index 4637b633e7..3450a2a08d 100644
--- a/scripts/decodetree.py
+++ b/scripts/decodetree.py
@@ -42,6 +42,10 @@ 
 output_fd = None
 insntype = 'uint32_t'
 decode_function = 'decode'
+field_data_type = 'int'
+extract_function = 'extract32'
+sextract_function = 'sextract32'
+deposit_function = 'deposit32'

 # An identifier for C.
 re_C_ident = '[a-zA-Z][a-zA-Z0-9_]*'
@@ -185,9 +189,9 @@  def __str__(self):

     def str_extract(self):
         if self.sign:
-            extr = 'sextract32'
+            extr = sextract_function
         else:
-            extr = 'extract32'
+            extr = extract_function
         return '{0}(insn, {1}, {2})'.format(extr, self.pos, self.len)

     def __eq__(self, other):
@@ -215,8 +219,8 @@  def str_extract(self):
             if pos == 0:
                 ret = f.str_extract()
             else:
-                ret = 'deposit32({0}, {1}, {2}, {3})' \
-                      .format(ret, pos, 32 - pos, f.str_extract())
+                ret = '{4}({0}, {1}, {2}, {3})' \
+                      .format(ret, pos, insnwidth - pos, f.str_extract(), deposit_function)
             pos += f.len
         return ret

@@ -311,7 +315,7 @@  def output_def(self):
         if not self.extern:
             output('typedef struct {\n')
             for n in self.fields:
-                output('    int ', n, ';\n')
+                output('    ', field_data_type, ' ', n, ';\n')
             output('} ', self.struct_name(), ';\n\n')
 # end Arguments

@@ -1264,6 +1268,10 @@  def main():
     global insntype
     global insnmask
     global decode_function
+    global extract_function
+    global sextract_function
+    global deposit_function
+    global field_data_type
     global variablewidth
     global anyextern

@@ -1293,6 +1301,13 @@  def main():
             if insnwidth == 16:
                 insntype = 'uint16_t'
                 insnmask = 0xffff
+            elif insnwidth == 64:
+                insntype = 'uint64_t'
+                insnmask = 0xffffffffffffffff
+                field_data_type = 'int64_t'
+                extract_function = 'extract64'
+                sextract_function = 'sextract64'
+                deposit_function = 'deposit64'
             elif insnwidth != 32:
                 error(0, 'cannot handle insns of width', insnwidth)
         else: