tobias: encoder, in countzero.vhdl, is PriorityEncoder in nmigen. however you have to invert the input bits for right-mode input[::-1] or something like that. there may be a function for it in nmigen l.