3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-13 04:28:18 +00:00

Improved ternary support for real values

This commit is contained in:
Clifford Wolf 2014-06-16 15:12:24 +02:00
parent 82bbd2f077
commit 6c17d4f242

View file

@ -1588,31 +1588,42 @@ skip_dynamic_range_lvalue_expansion:;
} }
break; break;
case AST_TERNARY: case AST_TERNARY:
if (children[0]->isConst()) { if (children[0]->isConst())
{
bool found_sure_true = false; bool found_sure_true = false;
bool found_maybe_true = false; bool found_maybe_true = false;
if (children[0]->type == AST_CONSTANT) {
if (children[0]->type == AST_CONSTANT)
for (auto &bit : children[0]->bits) { for (auto &bit : children[0]->bits) {
if (bit == RTLIL::State::S1) if (bit == RTLIL::State::S1)
found_sure_true = true; found_sure_true = true;
if (bit > RTLIL::State::S1) if (bit > RTLIL::State::S1)
found_maybe_true = true; found_maybe_true = true;
} }
} else { else
found_sure_true = children[0]->asReal(false) != 0; found_sure_true = children[0]->asReal(sign_hint) != 0;
}
AstNode *choice = NULL; AstNode *choice = NULL, *not_choice = NULL;
if (found_sure_true) if (found_sure_true)
choice = children[1]; choice = children[1], not_choice = children[2];
else if (!found_maybe_true) else if (!found_maybe_true)
choice = children[2]; choice = children[2], not_choice = children[1];
if (choice != NULL) { if (choice != NULL) {
if (choice->type == AST_CONSTANT) { if (choice->type == AST_CONSTANT) {
RTLIL::Const y = choice->bitsAsConst(width_hint, sign_hint); int other_width_hint = width_hint;
if (choice->is_string && y.bits.size() % 8 == 0 && sign_hint == false) bool other_sign_hint = sign_hint, other_real = false;
newNode = mkconst_str(y.bits); not_choice->detectSignWidth(other_width_hint, other_sign_hint, &other_real);
else if (other_real) {
newNode = mkconst_bits(y.bits, sign_hint); newNode = new AstNode(AST_REALVALUE);
newNode->realvalue = choice->asReal(sign_hint);
} else {
RTLIL::Const y = choice->bitsAsConst(width_hint, sign_hint);
if (choice->is_string && y.bits.size() % 8 == 0 && sign_hint == false)
newNode = mkconst_str(y.bits);
else
newNode = mkconst_bits(y.bits, sign_hint);
}
} else } else
if (choice->isConst()) { if (choice->isConst()) {
newNode = choice->clone(); newNode = choice->clone();