Created
May 1, 2019 16:50
-
-
Save Ravenslofty/719eb1cf8ebcb0401ccaf130eb360bd1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from nmigen import Const, Elaboratable, Module, Repl, Signal | |
| from nmigen.cli import main | |
| class PositiveAttacks(Elaboratable): | |
| def __init__(self, shift, mask): | |
| self.gen = Signal(64) | |
| self.prop = Signal(64) | |
| self.output = Signal(64) | |
| self.shift = shift | |
| self.mask = mask | |
| def elaborate(self, platform): | |
| m = Module() | |
| prop = Signal(64) | |
| gen = Signal(64) | |
| m.d.comb += [ | |
| prop.eq(self.prop & self.mask), | |
| gen.eq(self.gen | prop & (self.gen << self.shift)), | |
| # Breaks when the following two lines are uncommented | |
| # prop.eq(prop & (prop << self.shift)), | |
| # gen.eq(gen | prop & (gen << self.shift)), | |
| self.output.eq(gen) | |
| ] | |
| return m | |
| if __name__ == "__main__": | |
| pa = PositiveAttacks(8, Repl(Const(1), 64)) | |
| main(pa, ports=[pa.gen, pa.prop, pa.output]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment