Will always_comb block trigger if the signal value changes from 0/1 to X

Hi,

Will always_comb block trigger if the signal value changes from 0 or 1 to X ?

I am trying to force a signal to 0 if it changes to X. Below is my code. Will this work?


logic [2:0] signal;
always_comb begin
   if(signal === 3'bxxx) begin
     force signal = 3'b000;
     release signal;
   end
end

TIA

In reply to sj1992:

module try_me;
  logic signal = 1;
  always_comb if (signal === 'x) $display("signal is x at %0d", $realtime);
  initial #2 signal = 'x;
endmodule

In reply to dave_59:

Thanks Dave. I do see that the always_comb block gets triggered if the signal changes from 0/1 to X. But my force and release commands dont seem to be working. Should there be some time delay between force and release?

In reply to sj1992:

That is a completely different question. The code you show works. You don’t even need a force/release statement. A simple procedural assignment to 0 would work. There must be something different in your environment than what you have shown.

In reply to dave_59:

Hi Dave,

The Signal is inside the DUT RTL and is getting assigned in an always block. But when this signal gets assigned the value X in RTL I want to make it to 0. So I am trying to use force and release in my testbench so that the signal never becomes X. But this force and release dont seem to work.

Thanks

In reply to dave_59:

In reply to sj1992:
That is a completely different question. The code you show works. You don’t even need a force/release statement. A simple procedural assignment to 0 would work. There must be something different in your environment than what you have shown.

I tried the below code but the signal remains X after the force and release statements



module top;
  logic [2:0] signal = 1;
  logic clk = 0;
  always_comb  begin
     if (signal === 3'bxxx) begin
        $display("signal is x at %0d", $realtime);
        force signal = 0;
        release signal;
        $display("after release signal is: %0b at %0d", signal,$realtime);
      end
  end
  initial begin
     #2 signal = 'x;
     #10 $display("calling finish");
     $stop();
     
   end
   initial begin
     clk = 0;
     forever begin
        #1 clk = ~clk;
      end
     end 
endmodule

In reply to sj1992:

OK, my mistake (but a complete reproducible example would have helped me realize that sooner). The code you originally wrote will not work because a variable that is both read and written to in an alays_comb block is not part of its sensitivity. If you replace the always_comb with always @signal you get your desired results.

I think this is an mistake in the LRM because a force statement is not supposed to be considered as a procedural or continuous assignment for the other rules that disallow multiple drivers. It should not be considered an assignment for the sensitivity rules as well. But probably too late to change.