Mux Tree Generation

Open
#4,809 4 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
28/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
scala
Domain
compilers

Research direction

No repository files or tests are named. Start by reproducing the Chisel 6.5.0 MuxTree example and tracing indexed Vec selection through the generated FIRRTL/CIRCT firtool output. Done means a supported way to request explicit 2:1 mux intermediates exists and a regression test verifies the resulting SystemVerilog structure.

Written by the indexing model from the issue text.

Description

Hi,

I need to constraint the way multiplexer trees are generated.
Currently, with Chisel 6.5.0, the following code:

class MuxTree(nBit: Int) extends Module {
  val io = IO(new Bundle {
    val i_slct = Input(UInt(2.W))
    val i_in = Input(Vec(4, UInt(nBit.W)))   

    val o_out = Output(UInt(nBit.W))  
  })  

  io.o_out := io.i_in(io.i_slct)
}

leads to the following SystemVerilog:

// Generated by CIRCT firtool-1.62.0
module MuxTree(
  input        clock,
               reset,
  input  [1:0] io_i_slct,
  input  [3:0] io_i_in_0,
               io_i_in_1,
               io_i_in_2,
               io_i_in_3,
  output [3:0] io_o_out
);

  wire [3:0][3:0] _GEN = {{io_i_in_3}, {io_i_in_2}, {io_i_in_1}, {io_i_in_0}};
  assign io_o_out = _GEN[io_i_slct];
endmodule

In my case, I want the different multiplexers to be explicitly unrolled with intermediate signals, with the output of each 2:1 multiplexer. For example here:

// Manually written
module MuxTree(
  input        clock,
               reset,
  input  [1:0] io_i_slct,
  input  [3:0] io_i_in_0,
               io_i_in_1,
               io_i_in_2,
               io_i_in_3,
  output [3:0] io_o_out
);

wire [3:0] _GEN0_0;
wire [3:0] _GEN0_1;
wire [3:0] _GEN1_0;

assign _GEN0_0 = (io_i_slct[0] == 1'b1) ? io_i_in_1 : io_i_in_0;
assign _GEN0_1 = (io_i_slct[0] == 1'b1) ? io_i_in_3 : io_i_in_2;
assign _GEN1_0 = (io_i_slct[1] == 1'b1) ? _GEN0_1 : _GEN0_0;

assign io_o_out = _GEN1_0;
endmodule

Is it possible to force this kind of behavior in Chisel ?
Thanks for your support.

Dominant language
Scala
Stars
4.8k
Forks
669
Avg merge
1d 12h
Merged PRs (30d)
25

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from chipsalliance/chisel

All issues in chipsalliance/chisel

Similar issues

More Scala issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.