Add unique Priority Encoder to allow for multiple matches in the CAM. Name is up...
authorDaniel Benusovich <flyingmonkeys1996@gmail.com>
Fri, 1 Mar 2019 09:20:57 +0000 (01:20 -0800)
committerDaniel Benusovich <flyingmonkeys1996@gmail.com>
Fri, 1 Mar 2019 09:20:57 +0000 (01:20 -0800)
TLB/src/WalkingPriorityEncoder.py [new file with mode: 0644]
TLB/test/test_walking_priority_encoder.py [new file with mode: 0644]

diff --git a/TLB/src/WalkingPriorityEncoder.py b/TLB/src/WalkingPriorityEncoder.py
new file mode 100644 (file)
index 0000000..c520773
--- /dev/null
@@ -0,0 +1,45 @@
+from nmigen import Array, Module, Signal
+from nmigen.lib.coding import PriorityEncoder, Decoder
+
+class WalkingPriorityEncoder():
+    
+    def __init__(self, width):
+        # Internal
+        self.current = Signal(width)
+        self.encoder = PriorityEncoder(width)
+        
+        # Input
+        self.write = Signal(1)
+        self.input = Signal(width)
+        
+        # Output
+        self.match = Signal(1)
+        self.output = Signal(width)
+        
+    def elaborate(self, platform=None):
+        m = Module()
+        
+        m.submodules += self.encoder
+        
+        with m.If(self.write == 0):
+            with m.If(self.encoder.n == 0):
+                m.d.sync += [
+                    self.output.eq(self.encoder.o),
+                    self.match.eq(1)
+                ]
+                m.d.sync += self.current.eq(self.current ^ (1 << self.encoder.o))              
+                m.d.sync += self.encoder.i.eq(self.current ^ (1 << self.encoder.o))
+            
+            with m.Else():
+                m.d.sync += self.match.eq(0)
+                m.d.sync += self.encoder.i.eq(0)
+            
+        with m.Else():
+            m.d.sync += self.encoder.i.eq(self.input)
+            m.d.sync += self.current.eq(self.input)
+            m.d.sync += self.encoder.i.eq(self.input)
+            m.d.sync += self.match.eq(0)        
+           
+            
+        
+        return m
\ No newline at end of file
diff --git a/TLB/test/test_walking_priority_encoder.py b/TLB/test/test_walking_priority_encoder.py
new file mode 100644 (file)
index 0000000..6f1faa0
--- /dev/null
@@ -0,0 +1,32 @@
+import sys
+sys.path.append("../src")
+sys.path.append("../../TestUtil")
+
+from nmigen.compat.sim import run_simulation
+
+from WalkingPriorityEncoder import WalkingPriorityEncoder
+
+from test_helper import assert_eq, assert_ne
+
+def testbench(dut):
+    yield dut.write.eq(1)
+    yield dut.input.eq(5)
+    yield dut.output.eq(3)
+    yield
+    yield dut.write.eq(0)
+    yield dut.input.eq(0)
+    yield
+    yield
+    yield
+    yield
+    yield
+    yield
+    yield
+    yield
+    output = yield dut.output
+    #assert_eq("Output", output, 1) 
+
+if __name__ == "__main__":
+    dut = WalkingPriorityEncoder(4)
+    run_simulation(dut, testbench(dut), vcd_name="Waveforms/cam_walking_priority_encoder.vcd")
+    print("WalkingPriorityEncoder Unit Test Success")
\ No newline at end of file