Nicolas Winkler %!s(int64=5) %!d(string=hai) anos
pai
achega
0cf7da5813

+ 3 - 2
Almond.pro

@@ -128,14 +128,15 @@ unix|win32: LIBS += -L$FFMPEGPATH -lswscale
 
 RESOURCES += Almond.qrc
 
-unix|win32: LIBS += -L$$PWD/libmandel/ -lmandel -lqd -lasmjit -lrt
+unix|win32: LIBS += -L$$PWD/libmandel/ -lmandel -lqd -lasmjit
+unix: LIBS += -lrt
 
 INCLUDEPATH += $$PWD/libmandel/include $$PWD/libmandel/qd-2.3.22/include
 DEPENDPATH += $$PWD/libmandel/include $$PWD/libmandel/qd-2.3.22/include
 INCLUDEPATH += $$PWD/libmandel/include $$PWD/libmandel/asmjit/src
 DEPENDPATH += $$PWD/libmandel/include $$PWD/libmandel/asmjit/stc
 
-win32:!win32-g++: PRE_TARGETDEPS += $$PWD/libmandel/mandel.lib  $$PWD/libmandel/qd.lib
+win32:!win32-g++: PRE_TARGETDEPS += $$PWD/libmandel/asmjit.lib $$PWD/libmandel/mandel.lib $$PWD/libmandel/qd.lib
 else:unix|win32-g++: PRE_TARGETDEPS += $$PWD/libmandel/libmandel.a $$PWD/libmandel/libqd.a $$PWD/libmandel/libasmjit.a
 
 

+ 1 - 1
MandelWidget.cpp

@@ -14,7 +14,7 @@ Texture::Texture(const Bitmap<RGBColor>& bitmap, GLint param)
     glGenTextures(1, &id);
     glBindTexture(GL_TEXTURE_2D, id);
 
-    int lineLength = (bitmap.width * 3 + 3) & ~3;
+    //int lineLength = (bitmap.width * 3 + 3) & ~3;
 
     /*std::unique_ptr<unsigned char[]> pixels = std::make_unique<unsigned char[]>(lineLength * bitmap.height);
     for (int i = 0; i < bitmap.width; i++) {

+ 15 - 1
choosegenerators.cpp

@@ -297,5 +297,19 @@ void ChooseGenerators::on_compile_clicked()
     QString formula = this->ui->formula->text();
     mnd::IterationFormula itf{ mnd::parse(formula.toStdString()) };
     //chosenGenerator = std::make_unique<mnd::NaiveGenerator>(std::move(itf), mnd::getPrecision<double>());
-    chosenGenerator = std::make_unique<mnd::CompiledGenerator>(mndCtxt);
+    auto cg = std::make_unique<mnd::CompiledGenerator>(mndCtxt);
+    std::string asmCode = cg->dump();
+    printf("%s\n", asmCode.c_str()); fflush(stdout);
+    chosenGenerator = std::move(cg);
 }
+
+void ChooseGenerators::on_benchmark_clicked()
+{
+    if (!chosenGenerator)
+        return;
+    Benchmarker bm(mndCtxt, *chosenGenerator, 0, 0.0f);
+    double mips = bm.benchmarkResult(*chosenGenerator);
+    this->ui->compBenchResult->setText(QString::number(mips));
+}
+
+

+ 1 - 0
choosegenerators.h

@@ -85,6 +85,7 @@ private slots:
     void on_run_clicked();
     void on_generatorTable_cellDoubleClicked(int row, int column);
     void on_compile_clicked();
+    void on_benchmark_clicked();
 };
 
 #endif // CHOOSEGENERATORS_H

+ 10 - 0
choosegenerators.ui

@@ -46,6 +46,16 @@
                  </property>
                 </widget>
                </item>
+               <item row="1" column="0">
+                <widget class="QPushButton" name="benchmark">
+                 <property name="text">
+                  <string>Benchmark</string>
+                 </property>
+                </widget>
+               </item>
+               <item row="1" column="1">
+                <widget class="QLineEdit" name="compBenchResult"/>
+               </item>
               </layout>
              </item>
              <item>

+ 3 - 0
libmandel/CMakeLists.txt

@@ -51,7 +51,10 @@ target_include_directories(qd PUBLIC qd-2.3.22/include qd-2.3.22)
 
 FILE(GLOB AsmjitSources asmjit/src/asmjit/*/*.cpp)
 add_library(asmjit STATIC ${AsmjitSources})
