3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-06-26 18:48:51 +00:00

Merge pull request #5952 from YosysHQ/nella/vector-index

Optimize upto vector indexing (Fix #892).
This commit is contained in:
nella 2026-06-22 09:05:26 +00:00 committed by GitHub
commit 3d0c868af0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 169 additions and 0 deletions

View file

@ -0,0 +1,19 @@
# https://github.com/YosysHQ/yosys/issues/892
read_verilog <<EOT
module top (input clk, sel, di, output do);
reg [0:1] data [0:0];
always @(posedge clk)
data[0] <= {di, data[0][0]};
assign do = data[0][sel];
endmodule
EOT
proc
equiv_opt -assert -map +/xilinx/cells_sim.v synth_xilinx -noiopad
design -load postopt
select -assert-count 1 t:BUFG
select -assert-count 2 t:FDRE
select -assert-count 1 t:LUT3
select -assert-none t:BUFG t:FDRE t:LUT3 %% t:* %D

View file

@ -0,0 +1,100 @@
# Rewrite (2^k-1)-x into ~x when x is known to be smaller than 2^k
read_verilog -icells <<EOT
module test(input [3:0] b, output [3:0] y);
$sub #(
.A_WIDTH(4), .B_WIDTH(4), .Y_WIDTH(4),
.A_SIGNED(0), .B_SIGNED(0),
) sub (
.A(4'hf), .B(b), .Y(y),
);
endmodule
EOT
equiv_opt -assert opt_expr -fine
design -load postopt
select -assert-count 1 t:$not
select -assert-none t:$sub
select -assert-none t:$not t:* %D
design -reset
read_verilog -icells <<EOT
module test(input [1:0] b, output [3:0] y);
$sub #(
.A_WIDTH(4), .B_WIDTH(2), .Y_WIDTH(4),
.A_SIGNED(0), .B_SIGNED(0),
) sub (
.A(4'd3), .B(b), .Y(y),
);
endmodule
EOT
equiv_opt -assert opt_expr -fine
design -load postopt
select -assert-count 1 t:$not
select -assert-none t:$sub
design -reset
read_verilog -icells <<EOT
module test(input [3:0] b, output [3:0] y);
$sub #(
.A_WIDTH(4), .B_WIDTH(4), .Y_WIDTH(4),
.A_SIGNED(0), .B_SIGNED(0),
) sub (
.A(4'b1011), .B(b), .Y(y),
);
endmodule
EOT
equiv_opt -assert opt_expr -fine
design -load postopt
select -assert-none t:$not
design -reset
read_verilog -icells <<EOT
module test(input [3:0] b, output [3:0] y);
$sub #(
.A_WIDTH(2), .B_WIDTH(4), .Y_WIDTH(4),
.A_SIGNED(0), .B_SIGNED(0),
) sub (
.A(2'b11), .B(b), .Y(y),
);
endmodule
EOT
equiv_opt -assert opt_expr -fine
design -load postopt
select -assert-none t:$not
design -reset
read_verilog <<EOT
module test(input [1:0] sel, input [0:3] data, output out);
assign out = data[sel];
endmodule
EOT
equiv_opt -assert opt -full
design -load postopt
select -assert-none t:$sub t:$add t:$alu
design -reset
read_verilog <<EOT
module test(input sel, input [0:1] data, output out);
assign out = data[sel];
endmodule
EOT
equiv_opt -assert opt -full
design -load postopt
select -assert-none t:$sub t:$add t:$alu