From: Luke Kenneth Casson Leighton Date: Sun, 17 Feb 2019 10:03:51 +0000 (+0000) Subject: add a MultiShift class for generating single-cycle bit-shifters X-Git-Tag: ls180-24jan2020~1931 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c151716c38ad3a8a545f8e4193cdbc2c9d5e35ee;p=ieee754fpu.git add a MultiShift class for generating single-cycle bit-shifters --- 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<