User avatar
pathetic piss kitten @kitten@elizabeth.cat
1d
my archenemy, nested ternary operators
3
1
3
0
User avatar
Erin 💽✨ @erincandescent@erincandescent.net
1d
@kitten you would hate your average (System)Verilog file, its practically standard to write things like
assign x = condition_a ? foo :
           condition_b ? bar :
           condition_c ? baz :
           condition_d ? qux :
                         quux;
2
0
0
0
User avatar
pathetic piss kitten @kitten@elizabeth.cat
1d
@erincandescent nooooo neocat_cry

although at least this is a serially nested ternary. the one I saw had subternaries in both branches of the main ternary
2
0
1
0

User avatar
fungus (penicillin producer) @hypha@cafe.mycelium.locahlo.st
1d
@kitten @erincandescent who doesn’t like some cyclomatic complexity? :D
0
0
0
0
User avatar
Erin 💽✨ @erincandescent@erincandescent.net
1d
@kitten it's also pretty common to see "opencoded" conditions e.g. when you can assume due to structural factors that only one condition will ever be true:
conds_onehot: assert property ($onehot0({condition_a, condition_b, condition_c, condition_d, condition_e}));

assign x = ({8{condition_a}} & foo)
         | ({8{condition_b}} & bar)
         | ({8{condition_c}} & baz)
         | ({8{condition_d}} & qux)
         | ({8{condition_e}} & quux);



HDL is a weird world!
:neocat_think:1
1
0
0
1
User avatar
Erin 💽✨ @erincandescent@erincandescent.net
1d
@kitten ({8{foo}} is Verilog for repeat foo 8x)
1
0
0
0
User avatar
pathetic piss kitten @kitten@elizabeth.cat
1d
@erincandescent .......why do they do that?
1
0
0
0
User avatar
Erin 💽✨ @erincandescent@erincandescent.net
1d
@kitten produces smaller and hence faster synthesis outputs (assuming that the synthesis tool couldn't prove the mutual exclusiveness of the conditions in the original, which it probably can't. They can be pretty dumb)
:neocat_think:1
0
0
0
1