Improved handling of relational op of real values
authorClifford Wolf <clifford@clifford.at>
Tue, 17 Jun 2014 10:47:51 +0000 (12:47 +0200)
committerClifford Wolf <clifford@clifford.at>
Tue, 17 Jun 2014 10:47:51 +0000 (12:47 +0200)
frontends/ast/simplify.cc
tests/realmath/generate.py

index 7be287d196903616b730d020174e5b1008f1017b..7a98e2712836ccbf9a34f340ca6f5db3f2f4a140 100644 (file)
@@ -1538,15 +1538,16 @@ skip_dynamic_range_lvalue_expansion:;
                                newNode = mkconst_bits(y.bits, false);
                        } else
                        if (children[0]->isConst() && children[1]->isConst()) {
+                               bool cmp_signed = (children[0]->type == AST_REALVALUE || children[0]->is_signed) && (children[1]->type == AST_REALVALUE || children[1]->is_signed);
                                switch (type) {
-                               case AST_LT:  newNode = mkconst_int(children[0]->asReal(sign_hint) <  children[1]->asReal(sign_hint), false, 1); break;
-                               case AST_LE:  newNode = mkconst_int(children[0]->asReal(sign_hint) <= children[1]->asReal(sign_hint), false, 1); break;
-                               case AST_EQ:  newNode = mkconst_int(children[0]->asReal(sign_hint) == children[1]->asReal(sign_hint), false, 1); break;
-                               case AST_NE:  newNode = mkconst_int(children[0]->asReal(sign_hint) != children[1]->asReal(sign_hint), false, 1); break;
-                               case AST_EQX: newNode = mkconst_int(children[0]->asReal(sign_hint) == children[1]->asReal(sign_hint), false, 1); break;
-                               case AST_NEX: newNode = mkconst_int(children[0]->asReal(sign_hint) != children[1]->asReal(sign_hint), false, 1); break;
-                               case AST_GE:  newNode = mkconst_int(children[0]->asReal(sign_hint) >= children[1]->asReal(sign_hint), false, 1); break;
-                               case AST_GT:  newNode = mkconst_int(children[0]->asReal(sign_hint) >  children[1]->asReal(sign_hint), false, 1); break;
+                               case AST_LT:  newNode = mkconst_int(children[0]->asReal(cmp_signed) <  children[1]->asReal(cmp_signed), false, 1); break;
+                               case AST_LE:  newNode = mkconst_int(children[0]->asReal(cmp_signed) <= children[1]->asReal(cmp_signed), false, 1); break;
+                               case AST_EQ:  newNode = mkconst_int(children[0]->asReal(cmp_signed) == children[1]->asReal(cmp_signed), false, 1); break;
+                               case AST_NE:  newNode = mkconst_int(children[0]->asReal(cmp_signed) != children[1]->asReal(cmp_signed), false, 1); break;
+                               case AST_EQX: newNode = mkconst_int(children[0]->asReal(cmp_signed) == children[1]->asReal(cmp_signed), false, 1); break;
+                               case AST_NEX: newNode = mkconst_int(children[0]->asReal(cmp_signed) != children[1]->asReal(cmp_signed), false, 1); break;
+                               case AST_GE:  newNode = mkconst_int(children[0]->asReal(cmp_signed) >= children[1]->asReal(cmp_signed), false, 1); break;
+                               case AST_GT:  newNode = mkconst_int(children[0]->asReal(cmp_signed) >  children[1]->asReal(cmp_signed), false, 1); break;
                                default: log_abort();
                                }
                        }
index 9e48755c54374aa8e163532a4fb9a500b695f594..53015381e721377b60f07ec2f4f4f9de61ab2d49 100644 (file)
@@ -43,11 +43,15 @@ for idx in range(100):
     with file('temp/uut_%05d.v' % idx, 'w') as f, redirect_stdout(f):
         print('module uut_%05d(output [63:0] %s);\n' % (idx, ', '.join(['y%02d' % i for i in range(100)])))
         for i in range(30):
-            print('localparam p%02d = %s;' % (i, random_expression()))
-            # print('localparam%s p%02d = %s;' % (random.choice(['', ' real', ' integer']), i, random_expression()))
+            if idx < 10 or True:
+                print('localparam p%02d = %s;' % (i, random_expression()))
+            else:
+                print('localparam%s p%02d = %s;' % (random.choice(['', ' real', ' integer']), i, random_expression()))
         for i in range(30, 60):
-            print('localparam p%02d = %s;' % (i, random_expression(maxparam = 30)))
-            # print('localparam%s p%02d = %s;' % (random.choice(['', ' real', ' integer']), i, random_expression(maxparam = 30)))
+            if idx < 10 or True:
+                print('localparam p%02d = %s;' % (i, random_expression(maxparam = 30)))
+            else:
+                print('localparam%s p%02d = %s;' % (random.choice(['', ' real', ' integer']), i, random_expression(maxparam = 30)))
         for i in range(100):
             print('assign y%02d = 65536 * (%s);' % (i, random_expression(maxparam = 60)))
         print('endmodule')