Update to fix testbench for bls12 coprocessor

This commit is contained in:
bsdevlin 2019-06-25 17:53:50 +08:00
parent 1047ca1616
commit f8d4341a68
3 changed files with 101 additions and 16 deletions

View File

@ -393,12 +393,12 @@ task get_next_inst();
if(inst_ram_read == 0) begin
inst_ram_sys_if.a <= new_inst_pt_val_l ? new_inst_pt : inst_state == NOOP_WAIT ? inst_ram_sys_if.a : inst_ram_sys_if.a + 1;
inst_ram_read[0] <= 1;
if (new_inst_pt_val_l) new_inst_pt_val_l <= 0;
end
if (inst_ram_read[READ_CYCLE]) begin
inst_state <= curr_inst.code;
cnt <= 0;
end
new_inst_pt_val_l <= 0;
endtask
task task_copy_reg();
@ -575,6 +575,7 @@ task task_send_interrupt();
case(cnt) inside
// Load the data
0: begin
interrupt_in_if.eop <= 0;
data_ram_sys_if.a <= curr_inst.a;
if (interrupt_state != WAIT_FIFO) begin
// Wait here
@ -601,10 +602,10 @@ task task_send_interrupt();
if (data_ram_read[READ_CYCLE]) begin
pt_size <= pt_size - 1;
interrupt_in_if.dat <= curr_data.dat;
if (pt_size == 1) interrupt_in_if.eop <= 1;
interrupt_in_if.val <= 1;
data_ram_sys_if.a <= data_ram_sys_if.a + 1;
if (pt_size == 1) begin
interrupt_in_if.eop <= 1;
cnt <= cnt + 1;
end
end

View File

