c5207734505010a30bdbeed36c0be716a64a8af6
[soc.git] / TLB / src / WalkingPriorityEncoder.py
1 from nmigen import Array, Module, Signal
2 from nmigen.lib.coding import PriorityEncoder, Decoder
3
4 class WalkingPriorityEncoder():
5
6 def __init__(self, width):
7 # Internal
8 self.current = Signal(width)
9 self.encoder = PriorityEncoder(width)
10
11 # Input
12 self.write = Signal(1)
13 self.input = Signal(width)
14
15 # Output
16 self.match = Signal(1)
17 self.output = Signal(width)
18
19 def elaborate(self, platform=None):
20 m = Module()
21
22 m.submodules += self.encoder
23
24 with m.If(self.write == 0):
25 with m.If(self.encoder.n == 0):
26 m.d.sync += [
27 self.output.eq(self.encoder.o),
28 self.match.eq(1)
29 ]
30 m.d.sync += self.current.eq(self.current ^ (1 << self.encoder.o))
31 m.d.sync += self.encoder.i.eq(self.current ^ (1 << self.encoder.o))
32
33 with m.Else():
34 m.d.sync += self.match.eq(0)
35 m.d.sync += self.encoder.i.eq(0)
36
37 with m.Else():
38 m.d.sync += self.encoder.i.eq(self.input)
39 m.d.sync += self.current.eq(self.input)
40 m.d.sync += self.encoder.i.eq(self.input)
41 m.d.sync += self.match.eq(0)
42
43
44
45 return m