Guest
Hello,
my question is probably best explained on a piece of code (the snippet is Verilog, but the question should be mostly language-agnostic)
reg memory_access;
reg[1:0] memory_access_size;
always @ (posedge clk) begin
if (clk_en && should_decode_input) begin
memory_access_size <= 2'bxx; // <---
case(some_input_data)
ACTION_1: begin
memory_access <= 1;
memory_access_size <= 2'b10;
end
ACTION_2: begin
memory_access <= 1;
memory_access_size <= 2'b01;
end
ACTION_3: begin
memory_access <= 0;
end
endcase
end
end
(the actual scenario is a Thumb instruction decoder)
My question is about the line marked with "// <---". If I understand the semantics correctly, including this line should make the compiler's job easier, by basically saying "unless I assign a new value to memory_access_size, do whatever with it". Thus, in the ACTION_3 case, it doesn't have to care about preserving its previous value (which is no longer relevant), presumably reducing the logic complexity.
I'm wondering whether this really is the case, in particular:
- Will this actually lead to more efficient logic realization with generally available (Altera, Xilinx) tools?
- Does this introduce any caveats to be aware of?
- Would you generally consider this a good coding practice?
Thanks in advance
-M
my question is probably best explained on a piece of code (the snippet is Verilog, but the question should be mostly language-agnostic)
reg memory_access;
reg[1:0] memory_access_size;
always @ (posedge clk) begin
if (clk_en && should_decode_input) begin
memory_access_size <= 2'bxx; // <---
case(some_input_data)
ACTION_1: begin
memory_access <= 1;
memory_access_size <= 2'b10;
end
ACTION_2: begin
memory_access <= 1;
memory_access_size <= 2'b01;
end
ACTION_3: begin
memory_access <= 0;
end
endcase
end
end
(the actual scenario is a Thumb instruction decoder)
My question is about the line marked with "// <---". If I understand the semantics correctly, including this line should make the compiler's job easier, by basically saying "unless I assign a new value to memory_access_size, do whatever with it". Thus, in the ACTION_3 case, it doesn't have to care about preserving its previous value (which is no longer relevant), presumably reducing the logic complexity.
I'm wondering whether this really is the case, in particular:
- Will this actually lead to more efficient logic realization with generally available (Altera, Xilinx) tools?
- Does this introduce any caveats to be aware of?
- Would you generally consider this a good coding practice?
Thanks in advance
-M