从现有总线形成正交总线组(而不是行总线、列总线)
Form orthongonal group of busses from existing bus (instead of busses of the rows, busses of the columns)
我有这样的输入进入模块:
input wire [31:0] row0_Q,
input wire [31:0] row1_Q,
...
input wire [31:0] row30_Q,
input wire [31:0] row31_Q
并想组成 "columns" 的总线,因为没有更好的条件。我可以做很长的路要走:
assign col31 = {row31[31], row30[31], ... row1[31], row0[31]} ;
但需要大量输入。有没有更简单的方法?
Verilog 中没有简单的方法。尝试创建一个脚本来为您生成代码。您可以使用首选编程语言生成代码,然后在 verilog 文件中使用 `include
语句。或者您可以使用嵌入式路线:
- Perl 有 EP3:http://metacpan.org/pod/Text::EP3::Verilog
- Ruby 有 eRuby : http://www.tutorialspoint.com/ruby/eruby.htm
- Python 有 prepro : http://corner-case.com/indproj/prepro.html
- 我确信其他语言也存在类似的东西。如Tcl、JavaScript、C等
概念相同,只是嵌入式语言和用于转换的工具不同。
在这种情况下,需要像下面这样的双 for 循环:
foreach my $i (0..31) {
foreach my $j (0..31) {
printf("assign col%0d[%0d] = row%0d[%0d];\n", $i,$j, $j, $i);
}
}
使用 SystemVerilog,您可以使用阵列 input/output 端口重新定义模块。它可能会在实例化时增加难度,并且我尝试将合成器压平阵列。但它可以工作。 Verilog 不支持这个,SystemVerilog 支持。
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
我有这样的输入进入模块:
input wire [31:0] row0_Q,
input wire [31:0] row1_Q,
...
input wire [31:0] row30_Q,
input wire [31:0] row31_Q
并想组成 "columns" 的总线,因为没有更好的条件。我可以做很长的路要走:
assign col31 = {row31[31], row30[31], ... row1[31], row0[31]} ;
但需要大量输入。有没有更简单的方法?
Verilog 中没有简单的方法。尝试创建一个脚本来为您生成代码。您可以使用首选编程语言生成代码,然后在 verilog 文件中使用 `include
语句。或者您可以使用嵌入式路线:
- Perl 有 EP3:http://metacpan.org/pod/Text::EP3::Verilog
- Ruby 有 eRuby : http://www.tutorialspoint.com/ruby/eruby.htm
- Python 有 prepro : http://corner-case.com/indproj/prepro.html
- 我确信其他语言也存在类似的东西。如Tcl、JavaScript、C等
概念相同,只是嵌入式语言和用于转换的工具不同。
在这种情况下,需要像下面这样的双 for 循环:
foreach my $i (0..31) {
foreach my $j (0..31) {
printf("assign col%0d[%0d] = row%0d[%0d];\n", $i,$j, $j, $i);
}
}
使用 SystemVerilog,您可以使用阵列 input/output 端口重新定义模块。它可能会在实例化时增加难度,并且我尝试将合成器压平阵列。但它可以工作。 Verilog 不支持这个,SystemVerilog 支持。
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