Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

signed/unsigned multipliers

I can't seem to find a way to instantiate a multiplier that will dynamically select between signed and unsigned multiplication. This is on a Cyclone II, but applies to other parts as well.

Reading the Cyclone II documentation it is clear that signa, signb inputs does what I want, but none of the multipliers created with the Wizzard exports that as an input signal. Trying to infer it with the code below doesn't work (bug in Quartus II?); it complains that no logic depends on input_sign. However looking at the RTL with Tools/Netlist Viewers/RTL Viewer clearly shows it being used, however the technology map viewer shows input_sign as disconnected and signa and signb hardwired to ground.

This looks like a bug to me, but I could be doing something wrong.


module mult(input clock,
input        input_sign,
input  input_a,
input  input_b,
output reg  output_c);
reg  a, b;
reg sign;
always @(posedge clock) begin
  sign <= input_sign;
  a <= input_a;
  b <= input_b;
  
  if (sign)
        output_c <= $signed(a) * $signed(b);
  else
        output_c <= $unsigned(a) * $unsigned(b);
  end
 endmodule
 

42 Replies