diff --git a/techlibs/ice40/ice40_dsp.pmg b/techlibs/ice40/ice40_dsp.pmg index 63bc8de4b90..7e4c3ace2e4 100644 --- a/techlibs/ice40/ice40_dsp.pmg +++ b/techlibs/ice40/ice40_dsp.pmg @@ -23,7 +23,7 @@ match mul endmatch code sigA sigB sigH - auto unextend = [](const SigSpec &sig) { + auto unextend_signed = [](const SigSpec &sig) { int i; for (i = GetSize(sig)-1; i > 0; i--) if (sig[i] != sig[i-1]) @@ -32,8 +32,16 @@ code sigA sigB sigH ++i; return sig.extract(0, i); }; - sigA = unextend(port(mul, \A)); - sigB = unextend(port(mul, \B)); + auto unextend_unsigned = [](const SigSpec &sig) { + int i; + for (i = GetSize(sig)-1; i > 0; i--) + if (sig[i] != SigBit(State::S0)) + break; + ++i; + return sig.extract(0, i); + }; + sigA = param(mul, \A_SIGNED).as_bool() ? unextend_signed(port(mul, \A)) : unextend_unsigned(port(mul, \A)); + sigB = param(mul, \B_SIGNED).as_bool() ? unextend_signed(port(mul, \B)) : unextend_unsigned(port(mul, \B)); SigSpec O; if (mul->type == $mul) diff --git a/tests/arch/ice40/ice40_dsp_const.ys b/tests/arch/ice40/ice40_dsp_const.ys new file mode 100644 index 00000000000..c9c76a1acba --- /dev/null +++ b/tests/arch/ice40/ice40_dsp_const.ys @@ -0,0 +1,80 @@ +read_verilog << EOT +module top(input wire [14:0] a, output wire [18:0] b); +assign b = a*$unsigned(5'b01111); +endmodule +EOT + +prep +ice40_dsp + +read_verilog << EOT +module ref(a, b); + wire _0_; + wire _1_; + wire _2_; + wire [12:0] _3_; + (* src = "<