1 from nmigen
import (Elaboratable
, Signal
, Module
)
4 class ROTL(Elaboratable
):
5 def __init__(self
, 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)
11 self
.o
= Signal(width
, reset_less
=True)
13 def elaborate(self
, platform
):
17 shl
= Signal
.like(self
.a
)
18 shr
= Signal
.like(self
.a
)
20 comb
+= shl
.eq(self
.a
<< self
.b
)
21 comb
+= shr
.eq(self
.a
>> (self
.width
- self
.b
))
23 comb
+= self
.o
.eq(shl | shr
)