Form orthongonal group of busses from existing bus (instead of busses of the rows, busses of the columns)

倾然丶 夕夏残阳落幕 提交于 2019-12-13 01:25:10

问题


I have inputs like this coming into a module:

   input  wire [31:0]     row0_Q,
   input  wire [31:0]     row1_Q,
    ...
   input  wire [31:0]     row30_Q,
   input  wire [31:0]     row31_Q

and want to form busses of the "columns" for lack of better terms. I can do it the long way:

   assign col31 = {row31[31], row30[31], ... row1[31], row0[31]} ;

but it's a lot of typing. Is there an easier way?


回答1:


There is no easy way within Verilog. Try creating a script to generate the code for you. You can have the code generated by your preferred programming language, then use an `include statement in your verilog file. Or you can go with an embedded route:

  • Perl had EP3 : http://metacpan.org/pod/Text::EP3::Verilog
  • Ruby has eRuby : http://www.tutorialspoint.com/ruby/eruby.htm
  • Python has prepro : http://corner-case.com/indproj/prepro.html
  • I'm sure something like it exists for other languages to. Such as Tcl, JavaScript, C, etc.

Concept is the same, just a difference in embedded language and tool used for conversion.

In this case, a double for-loop like the following will be needed:

foreach my $i (0..31) {
  foreach my $j (0..31) {
    printf("assign col%0d[%0d] = row%0d[%0d];\n", $i,$j, $j, $i);
  }
}

With SystemVerilog you could redefine your module with arrayed input/output ports. It may add difficulty when instantiating, and a synthesizer my attempt flatten the array. But it could work. Verilog does not support this, SystemVerilog does.

module row2col #(parameter WIDTH=32) (
    input wire [WIDTH-1:0] row [WIDTH],
    output logic [WIDTH-1:0] col [WIDTH]
  );
  always_comb begin
    foreach(row[i,j]) begin
      col[j][i] = row[i][j];
    end
  end
endmodule : row2col


来源:https://stackoverflow.com/questions/32236515/form-orthongonal-group-of-busses-from-existing-bus-instead-of-busses-of-the-row

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!