comments and whitespace cleanup
[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 ^ \
31 (1 << self.encoder.o))
32 m.d.sync += self.encoder.i.eq(self.current ^ \
33 (1 << self.encoder.o))
34
35 with m.Else():
36 m.d.sync += self.match.eq(0)
37 m.d.sync += self.encoder.i.eq(0)
38
39 with m.Else():
40 m.d.sync += self.encoder.i.eq(self.input)
41 m.d.sync += self.current.eq(self.input)
42 m.d.sync += self.encoder.i.eq(self.input)
43 m.d.sync += self.match.eq(0)
44
45 return m