Skip to content

Commit

Permalink
Optimization of nowrshmsk
Browse files Browse the repository at this point in the history
Avoid multiplication of index by stride in the common case of a
two-dimensional packed array.
  • Loading branch information
daglem committed Aug 4, 2023
1 parent f37ce5c commit 679ecbd
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions frontends/ast/simplify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2875,12 +2875,23 @@ bool AstNode::simplify(bool const_fold, bool in_lvalue, int stage, int width_hin
{
// big case block

// Optimization for the common case of a two-dimensional packed array -
// remove multiplication of index by stride.
int div_stride = 1;
if (!source_offset && shift_expr->type == AST_MUL && shift_expr->children[1]->type == AST_CONSTANT && (int)shift_expr->children[1]->integer == stride)
{
AstNode *tmp = shift_expr->children[0]->clone();
delete shift_expr;
shift_expr = tmp;
div_stride = stride;
}

did_something = true;
newNode = new AstNode(AST_CASE, shift_expr);
for (int i = 0; i < source_width; i += stride) {
int start_bit = source_offset + i;
int end_bit = std::min(start_bit+result_width,source_width) - 1;
AstNode *cond = new AstNode(AST_COND, mkconst_int(start_bit, true));
AstNode *cond = new AstNode(AST_COND, mkconst_int(start_bit/div_stride, true));
AstNode *lvalue = children[0]->clone();
lvalue->delete_children();
if (member_node)
Expand All @@ -2893,7 +2904,7 @@ bool AstNode::simplify(bool const_fold, bool in_lvalue, int stage, int width_hin
}
else
{
// mask and shift operations, disabled for now
// mask and shift operations

AstNode *wire_mask = new AstNode(AST_WIRE, new AstNode(AST_RANGE, mkconst_int(source_width-1, true), mkconst_int(0, true)));
wire_mask->str = stringf("$bitselwrite$mask$%s:%d$%d", RTLIL::encode_filename(filename).c_str(), location.first_line, autoidx++);
Expand Down

0 comments on commit 679ecbd

Please sign in to comment.