Skip to content

Commit 29c1ea7

Browse files
authored
Merge pull request #1369 from diffblue/aval_bval_replication
Verilog: aval/bval lowering for replication operator
2 parents eb37218 + 11a386f commit 29c1ea7

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
KNOWNBUG
1+
CORE
22
replication.sv
33
--module main --bound 0
44
^EXIT=0$
55
^SIGNAL=0$
66
--
77
^warning: ignoring
88
--
9-
z-related tests fail

regression/verilog/asic-world-operators/replication.sv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module main(input[31:0] in1, in2, in3);
44
// http://www.asic-world.com/verilog/operators2.html
55

66
// replication
7-
always assert repli_p1: {4{4'b1001}} == 'b1001100110011001;
8-
always assert repli_p2: {4{4'b1001,1'bz}} == 'b1001z1001z1001z1001z;
7+
initial repli_p1: assert({4{4'b1001}} === 'b1001100110011001);
8+
initial repli_p2: assert({4{4'b1001,1'bz}} === 'b1001z1001z1001z1001z);
99

1010
endmodule

src/verilog/aval_bval_encoding.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,30 @@ exprt aval_bval_bitwise(const multi_ary_exprt &expr)
483483
return combine_aval_bval(aval, bval, lower_to_aval_bval(expr.type()));
484484
}
485485

486+
exprt aval_bval_replication(const replication_exprt &expr)
487+
{
488+
auto &type = expr.type();
489+
PRECONDITION(is_four_valued(type));
490+
PRECONDITION(!is_four_valued(expr.times()));
491+
492+
auto times_int = numeric_cast_v<mp_integer>(expr.times());
493+
494+
// separately replicate aval and bval
495+
auto op_aval = aval(expr.op());
496+
auto op_bval = bval(expr.op());
497+
498+
auto replication_type = bv_typet{numeric_cast_v<std::size_t>(
499+
to_bitvector_type(op_aval.type()).width() * times_int)};
500+
501+
auto aval_replicated =
502+
replication_exprt{expr.times(), op_aval, replication_type};
503+
auto bval_replicated =
504+
replication_exprt{expr.times(), op_bval, replication_type};
505+
506+
return combine_aval_bval(
507+
aval_replicated, bval_replicated, lower_to_aval_bval(type));
508+
}
509+
486510
exprt aval_bval(const power_exprt &expr)
487511
{
488512
PRECONDITION(is_four_valued(expr.type()));

src/verilog/aval_bval_encoding.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ exprt aval_bval(const bitnot_exprt &);
5353
exprt aval_bval_bitwise(const multi_ary_exprt &);
5454
/// lowering for reduction operators
5555
exprt aval_bval_reduction(const unary_exprt &);
56+
/// lowering for replication
57+
exprt aval_bval_replication(const replication_exprt &);
5658
/// lowering for ==?
5759
exprt aval_bval(const verilog_wildcard_equality_exprt &);
5860
/// lowering for !=?

src/verilog/verilog_lowering.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,16 @@ exprt verilog_lowering(exprt expr)
571571
else
572572
return expr; // leave as is
573573
}
574+
else if(expr.id() == ID_replication)
575+
{
576+
auto &replication_expr = to_replication_expr(expr);
577+
578+
// encode into aval/bval
579+
if(is_four_valued(expr.type()))
580+
return aval_bval_replication(replication_expr);
581+
else
582+
return expr; // leave as is
583+
}
574584
else if(
575585
expr.id() == ID_reduction_or || expr.id() == ID_reduction_and ||
576586
expr.id() == ID_reduction_nor || expr.id() == ID_reduction_nand ||

0 commit comments

Comments
 (0)