diff options
author | Jannis Harder <me@jix.one> | 2022-05-31 15:56:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-31 15:56:36 +0200 |
commit | 01cb02c81df14762cce117a823af742ed044a5c4 (patch) | |
tree | e766145cefa1dc2acf65be28fc0f12e9d0c51e49 /frontends/ast/genrtlil.cc | |
parent | a79a228c2ba3259a1d8783f69990acd10e0efb5a (diff) | |
parent | a650d9079fa4732a6d118f2764d5abc2522a6b37 (diff) | |
download | yosys-01cb02c81df14762cce117a823af742ed044a5c4.tar.gz yosys-01cb02c81df14762cce117a823af742ed044a5c4.tar.bz2 yosys-01cb02c81df14762cce117a823af742ed044a5c4.zip |
Merge pull request #3348 from zachjs/func-tern-hint
verilog: fix width/sign detection for functions
Diffstat (limited to 'frontends/ast/genrtlil.cc')
-rw-r--r-- | frontends/ast/genrtlil.cc | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/frontends/ast/genrtlil.cc b/frontends/ast/genrtlil.cc index a569c5ae2..d81c53dfb 100644 --- a/frontends/ast/genrtlil.cc +++ b/frontends/ast/genrtlil.cc @@ -1095,8 +1095,9 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun if (current_scope.count(str)) { // This width detection is needed for function calls which are - // unelaborated, which currently only applies to calls to recursive - // functions reached by unevaluated ternary branches. + // unelaborated, which currently applies to calls to functions + // reached via unevaluated ternary branches or used in case or case + // item expressions. const AstNode *func = current_scope.at(str); if (func->type != AST_FUNCTION) log_file_error(filename, location.first_line, "Function call to %s resolved to something that isn't a function!\n", RTLIL::unescape_id(str).c_str()); @@ -1107,8 +1108,8 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun break; } log_assert(wire && wire->type == AST_WIRE); - sign_hint = wire->is_signed; - width_hint = 1; + sign_hint &= wire->is_signed; + int result_width = 1; if (!wire->children.empty()) { log_assert(wire->children.size() == 1); @@ -1121,10 +1122,11 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun if (left->type != AST_CONSTANT || right->type != AST_CONSTANT) log_file_error(filename, location.first_line, "Function %s has non-constant width!", RTLIL::unescape_id(str).c_str()); - width_hint = abs(int(left->asInt(true) - right->asInt(true))); + result_width = abs(int(left->asInt(true) - right->asInt(true))); delete left; delete right; } + width_hint = max(width_hint, result_width); break; } YS_FALLTHROUGH |