]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
const folding for division
authorWolfgang (Blub) Bumiller <blub@speed.at>
Tue, 14 Aug 2012 21:43:08 +0000 (23:43 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Tue, 14 Aug 2012 21:43:08 +0000 (23:43 +0200)
parser.c

index 9887978771faf9f8f6488f1203668b87d91efb6b..4b09b4546ba2c917b2ad97ec386621a22f510913 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -608,7 +608,11 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy)
                            type_name[exprs[1]->expression.vtype]);
                 return false;
             }
-            out = (ast_expression*)ast_binary_new(ctx, INSTR_DIV_F, exprs[0], exprs[1]);
+            if (CanConstFold(exprs[0], exprs[1]))
+                out = (ast_expression*)parser_const_float(parser,
+                    asvalue[0]->constval.vfloat / asvalue[1]->constval.vfloat);
+            else
+                out = (ast_expression*)ast_binary_new(ctx, INSTR_DIV_F, exprs[0], exprs[1]);
             break;
         case opid1('%'):
         case opid2('%','='):