module priority_encoder (
input wire [3:0] req,
output reg [1:0] grant
);
always @(*) begin
if (req[3])
grant = 2'd3;
else if (req[2])
grant = 2'd2;
else if (req[1])
grant = 2'd1;
else if (req[0])
grant = 2'd0;
else
grant = 2'd0; // Default - CRITICAL!
end
endmodule
Always Include else!
In combinational logic, missing else clause causes latch
inference. Always assign a default value.