Skip to content

New IR causes DSP inference issues with Quartus #1148

Closed
@tpwrules

Description

@tpwrules

The following design (within the Details) infers 2 DSP blocks: Info (21062): Implemented 2 DSP elements.

from amaranth import *
from amaranth.lib import wiring
from amaranth.lib.wiring import In, Out

from amaranth_boards.de10_nano import DE10NanoPlatform

class DSPMACBlock(wiring.Component):
    # using signed 18x18->36 mode
    # https://www.intel.com/content/www/us/en/docs/programmable/683375/current/independent-multiplier-mode.html

    mul_a: In(signed(18)) # A input is 18 bits
    mul_b: In(signed(18)) # B input is 18 bits
    result: Out(signed(36)) # result is len(A)+len(B)

    def elaborate(self, platform):
        m = Module()

        m.d.sync += self.result.eq(self.mul_a * self.mul_b)

        return m

class Top(Elaboratable):
    def elaborate(self, platform):
        m = Module()

        m.submodules.mac = mac = DSPMACBlock()
        m.d.comb += [
            mac.mul_a.eq(Mux(platform.request("switch", 0).i, -1, 0)), # use all bits
            mac.mul_b.eq(Mux(platform.request("switch", 1).i, -1, 0)),
            platform.request("led", 0).o.eq(mac.result[-1])
        ]

        return m

if __name__ == "__main__":
    DE10NanoPlatform().build(Top())

Given that this is a supported DSP mode, I would expect this to infer only 1 block. This worked properly with the old IR. If I make both operands of the * signed by modifying line 107 of the generated Verilog (assign \$1 = ...) then correctly 1 block is inferred.

Not sure if there's any difference in functionality between the two scenarios.

Versions:

Activity

added a commit that references this issue on Feb 19, 2024
a0ab64a
whitequark

whitequark commented on Feb 19, 2024

@whitequark
Member

This worked properly with the old IR.

(Technically we use both IRs right now.)

added this to the 0.5 milestone on Feb 26, 2024
added a commit that references this issue on Apr 4, 2024
f5f3d20
added a commit that references this issue on Apr 4, 2024
d3c5b95
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Participants

      @whitequark@tpwrules

      Issue actions

        New IR causes DSP inference issues with Quartus · Issue #1148 · amaranth-lang/amaranth