Line 1... |
Line 1... |
// ============================================================================
|
// ============================================================================
|
// __
|
// __
|
// \\__/ o\ (C) 2020 Robert Finch, Waterloo
|
// \\__/ o\ (C) 2020-2022 Robert Finch, Waterloo
|
// \ __ / All rights reserved.
|
// \ __ / All rights reserved.
|
// \/_// robfinch@finitron.ca
|
// \/_// robfinch@finitron.ca
|
// ||
|
// ||
|
//
|
//
|
// mult32x32.sv
|
// mult32x32.sv
|
Line 35... |
Line 35... |
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
//
|
//
|
// ============================================================================
|
// ============================================================================
|
|
|
|
`define KARATSUBA 1
|
|
|
|
`ifdef KARATSUBA
|
|
|
module mult32x32(clk, ce, a, b, o);
|
module mult32x32(clk, ce, a, b, o);
|
input clk;
|
input clk;
|
input ce;
|
input ce;
|
input [31:0] a;
|
input [31:0] a;
|
input [31:0] b;
|
input [31:0] b;
|
Line 113... |
Line 117... |
if (ce) z0d <= z0c;
|
if (ce) z0d <= z0c;
|
always @(posedge clk)
|
always @(posedge clk)
|
if (ce) o <= {z2d,z0d} + {z1,16'd0};
|
if (ce) o <= {z2d,z0d} + {z1,16'd0};
|
|
|
endmodule
|
endmodule
|
|
|
|
`else
|
|
|
|
// This version of the multiply has a parameterized pipeline depth and allows
|
|
// the tools to perform the multiply. Relies on the ability of tools to retime.
|
|
|
|
module mult32x32(clk, ce, a, b, o);
|
|
parameter DEP = 6;
|
|
input clk;
|
|
input ce;
|
|
input [31:0] a;
|
|
input [31:0] b;
|
|
output reg [63:0] o;
|
|
|
|
reg [63:0] prod [0:DEP-1];
|
|
reg [63:0] prd;
|
|
integer n;
|
|
|
|
always_ff @(posedge clk)
|
|
if (ce) prd <= a * b;
|
|
always_ff @(posedge clk)
|
|
if (ce) prod[0] <= prd;
|
|
|
|
always_ff @(posedge clk)
|
|
for (n = 0; n < DEP - 1; n = n + 1)
|
|
if (ce) prod[n+1] <= prod[n];
|
|
|
|
always_ff @(posedge clk)
|
|
if(ce) o <= prod[DEP-1];
|
|
|
|
endmodule
|
|
|
|
`endif
|