calyxir / calyx

Intermediate Language (IL) for Hardware Accelerator Generators
https://calyxir.org
MIT License
450 stars 44 forks source link

Generate or-and trees for guarded assignments #2024

Open rachitnigam opened 3 weeks ago

rachitnigam commented 3 weeks ago

Instead of generating:

in = g0 ? o1 : 
       g1 ? o2 : 'x

This generates:

in = ({WIDTH{g0}} & o1) |
       ({WIDTH{g1}} & o2) | 0

Note that we have to generate 0 instead of 'x because otherwise the &-| chain will produce an 'x value.

The --emit-mux option simulates the old behavior.

I'm also noticing that a lot of optimizations around guards are now happening within the Verilog backend which is bad. We should move that logic into a pass if possible.

rachitnigam commented 3 weeks ago

Fixes #1423

andrewb1999 commented 3 weeks ago

I think if/when this gets merged this should not be made the default yet. As mentioned on slack I have concerns that this will have unintended effects on resource utilization because it makes it harder for synthesis to optimize away guards.

rachitnigam commented 3 weeks ago

Good point! The alternative is generating casex statements which might not have the best support in the simulators we use but should otherwise support the optimization and generation of non-priority logic.