update cpu seq item constraints and weighting biases

This commit is contained in:
2026-10-06 01:31:21 -04:00
parent c3391e4599
commit 1a163f47fb
+49 -25
View File
@@ -6,13 +6,16 @@
* All cpu_seq_item transactions get converted into cpu_xbar_item transactions by * All cpu_seq_item transactions get converted into cpu_xbar_item transactions by
* the sequencer. * the sequencer.
*/ */
class cpu_seq_item #(int DataSize=32, int AddrSize=14); class cpu_seq_item #(
int DataSize = 32,
int AddrSize = 14
);
// Randomizable instruction fields // Randomizable instruction fields
rand instr_e op; rand instr_e op;
rand logic [4:0] rs1; rand logic [ 4:0] rs1;
rand logic [4:0] rs2; rand logic [ 4:0] rs2;
rand logic [4:0] rd; rand logic [ 4:0] rd;
rand int imm; rand int imm;
// Set by the sequencer before randomize() // Set by the sequencer before randomize()
@@ -26,20 +29,37 @@ class cpu_seq_item #(int DataSize=32, int AddrSize=14);
logic [REG_COUNT-1:0][31:0] reg_snapshot; logic [REG_COUNT-1:0][31:0] reg_snapshot;
// Keep generated instructions within the supported instruction set // Keep generated instructions within the supported instruction set
constraint c_opcode { constraint c_opcode {op inside {OP_ADD, OP_ADDI, OP_SUB, OP_SLL, OP_SRL, OP_LW, OP_SW, OP_BEQ};}
op inside {OP_ADD, OP_ADDI, OP_SUB, OP_SLL, OP_SRL, OP_LW, OP_SW, OP_BEQ};
}
// Weighted distributions for registers to increase likelihood of register x0 in testing // Weighted distributions for registers to increase likelihood of register x0 in testing
constraint c_reg_bias { constraint c_reg_bias {
rd dist { 0 :/ 5, [1:7] :/ 70, [8:31] :/ 25 }; rd dist {
rs1 dist { 0 :/ 10, [1:7] :/ 70, [8:31] :/ 20 }; 0 :/ 5,
rs2 dist { 0 :/ 10, [1:7] :/ 70, [8:31] :/ 20 }; [1 : 7] :/ 70,
[8 : 31] :/ 25
};
rs1 dist {
0 :/ 10,
[1 : 7] :/ 70,
[8 : 31] :/ 20
};
rs2 dist {
0 :/ 10,
[1 : 7] :/ 70,
[8 : 31] :/ 20
};
} }
// TODO: Complete the immediate constraint
constraint c_imm_range { constraint c_imm_range {
(op inside {OP_ADDI, OP_SW, OP_LW}) -> {
imm >= -2048; imm >= -2048;
imm <= 2047;
}
(op == OP_BEQ) -> {
imm >= -4096;
imm <= 4094;
}
} }
// Keep each load/store effective byte address word-aligned and inside // Keep each load/store effective byte address word-aligned and inside
@@ -60,23 +80,27 @@ class cpu_seq_item #(int DataSize=32, int AddrSize=14);
// Immediate values are constrained to 0 during these register-only instructions // Immediate values are constrained to 0 during these register-only instructions
constraint c_imm_unused { constraint c_imm_unused {
(op inside {OP_ADD, OP_SUB, OP_SLL, OP_SRL}) -> imm == 0; (op inside {OP_ADD, OP_SUB, OP_SLL, OP_SRL}) ->
imm == 0;
} }
// TODO: Complete the branch constraint to avoid loops
constraint c_branch_target { constraint c_branch_target {
(op == OP_BEQ) -> (imm % 4 == 0) && (imm >= 4); (op == OP_BEQ) -> {
imm % 4 == 0;
imm >= 4;
imm <= (prog_len - idx - 1) * 4;
}
} }
// Prevent a branch in the final generated slot // Prevent a branch in the final generated slot
constraint c_no_branch_at_end { constraint c_no_branch_at_end {(prog_len - idx < 2) -> op != OP_BEQ;}
(prog_len - idx < 2) -> op != OP_BEQ;
}
// TODO: Randomly-generated registers rarely compare equal. Bias the operands
// so both branch outcomes occur often enough to close coverage.
constraint c_branch_taken_bias { constraint c_branch_taken_bias {
1; (op == OP_BEQ) ->
rs2 dist {
[rs1 : rs1] :/ 40,
[ 0 : 31] :/ 60
};
} }
// Constructor // Constructor
@@ -84,7 +108,7 @@ class cpu_seq_item #(int DataSize=32, int AddrSize=14);
idx = 0; idx = 0;
prog_len = 1; prog_len = 1;
reg_snapshot = '0; reg_snapshot = '0;
endfunction: new endfunction : new
// Encode the instruction fields into an instruction-memory word // Encode the instruction fields into an instruction-memory word
function logic [31:0] encode(); function logic [31:0] encode();
@@ -112,7 +136,7 @@ class cpu_seq_item #(int DataSize=32, int AddrSize=14);
endcase endcase
return word; return word;
endfunction: encode endfunction : encode
// Format the instruction for logs and scoreboard failures // Format the instruction for logs and scoreboard failures
function string asm(); function string asm();
@@ -128,10 +152,10 @@ class cpu_seq_item #(int DataSize=32, int AddrSize=14);
OP_EBREAK: return "ebreak"; OP_EBREAK: return "ebreak";
default: return "nop"; default: return "nop";
endcase endcase
endfunction: asm endfunction : asm
function void display(); function void display();
$display($stime, " Seq: [%0d] 0x%08x %s\n", idx, encode(), asm()); $display($stime, " Seq: [%0d] 0x%08x %s\n", idx, encode(), asm());
endfunction: display endfunction : display
endclass: cpu_seq_item endclass : cpu_seq_item