[HDL] Add more micro benchmarks for counter, and-gate and mac unit

This commit is contained in:
tangxifan 2021-06-21 16:48:35 -06:00
parent 70a4dc26d4
commit 07dcf3ad27
10 changed files with 235 additions and 0 deletions

View File

@ -0,0 +1,22 @@
/////////////////////////////////////////
// Functionality: 4-input AND
// Author: Xifan Tang
////////////////////////////////////////
`timescale 1ns / 1ps
module and4(
a,
b,
c,
d,
e);
input wire a;
input wire b;
input wire c;
input wire d;
output wire e;
assign e = a & b & c & d;
endmodule

View File

@ -0,0 +1,25 @@
///////////////////////////////////////////
// Functionality: Counter with asynchronous reset
// Author: Xifan Tang
////////////////////////////////////////
module counter (
clk,
reset,
result
);
input clk;
input reset;
output [127:0] result;
reg [127:0] result;
always @(posedge clk or posedge reset)
begin
if (reset)
result = 0;
else
result = result + 1;
end
endmodule

View File

@ -0,0 +1,25 @@
module counter_tb;
reg clk, reset;
wire [127:0] result;
counter DUT(
.clk(clk),
.reset(reset),
.result(result)
);
initial begin
#0 reset = 1'b1; clk = 1'b0;
#100 reset = 1'b0;
end
always begin
#10 clk = ~clk;
end
initial begin
#5000 $stop;
end
endmodule

View File

@ -0,0 +1,25 @@
///////////////////////////////////////////
// Functionality: Counter with asynchronous reset
// Author: Xifan Tang
////////////////////////////////////////
module counter (
clk,
resetb,
result
);
input clk;
input reset;
output [127:0] result;
reg [127:0] result;
always @(posedge clk or negedge resetb)
begin
if (~resetb)
result = 0;
else
result = result + 1;
end
endmodule

View File

@ -0,0 +1,25 @@
module counter_tb;
reg clk, resetb;
wire [127:0] result;
counter DUT(
.clk(clk),
.resetb(resetb),
.result(result)
);
initial begin
#0 reset = 1'b0; clk = 1'b0;
#100 reset = 1'b1;
end
always begin
#10 clk = ~clk;
end
initial begin
#5000 $stop;
end
endmodule

View File

@ -0,0 +1,22 @@
//-------------------------------------------------------
// Functionality: A 18-bit multiply-acculumate circuit
// Author: Xifan Tang
//-------------------------------------------------------
module mac_18(a, b, c, out);
parameter DATA_WIDTH = 18; /* declare a parameter. default required */
input [DATA_WIDTH - 1 : 0] a, b, c;
output [DATA_WIDTH - 1 : 0] out;
assign out = a * b + c;
endmodule

View File

@ -0,0 +1,22 @@
//-------------------------------------------------------
// Functionality: A 20-bit multiply-acculumate circuit
// Author: Xifan Tang
//-------------------------------------------------------
module mac_20(a, b, c, out);
parameter DATA_WIDTH = 20; /* declare a parameter. default required */
input [DATA_WIDTH - 1 : 0] a, b, c;
output [DATA_WIDTH - 1 : 0] out;
assign out = a * b + c;
endmodule

View File

@ -0,0 +1,22 @@
//-------------------------------------------------------
// Functionality: A 36-bit multiply-acculumate circuit
// Author: Xifan Tang
//-------------------------------------------------------
module mac_36(a, b, c, out);
parameter DATA_WIDTH = 4; /* declare a parameter. default required */
input [DATA_WIDTH - 1 : 0] a, b, c;
output [DATA_WIDTH - 1 : 0] out;
assign out = a * b + c;
endmodule

View File

@ -0,0 +1,25 @@
//-------------------------------------------------------
// Functionality:
// - A 8-bit multiply-acculumate circuit
// - A 9-bit multiply-acculumate circuit
// Author: Xifan Tang
//-------------------------------------------------------
module mac_8_9(a, b, c, out);
parameter DATA_WIDTH = 18; /* declare a parameter. default required */
input [DATA_WIDTH - 1 : 0] a, b, c;
output [DATA_WIDTH - 1 : 0] out;
assign out[8:0] = a[8:0] * b[8:0] + c[8:0];
assign out[17:9] = a[17:9] * b[17:9] + c[17:9];
endmodule

View File

@ -0,0 +1,22 @@
//-------------------------------------------------------
// Functionality: A 9-bit multiply-acculumate circuit
// Author: Xifan Tang
//-------------------------------------------------------
module mac_9(a, b, c, out);
parameter DATA_WIDTH = 9; /* declare a parameter. default required */
input [DATA_WIDTH - 1 : 0] a, b, c;
output [DATA_WIDTH - 1 : 0] out;
assign out = a * b + c;
endmodule