+
 target_include_directories(asmjit PUBLIC asmjit/src)
+target_compile_definitions(asmjit PUBLIC NOMINMAX)
+target_compile_definitions(asmjit PUBLIC ASMJIT_STATIC)
 
 #target_include_directories(mandel PUBLI#C qd-2.3.22/include)
 #target_include_directories(mandel PUBLI#C qd-2.3.22/include)

+ 3 - 3
libmandel/include/Fixed.h

@@ -19,7 +19,7 @@
 
 namespace mnd
 {
-#ifdef _MSC_VER
+#if defined(_MSC_VER) && defined(_WIN64)
     static inline std::pair<int64_t, uint64_t> mul64(int64_t a, int64_t b) {
         int64_t higher;
         int64_t lower = _mul128(a, b, &higher);
@@ -527,7 +527,7 @@ struct Fixed64
 
     inline Fixed64(double x)
     {
-        bits = x * (1LL << 48);
+        bits = int64_t(x * (1LL << 48));
     }
 
     inline operator float(void) const {
@@ -643,7 +643,7 @@ struct Fixed32
     ~Fixed32() = default;
 
 
-    inline Fixed32(int32_t bits, bool dummy) :
+    inline Fixed32(int32_t bits, bool) :
         bits{ bits }
     {
     }

+ 2 - 0
libmandel/include/IterationCompiler.h

@@ -21,6 +21,8 @@ public:
     CompiledGenerator(MandelContext& mndContext);
     virtual ~CompiledGenerator(void);
     virtual void generate(const MandelInfo& info, float* data);
+
+    std::string dump(void) const;
 };
 
 

+ 1 - 0
libmandel/include/IterationFormula.h

@@ -4,6 +4,7 @@
 #include <variant>
 #include <memory>
 #include <string>
+#include <stdexcept>
 
 namespace mnd
 {

+ 38 - 8
libmandel/src/IterationCompiler.cpp

@@ -46,6 +46,27 @@ CompiledGenerator::CompiledGenerator(mnd::MandelContext& mndContext) :
 CompiledGenerator::~CompiledGenerator(void)
 {
 }
+__declspec(noinline)
+int iter(double x, double y, int maxIter)
+{
+    int k = 0;
+
+    double a = x;
+    double b = y;
+
+    for (k = 0; k < maxIter; k++) {
+        double aa = a * a;
+        double bb = b * b;
+        double abab = a * b + a * b;
+        a = aa - bb + x;
+        b = abab + y;
+        if (aa + bb >= 16)
+            break;
+    }
+
+    return k;
+}
+
 
 
 void CompiledGenerator::generate(const mnd::MandelInfo& info, float* data)
@@ -62,6 +83,17 @@ void CompiledGenerator::generate(const mnd::MandelInfo& info, float* data)
     }
 }
 
+
+
+
+std::string CompiledGenerator::dump(void) const
+{
+    asmjit::String d;
+    execData->compiler->dump(d);
+    return d.data();
+}
+
+
 using namespace asmjit;
 
 struct Visitor
@@ -94,6 +126,7 @@ namespace mnd
         x86::Xmm b = comp.newXmmSd();
         x86::Xmm aa = comp.newXmmSd();
         x86::Xmm bb = comp.newXmmSd();
+        x86::Xmm t = comp.newXmmSd();
         x86::Xmm sumSq = comp.newXmmSd();
 
         comp.addFunc(FuncSignatureT<int, double, double, int>(CallConv::kIdHost));
@@ -108,21 +141,18 @@ namespace mnd
 
         comp.bind(startLoop);
         comp.movapd(aa, a);
+        comp.movapd(bb, b);
         comp.mulsd(aa, a);
-        comp.movsd(bb, b);
         comp.mulsd(bb, b);
-
+        comp.mulsd(b, a);
         comp.movapd(sumSq, aa);
         comp.addsd(sumSq, bb);
-        comp.comisd(sumSq, sixteen);
-        comp.jle(endLoop);
-
-        comp.subsd(aa, bb);
-        comp.mulsd(b, a);
         comp.addsd(b, b);
-
         comp.addsd(aa, x);
+        comp.comisd(sumSq, sixteen);
         comp.addsd(b, y);
+        comp.subsd(aa, bb);
+        comp.jle(endLoop);
         comp.movapd(a, aa);
 
         comp.inc(k);