mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-28 03:15:50 +00:00
Import more std:: stuff into Yosys namespace
This commit is contained in:
parent
da923c198e
commit
207736b4ee
39 changed files with 168 additions and 161 deletions
|
@ -547,14 +547,14 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun
|
|||
switch (type)
|
||||
{
|
||||
case AST_CONSTANT:
|
||||
width_hint = std::max(width_hint, int(bits.size()));
|
||||
width_hint = max(width_hint, int(bits.size()));
|
||||
if (!is_signed)
|
||||
sign_hint = false;
|
||||
break;
|
||||
|
||||
case AST_REALVALUE:
|
||||
*found_real = true;
|
||||
width_hint = std::max(width_hint, 32);
|
||||
width_hint = max(width_hint, 32);
|
||||
break;
|
||||
|
||||
case AST_IDENTIFIER:
|
||||
|
@ -617,7 +617,7 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun
|
|||
this_width = range->range_left - range->range_right + 1;
|
||||
sign_hint = false;
|
||||
}
|
||||
width_hint = std::max(width_hint, this_width);
|
||||
width_hint = max(width_hint, this_width);
|
||||
if (!id_ast->is_signed)
|
||||
sign_hint = false;
|
||||
break;
|
||||
|
@ -627,7 +627,7 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun
|
|||
if (children[0]->type != AST_CONSTANT)
|
||||
log_error("Left operand of tobits expression is not constant at %s:%d!\n", filename.c_str(), linenum);
|
||||
children[1]->detectSignWidthWorker(sub_width_hint, sign_hint);
|
||||
width_hint = std::max(width_hint, children[0]->bitsAsConst().as_int());
|
||||
width_hint = max(width_hint, children[0]->bitsAsConst().as_int());
|
||||
break;
|
||||
|
||||
case AST_TO_SIGNED:
|
||||
|
@ -646,7 +646,7 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun
|
|||
child->detectSignWidthWorker(sub_width_hint, sub_sign_hint);
|
||||
this_width += sub_width_hint;
|
||||
}
|
||||
width_hint = std::max(width_hint, this_width);
|
||||
width_hint = max(width_hint, this_width);
|
||||
sign_hint = false;
|
||||
break;
|
||||
|
||||
|
@ -655,7 +655,7 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun
|
|||
if (children[0]->type != AST_CONSTANT)
|
||||
log_error("Left operand of replicate expression is not constant at %s:%d!\n", filename.c_str(), linenum);
|
||||
children[1]->detectSignWidthWorker(sub_width_hint, sub_sign_hint);
|
||||
width_hint = std::max(width_hint, children[0]->bitsAsConst().as_int() * sub_width_hint);
|
||||
width_hint = max(width_hint, children[0]->bitsAsConst().as_int() * sub_width_hint);
|
||||
sign_hint = false;
|
||||
break;
|
||||
|
||||
|
@ -678,7 +678,7 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun
|
|||
case AST_REDUCE_XOR:
|
||||
case AST_REDUCE_XNOR:
|
||||
case AST_REDUCE_BOOL:
|
||||
width_hint = std::max(width_hint, 1);
|
||||
width_hint = max(width_hint, 1);
|
||||
sign_hint = false;
|
||||
break;
|
||||
|
||||
|
@ -698,7 +698,7 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun
|
|||
case AST_NEX:
|
||||
case AST_GE:
|
||||
case AST_GT:
|
||||
width_hint = std::max(width_hint, 1);
|
||||
width_hint = max(width_hint, 1);
|
||||
sign_hint = false;
|
||||
break;
|
||||
|
||||
|
@ -714,7 +714,7 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun
|
|||
case AST_LOGIC_AND:
|
||||
case AST_LOGIC_OR:
|
||||
case AST_LOGIC_NOT:
|
||||
width_hint = std::max(width_hint, 1);
|
||||
width_hint = max(width_hint, 1);
|
||||
sign_hint = false;
|
||||
break;
|
||||
|
||||
|
@ -729,7 +729,7 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun
|
|||
if (!id2ast->children[0]->range_valid)
|
||||
log_error("Failed to detect with of memory access `%s' at %s:%d!\n", str.c_str(), filename.c_str(), linenum);
|
||||
this_width = id2ast->children[0]->range_left - id2ast->children[0]->range_right + 1;
|
||||
width_hint = std::max(width_hint, this_width);
|
||||
width_hint = max(width_hint, this_width);
|
||||
break;
|
||||
|
||||
// everything should have been handled above -> print error if not.
|
||||
|
@ -1054,7 +1054,7 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
|
|||
detectSignWidth(width_hint, sign_hint);
|
||||
RTLIL::SigSpec left = children[0]->genRTLIL(width_hint, sign_hint);
|
||||
RTLIL::SigSpec right = children[1]->genRTLIL(width_hint, sign_hint);
|
||||
int width = std::max(left.size(), right.size());
|
||||
int width = max(left.size(), right.size());
|
||||
if (width_hint > 0)
|
||||
width = width_hint;
|
||||
is_signed = children[0]->is_signed && children[1]->is_signed;
|
||||
|
@ -1068,7 +1068,7 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
|
|||
if (0) { case AST_REDUCE_XNOR: type_name = "$reduce_xnor"; }
|
||||
{
|
||||
RTLIL::SigSpec arg = children[0]->genRTLIL();
|
||||
RTLIL::SigSpec sig = uniop2rtlil(this, type_name, std::max(width_hint, 1), arg);
|
||||
RTLIL::SigSpec sig = uniop2rtlil(this, type_name, max(width_hint, 1), arg);
|
||||
return sig;
|
||||
}
|
||||
|
||||
|
@ -1077,7 +1077,7 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
|
|||
if (0) { case AST_REDUCE_BOOL: type_name = "$reduce_bool"; }
|
||||
{
|
||||
RTLIL::SigSpec arg = children[0]->genRTLIL();
|
||||
RTLIL::SigSpec sig = arg.size() > 1 ? uniop2rtlil(this, type_name, std::max(width_hint, 1), arg) : arg;
|
||||
RTLIL::SigSpec sig = arg.size() > 1 ? uniop2rtlil(this, type_name, max(width_hint, 1), arg) : arg;
|
||||
return sig;
|
||||
}
|
||||
|
||||
|
@ -1123,7 +1123,7 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
|
|||
if (0) { case AST_GE: type_name = "$ge"; }
|
||||
if (0) { case AST_GT: type_name = "$gt"; }
|
||||
{
|
||||
int width = std::max(width_hint, 1);
|
||||
int width = max(width_hint, 1);
|
||||
width_hint = -1, sign_hint = true;
|
||||
children[0]->detectSignWidthWorker(width_hint, sign_hint);
|
||||
children[1]->detectSignWidthWorker(width_hint, sign_hint);
|
||||
|
@ -1145,7 +1145,7 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
|
|||
RTLIL::SigSpec left = children[0]->genRTLIL(width_hint, sign_hint);
|
||||
RTLIL::SigSpec right = children[1]->genRTLIL(width_hint, sign_hint);
|
||||
#if 0
|
||||
int width = std::max(left.size(), right.size());
|
||||
int width = max(left.size(), right.size());
|
||||
if (width > width_hint && width_hint > 0)
|
||||
width = width_hint;
|
||||
if (width < width_hint) {
|
||||
|
@ -1154,10 +1154,10 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
|
|||
if (type == AST_SUB && (!children[0]->is_signed || !children[1]->is_signed))
|
||||
width = width_hint;
|
||||
if (type == AST_MUL)
|
||||
width = std::min(left.size() + right.size(), width_hint);
|
||||
width = min(left.size() + right.size(), width_hint);
|
||||
}
|
||||
#else
|
||||
int width = std::max(std::max(left.size(), right.size()), width_hint);
|
||||
int width = max(max(left.size(), right.size()), width_hint);
|
||||
#endif
|
||||
is_signed = children[0]->is_signed && children[1]->is_signed;
|
||||
return binop2rtlil(this, type_name, width, left, right);
|
||||
|
@ -1169,14 +1169,14 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
|
|||
{
|
||||
RTLIL::SigSpec left = children[0]->genRTLIL();
|
||||
RTLIL::SigSpec right = children[1]->genRTLIL();
|
||||
return binop2rtlil(this, type_name, std::max(width_hint, 1), left, right);
|
||||
return binop2rtlil(this, type_name, max(width_hint, 1), left, right);
|
||||
}
|
||||
|
||||
// generate cells for unary operations: $logic_not
|
||||
case AST_LOGIC_NOT:
|
||||
{
|
||||
RTLIL::SigSpec arg = children[0]->genRTLIL();
|
||||
return uniop2rtlil(this, "$logic_not", std::max(width_hint, 1), arg);
|
||||
return uniop2rtlil(this, "$logic_not", max(width_hint, 1), arg);
|
||||
}
|
||||
|
||||
// generate multiplexer for ternary operator (aka ?:-operator)
|
||||
|
@ -1192,7 +1192,7 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
|
|||
if (cond.size() > 1)
|
||||
cond = uniop2rtlil(this, "$reduce_bool", 1, cond, false);
|
||||
|
||||
int width = std::max(val1.size(), val2.size());
|
||||
int width = max(val1.size(), val2.size());
|
||||
is_signed = children[1]->is_signed && children[2]->is_signed;
|
||||
widthExtend(this, val1, width, is_signed);
|
||||
widthExtend(this, val2, width, is_signed);
|
||||
|
|
|
@ -398,7 +398,7 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
|
|||
did_something = true;
|
||||
children[0]->detectSignWidth(backup_width_hint, backup_sign_hint);
|
||||
children[1]->detectSignWidth(width_hint, sign_hint);
|
||||
width_hint = std::max(width_hint, backup_width_hint);
|
||||
width_hint = max(width_hint, backup_width_hint);
|
||||
child_0_is_self_determined = true;
|
||||
break;
|
||||
|
||||
|
@ -412,7 +412,7 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
|
|||
did_something = true;
|
||||
if (!children[1]->range_valid)
|
||||
log_error("Non-constant width range on parameter decl at %s:%d.\n", filename.c_str(), linenum);
|
||||
width_hint = std::max(width_hint, children[1]->range_left - children[1]->range_right + 1);
|
||||
width_hint = max(width_hint, children[1]->range_left - children[1]->range_right + 1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -733,8 +733,8 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
|
|||
for (auto range : children[1]->children) {
|
||||
if (!range->range_valid)
|
||||
log_error("Non-constant range on memory decl at %s:%d.\n", filename.c_str(), linenum);
|
||||
multirange_dimensions.push_back(std::min(range->range_left, range->range_right));
|
||||
multirange_dimensions.push_back(std::max(range->range_left, range->range_right) - std::min(range->range_left, range->range_right) + 1);
|
||||
multirange_dimensions.push_back(min(range->range_left, range->range_right));
|
||||
multirange_dimensions.push_back(max(range->range_left, range->range_right) - min(range->range_left, range->range_right) + 1);
|
||||
total_size *= multirange_dimensions.back();
|
||||
}
|
||||
delete children[1];
|
||||
|
@ -1169,7 +1169,7 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
|
|||
log_error("Non-constant array range on cell array at %s:%d.\n", filename.c_str(), linenum);
|
||||
|
||||
newNode = new AstNode(AST_GENBLOCK);
|
||||
int num = std::max(children.at(0)->range_left, children.at(0)->range_right) - std::min(children.at(0)->range_left, children.at(0)->range_right) + 1;
|
||||
int num = max(children.at(0)->range_left, children.at(0)->range_right) - min(children.at(0)->range_left, children.at(0)->range_right) + 1;
|
||||
|
||||
for (int i = 0; i < num; i++) {
|
||||
int idx = children.at(0)->range_left > children.at(0)->range_right ? children.at(0)->range_right + i : children.at(0)->range_right - i;
|
||||
|
@ -2043,7 +2043,7 @@ skip_dynamic_range_lvalue_expansion:;
|
|||
if (0) { case AST_GE: const_func = RTLIL::const_ge; }
|
||||
if (0) { case AST_GT: const_func = RTLIL::const_gt; }
|
||||
if (children[0]->type == AST_CONSTANT && children[1]->type == AST_CONSTANT) {
|
||||
int cmp_width = std::max(children[0]->bits.size(), children[1]->bits.size());
|
||||
int cmp_width = max(children[0]->bits.size(), children[1]->bits.size());
|
||||
bool cmp_signed = children[0]->is_signed && children[1]->is_signed;
|
||||
RTLIL::Const y = const_func(children[0]->bitsAsConst(cmp_width, cmp_signed),
|
||||
children[1]->bitsAsConst(cmp_width, cmp_signed), cmp_signed, cmp_signed, 1);
|
||||
|
@ -2236,7 +2236,7 @@ AstNode *AstNode::readmem(bool is_readmemh, std::string mem_filename, AstNode *m
|
|||
|
||||
log_assert(GetSize(memory->children) == 2 && memory->children[1]->type == AST_RANGE && memory->children[1]->range_valid);
|
||||
int range_left = memory->children[1]->range_left, range_right = memory->children[1]->range_right;
|
||||
int range_min = std::min(range_left, range_right), range_max = std::max(range_left, range_right);
|
||||
int range_min = min(range_left, range_right), range_max = max(range_left, range_right);
|
||||
|
||||
if (start_addr < 0)
|
||||
start_addr = range_min;
|
||||
|
@ -2720,7 +2720,7 @@ void AstNode::meminfo(int &mem_width, int &mem_size, int &addr_bits)
|
|||
|
||||
if (mem_size < 0)
|
||||
mem_size *= -1;
|
||||
mem_size += std::min(children[1]->range_left, children[1]->range_right) + 1;
|
||||
mem_size += min(children[1]->range_left, children[1]->range_right) + 1;
|
||||
|
||||
addr_bits = 1;
|
||||
while ((1 << addr_bits) < mem_size)
|
||||
|
@ -2756,8 +2756,8 @@ void AstNode::replace_variables(std::map<std::string, AstNode::varinfo_t> &varia
|
|||
if (!children.at(0)->range_valid)
|
||||
log_error("Non-constant range in %s:%d (called from %s:%d).\n",
|
||||
filename.c_str(), linenum, fcall->filename.c_str(), fcall->linenum);
|
||||
offset = std::min(children.at(0)->range_left, children.at(0)->range_right);
|
||||
width = std::min(std::abs(children.at(0)->range_left - children.at(0)->range_right) + 1, width);
|
||||
offset = min(children.at(0)->range_left, children.at(0)->range_right);
|
||||
width = min(std::abs(children.at(0)->range_left - children.at(0)->range_right) + 1, width);
|
||||
}
|
||||
offset -= variables.at(str).offset;
|
||||
std::vector<RTLIL::State> &var_bits = variables.at(str).val.bits;
|
||||
|
@ -2797,7 +2797,7 @@ AstNode *AstNode::eval_const_function(AstNode *fcall)
|
|||
log_error("Can't determine size of variable %s in %s:%d (called from %s:%d).\n",
|
||||
child->str.c_str(), child->filename.c_str(), child->linenum, fcall->filename.c_str(), fcall->linenum);
|
||||
variables[child->str].val = RTLIL::Const(RTLIL::State::Sx, abs(child->range_left - child->range_right)+1);
|
||||
variables[child->str].offset = std::min(child->range_left, child->range_right);
|
||||
variables[child->str].offset = min(child->range_left, child->range_right);
|
||||
variables[child->str].is_signed = child->is_signed;
|
||||
if (child->is_input && argidx < fcall->children.size())
|
||||
variables[child->str].val = fcall->children.at(argidx++)->bitsAsConst(variables[child->str].val.bits.size());
|
||||
|
@ -2856,7 +2856,7 @@ AstNode *AstNode::eval_const_function(AstNode *fcall)
|
|||
if (!range->range_valid)
|
||||
log_error("Non-constant range in %s:%d (called from %s:%d).\n",
|
||||
range->filename.c_str(), range->linenum, fcall->filename.c_str(), fcall->linenum);
|
||||
int offset = std::min(range->range_left, range->range_right);
|
||||
int offset = min(range->range_left, range->range_right);
|
||||
int width = std::abs(range->range_left - range->range_right) + 1;
|
||||
varinfo_t &v = variables[stmt->children.at(0)->str];
|
||||
RTLIL::Const r = stmt->children.at(1)->bitsAsConst(v.val.bits.size());
|
||||
|
|
|
@ -121,7 +121,7 @@ attr_stmt:
|
|||
|
||||
autoidx_stmt:
|
||||
TOK_AUTOIDX TOK_INT EOL {
|
||||
autoidx = std::max(autoidx, $2);
|
||||
autoidx = max(autoidx, $2);
|
||||
};
|
||||
|
||||
wire_stmt:
|
||||
|
|
|
@ -541,7 +541,7 @@ static void import_netlist(RTLIL::Design *design, Netlist *nl, std::set<Netlist*
|
|||
// log(" importing portbus %s.\n", portbus->Name());
|
||||
|
||||
RTLIL::Wire *wire = module->addWire(RTLIL::escape_id(portbus->Name()), portbus->Size());
|
||||
wire->start_offset = std::min(portbus->LeftIndex(), portbus->RightIndex());
|
||||
wire->start_offset = min(portbus->LeftIndex(), portbus->RightIndex());
|
||||
import_attributes(wire->attributes, portbus);
|
||||
|
||||
if (portbus->GetDir() == DIR_INOUT || portbus->GetDir() == DIR_IN)
|
||||
|
@ -580,11 +580,11 @@ static void import_netlist(RTLIL::Design *design, Netlist *nl, std::set<Netlist*
|
|||
int bits_in_word = number_of_bits;
|
||||
FOREACH_PORTREF_OF_NET(net, si, pr) {
|
||||
if (pr->GetInst()->Type() == OPER_READ_PORT) {
|
||||
bits_in_word = std::min<int>(bits_in_word, pr->GetInst()->OutputSize());
|
||||
bits_in_word = min<int>(bits_in_word, pr->GetInst()->OutputSize());
|
||||
continue;
|
||||
}
|
||||
if (pr->GetInst()->Type() == OPER_WRITE_PORT || pr->GetInst()->Type() == OPER_CLOCKED_WRITE_PORT) {
|
||||
bits_in_word = std::min<int>(bits_in_word, pr->GetInst()->Input2Size());
|
||||
bits_in_word = min<int>(bits_in_word, pr->GetInst()->Input2Size());
|
||||
continue;
|
||||
}
|
||||
log_error("Verific RamNet %s is connected to unsupported instance type %s (%s).\n",
|
||||
|
@ -630,7 +630,7 @@ static void import_netlist(RTLIL::Design *design, Netlist *nl, std::set<Netlist*
|
|||
|
||||
RTLIL::IdString wire_name = module->uniquify(RTLIL::escape_id(netbus->Name()));
|
||||
RTLIL::Wire *wire = module->addWire(wire_name, netbus->Size());
|
||||
wire->start_offset = std::min(netbus->LeftIndex(), netbus->RightIndex());
|
||||
wire->start_offset = min(netbus->LeftIndex(), netbus->RightIndex());
|
||||
import_attributes(wire->attributes, netbus);
|
||||
|
||||
for (int i = netbus->LeftIndex();; i += netbus->IsUp() ? +1 : -1) {
|
||||
|
@ -752,7 +752,7 @@ static void import_netlist(RTLIL::Design *design, Netlist *nl, std::set<Netlist*
|
|||
if (pr->GetPort()->Bus()) {
|
||||
port_name = pr->GetPort()->Bus()->Name();
|
||||
port_offset = pr->GetPort()->Bus()->IndexOf(pr->GetPort()) -
|
||||
std::min(pr->GetPort()->Bus()->LeftIndex(), pr->GetPort()->Bus()->RightIndex());
|
||||
min(pr->GetPort()->Bus()->LeftIndex(), pr->GetPort()->Bus()->RightIndex());
|
||||
}
|
||||
RTLIL::SigSpec conn;
|
||||
if (cell->hasPort(RTLIL::escape_id(port_name)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue