opt_expr: const_xnor replacement to pad Y with 1'b1
authorEddie Hung <eddie@fpgeh.com>
Fri, 24 Apr 2020 21:13:45 +0000 (14:13 -0700)
committerEddie Hung <eddie@fpgeh.com>
Fri, 24 Apr 2020 21:13:45 +0000 (14:13 -0700)
passes/opt/opt_expr.cc
tests/opt/opt_expr_xnor.ys

index 38dc09af5435a566ea98f60c0b058455cc707aeb..d895fc691ae62f02388d9868364050df42cf821a 100644 (file)
@@ -575,7 +575,8 @@ void replace_const_cells(RTLIL::Design *design, RTLIL::Module *module, bool cons
                                if (cell->type.in(ID($xnor), ID($_XNOR_))) {
                                        cover("opt.opt_expr.const_xnor");
                                        // For consistency since simplemap does $xnor -> $_XOR_ + $_NOT_
-                                       replace_cell(assign_map, module, cell, "const_xnor", ID::Y, RTLIL::State::S1);
+                                       int width = cell->getParam(ID::Y_WIDTH).as_int();
+                                       replace_cell(assign_map, module, cell, "const_xnor", ID::Y, SigSpec(RTLIL::State::S1, width));
                                        goto next_cell;
                                }
                                log_abort();
index 0f9463379d1c3e7c7a602017d6ae0009c19859a0..f8ef0d352a8a435952f07c9fc0e8b6674e0133bb 100644 (file)
@@ -83,3 +83,49 @@ miter -equiv -flatten -make_assert -make_outputs gold coarse_keepdc miter3
 sat -verify -prove-asserts -show-ports -enable_undef miter3
 miter -equiv -flatten -make_assert -make_outputs coarse_keepdc fine_keepdc miter4
 sat -verify -prove-asserts -show-ports -enable_undef miter4
+
+
+# Single-bit $xnor extension
+design -reset
+read_verilog -noopt <<EOT
+module gold(input i, output [1:0] o, p, q);
+assign o =  i ~^ i;
+assign p =  1'b0 ~^ i;
+assign q =  1'b1 ~^ i;
+endmodule
+EOT
+select -assert-count 3 t:$xnor
+copy gold coarse
+copy gold fine
+copy gold coarse_keepdc
+copy gold fine_keepdc
+
+cd coarse
+opt_expr -fine
+select -assert-none t:$xnor
+
+cd fine
+simplemap
+opt_expr
+select -assert-none t:$_XNOR_
+
+cd
+miter -equiv -flatten -make_assert -make_outputs -ignore_gold_x gold coarse miter
+sat -verify -prove-asserts -show-ports -enable_undef miter
+miter -equiv -flatten -make_assert -make_outputs coarse fine miter2
+sat -verify -prove-asserts -show-ports -enable_undef miter2
+
+cd coarse_keepdc
+opt_expr -keepdc -fine
+select -assert-count 1 t:$xnor
+
+cd fine_keepdc
+simplemap
+opt_expr -keepdc
+select -assert-count 0 c:$_XNOR_
+
+cd
+miter -equiv -flatten -make_assert -make_outputs gold coarse_keepdc miter3
+sat -verify -prove-asserts -show-ports -enable_undef miter3
+miter -equiv -flatten -make_assert -make_outputs coarse_keepdc fine_keepdc miter4
+sat -verify -prove-asserts -show-ports -enable_undef miter4