d2ebfcf71a622c4935686a37ed33acb121086b9b
[soc.git] / src / soc / fu / shift_rot / rotl.py
1 from nmigen import (Elaboratable, Signal, Module)
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
17 shl = Signal.like(self.a)
18 shr = Signal.like(self.a)
19
20 comb += shl.eq(self.a << self.b)
21 comb += shr.eq(self.a >> (self.width - self.b))
22
23 comb += self.o.eq(shl | shr)
24 return m