Commit 050cc693 by SergeyDegtyar

Fix all review comments form Clifford Wolf

parent 957b69f0
......@@ -20,7 +20,7 @@ endef
$(eval $(call template,alu,gates luts))
# DFF with constant drivers
$(eval $(call template,dff, dff))
$(eval $(call template,dff_d0, dff))
$(eval $(call template,dffr, dff))
$(eval $(call template,dffc, dff))
$(eval $(call template,dffcp, dff))
......
module assert_dff(input clk, input test, input pat);
always @(posedge clk)
begin
if (test != pat)
begin
$display("ERROR: ASSERTION FAILED in %m:",$time);
$stop;
end
end
endmodule
module assert_tri(input en, input A, input B);
always @(posedge en)
begin
//#1;
if (A !== B)
begin
$display("ERROR: ASSERTION FAILED in %m:",$time," ",A," ",B);
$stop;
end
end
endmodule
module assert_Z(input clk, input A);
always @(posedge clk)
begin
//#1;
if (A === 1'bZ)
begin
$display("ERROR: ASSERTION FAILED in %m:",$time," ",A);
$stop;
end
end
endmodule
......@@ -15,33 +15,20 @@ module testbench;
end
reg dinA;
wire dinB;
reg dinA = 0;
wire doutB;
top uut (
.clk (clk ),
.a (dinA ),
.b (dinB )
.b (doutB )
);
initial begin
dinA <= 0;
repeat (20000) #3 dinA = !dinA;
end
assert ff_test(.clk(clk), .test(dinB));
endmodule
module assert(input clk, input test);
always @(posedge clk)
begin
if (test == 1)
begin
$display("ASSERTION FAILED in %m:",$time);
//$finish;
end
always @(posedge clk) begin
#3;
dinA <= !dinA;
end
assert_dff ff_test(.clk(clk), .test(doutB), .pat(1'b0));
endmodule
......@@ -16,7 +16,11 @@ output b
dff u_dff (
.clk (clk ),
`ifndef BUG
.d (1'b0 ),
`else
.d (a ),
`endif
.q (b )
);
......
......@@ -14,46 +14,32 @@ module testbench;
$display("OKAY");
end
function [31:0] xorshift32;
input [31:0] arg;
begin
xorshift32 = arg;
// Xorshift32 RNG, doi:10.18637/jss.v008.i14
xorshift32 = xorshift32 ^ (xorshift32 << 13);
xorshift32 = xorshift32 ^ (xorshift32 >> 17);
xorshift32 = xorshift32 ^ (xorshift32 << 5);
end
endfunction
reg [31:0] rng = 123456789;
always @(posedge clk) rng <= xorshift32(rng);
wire dinA = xorshift32(rng * 5);
wire dinC = xorshift32(rng * 7);
reg dinA;
reg dinC;
wire dinB;
wire doutB;
top uut (
.clk (clk ),
.a (dinA ),
.c (dinC),
.b (dinB )
.b (doutB )
);
initial begin
dinC <= 1;
#5
dinC <= 0;
#10
dinC <= 1;
#10
dinC <= 0;
end
initial begin
dinA <= 0;
repeat (20000) #3 dinA = !dinA;
end
assert ff_test(.clk(clk), .test(dinB));
assert_dff ff_test(.clk(clk), .test(doutB), .pat(1'b1));
endmodule
module assert(input clk, input test);
always @(posedge clk)
begin
if (test == 0)
begin
$display("ASSERTION FAILED in %m:",$time);
//$finish;
end
end
endmodule
......@@ -20,7 +20,11 @@ output b
dffcp u_dffcp (
.clk (clk ),
.clr (c ),
`ifndef BUG
.pre (1'b1),
`else
.pre (1'b0),
`endif
.d (a ),
.q (b )
);
......
......@@ -15,33 +15,20 @@ module testbench;
end
reg dinA;
wire dinB;
reg dinA = 0;
wire doutB;
top uut (
.clk (clk ),
.a (dinA ),
.b (dinB )
.b (doutB )
);
initial begin
dinA <= 0;
repeat (20000) #3 dinA = !dinA;
end
always @(posedge clk) begin
#3;
dinA <= !dinA;
end
assert ff_test(.clk(clk), .test(dinB));
assert_dff ff_test(.clk(clk), .test(doutB), .pat(1'b1));
endmodule
module assert(input clk, input test);
always @(posedge clk)
begin
if (test == 0)
begin
$display("ASSERTION FAILED in %m:",$time);
//$finish;
end
end
endmodule
......@@ -17,8 +17,13 @@ output b
dffcp u_dffcp (
.clk (clk ),
`ifndef BUG
.clr (1'b0),
.pre (1'b1),
`else
.clr (1'b1),
.pre (1'b0),
`endif
.d (a ),
.q (b )
);
......
......@@ -15,33 +15,20 @@ module testbench;
end
reg dinA;
wire dinB;
reg dinA = 0;
wire doutB;
top uut (
.clk (clk ),
.a (dinA ),
.b (dinB )
.b (doutB )
);
initial begin
dinA <= 0;
repeat (20000) #3 dinA = !dinA;
end
assert ff_test(.clk(clk), .test(dinB));
endmodule
module assert(input clk, input test);
always @(posedge clk)
begin
if (test == 1)
begin
$display("ASSERTION FAILED in %m:",$time);
//$finish;
end
always @(posedge clk) begin
#3;
dinA <= !dinA;
end
assert_dff ff_test(.clk(clk), .test(doutB), .pat(1'b0));
endmodule
......@@ -16,7 +16,11 @@ output b
dffr u_dffr (
.clk (clk),
`ifndef BUG
.rst (1'b1),
`else
.rst (1'b0),
`endif
.d (a ),
.q (b )
);
......
......@@ -15,33 +15,20 @@ module testbench;
end
reg dinA;
wire dinB;
reg dinA = 0;
wire doutB;
top uut (
.clk (clk ),
.a (dinA ),
.b (dinB )
.b (doutB )
);
initial begin
dinA <= 0;
repeat (20000) #3 dinA = !dinA;
end
assert ff_test(.clk(clk), .test(dinB));
endmodule
module assert(input clk, input test);
always @(posedge clk)
begin
if (test == 0)
begin
$display("ASSERTION FAILED in %m:",$time);
//$finish;
end
always @(posedge clk) begin
#3;
dinA <= !dinA;
end
assert_dff ff_test(.clk(clk), .test(doutB), .pat(1'b1));
endmodule
......@@ -17,8 +17,13 @@ output b
dffsr u_dffsr (
.clk (clk ),
`ifndef BUG
.clr (1'b1),
.pre (1'b1),
`else
.clr (1'b0),
.pre (1'b0),
`endif
.d (a ),
.q (b )
);
......
......@@ -14,9 +14,22 @@ module testbench;
$display("OKAY");
end
reg a;
reg b;
function [31:0] xorshift32;
input [31:0] arg;
begin
xorshift32 = arg;
// Xorshift32 RNG, doi:10.18637/jss.v008.i14
xorshift32 = xorshift32 ^ (xorshift32 << 13);
xorshift32 = xorshift32 ^ (xorshift32 >> 17);
xorshift32 = xorshift32 ^ (xorshift32 << 5);
end
endfunction
reg [31:0] rng = 123456789;
always @(posedge clk) rng <= xorshift32(rng);
wire a = xorshift32(rng * 5);
wire b = xorshift32(rng * 7);
reg rst;
wire g0;
wire g1;
......@@ -36,30 +49,7 @@ module testbench;
rst <= 0;
end
initial begin
a <= 0;
repeat (20000) #3 a = !a;
end
initial begin
b <= 0;
repeat (20000) #4 b = !b;
end
assert g0_test(.clk(clk), .A(g0));
assert g1_test(.clk(clk), .A(g1));
assert_Z g0_test(.clk(clk), .A(g0));
assert_Z g1_test(.clk(clk), .A(g1));
endmodule
module assert(input clk, input A);
always @(posedge clk)
begin
//#1;
if (A == 1'bZ)
begin
$display("ASSERTION FAILED in %m:",$time," ",A);
//$finish;
end
end
endmodule
......@@ -27,7 +27,11 @@
case(state)
IDLE : if (req_0 == 1'b1) begin
state <= #1 GNT0;
`ifndef BUG
gnt_0 <= 1;
`else
gnt_0 <= 1'bZ;
`endif
end else if (req_1 == 1'b1) begin
gnt_1 <= 1;
state <= #1 GNT0;
......
......@@ -14,9 +14,22 @@ module testbench;
$display("OKAY");
end
reg a;
reg b;
function [31:0] xorshift32;
input [31:0] arg;
begin
xorshift32 = arg;
// Xorshift32 RNG, doi:10.18637/jss.v008.i14
xorshift32 = xorshift32 ^ (xorshift32 << 13);
xorshift32 = xorshift32 ^ (xorshift32 >> 17);
xorshift32 = xorshift32 ^ (xorshift32 << 5);
end
endfunction
reg [31:0] rng = 123456789;
always @(posedge clk) rng <= xorshift32(rng);
wire a = xorshift32(rng * 5);
wire b = xorshift32(rng * 7);
reg rst;
wire g0;
wire g1;
......@@ -36,30 +49,7 @@ module testbench;
rst <= 0;
end
initial begin
a <= 0;
repeat (20000) #3 a = !a;
end
initial begin
b <= 0;
repeat (20000) #4 b = !b;
end
assert g0_test(.clk(clk), .A(g0));
assert g1_test(.clk(clk), .A(g1));
assert_Z g0_test(.clk(clk), .A(g0));
assert_Z g1_test(.clk(clk), .A(g1));
endmodule
module assert(input clk, input A);
always @(posedge clk)
begin
//#1;
if (A == 1'bZ)
begin
$display("ASSERTION FAILED in %m:",$time," ",A);
//$finish;
end
end
endmodule
......@@ -27,7 +27,11 @@
case(state)
IDLE : if (req[0] == 1'b1) begin
state <= #1 GNT0;
`ifndef BUG
gnt[0] <= 1;
`else
gnt[0] <= 1'bZ;
`endif
end else if (req[1] == 1'b1) begin
gnt[1] <= 1;
state <= #1 GNT0;
......
......@@ -23,7 +23,7 @@ module testbench;
wire [4:0] y;
wire [4:0] z;
top uut (
top uut_fsm (
.clk (clk),
.rst (rst),
.a (a),
......@@ -35,44 +35,53 @@ module testbench;
);
initial begin
rst <= 0;
rst <= 0;
#5
rst <= 1;
#5
rst <= 0;
#5
@(posedge clk);
a <= 4'b1111;
b <= 4'b1010;
c <= 4'b1011;
#50
repeat (10) @(posedge clk);
a <= 4'b1000;
b <= 4'b1100;
c <= 4'b1010;
#50
repeat (10) @(posedge clk);
a <= 4'b1100;
b <= 4'b0100;
c <= 4'b1011;
#50
repeat (10) @(posedge clk);
a <= 4'b1101;
b <= 4'b1110;
c <= 4'b0000;
end
assert x_test(.clk(clk), .A(x));
assert y_test(.clk(clk), .A(y));
assert z_test(.clk(clk), .A(z));
uut_fsm_checker x_test(.clk(clk), .A(x));
uut_fsm_checker y_test(.clk(clk), .A(y));
uut_fsm_checker z_test(.clk(clk), .A(z));
endmodule
module assert(input clk, input [4:0] A);
module uut_fsm_checker(input clk, input [4:0] A);
always @(posedge clk)
begin
//#1;
if (A == 4'b0000)
begin
$display("ASSERTION FAILED in %m:",$time," ",A);
//$finish;
$display("ERROR: ASSERTION FAILED in %m:",$time," ",A);
$stop;
end
end
endmodule
......@@ -16,9 +16,15 @@ module top(clk, rst, a, b, c, x, y, z);
end else begin
case (state)
1: begin
`ifndef BUG
x <= x;
y <= b;
z <= 1;
`else
x <= 5'd0;
y <= 5'd0;
z <= 5'd0;
`endif
end
2: begin
x <= a;
......
......@@ -15,40 +15,26 @@ module testbench;
end
reg dinA;
wire [1:0] dinB;
wire [1:0] dinC;
reg dinA = 0;
wire [1:0] dioB;
wire [1:0] doutC;
top uut (
.en (en ),
.a (dinA ),
.b (dinB ),
.c (dinC )
.b (dioB ),
.c (doutC )
);
initial begin
dinA <= 0;
repeat (20000) #3 dinA = !dinA;
end
always @(posedge en) begin
#3;
dinA <= !dinA;
end
assert b_test(.en(en), .A(dinA), .B(dinB[0]));
assert_dff b_test(.clk(en), .test(dinA), .pat(dioB[0]));
assert c_test(.en(en), .A(dinA), .B(dinC[0]));
assert_dff c_test(.clk(en), .test(dinA), .pat(doutC[0]));
assert cz_test(.en(!en), .A(1'bZ), .B(dinC[0]));
assert_dff cz_test(.clk(!en), .test(1'bZ), .pat(doutC[0]));
endmodule
module assert(input en, input A, input B);
always @(posedge en)
begin
//#1;
if (A != B)
begin
$display("ASSERTION FAILED in %m:",$time," ",A," ",B);
//$finish;
end
end
endmodule
......@@ -3,14 +3,20 @@ module tristate (en, i, io, o);
input i;
inout [1:0] io;
output [1:0] o;
always @(en or i)
io[0] <= (en)? i : 1'bZ;
`ifndef BUG
assign io[0] = (en)? i : 1'bZ;
always @(en or i)
io[1] <= (i)? en : 1'bZ;
assign io[1] = (i)? en : 1'bZ;
assign o = io;
`else
assign io[0] = (en)? ~i : 1'bZ;
assign io[1] = (i)? ~en : 1'bZ;
assign o = ~io;
`endif
endmodule
......
......@@ -15,41 +15,27 @@ module testbench;
end
reg dinA;
wire [1:0] dinB;
wire [1:0] dinC;
reg dinA = 0;
wire [1:0] dioB;
wire [1:0] doutC;
top uut (
.en (en ),
.a (dinA ),
.b (dinB ),
.c (dinC )
.b (dioB ),
.c (doutC )
);
initial begin
dinA <= 0;
repeat (20000) #3 dinA = !dinA;
end
always @(posedge en) begin
#3;
dinA <= !dinA;
end
assert b_test(.en(en), .A(dinA), .B(dinB[0]));
assert_dff b_test(.clk(en), .test(dinA), .pat(dioB[0]));
assert c_test(.en(en), .A(dinA), .B(dinC[0]));
assert_dff c_test(.clk(en), .test(dinA), .pat(doutC[0]));
assert cz_test(.en(!en), .A(1'bZ), .B(dinC[0]));
assert_dff cz_test(.clk(!en), .test(1'bZ), .pat(doutC[0]));
endmodule
module assert(input en, input A, input B);
always @(posedge en)
begin
//#1;
if (A != B)
begin
$display("ASSERTION FAILED in %m:",$time," ",A," ",B);
//$finish;
end
end
endmodule
......@@ -3,7 +3,7 @@ module tristate (en, i, io, o);
input i;
inout [1:0] io;
output [1:0] o;
`ifndef BUG
always @(en or i)
io[0] <= (en)? i : 1'bZ;
......@@ -11,6 +11,15 @@ module tristate (en, i, io, o);
io[1] <= (i)? en : 1'bZ;
assign o = (en)? io : 2'bZZ;
`else
always @(en or i)
io[0] <= (en)? ~i : 1'bZ;
always @(en or i)
io[1] <= (i)? ~en : 1'bZ;
assign o = (en)? ~io : 2'bZZ;
`endif
endmodule
......
......@@ -21,7 +21,7 @@ module testbench;
reg rst;
wire [47:0] p;
top uut (
top uut_macc (
.p (p),
.a (dinA),
.b (dinB),
......@@ -35,42 +35,47 @@ module testbench;
#5
rst <= 1;
#5
@(posedge clk);
dinA <= 38;
dinB <= 22;
carryin <= 1;
#50
repeat (10) @(posedge clk);
dinA <= 0;
dinB <= 0;
carryin <= 0;
#50
repeat (10) @(posedge clk);
dinA <= 33;
dinB <= 12;
carryin <= 0;
#50
repeat (10) @(posedge clk);
dinA <= 0;
dinB <= 0;
carryin <= 0;
end
assert macc_test(.clk(clk), .A(dinA), .B(dinB), .C(carryin), .P(p));
uut_macc_checker macc_check(.clk(clk), .A(dinA), .B(dinB), .C(carryin), .P(p));
endmodule
module assert(input clk, input [24:0] A, input [17:0] B, input C, input [47:0] P);
module uut_macc_checker(input clk, input [24:0] A, input [17:0] B, input C, input [47:0] P);
reg [47:0] p;
always @(posedge clk)
begin
//#1;
@(posedge clk);
@(posedge clk);
@(posedge clk);
@(posedge clk);
assign p = (A * B) + C;
#20
p <= (A * B) + C;
if (P != p)
begin
$display("ASSERTION FAILED in %m:",$time," ",P," ",p);
//$finish;
$display("ERROR: ASSERTION FAILED in %m:",$time," ",P," ",p);
//$stop;
end
end
endmodule
......@@ -22,7 +22,11 @@ module MACC (P, A, B, CARRYIN, CLK, RST);
if(!RST)
P <= 'b0;
else
`ifndef BUG
P <= mult_reg + CARRYIN;
`else
P <= mult_reg - CARRYIN;
`endif
end
endmodule
......
......@@ -9,7 +9,7 @@ mkdir $1/work_$2
cd $1/work_$2
yosys -ql yosys.log ../../scripts/$2.ys
iverilog -o testbench ../testbench.v synth.v ../../../../../techlibs/common/simcells.v
iverilog -o testbench ../testbench.v synth.v ../../common.v ../../../../../techlibs/common/simcells.v
if ! vvp -N testbench > testbench.log 2>&1; then
grep 'ERROR' testbench.log
......
......@@ -15,34 +15,20 @@ module testbench;
end
reg dinA;
wire dinB;
reg dinA = 0;
wire doutB;
top uut (
.en (en ),
.a (dinA ),
.b (dinB )
.b (doutB )
);
initial begin
dinA <= 0;
repeat (20000) #3 dinA = !dinA;
end
always @(posedge en) begin
#3;
dinA <= !dinA;
end
assert b_test(.en(en), .A(dinA), .B(dinB));
assert_tri b_test(.en(en), .A(dinA), .B(doutB));
endmodule
module assert(input en, input A, input B);
always @(posedge en)
begin
//#1;
if (A != B)
begin
$display("ASSERTION FAILED in %m:",$time," ",A," ",B);
//$finish;
end
end
endmodule
......@@ -2,9 +2,15 @@ module tristate (en, i, o);
input en;
input i;
output o;
`ifndef BUG
always @(en or i)
o <= (en)? i : 1'bZ;
`else
always @(en or i)
o <= (en)? ~i : 1'bZ;
`endif
endmodule
......
......@@ -15,34 +15,20 @@ module testbench;
end
reg dinA;
wire dinB;
reg dinA = 0;
wire doutB;
top uut (
.en (en ),
.a (dinA ),
.b (dinB )
.b (doutB )
);
initial begin
dinA <= 0;
repeat (20000) #3 dinA = !dinA;
end
always @(posedge en) begin
#3;
dinA <= !dinA;
end
assert b_test(.en(en), .A(dinA), .B(dinB));
assert_tri b_test(.en(en), .A(dinA), .B(doutB));
endmodule
module assert(input en, input A, input B);
always @(posedge en)
begin
//#1;
if (A != B)
begin
$display("ASSERTION FAILED in %m:",$time," ",A," ",B);
//$finish;
end
end
endmodule
......@@ -6,7 +6,11 @@ module tristate (en, i, o);
always @(en or i)
begin
case (en)
`ifndef BUG
1:o <= i;
`else
1:o <= ~i;
`endif
default :o <= 1'bZ;
endcase
end
......
......@@ -15,34 +15,20 @@ module testbench;
end
reg dinA;
wire dinB;
reg dinA = 0;
wire doutB;
top uut (
.en (en ),
.a (dinA ),
.b (dinB )
.b (doutB )
);
initial begin
dinA <= 0;
repeat (20000) #3 dinA = !dinA;
end
always @(posedge en) begin
#3;
dinA <= !dinA;
end
assert b_test(.en(en), .A(dinA), .B(dinB));
assert_tri b_test(.en(en), .A(1'bZ), .B(doutB));
endmodule
module assert(input en, input A, input B);
always @(posedge en)
begin
//#1;
if (A === B)
begin
$display("ASSERTION FAILED in %m:",$time," ",A," ",B);
//$finish;
end
end
endmodule
......@@ -4,7 +4,11 @@ module tristate (en, i, o);
output o;
always @(en or i)
`ifndef BUG
o <= (en)? i : 1'bZ;
`else
o <= (en)? ~i : 1'bZ;
`endif
endmodule
......
......@@ -15,34 +15,20 @@ module testbench;
end
reg dinA;
wire dinB;
reg dinA = 0;
wire doutB;
top uut (
.en (en ),
.a (dinA ),
.b (dinB )
.b (doutB )
);
initial begin
dinA <= 0;
repeat (20000) #3 dinA = !dinA;
end
always @(posedge en) begin
#3;
dinA <= !dinA;
end
assert b_test(.en(en), .A(dinA), .B(dinB));
assert_tri b_test(.en(en), .A(dinA), .B(doutB));
endmodule
module assert(input en, input A, input B);
always @(posedge en)
begin
//#1;
if (A !== B)
begin
$display("ASSERTION FAILED in %m:",$time," ",A," ",B);
//$finish;
end
end
endmodule
......@@ -4,7 +4,11 @@ module tristate (en, i, o);
output o;
always @(en or i)
`ifndef BUG
o <= (en)? i : 1'bZ;
`else
o <= (en)? ~i : 1'bZ;
`endif
endmodule
......
......@@ -15,34 +15,20 @@ module testbench;
end
reg dinA;
wire dinB;
reg dinA = 0;
wire doutB;
top uut (
.en (en ),
.a (dinA ),
.b (dinB )
.b (doutB )
);
initial begin
dinA <= 0;
repeat (20000) #3 dinA = !dinA;
end
always @(posedge en) begin
#3;
dinA <= !dinA;
end
assert b_test(.en(en), .A(dinA), .B(dinB));
assert_tri b_test(.en(en), .A(1'b0), .B(doutB));
endmodule
module assert(input en, input A, input B);
always @(posedge en)
begin
//#1;
if (A != B)
begin
$display("ASSERTION FAILED in %m:",$time," ",A," ",B);
//$finish;
end
end
endmodule
......@@ -16,7 +16,11 @@ output b
tristate u_tri (
.en (en ),
.i (1'bZ ),
`ifndef BUG
.i (1'b0 ),
`else
.i (a ),
`endif
.o (b )
);
......
......@@ -15,34 +15,20 @@ module testbench;
end
reg dinA;
wire dinB;
reg dinA = 0;
wire doutB;
top uut (
.en (en ),
.a (dinA ),
.b (dinB )
.b (doutB )
);
initial begin
dinA <= 0;
repeat (20000) #3 dinA = !dinA;
end
always @(posedge en) begin
#3;
dinA <= !dinA;
end
assert b_test(.en(en), .A(dinA), .B(dinB));
assert_tri b_test(.en(en), .A(dinA), .B(doutB));
endmodule
module assert(input en, input A, input B);
always @(posedge en)
begin
//#1;
if (A != B)
begin
$display("ASSERTION FAILED in %m:",$time," ",A," ",B);
//$finish;
end
end
endmodule
......@@ -6,7 +6,11 @@ module tribuf (en, i, o);
always @*
begin
if (en)
`ifndef BUG
o = i;
`else
o = ~i;
`endif
else
o = 1'bZ;
end
......
......@@ -15,34 +15,20 @@ module testbench;
end
reg dinA;
wire dinB;
reg dinA = 0;
wire doutB;
top uut (
.en (en ),
.a (dinA ),
.b (dinB )
.b (doutB )
);
initial begin
dinA <= 0;
repeat (20000) #3 dinA = !dinA;
end
always @(posedge en) begin
#3;
dinA <= !dinA;
end
assert b_test(.en(en), .A(dinA), .B(dinB));
assert_tri b_test(.en(en), .A(dinA), .B(doutB));
endmodule
module assert(input en, input A, input B);
always @(posedge en)
begin
//#1;
if (A != B)
begin
$display("ASSERTION FAILED in %m:",$time," ",A," ",B);
//$finish;
end
end
endmodule
......@@ -3,7 +3,11 @@ module tristate (en, i, o);
input i;
output o;
`ifndef BUG
assign o = (en)? i : 1'bZ;
`else
assign o = (en)? ~i : 1'bZ;
`endif
endmodule
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment