From 3540d700a3f391a5ff555f1bf6629e73ea85af0f Mon Sep 17 00:00:00 2001 From: Johan Olby Date: Thu, 16 Jul 2026 17:35:55 +0200 Subject: [PATCH] gowin: Correct B_MINWIDTH for 27x17 The 27x18 rule carried B_MINWIDTH=13, so any product whose narrower operand was below 13 (e.g. 27x4, 4x13) was rejected even though it fits one MULTALU27X18 tile, and decomposed onto MULT12X12 partials instead. Drop the floor to 2 so the rule blocks only degenerate Nx1 multiplies, matching the rest of the tree. Adds a 4x13 regression case. --- techlibs/gowin/synth_gowin.cc | 2 +- tests/arch/gowin/mul_gw5a.ys | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/techlibs/gowin/synth_gowin.cc b/techlibs/gowin/synth_gowin.cc index f76f49deb..876a727c5 100644 --- a/techlibs/gowin/synth_gowin.cc +++ b/techlibs/gowin/synth_gowin.cc @@ -46,7 +46,7 @@ struct SynthGowinPass : public ScriptPass const std::vector gw5a_dsp_rules = { {27, 36, 2, 19, "$__MUL27X36"}, - {27, 18, 13, 13, "$__MUL27X18"}, + {27, 18, 13, 2, "$__MUL27X18"}, {12, 12, 2, 2, "$__MUL12X12"}, }; diff --git a/tests/arch/gowin/mul_gw5a.ys b/tests/arch/gowin/mul_gw5a.ys index a8b0c2e7d..7dd3ad4f6 100644 --- a/tests/arch/gowin/mul_gw5a.ys +++ b/tests/arch/gowin/mul_gw5a.ys @@ -37,6 +37,19 @@ cd top select -assert-count 1 t:MULTALU27X18 +# 4x13 -> 1 MULTALU27X18 (asymmetric: narrower operand below the 12x12 cell's +# width, yet the product fits one 27x18 tile; relies on operand-order +# normalization in mul2dsp plus B_MIN=2 on the 27x18 rule) +design -reset +read_verilog mul_gw5a.v +chparam -set X_WIDTH 4 -set Y_WIDTH 13 -set A_WIDTH 17 +hierarchy -top top +proc +synth_gowin -family gw5a +cd top +select -assert-count 1 t:MULTALU27X18 + + # 28x18 -> A overflows 27: 1 MULTALU27X18 + MULT12X12 partials design -reset read_verilog mul_gw5a.v