From 8a45a6610a8c4c457b1658db2e49607b284fe391 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 13 Jul 2020 15:13:21 +0100 Subject: [PATCH] reduce rotl module to one line (use bit_select) --- src/soc/fu/shift_rot/rotl.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/soc/fu/shift_rot/rotl.py b/src/soc/fu/shift_rot/rotl.py index d2ebfcf7..8a62460d 100644 --- a/src/soc/fu/shift_rot/rotl.py +++ b/src/soc/fu/shift_rot/rotl.py @@ -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 -- 2.30.2