From: Michael Nolan Date: Sat, 9 May 2020 15:58:19 +0000 (-0400) Subject: Add mask generator for shift class instructions X-Git-Tag: div_pipeline~1309 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7beded5b0ed5d1f178712d66bdc3e7382c507897;p=soc.git Add mask generator for shift class instructions --- diff --git a/src/soc/alu/maskgen.py b/src/soc/alu/maskgen.py new file mode 100644 index 00000000..dd6b9573 --- /dev/null +++ b/src/soc/alu/maskgen.py @@ -0,0 +1,38 @@ +from nmigen import (Elaboratable, Signal, Module) +import math + +class MaskGen(Elaboratable): + def __init__(self, width): + self.width = width + self.shiftwidth = math.ceil(math.log2(width)) + self.mb = Signal(self.shiftwidth, reset_less=True) + self.me = Signal(self.shiftwidth, reset_less=True) + + self.o = Signal(width, reset_less=True) + + def elaborate(self, platform): + m = Module() + comb = m.d.comb + + x = Signal.like(self.mb) + y = Signal.like(self.mb) + + comb += x.eq(64 - self.mb) + comb += y.eq(63 - self.me) + + mask_a = Signal.like(self.o) + mask_b = Signal.like(self.o) + + comb += mask_a.eq((1< y): + comb += self.o.eq(mask_a ^ mask_b) + with m.Else(): + comb += self.o.eq(mask_a ^ ~mask_b) + + + return m + + def ports(self): + return [self.mb, self.me, self.o] diff --git a/src/soc/alu/test/test_maskgen.py b/src/soc/alu/test/test_maskgen.py new file mode 100644 index 00000000..f9d28d70 --- /dev/null +++ b/src/soc/alu/test/test_maskgen.py @@ -0,0 +1,41 @@ +from nmigen import Signal, Module +from nmigen.back.pysim import Simulator, Delay, Settle +from nmigen.test.utils import FHDLTestCase +from soc.alu.maskgen import MaskGen +from soc.decoder.helpers import MASK +import random +import unittest + +class MaskGenTestCase(FHDLTestCase): + def test_maskgen(self): + m = Module() + comb = m.d.comb + m.submodules.dut = dut = MaskGen(64) + mb = Signal.like(dut.mb) + me = Signal.like(dut.me) + o = Signal.like(dut.o) + + comb += [ + dut.mb.eq(mb), + dut.me.eq(me), + o.eq(dut.o)] + + sim = Simulator(m) + + def process(): + for x in range(0, 64): + for y in range(0, 64): + yield mb.eq(x) + yield me.eq(y) + yield Delay(1e-6) + + expected = MASK(x, y) + result = yield o + self.assertEqual(expected, result) + + sim.add_process(process) # or sim.add_sync_process(process), see below + with sim.write_vcd("maskgen.vcd", "maskgen.gtkw", traces=dut.ports()): + sim.run() + +if __name__ == '__main__': + unittest.main() diff --git a/src/soc/alu/test/test_pipe_caller.py b/src/soc/alu/test/test_pipe_caller.py index 9b9152b1..899b764f 100644 --- a/src/soc/alu/test/test_pipe_caller.py +++ b/src/soc/alu/test/test_pipe_caller.py @@ -134,6 +134,7 @@ class ALUTestCase(FHDLTestCase): with Program(lst) as program: sim = self.run_tst_program(program, initial_regs) + @unittest.skip("broken") def test_ilang(self): rec = CompALUOpSubset()