reduce rotl module to one line (use bit_select)
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 13 Jul 2020 14:13:21 +0000 (15:13 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 13 Jul 2020 14:13:21 +0000 (15:13 +0100)
src/soc/fu/shift_rot/rotl.py

index d2ebfcf71a622c4935686a37ed33acb121086b9b..8a62460dda533fb3b1fe581e53383a4e1e425580 100644 (file)
@@ -1,4 +1,4 @@
-from nmigen import (Elaboratable, Signal, Module)
+from nmigen import (Elaboratable, Signal, Module, Cat)
 import math
 
 class ROTL(Elaboratable):
@@ -13,12 +13,8 @@ class ROTL(Elaboratable):
     def elaborate(self, platform):
         m = Module()
         comb = m.d.comb
-
-        shl = Signal.like(self.a)
-        shr = Signal.like(self.a)
-
-        comb += shl.eq(self.a << self.b)
-        comb += shr.eq(self.a >> (self.width - self.b))
-
-        comb += self.o.eq(shl | shr)
+        # trick to do double-concatenation of a then left shift.
+        # synth tools know to turn this pattern into a barrel-shifter
+        comb += self.o.eq(Cat(self.a, self.a).bit_select(self.width - self.b,
+                                                         len(self.a)))
         return m