@ -63,46 +63,46 @@ begin
jb_point_t out_p, exp_p;
logic [DAT_BITS-1:0] in_k;
bls12_381_interrupt_rpl_t interrupt_rpl;
failed = 0;
in_k = 381'haaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
exp_p = point_mult(in_k, g_point);
$display("Running test_fp_point_mult...");
axi_lite_if.peek(.addr(0), .data(rdata));
assert(rdata == INST_AXIL_START) else $fatal("ERROR: AXI lite register returned wrong value");
axi_lite_if.peek(.addr(4), .data(rdata));
assert(rdata == DATA_AXIL_START) else $fatal("ERROR: AXI lite register returned wrong value");
axi_lite_if.peek(.addr(8), .data(rdata));
assert(rdata == DATA_RAM_DEPTH*DATA_RAM_ALIGN_BYTE) else $fatal("ERROR: AXI lite register returned wrong value");
axi_lite_if.peek(.addr(12), .data(rdata));
assert(rdata == INST_RAM_DEPTH*INST_RAM_ALIGN_BYTE) else $fatal("ERROR: AXI lite register returned wrong value");
data = '{dat:in_k, pt:SCALAR};
axi_lite_if.put_data_multiple(.data(data), .addr(DATA_AXIL_START), .len(48));
inst = '{code:SEND_INTERRUPT, a:16'd1, b:16'hbeef, c:16'd0};
axi_lite_if.put_data_multiple(.data(inst), .addr(INST_AXIL_START + 8), .len(8));
// Write slot 0 to start
inst = '{code:FP_FPOINT_MULT, a:16'd0, b:16'd1, c:16'd0};
axi_lite_if.put_data_multiple(.data(inst), .addr(INST_AXIL_START), .len(8));
fork
begin
out_if.get_stream(get_dat, get_len, 0);
interrupt_rpl = get_dat;
assert(interrupt_rpl.hdr.cmd == BLS12_381_INTERRUPT_RPL) else $fatal(1, "ERROR: Received non-interrupt message");
assert(interrupt_rpl.index == 16'hbeef) else $fatal(1, "ERROR: Received wrong index value in message");
assert(interrupt_rpl.data_type == FP_JB) else $fatal(1, "ERROR: Received wrong data type value in message");
get_dat = get_dat >> $bits(bls12_381_interrupt_rpl_t);
for (int i = 0; i < 3; i++)
for (int i = 0; i < 3; i++)
out_p[i*381 +: 381] = get_dat[i*(48*8) +: 381];
if (out_p == exp_p) begin
@ -122,7 +122,7 @@ begin
end
join_any
disable fork;
axi_lite_if.peek(.addr(32'h14), .data(rdata));
$display("INFO: Last cycle count was %d", rdata);
@ -133,7 +133,90 @@ begin
end
endtask;
task test_fp2_point_mult();
begin
integer signed get_len;
logic [common_pkg::MAX_SIM_BYTS*8-1:0] get_dat;
inst_t inst;
logic failed;
data_t data;
logic [31:0] rdata;
fp2_jb_point_t out_p, exp_p;
logic [DAT_BITS-1:0] in_k;
bls12_381_interrupt_rpl_t interrupt_rpl;
failed = 0;
in_k = 381'h33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333;
exp_p = fp2_point_mult(in_k, g2_point);
$display("Running test_fp2_point_mult...");
// See what current instruction pointer is
axi_lite_if.peek(.addr(32'h10), .data(rdata));
data = '{dat:in_k, pt:SCALAR};
axi_lite_if.put_data_multiple(.data(data), .addr(DATA_AXIL_START + 64), .len(48)); // Scalar to multiply by goes in data slot 1
inst = '{code:SEND_INTERRUPT, a:16'd3, b:16'habcd, c:16'd0};
axi_lite_if.put_data_multiple(.data(inst), .addr(INST_AXIL_START + (rdata+1)*8), .len(8));
// Write to current slot to start
inst = '{code:FP2_FPOINT_MULT, a:16'd1, b:16'd3, c:16'd0};
axi_lite_if.put_data_multiple(.data(inst), .addr(INST_AXIL_START + (rdata)*8), .len(8));
fork
begin
out_if.get_stream(get_dat, get_len, 0);
interrupt_rpl = get_dat;
assert(interrupt_rpl.hdr.cmd == BLS12_381_INTERRUPT_RPL) else $fatal(1, "ERROR: Received non-interrupt message");
assert(interrupt_rpl.index == 16'habcd) else $fatal(1, "ERROR: Received wrong index value in message");
assert(interrupt_rpl.data_type == FP2_JB) else $fatal(1, "ERROR: Received wrong data type value in message");
get_dat = get_dat >> $bits(bls12_381_interrupt_rpl_t);
for (int i = 0; i < 6; i++)
out_p[i*381 +: 381] = get_dat[i*(48*8) +: 381];
if (out_p == exp_p) begin
$display("INFO: Output point matched expected:");
print_fp2_jb_point(out_p);
end else begin
$display("ERROR: Output point did NOT match expected:");
print_fp2_jb_point(out_p);
$display("Expected:");
print_fp2_jb_point(exp_p);
failed = 1;
end
end
begin
repeat(100000) @(posedge out_if.i_clk);
$fatal("ERROR: Timeout while waiting for result");
end
join_any
disable fork;
axi_lite_if.peek(.addr(32'h14), .data(rdata));
$display("INFO: Last cycle count was %d", rdata);
// See what current instruction pointer is
axi_lite_if.peek(.addr(32'h10), .data(rdata));
$display("INFO: Current instruction pointer is 0x%x, setting to 0 and writing NULL instruction", rdata);
inst = '{code:NOOP_WAIT, a:16'd0, b:16'h0, c:16'd0};
axi_lite_if.put_data_multiple(.data(inst), .addr(INST_AXIL_START), .len(8));
axi_lite_if.poke(.addr(32'h10), .data(32'd0));
repeat(10) @(posedge clk);
axi_lite_if.peek(.addr(32'h10), .data(rdata));
assert(rdata == 32'd0) else $fatal(1, "ERROR: could not set instruction pointer");
if(failed)
$fatal(1, "ERROR: test_fp2_point_mult FAILED");
else
$display("INFO: test_fp2_point_mult PASSED");
end
endtask;
initial begin
axi_lite_if.reset_source();
@ -145,6 +228,7 @@ initial begin
@(posedge clk);
test_fp_point_mult();
test_fp2_point_mult();
#1us $finish();
end