Skip to content

Commit

Permalink
Less confusing variables names for indexing of lhs wire
Browse files Browse the repository at this point in the history
  • Loading branch information
daglem committed Nov 20, 2023
1 parent b811e48 commit 1cf4925
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions frontends/ast/simplify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2830,10 +2830,10 @@ bool AstNode::simplify(bool const_fold, int stage, int width_hint, bool sign_hin
goto skip_dynamic_range_lvalue_expansion;

AST::AstNode *member_node = get_struct_member(children[0]);
int source_width = member_node ?
int wire_width = member_node ?
member_node->range_left - member_node->range_right + 1 :
children[0]->id2ast->range_left - children[0]->id2ast->range_right + 1;
int source_offset = children[0]->id2ast->range_right;
int wire_offset = children[0]->id2ast->range_right;
int result_width = 1;

AstNode *shift_expr = NULL;
Expand Down Expand Up @@ -2890,15 +2890,15 @@ bool AstNode::simplify(bool const_fold, int stage, int width_hint, bool sign_hin
else if (member_node) // Member in packed struct/union
{
// Clamp chunk to range of member within struct/union.
log_assert(!source_offset && !children[0]->id2ast->range_swapped);
log_assert(!wire_offset && !children[0]->id2ast->range_swapped);

// When the (* nowrshmsk *) attribute is set, a CASE block is generated below
// to select the indexed bit slice. When a multirange array is indexed, the
// start of each possible slice is separated by the bit stride of the last
// index dimension, and we can optimize the CASE block accordingly.
// The dimension of the original array expression is saved in the 'integer' field.
int dims = children[0]->integer;
stride = source_width;
stride = wire_width;
for (int dim = 0; dim < dims; dim++) {
stride /= get_struct_range_width(member_node, dim);
}
Expand All @@ -2924,9 +2924,9 @@ bool AstNode::simplify(bool const_fold, int stage, int width_hint, bool sign_hin

did_something = true;
newNode = new AstNode(AST_CASE, shift_expr);
for (int i = 1 - result_width; i < source_width; i++) {
for (int i = 1 - result_width; i < wire_width; i++) {
// Out of range indexes are handled in genrtlil.cc
int start_bit = source_offset + i;
int start_bit = wire_offset + i;
int end_bit = start_bit + result_width - 1;
// Check whether the current index can be generated by shift_expr.
if (start_bit < min_offset || start_bit > max_offset)
Expand All @@ -2949,14 +2949,14 @@ bool AstNode::simplify(bool const_fold, int stage, int width_hint, bool sign_hin
{
// 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)));
AstNode *wire_mask = new AstNode(AST_WIRE, new AstNode(AST_RANGE, mkconst_int(wire_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++);
wire_mask->set_attribute(ID::nosync, AstNode::mkconst_int(1, false));
wire_mask->is_logic = true;
while (wire_mask->simplify(true, 1, -1, false)) { }
current_ast_mod->children.push_back(wire_mask);

AstNode *wire_data = new AstNode(AST_WIRE, new AstNode(AST_RANGE, mkconst_int(source_width-1, true), mkconst_int(0, true)));
AstNode *wire_data = new AstNode(AST_WIRE, new AstNode(AST_RANGE, mkconst_int(wire_width-1, true), mkconst_int(0, true)));
wire_data->str = stringf("$bitselwrite$data$%s:%d$%d", RTLIL::encode_filename(filename).c_str(), location.first_line, autoidx++);
wire_data->set_attribute(ID::nosync, AstNode::mkconst_int(1, false));
wire_data->is_logic = true;
Expand Down Expand Up @@ -3012,12 +3012,12 @@ bool AstNode::simplify(bool const_fold, int stage, int width_hint, bool sign_hin
shamt = new AstNode(AST_TO_SIGNED, shamt);

// offset the shift amount by the lower bound of the dimension
int start_bit = source_offset;
int start_bit = wire_offset;
shamt = new AstNode(AST_SUB, shamt, mkconst_int(start_bit, true));

// reflect the shift amount if the dimension is swapped
if (children[0]->id2ast->range_swapped)
shamt = new AstNode(AST_SUB, mkconst_int(source_width - result_width, true), shamt);
shamt = new AstNode(AST_SUB, mkconst_int(wire_width - result_width, true), shamt);

// AST_SHIFT uses negative amounts for shifting left
shamt = new AstNode(AST_NEG, shamt);
Expand Down

0 comments on commit 1cf4925

Please sign in to comment.