`timescale 1ns / 1ps
|
`timescale 1ns / 1ps
|
module positSqrt_tb_v;
|
module positSqrt_tb_v;
|
|
|
function [31:0] log2;
|
function [31:0] log2;
|
input reg [31:0] value;
|
input reg [31:0] value;
|
begin
|
begin
|
value = value-1;
|
value = value-1;
|
for (log2=0; value>0; log2=log2+1)
|
for (log2=0; value>0; log2=log2+1)
|
value = value>>1;
|
value = value>>1;
|
end
|
end
|
endfunction
|
endfunction
|
|
|
parameter N=32;
|
parameter N=32;
|
parameter E=8;
|
parameter E=8;
|
parameter Bs=log2(N);
|
parameter Bs=log2(N);
|
parameter es = 6;
|
parameter es = 2;
|
|
|
reg [N-1:0] in;
|
reg [N-1:0] in;
|
reg clk;
|
reg clk;
|
reg [7:0] cnt;
|
reg [7:0] cnt;
|
reg start;
|
reg start;
|
wire done;
|
wire done;
|
reg done1;
|
reg done1;
|
|
|
wire [N-1:0] out, out2, out3;
|
wire [N-1:0] out, out2, out3;
|
|
|
reg [N-1:0] a1, a2;
|
reg [N-1:0] a1, a2;
|
wire [N-1:0] a, sqrt, sqr, sqr2;
|
wire [N-1:0] a, sqrt, sqr, sqr2;
|
wire i,z,d,i1,z1,d1;
|
wire i,z,d,i1,z1,d1;
|
|
|
// Instantiate the Unit Under Test (UUT)
|
// Instantiate the Unit Under Test (UUT)
|
|
|
intToPosit #(.PSTWID(N), .es(es)) u1a (.i(a1), .o(a));
|
//intToPosit #(.PSTWID(N), .es(es)) u1a (.i(a1), .o(a));
|
|
assign a = a1;
|
positSqrt #(.PSTWID(N), .es(es)) usqrt1 (.clk(clk), .ce(1'b1), .i(a), .o(sqrt), .start(start), .done(done), .zero(), .inf());
|
positSqrt #(.PSTWID(N), .es(es)) usqrt1 (.clk(clk), .ce(1'b1), .i(a), .o(sqrt), .start(start), .done(done), .zero(), .inf());
|
positMul #(.PSTWID(N), .es(es)) umul1 (sqrt,sqrt,sqr,z,i);
|
positMul #(.PSTWID(N), .es(es)) umul1 (sqrt,sqrt,sqr,z,i);
|
posit_mult #(.N(N), .es(es)) umul2 (sqrt,sqrt,1'b1,sqr2,i1,z1,d1);
|
posit_mult #(.N(N), .es(es)) umul2 (sqrt,sqrt,1'b1,sqr2,i1,z1,d1);
|
|
|
initial begin
|
initial begin
|
start = 0;
|
start = 0;
|
a1 = $urandom(1);
|
a1 = $urandom(1);
|
cnt = 0;
|
cnt = 0;
|
// Initialize Inputs
|
// Initialize Inputs
|
clk = 1;
|
clk = 1;
|
// Wait 100 ns for global reset to finish
|
// Wait 100 ns for global reset to finish
|
#101 in = 32'h0080ffff;
|
#101 in = 32'h0080ffff;
|
#325150
|
#325150
|
$fclose(outfile);
|
$fclose(outfile);
|
$finish;
|
$finish;
|
end
|
end
|
|
|
always #5 clk=~clk;
|
always #5 clk=~clk;
|
always @(posedge clk) begin
|
always @(posedge clk) begin
|
done1 = done;
|
done1 = done;
|
casez(cnt)
|
casez(cnt)
|
8'b00000000:
|
8'b00000000:
|
begin
|
begin
|
start = 1;
|
start = 1;
|
a1 = 16;
|
a1 = 16;
|
a2 = a;
|
a2 = a;
|
cnt = cnt + 1;
|
cnt = cnt + 1;
|
end
|
end
|
8'b???????0:
|
8'b???????0:
|
begin
|
begin
|
start = 1;
|
start = 1;
|
a2 = a;
|
a2 = a;
|
cnt = cnt + 1;
|
cnt = cnt + 1;
|
end
|
end
|
8'b???????1:
|
8'b???????1:
|
begin
|
begin
|
start = 0;
|
start = 0;
|
if (done) begin
|
if (done) begin
|
a1 = $urandom();
|
a1 = $urandom();
|
cnt = cnt + 1;
|
cnt = cnt + 1;
|
end
|
end
|
end
|
end
|
default:
|
default:
|
begin
|
begin
|
a1 = $urandom();
|
a1 = $urandom();
|
cnt = cnt + 1;
|
cnt = cnt + 1;
|
end
|
end
|
endcase
|
endcase
|
end
|
end
|
|
|
integer outfile;
|
integer outfile;
|
initial outfile = $fopen("d:/cores6/Thor2020/v3/rtl/fpu/test_bench/positSqrt_tvo32.txt", "wb");
|
initial outfile = $fopen("d:/cores6/Thor2020/v3/rtl/fpu/test_bench/positSqrt_tvo32.txt", "wb");
|
always @(negedge clk) begin
|
always @(negedge clk) begin
|
if (done & !done1) begin
|
if (done & !done1) begin
|
if (a2!=sqr)
|
if (a2!=sqr)
|
$fwrite(outfile, "*%h\t%h\t%h\t%h\n",a2,sqr,sqr2,sqrt);
|
$fwrite(outfile, "*%h\t%h\t%h\t%h\n",a2,sqr,sqr2,sqrt);
|
else
|
else
|
$fwrite(outfile, " %h\t%h\t%h\t%h\n",a2,sqr,sqr2,sqrt);
|
$fwrite(outfile, " %h\t%h\t%h\t%h\n",a2,sqr,sqr2,sqrt);
|
end
|
end
|
end
|
end
|
|
|
endmodule
|
endmodule
|
|
|
|
|