Use undef (x/z vs. NaN) rules for real values from IEEE Std 1800-2012
authorClifford Wolf <clifford@clifford.at>
Mon, 16 Jun 2014 13:05:37 +0000 (15:05 +0200)
committerClifford Wolf <clifford@clifford.at>
Mon, 16 Jun 2014 13:05:37 +0000 (15:05 +0200)
frontends/ast/ast.cc
frontends/ast/simplify.cc

index 967111d306333ffa760352d2f9fb38cd3847d4f5..3f704bea4fabf40b5081304fd3a2e6ca935375f4 100644 (file)
@@ -783,6 +783,8 @@ double AstNode::asReal(bool is_signed)
 
                double v = 0;
                for (size_t i = 0; i < val.bits.size(); i++)
+                       // IEEE Std 1800-2012 Par 6.12.2: Individual bits that are x or z in
+                       // the net or the variable shall be treated as zero upon conversion.
                        if (val.bits.at(i) == RTLIL::State::S1)
                                v += exp2(i);
                if (is_negative)
index 80fd28d55db6bba0cd05987cdb4992e3cec9a9be..3f712510b9df233a672c837b9723a5fbe8653349 100644 (file)
@@ -1625,6 +1625,15 @@ skip_dynamic_range_lvalue_expansion:;
                                                if (a.bits[i] != b.bits[i])
                                                        a.bits[i] = RTLIL::State::Sx;
                                        newNode = mkconst_bits(a.bits, sign_hint);
+                               } else if (children[1]->isConst() && children[2]->isConst()) {
+                                       newNode = new AstNode(AST_REALVALUE);
+                                       if (children[1]->asReal(sign_hint) == children[2]->asReal(sign_hint))
+                                               newNode->realvalue = children[1]->asReal(sign_hint);
+                                       else
+                                               // IEEE Std 1800-2012 Sec. 11.4.11 states that the entry in Table 7-1 for
+                                               // the data type in question should be returned if the ?: is ambiguous. The
+                                               // value in Table 7-1 for the 'real' type is 0.0.
+                                               newNode->realvalue = 0.0;
                                }
                        }
                        break;