bit of a mess. getting carry recognised and output for shiftrot
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 19 Jun 2020 12:45:01 +0000 (13:45 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 19 Jun 2020 12:45:01 +0000 (13:45 +0100)
was interfering with fixedarith carry "implicit" computation.
had to special-case this in pywriter.py and parser.py

src/soc/decoder/isa/caller.py
src/soc/decoder/power_pseudo.py
src/soc/decoder/pseudo/parser.py
src/soc/decoder/pseudo/pywriter.py

index e5d14652892e9a3be613e02cbbb79d1078ae6709..79e8b13ec5522791e75bd1184f228005a29c6520 100644 (file)
@@ -335,8 +335,16 @@ class ISACaller:
             imm = yield self.dec2.e.imm_data.data
             inputs.append(SelectableInt(imm, 64))
         assert len(outputs) >= 1
-        output = outputs[0]
-        gts = [(x > output) for x in inputs]
+        print ("outputs", repr(outputs))
+        if isinstance(outputs, list) or isinstance(outputs, tuple):
+            output = outputs[0]
+        else:
+            output = outputs
+        gts = []
+        for x in inputs:
+            print ("gt input", x, output)
+            gt = (x > output)
+            gts.append(gt)
         print(gts)
         cy = 1 if any(gts) else 0
         if not (1 & already_done):
@@ -344,8 +352,11 @@ class ISACaller:
 
         print ("inputs", inputs)
         # 32 bit carry
-        gts = [(x[32:64] > output[32:64]) == SelectableInt(1, 1)
-               for x in inputs]
+        gts = []
+        for x in inputs:
+            print ("input", x, output)
+            gt = (x[32:64] > output[32:64]) == SelectableInt(1, 1)
+            gts.append(gt)
         cy32 = 1 if any(gts) else 0
         if not (2 & already_done):
             self.spr['XER'][XER_bits['CA32']] = cy32
index 67ae8bc83fef15a3f198d06afd3f442ae41083bc..e2b6440a6065c28aa4d1c896db211fddac0d8419 100644 (file)
@@ -211,10 +211,10 @@ def tolist(num):
 def get_reg_hex(reg):
     return hex(reg.value)
 
-def convert_to_python(pcode, form):
+def convert_to_python(pcode, form, incl_carry):
 
     print ("form", form)
-    gsc = GardenSnakeCompiler(form=form)
+    gsc = GardenSnakeCompiler(form=form, incl_carry=incl_carry)
 
     tree = gsc.compile(pcode, mode="exec", filename="string")
     tree = ast.fix_missing_locations(tree)
index 9b3e8f82d89dbf237b4a07ec5fe75a4491f4537b..d92e43aad05a002d0952983e3260e628670a96f2 100644 (file)
@@ -240,7 +240,8 @@ class PowerParser:
         ("left", "INVERT"),
     )
 
-    def __init__(self, form):
+    def __init__(self, form, include_carry_in_write=False):
+        self.include_ca_in_write = include_carry_in_write
         self.gprs = {}
         form = self.sd.sigforms[form]
         print(form)
@@ -248,6 +249,7 @@ class PowerParser:
         self.declared_vars = set()
         for rname in ['RA', 'RB', 'RC', 'RT', 'RS']:
             self.gprs[rname] = None
+            self.declared_vars.add(rname)
         self.available_op_fields = set()
         for k in formkeys:
             if k not in self.gprs:
@@ -631,8 +633,9 @@ class PowerParser:
         name = p[1]
         if name in self.available_op_fields:
             self.op_fields.add(name)
-        if name in ['CA', 'CA32']:
-            self.write_regs.add(name)
+        if self.include_ca_in_write:
+            if name in ['CA', 'CA32']:
+                self.write_regs.add(name)
         if name in ['CR', 'LR', 'CTR', 'TAR', 'FPSCR', 'MSR']:
             self.special_regs.add(name)
             self.write_regs.add(name) # and add to list to write
@@ -795,9 +798,9 @@ class PowerParser:
 
 
 class GardenSnakeParser(PowerParser):
-    def __init__(self, lexer=None, debug=False, form=None):
+    def __init__(self, lexer=None, debug=False, form=None, incl_carry=False):
         self.sd = create_pdecode()
-        PowerParser.__init__(self, form)
+        PowerParser.__init__(self, form, incl_carry)
         self.debug = debug
         if lexer is None:
             lexer = IndentLexer(debug=0)
@@ -817,8 +820,9 @@ class GardenSnakeParser(PowerParser):
 #from compiler import misc, syntax, pycodegen
 
 class GardenSnakeCompiler(object):
-    def __init__(self, debug=False, form=None):
-        self.parser = GardenSnakeParser(debug=debug, form=form)
+    def __init__(self, debug=False, form=None, incl_carry=False):
+        self.parser = GardenSnakeParser(debug=debug, form=form,
+                                        incl_carry=incl_carry)
 
     def compile(self, code, mode="exec", filename="<string>"):
         tree = self.parser.parse(code)
index 88b7539de344ed4dc760d0ef3aa9de8a4197d729..f6c1ef6a7f9047af16dcd40ee43146e94c75917c 100644 (file)
@@ -55,7 +55,8 @@ class PyISAWriter(ISA):
                 print (fname, d.opcode)
                 pcode = '\n'.join(d.pcode) + '\n'
                 print (pcode)
-                pycode, rused = convert_to_python(pcode, d.form)
+                incl_carry = page == 'fixedshift'
+                pycode, rused = convert_to_python(pcode, d.form, incl_carry)
                 # create list of arguments to call
                 regs = list(rused['read_regs']) + list(rused['uninit_regs'])
                 regs += list(rused['special_regs'])