Replace non-unique case constructs by unique case

Our coding guidelines require the usage of `unique case` constructs with
proper `default` cases. This commit implements this change and also makes sure
that potential `'X` are propagated.
This commit is contained in:
Pirmin Vogel 2019-05-20 16:49:09 +01:00 committed by Philipp Wagner
parent 74abc47b71
commit db75d30547
6 changed files with 50 additions and 40 deletions

View file

@ -72,7 +72,7 @@ module ibex_alu (
ALU_SLT, ALU_SLTU,
ALU_SLET, ALU_SLETU: adder_op_b_negate = 1'b1;
default: ;
default:;
endcase
end
@ -200,7 +200,7 @@ module ibex_alu (
ALU_SLETU,
ALU_LE, ALU_LEU: cmp_result = ~is_greater_equal | is_equal;
default: ;
default:;
endcase
end
@ -237,7 +237,7 @@ module ibex_alu (
ALU_SLT, ALU_SLTU,
ALU_SLET, ALU_SLETU: result_o = {31'h0,cmp_result};
default: ; // default case to suppress unique warning
default:;
endcase
end

View file

@ -190,8 +190,7 @@ module ibex_cs_registers #(
// read logic
always_comb begin
csr_rdata_int = '0;
case (csr_addr_i)
unique case (csr_addr_i)
// mstatus: always M-mode, contains IE bit
CSR_MSTATUS: csr_rdata_int = {
19'b0,
@ -219,11 +218,10 @@ module ibex_cs_registers #(
CSR_DPC: csr_rdata_int = depc_q;
CSR_DSCRATCH0: csr_rdata_int = dscratch0_q;
CSR_DSCRATCH1: csr_rdata_int = dscratch1_q;
default: ;
default:;
endcase
end
// write logic
always_comb begin
mepc_n = mepc_q;
@ -235,7 +233,7 @@ module ibex_cs_registers #(
mcause_n = mcause_q;
exception_pc = pc_id_i;
case (csr_addr_i)
unique case (csr_addr_i)
// mstatus: IE bit
CSR_MSTATUS: if (csr_we_int) begin
mstatus_n = '{
@ -283,7 +281,7 @@ module ibex_cs_registers #(
begin
dscratch1_n = csr_wdata_int;
end
default: ;
default:;
endcase
// exception controller gets priority over other writes
@ -332,7 +330,6 @@ module ibex_cs_registers #(
// CSR operation logic
always_comb begin
csr_wdata_int = csr_wdata_i;
csr_we_int = 1'b1;
unique case (csr_op_i)
@ -343,7 +340,10 @@ module ibex_cs_registers #(
csr_wdata_int = csr_wdata_i;
csr_we_int = 1'b0;
end
default:;
default: begin
csr_wdata_int = 'X;
csr_we_int = 1'bX;
end
endcase
end
@ -481,7 +481,7 @@ module ibex_cs_registers #(
CSR_OP_WRITE: PCCR_n[0] = csr_wdata_i;
CSR_OP_SET: PCCR_n[0] = csr_wdata_i | PCCR_q[0];
CSR_OP_CLEAR: PCCR_n[0] = csr_wdata_i & ~(PCCR_q[0]);
default: ;
default: PCCR_n[0] = 'X;
endcase
end
end
@ -502,7 +502,7 @@ module ibex_cs_registers #(
CSR_OP_WRITE: PCCR_n[c] = csr_wdata_i;
CSR_OP_SET: PCCR_n[c] = csr_wdata_i | PCCR_q[c];
CSR_OP_CLEAR: PCCR_n[c] = csr_wdata_i & ~(PCCR_q[c]);
default: ;
default: PCCR_n[c] = 'X;
endcase
end
end
@ -520,7 +520,7 @@ module ibex_cs_registers #(
CSR_OP_WRITE: PCMR_n = csr_wdata_i[1:0];
CSR_OP_SET: PCMR_n = csr_wdata_i[1:0] | PCMR_q;
CSR_OP_CLEAR: PCMR_n = csr_wdata_i[1:0] & ~(PCMR_q);
default: ;
default: PCMR_n = 'X;
endcase
end
@ -530,7 +530,7 @@ module ibex_cs_registers #(
CSR_OP_WRITE: PCER_n = csr_wdata_i[N_PERF_COUNTERS-1:0];
CSR_OP_SET: PCER_n = csr_wdata_i[N_PERF_COUNTERS-1:0] | PCER_q;
CSR_OP_CLEAR: PCER_n = csr_wdata_i[N_PERF_COUNTERS-1:0] & ~(PCER_q);
default: ;
default: PCER_n = 'X;
endcase
end
end

View file

@ -340,7 +340,10 @@ module ibex_decoder #(
illegal_insn_o = 1'b1;
end
end
default:;
default: begin
alu_operator_o = alu_op_e'({$bits(alu_op_e){1'bX}});
end
endcase
end

View file

@ -272,12 +272,12 @@ module ibex_id_stage #(
// ALU_Op_a Mux
always_comb begin : alu_operand_a_mux
case (alu_op_a_mux_sel)
unique case (alu_op_a_mux_sel)
OP_A_REGA_OR_FWD: alu_operand_a = operand_a_fw_id;
OP_A_CURRPC: alu_operand_a = pc_id_i;
OP_A_IMM: alu_operand_a = imm_a;
default: alu_operand_a = operand_a_fw_id;
endcase // case (alu_op_a_mux_sel)
default: alu_operand_a = 'X;
endcase
end
assign imm_a = (imm_a_mux_sel == IMM_A_Z) ? zimm_rs1_type : '0;

View file

@ -94,8 +94,6 @@ module ibex_if_stage #(
// exception PC selection mux
always_comb begin : exc_pc_mux
exc_pc = '0;
// TODO: The behavior below follows an outdated (pre-1.10) RISC-V Privileged
// Spec to implement a "free-form" vectored trap handler.
// We need to update this code and crt0.S to follow the new mtvec spec.
@ -108,14 +106,12 @@ module ibex_if_stage #(
EXC_PC_IRQ: exc_pc = { boot_addr_i[31:8], {exc_vec_pc_mux_i}, 2'b0 };
EXC_PC_DBD: exc_pc = { DmHaltAddr };
EXC_PC_DBGEXC: exc_pc = { DmExceptionAddr };
default:;
default: exc_pc = 'X;
endcase
end
// fetch address selection mux
always_comb begin : fetch_addr_mux
fetch_addr_n = '0;
unique case (pc_mux_i)
PC_BOOT: fetch_addr_n = {boot_addr_i[31:8], {EXC_OFF_RST}};
PC_JUMP: fetch_addr_n = jump_target_ex_i;
@ -123,8 +119,7 @@ module ibex_if_stage #(
PC_ERET: fetch_addr_n = exception_pc_reg_i; // PC is restored when returning
// from IRQ/exception
PC_DRET: fetch_addr_n = depc_i;
default:;
default: fetch_addr_n = 'X;
endcase
end

View file

@ -98,7 +98,7 @@ module ibex_load_store_unit (
// BE generation //
///////////////////
always_comb begin
case (data_type_ex_i) // Data type 00 Word, 01 Half word, 11,10 byte
unique case (data_type_ex_i) // Data type 00 Word, 01 Half word, 11,10 byte
2'b00: begin // Writing a word
if (!misaligned_st) begin // non-misaligned case
unique case (data_addr_int[1:0])
@ -143,6 +143,8 @@ module ibex_load_store_unit (
default: data_be = 'X;
endcase // case (data_addr_int[1:0])
end
default: data_be = 'X;
endcase // case (data_type_ex_i)
end
@ -189,17 +191,18 @@ module ibex_load_store_unit (
// take care of misaligned words
always_comb begin
case (rdata_offset_q)
2'b00: rdata_w_ext = data_rdata_i[31:0];
2'b01: rdata_w_ext = {data_rdata_i[ 7:0], rdata_q[31:8]};
2'b10: rdata_w_ext = {data_rdata_i[15:0], rdata_q[31:16]};
2'b11: rdata_w_ext = {data_rdata_i[23:0], rdata_q[31:24]};
unique case (rdata_offset_q)
2'b00: rdata_w_ext = data_rdata_i[31:0];
2'b01: rdata_w_ext = {data_rdata_i[ 7:0], rdata_q[31:8]};
2'b10: rdata_w_ext = {data_rdata_i[15:0], rdata_q[31:16]};
2'b11: rdata_w_ext = {data_rdata_i[23:0], rdata_q[31:24]};
default: rdata_w_ext = 'X;
endcase
end
// sign extension for half words
always_comb begin
case (rdata_offset_q)
unique case (rdata_offset_q)
2'b00: begin
if (!data_sign_ext_q) begin
rdata_h_ext = {16'h0000, data_rdata_i[15:0]};
@ -231,12 +234,14 @@ module ibex_load_store_unit (
rdata_h_ext = {{16{data_rdata_i[7]}}, data_rdata_i[7:0], rdata_q[31:24]};
end
end
default: rdata_h_ext = 'X;
endcase // case (rdata_offset_q)
end
// sign extension for bytes
always_comb begin
case (rdata_offset_q)
unique case (rdata_offset_q)
2'b00: begin
if (!data_sign_ext_q) begin
rdata_b_ext = {24'h00_0000, data_rdata_i[7:0]};
@ -268,15 +273,18 @@ module ibex_load_store_unit (
rdata_b_ext = {{24{data_rdata_i[31]}}, data_rdata_i[31:24]};
end
end
default: rdata_b_ext = 'X;
endcase // case (rdata_offset_q)
end
// select word, half word or byte sign extended version
always_comb begin
case (data_type_q)
unique case (data_type_q)
2'b00: data_rdata_ext = rdata_w_ext;
2'b01: data_rdata_ext = rdata_h_ext;
2'b10,2'b11: data_rdata_ext = rdata_b_ext;
default: data_rdata_ext = 'X;
endcase //~case(rdata_type_q)
end
@ -340,7 +348,7 @@ module ibex_load_store_unit (
increase_address = 1'b0;
data_misaligned_o = 1'b0;
case(CS)
unique case(CS)
// starts from not active and stays in IDLE until request was granted
IDLE: begin
if (data_req_ex_i) begin
@ -416,9 +424,8 @@ module ibex_load_store_unit (
end
end //~ WAIT_RVALID
default: begin
NS = IDLE;
NS = ls_fsm_e'({$bits(ls_fsm_e){1'bX}});
end
endcase
end
@ -430,18 +437,23 @@ module ibex_load_store_unit (
data_misaligned = 1'b0;
if (data_req_ex_i && !data_misaligned_q) begin
case (data_type_ex_i)
unique case (data_type_ex_i)
2'b00: begin // word
if (data_addr_int[1:0] != 2'b00) begin
data_misaligned = 1'b1;
end
end
2'b01: begin // half word
if (data_addr_int[1:0] == 2'b11) begin
data_misaligned = 1'b1;
end
end
default: ;
2'b10,
2'b11:;
default: data_misaligned = 1'bX;
endcase // case (data_type_ex_i)
end
end