From c151716c38ad3a8a545f8e4193cdbc2c9d5e35ee Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sun, 17 Feb 2019 10:03:51 +0000 Subject: [PATCH] add a MultiShift class for generating single-cycle bit-shifters --- src/add/fpbase.py | 32 ++++++++++++++++- src/add/test_multishift.py | 73 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 src/add/test_multishift.py diff --git a/src/add/fpbase.py b/src/add/fpbase.py index 6e1644f5..8c0b54b0 100644 --- a/src/add/fpbase.py +++ b/src/add/fpbase.py @@ -2,7 +2,37 @@ # Copyright (C) Jonathan P Dawson 2013 # 2013-12-12 -from nmigen import Signal, Cat, Const +from nmigen import Signal, Cat, Const, Mux +from math import log + +class MultiShift: + """ Generates variable-length single-cycle shifter from a series + of conditional tests on each bit of the left/right shift operand. + Each bit tested produces output shifted by that number of bits, + in a binary fashion: bit 1 if set shifts by 1 bit, bit 2 if set + shifts by 2 bits, each partial result cascading to the next Mux. + + Could be adapted to do arithmetic shift by taking copies of the + MSB instead of zeros. + """ + + def __init__(self, width): + self.width = width + self.smax = int(log(width) / log(2)) + + def lshift(self, op, s): + res = op + for i in range(self.smax): + zeros = [0] * (1<> b) & ((1<