Multiplier.v.html 520 B

12345678910111213141516171819202122232425
  1. `timescale 1ns / 1ps // NW 14.9.2015
  2. module Multiplier(
  3. input clk, run, u,
  4. output stall,
  5. input [31:0] x, y,
  6. output [63:0] z);
  7. reg [5:0] S; // state
  8. reg [63:0] P; // product
  9. wire [31:0] w0;
  10. wire [32:0] w1;
  11. assign stall = run & ~(S == 33);
  12. assign w0 = P[0] ? y : 0;
  13. assign w1 = (S == 32) & u ? {P[63], P[63:32]} - {w0[31], w0} :
  14. {P[63], P[63:32]} + {w0[31], w0};
  15. assign z = P;
  16. always @ (posedge(clk)) begin
  17. P <= (S == 0) ? {32'b0, x} : {w1[32:0], P[31:1]};
  18. S <= run ? S+1 : 0;
  19. end
  20. endmodule