serdes-transceiver/util.py

12 lines
384 B
Python

from migen import *
class PriorityEncoderMSB(Module):
def __init__(self, width):
self.i = Signal(width) # one-hot, msb has priority
self.o = Signal(max=max(2, width)) # binary
self.n = Signal() # none
for j in range(width): # first has priority
self.comb += If(self.i[j], self.o.eq(j))
self.comb += self.n.eq(self.i == 0)