Working of edge_expressions

Hi Forum,

Consider the following edacode where we have always@(posedge edge_expr) / always@(negedge edge_expr)

I observe that at T:4 only p1_a executes and am trying to understand the reason behind it

Here is my current understanding ::

(A) At T:4 clk transitions from X to 1 i.e posedge of clk occurs.

Hence only p1 , p1_a , p2 and p4 are evaluated (due to posedge clk within the sampled functions)

(a1) $past(clk) returns X i.e default sample value while $rose(clk) returns 1.

$past(clk) === 0 would be 1’bX === 1’b0 i.e 1’b0

Essentially the current edge_expression at T:4 is 1’b0 ( due to 1’b0 && 1’b1 )

[Q1] For always@(posedge edge_expression) to execute/unblock, the edge_expression should transition from 0 to 1/X/Z or from X/Z to 1. The current edge_expression is 1’b0

How to calculate the previous edge_expression ( $past(clk) && $rose(clk) ) for p1 ?

(a2) $past(clk) returns X i.e default sample value while $rose(clk) returns 1.

$past(clk) == 0 would be 1’bX == 1’b0 i.e 1’bX

Essentially the current edge_expression at T:4 is 1’bX && 1’b1 i.e 1’bX

[Q2] Similar to [Q1] what is the previous edge_expression ( $past(clk) && $rose(clk) ) for p1_a ?

Since I observe p1_a executes at T:4, I know that it (previous edge_expression) would be 0 but I am not sure on how it’s calculated

(B) At T:6 clk transitions from 1 to 0 i.e negedge of clk occurs

Hence only p3 would be evaluated ( due to negedge clk within the sampled functions )

Within p3, $past(clk) === 1 would be false 1’b0 ( as default sample value is 1’bX due to no previous negegde of clk ). $fell(clk) would be true ( due to 1’bX (default sampled value) to 0 transition in clk )

Hence the current edge_expression at T:6 is 0

[Q3] How to calculate the previous edge_expression ( $past(clk) && $fell(clk) ) for p3 ?

On changing always@(nedgedge .. ) in p3 to always@(posedge .. ) I observe T:6 p3 Pass

( same can be verified via p3_a )

[Q4] Why does p3_a execute at T:6 ? What is the previous edge_expression for p3_a ?

The current edge_expression at T:6 for p3_a would be same as p3 i.e 0

(C) At T:11 clk transitions from 0 to 1 i.e posedge of clk occurs.

For reasons similar to (A), only p1 , p1_a , p2 and p4 are evaluated

Within p4, $past(clk) === 1 is true ( as last posedge of clk occurred at T:4 where clk was 1 )

$fell(clk) is false ( as last posedge of clk occurred at T:4 where clk was 1 )

Hence current edge_expression is 0 ( i.e 1’b1 && 1’b0 ) at T:11 for p4

[Q5] I observe that p4 doesn’t execute at T:11,how do I calculate the previous edge_expression for p4 at T:11 ( which is same as the current edge_expr of p4 at T:4 ) ?

Another question/confusion is due to clk transition from 1’bX to 1’b1 at T:4,

would $rose(clk,@(posedge clk)) return 1 (due to 1’bX to 1’b1) or 0 (due to 1’bX to 1’bX) ?

At T:4, would $rose(clk) use the sampled value of clk as 1’b1 or 1’bX ? ( as clk does transition to 1 prior to @(posedge clk) )