Browse Source

fixed unary minus problems

Nicolas Winkler 5 years ago
parent
commit
4725bd30ec
3 changed files with 13 additions and 9 deletions
  1. 5 3
      choosegenerators.cpp
  2. 5 5
      libmandel/src/IterationFormula.cpp
  3. 3 1
      libmandel/src/IterationIR.cpp

+ 5 - 3
choosegenerators.cpp

@@ -45,7 +45,7 @@ static std::vector<mnd::MandelInfo> createBenches()
 }
 
 
-const std::vector<mnd::MandelInfo> Benchmarker::benches = createBenches(); /*{
+const std::vector<mnd::MandelInfo> Benchmarker::benches = {
     mnd::MandelInfo{ benchViewport(), 32, 32, 15, false },
     mnd::MandelInfo{ benchViewport(), 32, 32, 25, false },
     mnd::MandelInfo{ benchViewport(), 32, 32, 75, false },
@@ -85,7 +85,7 @@ const std::vector<mnd::MandelInfo> Benchmarker::benches = createBenches(); /*{
     mnd::MandelInfo{ benchViewport(), 2048, 2048, 524288000, false },
     mnd::MandelInfo{ benchViewport(), 2048, 2048, 1048576000, false },
     mnd::MandelInfo{ benchViewport(), 2048, 2048, 2097152000, false },
-};*/
+};
 
 
 Benchmarker::~Benchmarker(void)
@@ -123,7 +123,7 @@ double Benchmarker::benchmarkResult(mnd::MandelGenerator& mg) const
             testIndex = i + 4;
             printf("testing index for generator %s: %d\n", (mnd::toString(mg.getType()) + ", " + mnd::toString(mg.getExtension())).c_str(), testIndex);
             printf("    w: %d, h: %d, iter: %d\n", benches[testIndex].bWidth, benches[testIndex].bHeight, benches[testIndex].maxIter);
-            fflush(stdout);fflush(stdout);fflush(stdout);fflush(stdout);fflush(stdout);fflush(stdout);fflush(stdout);
+            fflush(stdout);
             break;
         }
         else if (time < std::chrono::milliseconds(10)) {
@@ -139,6 +139,8 @@ double Benchmarker::benchmarkResult(mnd::MandelGenerator& mg) const
             return &bmp;
         });
 
+        printf("%lld iterations in %lld microseconds\n\n", iters, time.count() / 1000);
+
         return double(iters) / time.count() * 1000;
     }
     catch(const std::string& c) {

+ 5 - 5
libmandel/src/IterationFormula.cpp

@@ -273,7 +273,7 @@ public:
             }
             else if (token == "+" || token == "-") {
                 if (expectingBinaryOperator) {
-                    while (!operators.empty() && getTopPrecedence() > 3) {
+                    while (!operators.empty() && getTopPrecedence() >= 1) {
                         popOperator();
                     }
                     operators.push(token[0]);
@@ -325,9 +325,10 @@ public:
             throw ParseError("error parsing expression");
         }
         char top = operators.top();
+        operators.pop();
 
         if (output.size() < 1) {
-            throw ParseError("not enough operands for unary operator '-'");
+            throw ParseError("not enough operands");
         }
 
 
@@ -343,7 +344,6 @@ public:
         if (output.size() < 2) {
             throw ParseError(std::string("not enough operands for operator '") + top + "'");
         }
-        operators.pop();
         mnd::Expression& left = output.at(output.size() - 2);
         mnd::Expression& right = output.at(output.size() - 1);
         mnd::Expression newExpr = mnd::Constant{ 0.0 };
@@ -387,11 +387,11 @@ public:
 
     int getPrecedence(char op) const {
         char t = op;
-        if (t == '+' || t == '-') // 'm' == unary minus
+        if (t == '+' || t == '-')
             return 1;
         else if (t == '*' || t == '/')
             return 2;
-        else if (t == '^' || t == 'm')
+        else if (t == '^' || t == 'm') // 'm' == unary minus
             return 3;
         return 0;
     }

+ 3 - 1
libmandel/src/IterationIR.cpp

@@ -410,11 +410,13 @@ struct ConstantPropagator
     void propagateConstants(void) {
         visitNode(formula.newA);
         visitNode(formula.newB);
+        visitNode(formula.newA);
+        visitNode(formula.newB);
     }
 
     bool hasBeenVisited(Node* n) {
         return std::visit([] (auto& x) {
-            if (auto* b = std::any_cast<bool>(&x.nodeData))
+            if (auto* b = std::any_cast<bool>(x.nodeData))
                 return *b;
             else
                 return false;