Skip to content

Commit

Permalink
coding.py: rewrite If() to make verilog more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens authored and Sebastien Bourdeauducq committed Jun 30, 2013
1 parent b0d467d commit 9d241f8
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions migen/genlib/coding.py
Expand Up @@ -22,10 +22,8 @@ def __init__(self, width):
self.i = Signal(width) # one-hot, lsb has priority
self.o = Signal(max=width) # binary
self.n = Signal() # none
act = If(0)
for j in range(width):
act = act.Elif(self.i[j], self.o.eq(j))
self.comb += act
for j in range(width)[::-1]: # last has priority
self.comb += If(self.i[j], self.o.eq(j))
self.comb += self.n.eq(self.i == 0)

class Decoder(Module):
Expand All @@ -41,9 +39,7 @@ class PriorityDecoder(Decoder):
pass # same

def _main():
from migen.sim.generic import Simulator, TopLevel
from migen.fhdl import verilog

e = Encoder(8)
print(verilog.convert(e, ios={e.i, e.o, e.n}))
pe = PriorityEncoder(8)
Expand Down

0 comments on commit 9d241f8

Please sign in to comment.