serial/parallel multiplier now supports sign-magnitude coefficients

This commit is contained in:
Niels Moseley 2017-10-10 02:55:49 +02:00
parent 4f30621f28
commit b9789bc4c4
2 changed files with 12 additions and 6 deletions

View File

@ -50,12 +50,14 @@ module SPMUL (
end end
else if (domul == 1) else if (domul == 1)
begin begin
if (coefreg[9] == 1'b1) // note: leave coefreg[9] untouched
// as this is the sign bit...
if (coefreg[8] == 1'b1)
accumulator <= {accumulator[23:0], 1'b0} + sigreg; accumulator <= {accumulator[23:0], 1'b0} + sigreg;
else else
accumulator <= {accumulator[23:0], 1'b0}; accumulator <= {accumulator[23:0], 1'b0};
coefreg <= {coefreg[8:0], 1'b0}; coefreg[8:0] <= {coefreg[7:0], 1'b0};
end end
end end
@ -131,13 +133,16 @@ module SPMUL (
end end
4'b1010: 4'b1010:
begin begin
domul <= 1; domul <= 0;
end end
4'b1011: 4'b1011:
begin begin
domul <= 0; domul <= 0;
done <= 1; done <= 1;
result_out <= accumulator[23:8]; if (coefreg[9] == 0)
result_out <= {1'b0, accumulator[23:9]};
else
result_out <= {1'b1, ~accumulator[23:9]};
state <= 0; state <= 0;
end end
default: default:

View File

@ -29,7 +29,8 @@ module SPMUL_TB;
clk = 0; clk = 0;
rst_an = 0; rst_an = 0;
sig = 16'h7FFF; sig = 16'h7FFF;
coef = 10'h1FF; //coef = 10'h1FF;
coef = 10'h3FF; // sign-magnitude
start = 0; start = 0;
#3 #3
rst_an = 1; rst_an = 1;