From: Jacob Lifshay Date: Mon, 4 Jul 2022 06:15:14 +0000 (-0700) Subject: fix MultiShift* classes to correctly calculate shift-amount bit width X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3b32864bee52cff37b69566335498d0133d03733;p=ieee754fpu.git fix MultiShift* classes to correctly calculate shift-amount bit width --- diff --git a/src/ieee754/fpcommon/fpbase.py b/src/ieee754/fpcommon/fpbase.py index f3e68fe6..ab6cc705 100644 --- a/src/ieee754/fpcommon/fpbase.py +++ b/src/ieee754/fpcommon/fpbase.py @@ -8,7 +8,7 @@ Copyright (C) 2019,2022 Jacob Lifshay from nmigen import (Signal, Cat, Const, Mux, Module, Elaboratable, Array, Value, Shape) -from math import log +from nmigen.utils import bits_for from operator import or_ from functools import reduce @@ -526,11 +526,11 @@ class TestFPFormat(unittest.TestCase): self.assertEqual(i, True) -class MultiShiftR: +class MultiShiftR(Elaboratable): def __init__(self, width): self.width = width - self.smax = int(log(width) / log(2)) + self.smax = bits_for(width - 1) self.i = Signal(width, reset_less=True) self.s = Signal(self.smax, reset_less=True) self.o = Signal(width, reset_less=True) @@ -554,7 +554,7 @@ class MultiShift: def __init__(self, width): self.width = width - self.smax = int(log(width) / log(2)) + self.smax = bits_for(width - 1) def lshift(self, op, s): res = op << s @@ -808,7 +808,7 @@ class MultiShiftRMerge(Elaboratable): def __init__(self, width, s_max=None): if s_max is None: - s_max = int(log(width) / log(2)) + s_max = bits_for(width - 1) self.smax = Shape.cast(s_max) self.m = Signal(width, reset_less=True) self.inp = Signal(width, reset_less=True)