From 859050716c15df1981067e8ac0568ac860660d41 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 18 Feb 2019 07:00:56 +0000 Subject: [PATCH] use straight << and >> operator instead of multi-level Mux --- src/add/fpbase.py | 21 ++++++++++++++++++++- src/add/test_multishift.py | 22 +++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/add/fpbase.py b/src/add/fpbase.py index 48e93a01..8c10d782 100644 --- a/src/add/fpbase.py +++ b/src/add/fpbase.py @@ -2,11 +2,26 @@ # Copyright (C) Jonathan P Dawson 2013 # 2013-12-12 -from nmigen import Signal, Cat, Const, Mux +from nmigen import Signal, Cat, Const, Mux, Module from math import log from operator import or_ from functools import reduce +class MultiShiftR: + + def __init__(self, width): + self.width = width + self.smax = int(log(width) / log(2)) + self.i = Signal(width) + self.s = Signal(self.smax) + self.o = Signal(width) + + def elaborate(self, platform): + m = Module() + m.d.comb += self.o.eq(self.i >> self.s) + return m + + class MultiShift: """ Generates variable-length single-cycle shifter from a series of conditional tests on each bit of the left/right shift operand. @@ -23,6 +38,8 @@ class MultiShift: self.smax = int(log(width) / log(2)) def lshift(self, op, s): + res = op << s + return res[:len(op)] res = op for i in range(self.smax): zeros = [0] * (1<> s + return res[:len(op)] res = op for i in range(self.smax): zeros = [0] * (1<