Quellcode durchsuchen

compiler improvements

Nicolas Winkler vor 5 Jahren
Ursprung
Commit
d8f888fe39

+ 1 - 1
choosegenerators.cpp

@@ -313,7 +313,7 @@ void ChooseGenerators::on_compile_clicked()
 
     const mnd::MandelDevice& dev = mndCtxt.getDevices()[0];
     try {
-        chosenGenerator = mnd::compileCl(irform, dev);
+        //chosenGenerator = mnd::compileCl(irform, dev);
     }
     catch(const std::string& msg) {
         printf("error compiling: %s", msg.c_str());

+ 2 - 1
libmandel/include/IterationIR.h

@@ -7,6 +7,7 @@
 #include <any>
 
 #include "IterationFormula.h"
+#include "Types.h"
 #include "Arena.h"
 
 namespace mnd
@@ -67,7 +68,7 @@ struct mnd::ir::NodeBase
 
 struct mnd::ir::Constant : NodeBase
 {
-    double value;
+    mnd::Real value;
     inline Constant(double val) : value{ val } {}
 };
 

+ 14 - 11
libmandel/src/IterationCompiler.cpp

@@ -70,7 +70,7 @@ namespace mnd
         }
 
         Reg operator()(const ir::Constant& c) {
-            auto constant = cc.newDoubleConst(asmjit::ConstPool::kScopeLocal, c.value);
+            auto constant = cc.newDoubleConst(asmjit::ConstPool::kScopeLocal, mnd::convert<double>(c.value));
             auto reg = cc.newXmmSd();
             cc.movsd(reg, constant);
             return reg;
@@ -222,8 +222,11 @@ namespace mnd
         comp.setArg(0, x);
         comp.setArg(1, y);
         comp.setArg(2, maxIter);
-        comp.movapd(a, x);
-        comp.movapd(b, y);
+        //comp.movapd(a, x);
+        //comp.movapd(b, y);
+
+        comp.xorpd(a, a);
+        comp.movapd(b, b);
 
         comp.xor_(k, k);
 
@@ -291,7 +294,7 @@ namespace mnd
         }
 
         std::string operator()(const ir::Constant& c) {
-            return std::to_string(c.value);
+            return std::to_string(mnd::convert<double>(c.value));
         }
 
         std::string operator()(const ir::Variable& v) {
@@ -335,7 +338,7 @@ namespace mnd
         }
 
         std::string operator()(const ir::Ln& a) {
-            return "ln("s + visitNode(*a.value) + ")";
+            return "log("s + visitNode(*a.value) + ")";
         }
     };
 
@@ -349,10 +352,10 @@ namespace mnd
 "   int index = get_global_id(0);\n"
 "   int ix = index % width;\n"
 "   int iy = index / width;\n"
-"   float a = ix * pixelScaleX + xl;\n"
-"   float b = iy * pixelScaleY + yt;\n"
-"   float x = a;\n"
-"   float y = b;\n"
+"   float a = 0;\n"
+"   float b = 0;\n"
+"   float x = ix * pixelScaleX + xl;\n"
+"   float y = iy * pixelScaleY + yt;\n"
 "\n"
 "   int n = 0;\n"
 "   while (n < max - 1) {\n";
@@ -552,8 +555,8 @@ namespace mnd
         comp.setArg(1, y);
         comp.setArg(2, maxIter);
 
-        comp.movapd(a, x);
-        comp.movapd(b, y);
+        comp.xorpd(a, a);
+        comp.movapd(b, b);
 
         comp.xor_(k, k);
 

+ 5 - 0
libmandel/src/IterationGenerator.cpp

@@ -49,6 +49,9 @@ void NaiveGenerator::generate(const mnd::MandelInfo& info, float* data)
             T cx = info.julia ? juliaX : x;
             T cy = info.julia ? juliaY : y;
             std::complex<double> z{ x, y };
+            if (!info.julia) {
+                z = 0;
+            }
             std::complex<double> c{ cx, cy };
 
             int k = 0;
@@ -94,6 +97,8 @@ std::complex<double> NaiveGenerator::calc(mnd::Expression& expr, std::complex<do
                 result = z;
             else if (ex.name == "c")
                 result = c;
+            else if (ex.name == "i")
+                result = std::complex{ 0.0, 1.0 };
         }
         else if constexpr (std::is_same<T, mnd::UnaryOperation>::value) {
             result = -calc(*ex.operand, z, c);

+ 3 - 2
libmandel/src/IterationIR.cpp

@@ -127,8 +127,9 @@ namespace mnd
             auto carg = arena.allocate(ir::Multiplication{ arg, c });
 
             auto halfd = arena.allocate(ir::Multiplication{ d, half });
+                //absSq = arena.allocate(ir::Addition{ absSq, half });
             auto lnabsSq = arena.allocate(ir::Ln{ absSq });
-            auto halfdlnabsSq = arena.allocate(ir::Multiplication{ halfd, absSq });
+            auto halfdlnabsSq = arena.allocate(ir::Multiplication{ halfd, lnabsSq });
             auto newArg = arena.allocate(ir::Addition{ halfdlnabsSq, carg });
 
             auto cosArg = arena.allocate(ir::Cos{ newArg });
@@ -156,7 +157,7 @@ std::string mnd::ir::Formula::toString(void) const
     struct ToStringVisitor
     {
         std::string operator()(const ir::Constant& c) {
-            return std::to_string(c.value);
+            return mnd::toString(c.value);
         }
 
         std::string operator()(const ir::Variable& v) {