Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Efficient handling of patterns emitted by sv2v #4615

Open
povik opened this issue Sep 26, 2024 · 7 comments
Open

Efficient handling of patterns emitted by sv2v #4615

povik opened this issue Sep 26, 2024 · 7 comments

Comments

@povik
Copy link
Member

povik commented Sep 26, 2024

Feature Description

The external tool sv2v rewrites member accesses, element selects and other operations into part-selects and a bit of arithmetic.

Take e.g. (source)

mem_q[trans_id_i[k]].sbe.rd

it gets rewritten into

mem_q[(trans_id_i[0+:2] * 467) + 376-:5]

Within the read_verilog frontend, this gets parsed as a shift cell with the shift amount driven by arithmetic cells. Notwithstanding peepopt transformations some of those shift cells survive to the techmap stage at which time they are expanded into a sea of mux gates. Due to the presence of constant bits most of those gates are redundant as evinced by subsequent opt_expr -mux_undef cleaning them up. This redundant mux effect can be so bad it accounts for >80 % of Yosys peak memory usage in a real world synthesis flow incorporating sv2v.

This can get addressed at different points:

  • the frontend detecting these patterns and emitting a more efficient structure right away
  • additional opt_expr rules which transform a shift cell with constant bits on some of its inputs
  • efficiently lowering the cells within techmap provided second-order constant propagation isn't a significant factor

Cc @zachjs @phsauter

@whitequark
Copy link
Member

Amaranth lowers such constructs into cases assigning to/from an intermediate variable for the same reason. I am not sure why sv2v is using arithmetic; perhaps it should stop.

@povik
Copy link
Member Author

povik commented Sep 26, 2024

yosys-slang uses $bmux for element selects (within a complex type also)

@phsauter
Copy link
Contributor

Amaranth lowers such constructs into cases assigning to/from an intermediate variable for the same reason. I am not sure why sv2v is using arithmetic; perhaps it should stop.

Good to know because I would have informed Robert next week as well, so there is no need.
I do think the way sv2v does this transformation is probably not the best choice but I can see where it comes from.

In general I think this is worth solving because the alternative, ensuring no other tool produces similar constructs, does not seem feasible to me.
Also you can have shifts coming from other RTL constructs (or even just from people actually writing it like that).

@whitequark
Copy link
Member

(Robert?)

@phsauter
Copy link
Contributor

Sorry, Rob Taylor.

@zachjs
Copy link
Collaborator

zachjs commented Sep 29, 2024

I have no objection to the premise of handling these patterns more efficiently in general, but insofar as sv2v targets yosys, I really don't intend for its output to be pathological. Detecting this pattern doesn't seem hard. (Any time a variable is used to index into something multi-dimensional?) Then adding the appropriate read/write attribute to the declaration seems harmless, if we go that route. Adding a temporary would be a bit more complex but also doable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants