Nicolas Winkler 5 년 전
부모
커밋
1348680002
4개의 변경된 파일74개의 추가작업 그리고 9개의 파일을 삭제
  1. 40 4
      libmandel/include/IterationFormula.h
  2. 1 0
      libmandel/include/IterationGenerator.h
  3. 30 0
      libmandel/src/opencl/double.cl
  4. 3 5
      libmandel/src/opencl/fixed64.cl

+ 40 - 4
libmandel/include/IterationFormula.h

@@ -6,6 +6,11 @@ namespace mnd
 {
     struct IterationFormula;
 
+    struct Expression;
+    struct Constant;
+    struct Variable;
+    struct UnaryOperation;
+    struct BinaryOperation;
     struct Addition;
     struct Multiplication;
     struct Division;
@@ -15,26 +20,57 @@ namespace mnd
 
 struct mnd::IterationFormula
 {
+    std::unique_ptr<Expression> expr;
 };
 
 
-struct mnd::Addition : IterationFormula
+struct mnd::Expression
+{
+};
+
+
+struct mnd::Constant : mnd::Expression
+{
+    double value;
+};
+
+
+struct mnd::Variable : mnd::Expression
+{
+    std::string name;
+};
+
+
+struct mnd::UnaryOperation : mnd::Expression
+{
+    std::unique_ptr<Expression> operand;
+};
+
+
+struct mnd::BinaryOperation : mnd::Expression
+{
+    std::unique_ptr<Expression> left;
+    std::unique_ptr<Expression> right;
+};
+
+
+struct mnd::Addition : mnd::BinaryOperation
 {
     bool subtraction = false;
 };
 
 
-struct mnd::Multiplication : IterationFormula
+struct mnd::Multiplication : mnd::BinaryOperation 
 {
 };
 
 
-struct mnd::Division : IterationFormula
+struct mnd::Division : mnd::BinaryOperation 
 {
 };
 
 
-struct mnd::Pow : IterationFormula
+struct mnd::Pow : mnd::BinaryOperation 
 {
 };
 

+ 1 - 0
libmandel/include/IterationGenerator.h

@@ -2,6 +2,7 @@
 #define MANDEL_ITERATIONGENERATOR_H
 
 #include "Generators.h"
+#include "IterationFormula.h"
 
 
 namespace mnd

+ 30 - 0
libmandel/src/opencl/double.cl

@@ -0,0 +1,30 @@
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n"
+__kernel void iterate(__global float* A, const int width, double xl, double yt, double pixelScaleX, double pixelScaleY, int max, int smooth) {\n"
+   int index = get_global_id(0);\n"
+   int x = index % width;"
+   int y = index / width;"
+   double a = x * pixelScaleX + xl;"
+   double b = y * pixelScaleY + yt;"
+   double ca = a;"
+   double cb = b;"
+"
+   int n = 0;"
+   while (n < max - 1) {"
+       double aa = a * a;"
+       double bb = b * b;"
+       double ab = a * b;"
+       if (aa + bb > 16) break;"
+       a = aa - bb + ca;"
+       b = ab + ab + cb;"
+       n++;"
+   }\n"
+// N + 1 - log (log  |Z(N)|) / log 2
+   if (n >= max - 1)\n"
+       A[index] = max;\n"
+   else {"
+       if (smooth != 0)\n"
+           A[index] = ((float)n) + 1 - log(log((float)(a * a + b * b)) / 2) / log(2.0f);\n"
+       else\n"
+           A[index] = ((float)n);\n"
+   }"
+}";

+ 3 - 5
libmandel/src/opencl/fixed64.cl

@@ -1,5 +1,3 @@
-
-
 long mul(long a, long b) {
     long upper = mul_hi(a, b);
     long lower = a * b;
@@ -8,7 +6,7 @@ long mul(long a, long b) {
 
 
 __kernel void iterate(__global float* A, const int width,
-                      ulong x, ulong y, ulong pw, ulong ph, int max, int smooth) {
+                      ulong x, ulong y, ulong pw, ulong ph, int max, int smooth, int julia, ulong juliaX, ulong juliaY) {
     int index = get_global_id(0);
     long px = (index % width);
     long py = (index / width);
@@ -20,8 +18,8 @@ __kernel void iterate(__global float* A, const int width,
 
     long a = xl + pixelScaleX * px; // pixelScaleX * px + xl
     long b = yt + pixelScaleY * py; // pixelScaleY * py + yt
-    long ca = a;
-    long cb = b;
+    long ca = julia ? juliaX : a;
+    long cb = julia ? juliaY : b;
 
     int n = 0;
     while (n < max - 1) {