use XLEN in Function Units (starting with ALU)
[soc.git] / src / soc / fu / shift_rot / rotl.py
1 from nmigen import (Elaboratable, Signal, Module, Cat)
2 import math
3
4 class ROTL(Elaboratable):
5 def __init__(self, width):
6 self.width = width
7 self.shiftwidth = math.ceil(math.log2(width))
8 self.a = Signal(width, reset_less=True)
9 self.b = Signal(self.shiftwidth, reset_less=True)
10
11 self.o = Signal(width, reset_less=True)
12
13 def elaborate(self, platform):
14 m = Module()
15 comb = m.d.comb
16 # trick to do double-concatenation of a then left shift.
17 # synth tools know to turn this pattern into a barrel-shifter
18 comb += self.o.eq(Cat(self.a, self.a).bit_select(self.width - self.b,
19 len(self.a)))
20 return m