Closed rob-ng15 closed 2 years ago
Interesting! The problem lies with this expression: out = ~in[1,1];
Replacing by out = in[1,1] ? 0 : 1;
or by !in[1,1]
works as expected.
This expression directly translates to its Verilog counterpart, where lhs is 5 bits (cnt) and rhs is 2 bits (test2). The expression is widened to 5 bits before the ~ operator is applied, hence the 31. The !
operator has a different behavior, setting 1 appropriately (logical vs bitwise negation).
Btw, the original (linked at the top) did not have this problem (it does use !
), I did introduce this bug 👎 .
Can confirm that changing to !in[1,1] works. Which, technically is the correct expression ~in[1,1] or !in[1,1] ?
!in[1,1]
is the correct one, this is the 'bottom' case of the recursion, so we only count 1 is the second bit is set.
This is fixed, circuit was performing correctly.
Gives as output:
Would expect 7 and 1.