inorder.py: Added draft get_input/output_regs functions.
authorAndrey Miroshnikov <andrey@technepisteme.xyz>
Sun, 28 May 2023 20:40:58 +0000 (20:40 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 2 Jun 2023 18:51:19 +0000 (19:51 +0100)
Passing trace (insn and Hazards()) to the fetch phase.
Decoder not yet using Hazard info.

src/openpower/cyclemodel/inorder.py

index 03ca65ddd93dbc8b47597a2a9ddc65b6435b5f86..9bf6f88b3f88cfd23400b81aa98c1d3efa62b75c 100644 (file)
@@ -89,6 +89,19 @@ def read_file(fname):
     if not is_file:
         fname.close()
 
+    # TODO: Determine from Hazard() object
+def get_input_regs(hazard):
+    if hazard.action == 'r':
+        # return the reg to be read
+        return (hazard.target, hazard.ident)
+    return None
+
+def get_output_regs(hazard):
+    if hazard.action == 'w':
+        # return the reg to be read
+        return (hazard.target, hazard.ident)
+    return None
+
 
 class RegisterWrite:
     """
@@ -161,13 +174,14 @@ class Fetch:
     def tick(self):
         self.stages[0] = None
 
-    def process_instructions(self, stall):
+    #TODO: rename 'trace', temp name
+    def process_instructions(self, stall, trace):
         if stall: return stall
         insn = self.stages[0] # get current instruction
         if insn is not None:
-            self.cpu.decode.add_instructions(insn) # pass on instruction
+            self.cpu.decode.add_instruction(insn) # pass on instruction
         # read from log file, write into self.stages[0]
-        # XXX TODO
+        self.stages = trace
         return stall
 
 
@@ -206,7 +220,6 @@ class Decode:
         self.cpu.issue.add_instruction(insn, writeregs)
         return stall
 
-
 class Issue:
     """
     Issue phase: if not stalled will place the instruction into execute.
@@ -279,6 +292,8 @@ class CPU:
 class TestTrace(unittest.TestCase):
 
     def test_trace(self): # TODO, assert this is valid
+        basic_cpu = CPU()
+
         lines = (
             "r:GPR:0:0:64 w:GPR:1:0:64              # addi 1, 0, 0x0010",
             "r:GPR:0:0:64 w:GPR:2:0:64              # addi 2, 0, 0x1234",
@@ -293,6 +308,10 @@ class TestTrace(unittest.TestCase):
         lines = read_file(f)
         for trace in lines:
             print(trace)
+            # TODO: Only checking the fetch step,
+            # change to cpu.process_instructions() once working
+            #basic_cpu.stall = basic_cpu.fetch.process_instructions(
+            #                  basic_cpu.stall, trace)
 
 def help():
     print ("-t             runs unit tests")