Skip to content

Commit 7693225

Browse files
author
pascalgouedo
authored
Merge pull request #2463 from dd-baoshan/cv32e40p/dev
Fix issue found in random tests
2 parents e4e265a + f04d58a commit 7693225

File tree

3 files changed

+45
-36
lines changed

3 files changed

+45
-36
lines changed

cv32e40p/env/corev-dv/instr_lib/cv32e40p_float_instr_lib.sv

+31-28
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class cv32e40p_float_zfinx_base_instr_stream extends cv32e40p_base_instr_stream;
7575
logic [31:0] csr_rm = $urandom_range(0,4);
7676
logic [31:0] csr_mstatus_fs = 0;
7777
// for clr_crs_fflags usage - end
78+
79+
riscv_reg_t xreg_for_set_fpr = ZERO;
7880

7981
rand int unsigned num_of_instr_per_stream;
8082
rand riscv_reg_t avail_gp_regs[][]; // regs for extension zfinx and f
@@ -389,28 +391,29 @@ class cv32e40p_float_zfinx_base_instr_stream extends cv32e40p_base_instr_stream;
389391
virtual function void initialize_regs();
390392
// set random value on all gpr/fpr registers prior directed stream
391393
// random fp value with mantissa not zeroes
392-
if (init_gpr) begin : SET_GPR_RAND_VALUE
393-
logic [31:0] i_imm;
394-
for (int i=1; i<32; i++) begin
395-
riscv_reg_t i_gpr = riscv_reg_t'(i);
396-
// if (i_gpr inside {cfg.reserved_regs}) continue;
397-
if (i == int'(cfg.sp)) continue; // do not alter stack pointer
398-
if (i == int'(cfg.tp)) continue; // do not alter thread pointer
399-
if (cfg.gen_debug_section) begin
400-
if (i == int'(cfg_cv32e40p.dp)) continue; // do not alter debug pointer
401-
end
394+
logic [31:0] i_imm;
395+
for (int i=1; i<32; i++) begin
396+
riscv_reg_t i_gpr = riscv_reg_t'(i);
397+
// if (i_gpr inside {cfg.reserved_regs}) continue;
398+
if (i == int'(cfg.sp)) continue; // do not alter stack pointer
399+
if (i == int'(cfg.tp)) continue; // do not alter thread pointer
400+
if (cfg.gen_debug_section) begin
401+
if (i == int'(cfg_cv32e40p.dp)) continue; // do not alter debug pointer
402+
end
403+
if (init_gpr) begin : SET_GPR_RAND_VALUE
402404
rand_fp_val(i_imm);
403405
`SET_GPR_VALUE(i_gpr,i_imm);
404406
end
407+
if (xreg_for_set_fpr == ZERO) xreg_for_set_fpr = i_gpr;
405408
end
406-
if (init_fpr) begin : SET_FPR_RAND_VALUE
407-
logic [31:0] i_imm;
408-
for (int i=0; i<32; i++) begin
409-
riscv_fpr_t i_fpr = riscv_fpr_t'(i);
409+
for (int i=0; i<32; i++) begin
410+
riscv_fpr_t i_fpr = riscv_fpr_t'(i);
411+
if (init_fpr) begin : SET_FPR_RAND_VALUE
410412
rand_fp_val(i_imm);
411-
`SET_FPR_VALUE(i_fpr,i_imm);
413+
`SET_FPR_VALUE(i_fpr,i_imm,xreg_for_set_fpr);
412414
end
413415
end
416+
414417
set_reserved_sp_addr();
415418
set_csr_fm(gp_reg_scratch);
416419
endfunction : initialize_regs
@@ -426,9 +429,9 @@ class cv32e40p_float_zfinx_base_instr_stream extends cv32e40p_base_instr_stream;
426429
bit select_fp_instr, include_fpc, rand_status;
427430

428431
rand_status = std::randomize(select_fp_instr) with {select_fp_instr dist {0:=1, 1:=1};};
429-
assert(rand_status);
432+
assert(rand_status) else begin `uvm_error(_header, $sformatf("assertion error")); end
430433
rand_status = std::randomize(include_fpc) with {include_fpc dist {0:=3, 1:=1};}; // less weight on fpc
431-
assert(rand_status);
434+
assert(rand_status) else begin `uvm_error(_header, $sformatf("assertion error")); end
432435

433436
if (!use_same_instr_per_stream) include_instr.delete();
434437
include_group.delete();
@@ -492,7 +495,7 @@ class cv32e40p_float_zfinx_base_instr_stream extends cv32e40p_base_instr_stream;
492495
exclude_instr = new[exclude_instr.size()+1] ({exclude_instr, prev_instr.instr_name});
493496
end
494497
if (use_same_instr_per_stream && prev_instr != null) begin
495-
assert (use_fp_only_for_directed_instr && use_same_instr_per_stream);
498+
assert (use_fp_only_for_directed_instr && use_same_instr_per_stream) else begin `uvm_error(_header, $sformatf("assertion error")); end
496499
include_instr = new[1] ({prev_instr.instr_name});
497500
end
498501
endfunction: update_next_instr_arg_list
@@ -1025,7 +1028,7 @@ class cv32e40p_float_zfinx_base_instr_stream extends cv32e40p_base_instr_stream;
10251028
logic [11:0] csr=12'h000, int idx=0
10261029
);
10271030
riscv_instr instr;
1028-
assert(instr_name != INVALID_INSTR);
1031+
assert(instr_name != INVALID_INSTR) else begin `uvm_error(_header, $sformatf("assertion error")); end
10291032
instr = new riscv_instr::get_rand_instr(
10301033
.include_instr({instr_name})
10311034
);
@@ -1298,8 +1301,8 @@ class cv32e40p_constraint_mc_fp_instr_stream extends cv32e40p_float_zfinx_base_i
12981301
int rand_mc_latency = $urandom_range(0,mc_instr_latency);
12991302
int loop_cnt = 0;
13001303

1301-
assert(!(instr == null && instr_zfinx == null && instr_f == null));
1302-
assert(rand_mc_latency >= 0);
1304+
assert(!(instr == null && instr_zfinx == null && instr_f == null)) else begin `uvm_error(_header, $sformatf("assertion error")); end
1305+
assert(rand_mc_latency >= 0) else begin `uvm_error(_header, $sformatf("assertion error")); end
13031306

13041307
while (!(loop_cnt == 100) && rand_mc_latency > 0) begin
13051308
int p_rand_mc_latency = rand_mc_latency;
@@ -1426,7 +1429,7 @@ class cv32e40p_fp_op_fwd_instr_stream extends cv32e40p_float_zfinx_base_instr_st
14261429
en_clr_fflags_af_instr = 0;
14271430
num_of_instr_per_block = 10;
14281431
include_load_store_base_sp = 0; // exclude store instrs for this stream
1429-
assert (num_of_instr_per_block != 0 && num_of_instr_per_block%10 == 0);
1432+
assert (num_of_instr_per_block != 0 && num_of_instr_per_block%10 == 0) else begin `uvm_error(_header, $sformatf("assertion error")); end
14301433
endfunction: pre_randomize
14311434

14321435
virtual function void print_stream_setting();
@@ -1699,7 +1702,7 @@ class cv32e40p_fp_op_fwd_instr_w_loadstore_stream extends cv32e40p_float_zfinx_b
16991702

17001703
riscv_fpr_t i_fs1 = (is_zfinx) ? FT0 : p_instr_f.fs1;
17011704

1702-
assert(!(p_instr_zfinx == null && p_instr_f == null));
1705+
assert(!(p_instr_zfinx == null && p_instr_f == null)) else begin `uvm_error(_header, $sformatf("assertion error")); end
17031706
`SET_GPR_VALUE(i_rd, v_rd);
17041707

17051708
if (p_instr_zfinx != null) begin
@@ -1719,8 +1722,8 @@ class cv32e40p_fp_op_fwd_instr_w_loadstore_stream extends cv32e40p_float_zfinx_b
17191722
end
17201723
else begin
17211724
unique case (p_instr_f.instr_name)
1722-
FCVT_W_S, FCVT_WU_S : begin `SET_FPR_VALUE(i_fs1, F_POS_VAL1); end // rd(int) = fs1
1723-
FMV_X_W : begin `SET_FPR_VALUE(i_fs1, F_NEG_ZERO_DIV2); end // rd(int) <- fs1
1725+
FCVT_W_S, FCVT_WU_S : begin `SET_FPR_VALUE(i_fs1, F_POS_VAL1, xreg_for_set_fpr); end // rd(int) = fs1
1726+
FMV_X_W : begin `SET_FPR_VALUE(i_fs1, F_NEG_ZERO_DIV2, xreg_for_set_fpr); end // rd(int) <- fs1
17241727
endcase
17251728
end
17261729

@@ -1876,7 +1879,7 @@ class cv32e40p_fp_op_fwd_instr_w_loadstore_stream extends cv32e40p_float_zfinx_b
18761879
STORE, POST_INC_STORE : begin // S[B|H|WW], C_SW[SP], C_FSW[SP], CV_S[B|H|W]
18771880
instr2.rs1 = (is_zfinx) ? instr_zfinx.rd : instr_f.rd;
18781881
if (instr2.category == POST_INC_STORE && j != num_of_load_store_instr-1) begin // no special handle on last load/store
1879-
assert(instr2.has_rd); // rd here is rs3 in spec
1882+
assert(instr2.has_rd) else begin `uvm_error(_header, $sformatf("assertion error")); end // rd here is rs3 in spec
18801883
instr2.rd = ZERO; // prevent post incr to update rs1 that target into code space
18811884
end
18821885
last_store_rs1 = instr2.rs1; has_store = 1;
@@ -1890,7 +1893,7 @@ class cv32e40p_fp_op_fwd_instr_w_loadstore_stream extends cv32e40p_float_zfinx_b
18901893
end
18911894
if (instr2.has_rd) begin last_load_rd = instr2.rd; has_load_rd = 1; end
18921895
if (instr2.category == POST_INC_LOAD && j != num_of_load_store_instr-1) begin // no special handle on last load/store
1893-
assert(instr2.has_rs2);
1896+
assert(instr2.has_rs2) else begin `uvm_error(_header, $sformatf("assertion error")); end
18941897
instr2.rs2 = ZERO; // prevent post incr to update rs1 that target into code space
18951898
end
18961899
cnt = 0;
@@ -2050,7 +2053,7 @@ class cv32e40p_mstatus_fs_stream extends cv32e40p_float_zfinx_base_instr_stream;
20502053
if (idx == 0) loop_cnt++;
20512054
else if (idx != 0 && idx%total_instr == 0) begin
20522055
loop_cnt++;
2053-
assert (loop_cnt <= loop_cnt_limit);
2056+
assert (loop_cnt <= loop_cnt_limit) else begin `uvm_error(_header, $sformatf("assertion error")); end
20542057
exclude_instr.delete();
20552058
csr_mstatus_fs = 32'd2; // Clean
20562059
clr_csr_init_done = 0; // Update csrrw_val

cv32e40p/env/corev-dv/instr_lib/cv32e40p_float_instr_lib_defines.sv

+4-3
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,16 @@
158158
}
159159

160160
// Overhead instruction to set fpr with specific value
161-
`define SET_FPR_VALUE(FRD,IMM) \
161+
`define SET_FPR_VALUE(FRD,IMM,XREG) \
162162
begin\
163163
riscv_instr m_instr;\
164164
riscv_pseudo_instr p_instr;\
165165
riscv_floating_point_instr f_instr;\
166+
assert(``XREG`` != ZERO) else begin `uvm_error("SET_FPR_VALUE", $sformatf("XREG is %s", ``XREG``.name())); end \
166167
p_instr = riscv_pseudo_instr::type_id::create("p_instr");\
167168
`DV_CHECK_RANDOMIZE_WITH_FATAL(p_instr,\
168169
pseudo_instr_name == LI;\
169-
rd == T2;\
170+
rd == ``XREG``;\
170171
);\
171172
p_instr.imm = ``IMM``;\
172173
p_instr.update_imm_str();\
@@ -176,7 +177,7 @@
176177
override_instr(\
177178
.f_instr (f_instr),\
178179
.fd (``FRD``),\
179-
.rs1 (T2)\
180+
.rs1 (``XREG``)\
180181
);\
181182
instr_list.push_back(f_instr);\
182183
instr_list[$].comment = {instr_list[$].comment, $sformatf(`" [SET REG TO 32'h%8h] `", ``IMM``)};\

cv32e40p/env/corev-dv/instr_lib/cv32e40p_instr_for_func_cvg_lib.sv

+10-5
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,15 @@ class cv32e40p_xpulp_single_hwloop_stream_directed extends cv32e40p_xpulp_hwloop
207207
}
208208

209209
constraint no_imm_hwloop_setup_instr_c {
210-
use_loop_counti_inst[0] == 0;
211-
use_loop_counti_inst[1] == 0;
212-
use_loop_setupi_inst[0] == 0;
213-
use_loop_setupi_inst[1] == 0;
210+
foreach (use_loop_counti_inst[i]) {
211+
use_loop_counti_inst[i] == 0;
212+
use_loop_setupi_inst[i] == 0;
213+
}
214214
}
215215

216216
constraint num_hwloop_instr_c {
217217
solve use_loop_endi_inst before num_hwloop_instr;
218+
solve num_hwloop_instr before num_fill_instr_loop_ctrl_to_loop_start;
218219
foreach (num_hwloop_instr[i]) {
219220
// the max setting of Uimm[11:0] is 4092 however the the hwloop start label is not immediately following after cv.endi,
220221
// there is randomize numberof instr inserted between cv.endi and hwloop start label we need to keep some buffer from
@@ -224,7 +225,11 @@ class cv32e40p_xpulp_single_hwloop_stream_directed extends cv32e40p_xpulp_hwloop
224225
} else {
225226
num_hwloop_instr[i] dist { 3 := 1, 3074 := 5, 4092 := 1 };
226227
}
227-
num_fill_instr_loop_ctrl_to_loop_start[i] inside {[0:7]};
228+
if (num_hwloop_instr[i] > 4080) {
229+
num_fill_instr_loop_ctrl_to_loop_start[i] == 0;
230+
} else {
231+
num_fill_instr_loop_ctrl_to_loop_start[i] inside {[0:7]};
232+
}
228233
}
229234
num_fill_instr_in_loop1_till_loop0_setup == 0;
230235
}

0 commit comments

Comments
 (0)