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

[LowerToHW] Implement MuxCell intrinsics lowering #5458

Merged
merged 4 commits into from
Jul 3, 2023

Conversation

uenoku
Copy link
Member

@uenoku uenoku commented Jun 22, 2023

This commit deprecates addMuxPragma flag in LowerToHW and implements lowering of MuxCell intrinsics.

MuxCell intrinsics are lowered into a wire declaration, an assignment with infer_mux_override pragma and a value with map_to_mux pragma. Operands are probed to hw.wire with inner symbols to prevent optimizations from destructing AST structures.

@uenoku uenoku force-pushed the dev/uenoku/mux-cell-lower branch from 66997a3 to 4b1b604 Compare June 27, 2023 08:18
@uenoku uenoku changed the base branch from main to dev/uenoku/mux-sv-attr June 27, 2023 08:19
@uenoku uenoku force-pushed the dev/uenoku/mux-cell-lower branch from 4b1b604 to 650c7bb Compare June 27, 2023 08:19
Comment on lines +308 to +324
module Mux2Cell:
input cond: UInt<1>
input low: UInt<1>
output out: UInt<1>[2]
wire w: UInt<1>
inst mux2 of Mux2
inst ext of Val
w <= ext.v
mux2.sel <= xor(cond, UInt<1>(1))
mux2.high <= w
mux2.low <= low
out[0] <= mux2.out
inst mux2_1 of Mux2
mux2_1.sel <= xor(cond, UInt<1>(1))
mux2_1.high <= ext.v
mux2_1.low <= low
out[1] <= mux2_1.out
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a bit complicated but this is an example that produces incorrect results if CSE prevention was not added.

Base automatically changed from dev/uenoku/mux-sv-attr to main June 28, 2023 09:41
@uenoku
Copy link
Member Author

uenoku commented Jun 29, 2023

circuit Mux2Cell: 
  intmodule Mux2:
     input sel: UInt<1>
     input high: UInt
     input low: UInt
     output out: UInt
     intrinsic = circt_mux2cell

  extmodule Val:
     output v: UInt<1>
  module Mux2Cell:
    input cond: UInt<1>
    input low: UInt<1>
    output out: UInt<1>[2]
    wire w: UInt<1>
    inst mux2 of Mux2
    inst ext of Val
    w <= ext.v
    mux2.sel <= xor(cond, UInt<1>(1))
    mux2.high <= w
    mux2.low <= low
    out[0] <= mux2.out
    inst mux2_1 of Mux2
    mux2_1.sel <= xor(cond, UInt<1>(1))
    mux2_1.high <= ext.v
    mux2_1.low <= low
    out[1] <= mux2_1.out

This is the output verilog when we didn't do CSE prevention. _GEN ? /* cadence map_to_mux */ _ext_v : low; is spilled to a wire because of the multiple uses. As a result /* synopsys infer_mux_override */ is located in an invalid place.

// Generated by CIRCT firtool-1.44.0-88-gdf6361bc3
// external module Val

module Mux2Cell(
  input  cond,
         low,
  output out_0,
         out_1
);

  wire _GEN;
  wire _ext_v;
  wire _GEN_0 = _GEN ? /* cadence map_to_mux */ _ext_v : low;
  wire _GEN_1;
  /* synopsys infer_mux_override */
  assign _GEN_1 = _GEN_0;
  assign _GEN = ~cond;
  wire _GEN_2;
  /* synopsys infer_mux_override */
  assign _GEN_2 = _GEN_0;
  Val ext (
    .v (_ext_v)
  );
  assign out_0 = _GEN_1;
  assign out_1 = _GEN_2;
endmodule

@uenoku uenoku force-pushed the dev/uenoku/mux-cell-lower branch from 387213f to 1d5dddb Compare June 30, 2023 14:59
@uenoku
Copy link
Member Author

uenoku commented Jul 3, 2023

I changed to use hw.wires and inner symbols to block optimizations so that we can keep AST structures. I'm going to merge the PR but post commit review is welcomed.

@uenoku uenoku merged commit b903f48 into main Jul 3, 2023
5 checks passed
@uenoku uenoku deleted the dev/uenoku/mux-cell-lower branch July 3, 2023 20:41
@darthscsi
Copy link
Contributor

OrderedOutputOp might help keep things in the right order. (or similar)

calebmkim pushed a commit to andrewb1999/circt that referenced this pull request Jul 12, 2023
This commit deprecates addMuxPragma flag in LowerToHW and implements lowering of MuxCell intrinsics.

MuxCell intrinsics are lowered into a wire declaration, an assignment with infer_mux_override pragma and a value with map_to_mux pragma. Operands are probed to hw.wire with inner symbols to prevent optimizations from destructing AST structures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants