Closed KelvinChung2000 closed 12 months ago
I tried executing your example, but I am a little confused on what the observable error is here?
When you use s.table2[0] <<= s.table2[i]
on the third cycle the value of the four match bits before the edge is 0001
... so on the third cycle in table2Update
you will end doing this:
i = 0 : table2[0] <<= 01 (via the then clause)
i = 1 : table2[0] <<= 00 (via the else clause)
i = 2 : table2[0] <<= 00 (via the else clause)
i = 3 : table2[0] <<= 00 (via the else clause)
I think this is the expected behavior as your code is written? The else clause will be executed three times for the second, third, and fourth match bits? And the else clause always sets the first entry in table2 to be zero ... so all of that looks ok?
When you use s.table2[i] <<= s.table2[i]
on the third cycle the value of the four match bits will still be 0001
... so on the third cycle in table2Update
you will end doing this:
i = 0 : table2[0] <<= 01 (via the then clause)
i = 1 : table2[1] <<= 00 (via the else clause)
i = 2 : table2[2] <<= 00 (via the else clause)
i = 3 : table2[3] <<= 00 (via the else clause)
Again, the else clause will be executed three times the second, third, and fourth match bits? And the else clause sets the corresponding entry in table2 to be zero ... but table2[0]
will still be 01 ... again I think everything is executing as expected given your code?
Ok, I understand the problem now. I am confused about the assignment order. However, in this situation, table2[0]
will be having multiple drivers? Since now table2[0]
can be both 0 or 1
It is perfectly fine to write a signal multiple times in the same update
block (just like in verilog). The final write takes precedence. In this case, the writes are actually disjoint which is a simpler case ... for example in Verilog:
always @(posedge clk) begin
if ( reset )
out <= 0;
else
out <= in_;
end
and in PyMTL3:
@update_ff
def upblock():
if ( s.reset )
s.out <<= 0;
else
s.out <<= s.in_;
end
You cannot write a signal from two different update
blocks (just like you cannot write a signal from two different always
blocks in Verilog), but it is fine to write a signal multiple times within the same update
block ... But maybe this is not your question?
Thanks for your clarification.
No problem! Glad you are trying out PyMTL3!
The following script will produce different results depending on how
table2Update
is written.If using
s.table2[0] <<= s.table2[i]
will result in the following resultbut when using
s.table2[i] <<= s.table2[i]
will produce the followingIn both situations, the else clauses should not affect the assignment in the if clauses. However, for some reason, this is causing problems.