- Renamed the command line option to specify the array limit size
- Added a new test to test the command line option
- Fixed the existing test to verify all the supported operators
- Use AstExprStmt and AstCReturn for proper lambda generation
- Add --constraint-with-limit option to prevent code explosion on large arrays
- Emit CONSTRAINTIGN warning when array size exceeds limit
- Updated test to check for all the operators (sum, product, and, or, xor)
Fixes#6455
This commit adds support for array reduction methods (sum, product, and, or, xor)
with 'with' clauses in randomization constraints. Previously, expressions like
'array.sum() with (int'(item == value))' were not supported in constraints.
Implementation details:
- Added handler in ConstraintExprVisitor::visit(AstCMethodHard*) for
ARRAY_R_SUM, ARRAY_R_PRODUCT, ARRAY_R_AND, ARRAY_R_OR, ARRAY_R_XOR
- Substitutes lambda argument references (item/index) in the with expression
- Generates appropriate SMT operations (bvadd, bvmul, bvand, bvor, bvxor)
- Uses correct identity elements for each reduction operation
- Marks non-constant nodes with user1() flag to ensure proper SMT code generation
The implementation follows the same pattern as the existing ARRAY_INSIDE handler,
generating SMT expressions at Verilator compile time that are evaluated by the
constraint solver at runtime.
Re-inline ConstPool entries in V3Subst that have been expanded into
word-wise accessed by V3Expand. This enables downstream constant folding
on the word-wise expressions.
As V3Subst now understands ConstPool entries, we can also omit expanding
straight assignments with a ConstPool entry on the RHS. This allows the
C++ compiler to see the memcpy directly.
V3Expand wide SHIFTL and SHIFTR if the shift amount is know and is a
multiple of VL_EDATA_SIZE. This case results in each word requiring a
simple copy from the original, or store of a constant zero, which
subsequent V3Subst can then eliminate.
A temporary introduced by V3Premit could not be eliminated in V3Subst if
it was involved in an expression that did a write back to a
non-temporary. To enables removing these, we need to track all variables
in V3Subst, not just the ones we would consider for elimination. Note
the new implementation is marginally faster than the old one even though
it does more work. It can eliminate ~5% more of wide temporaries on some
designs. Algorithm is largely the same.
Concatenations that are only used by Sel expressions that do not consume
some bits on the edges can be narrowed to not compute the unused bits.
E.g.: `{a[4:0], b[4:0]}[5:4]` -> `{a[0], b[4]}[1:0]`
This is a superset or the PUSH_SEL_THROUGH_CONCAT DFG pattern, which is
removed.
Minor performance improvement, especially for assertions heavy code.
Strings are often used as temporaries in unlikely branches. Do not
localize them to avoid an unnecessary initialization on function entry.