I'm trying to code a riscv decoder in system verilog, here's the code :
case(opcode)
7'b0110011: assign r_type = 1'b1;
7'b0010011: assign i_type = 1'b1;
7'b0000011: assign i_type = 1'b1;
7'b0100011: assign s_type = 1'b1;
7'b1100011: assign b_type = 1'b0;
7'b0110111: assign u_type = 1'b1;
7'b1101111: assign j_type = 1'b1;
endcase
casez({opcode, funct3, funct7})
// r-type
{r_type, 3'b000, 7'b0000000} : assign add = 1'b1;
{r_type, 3'b000, 7'b0100000} : assign sub = 1'b1;
{r_type, 3'b001, 7'b0000000} : assign sll = 1'b1;
{r_type, 3'b010, 7'b0000000} : assign slt = 1'b1;
{r_type, 3'b011, 7'b0000000} : assign sltu = 1'b1;
{r_type, 3'b100, 7'b0000000} : assign xorr = 1'b1;
{r_type, 3'b101, 7'b0000000} : assign srl = 1'b1;
{r_type, 3'b101, 7'b0100000} : assign sra = 1'b1;
{r_type, 3'b110, 7'b0000000} : assign orr = 1'b1;
{r_type, 3'b111, 7'b0000000} : assign andd = 1'b1;
// i-type
{i_type, 3'b000, 7'b???????} : assign addi = 1'b1;
{i_type, 3'b010, 7'b???????} : assign slti = 1'b1;
{i_type, 3'b011, 7'b???????} : assign sltiu = 1'b1;
{i_type, 3'b100, 7'b???????} : assign xori = 1'b1;
{i_type, 3'b110, 7'b???????} : assign ori = 1'b1;
{i_type, 3'b111, 7'b???????} : assign andi = 1'b1;
{i_type, 3'b001, 7'b???????} : assign slli = 1'b1;
{i_type, 3'b101, 7'b???????} : assign srli = 1'b1;
{i_type, 3'b101, 7'b???????} : assign srai = 1'b1;
endcase
It seems verilator doesn't recognize that ?? marks
I tried to ue casex and casez and i search through the verilator documentation but i didn't found any information about this
A case statement outside of the always block is part of the generate construct. Per the LRM only
caseandifare supported for generate construct (IEEE1800-2017 § A.4.2 Generated instantiation).casezis not officially supported as a generate construct. Even then, the arguments and case item index must be constant expressions. You are usingopcode,funct3, andfunct7which are likely dynamic.Simple solution: Use an always block. Drop the assign statments in the always block. And remember to initialize/set-default-value all variables assigned in the always block (or latches will be inferred). Reminder your variables should be defined as
logictype for SystemVerilog (regif Verilog).