compile performance benchmark works compile-performance-test
authorJacob Lifshay <programmerjake@gmail.com>
Sun, 11 Jun 2017 11:37:26 +0000 (04:37 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Sun, 11 Jun 2017 11:37:26 +0000 (04:37 -0700)
.gitignore
Makefile [new file with mode: 0644]
shader.cpp

index f7d2a05229ccf93bc0d35c04010f23f445141a9b..4459f9bcb35bdd964db2f7ead36eec0ae69f234e 100644 (file)
@@ -1,2 +1,3 @@
 shader.bc
 shader.o
+shader.ll
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..ec66fef
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,17 @@
+.PHONY: all always_build clean
+
+all: shader.o
+
+always_build:
+
+INITIAL_OPT := -inline -mem2reg -sccp -dce -simplifycfg
+
+shader.bc: shader.cpp
+       clang++ -std=c++14 -march=corei7 -Wall -o shader.ll shader.cpp -emit-llvm -S && opt $(INITIAL_OPT) shader.ll > shader.bc && llvm-dis shader.bc
+
+shader.o: shader.bc always_build
+       time -p bash -c 'for i in {1..10}; do echo $$i; opt -O3 < shader.bc | llc -filetype=obj -O3 -o shader.o; done'
+
+clean:
+       rm -f shader.bc shader.o shader.ll
+
index 0e932061ca97bef49e7b3b619dafbadf902ed6dc..573d470f1d6225adae7eeed908b5127899d0454b 100644 (file)
@@ -1,8 +1,61 @@
+#ifndef RECURSIVE_INVOCATION
+#define UNIQUEIFY3(v, c) v ## _ ## c
+#define UNIQUEIFY2(v, c) UNIQUEIFY3(v, c)
+#define UNIQUEIFY(v) UNIQUEIFY2(v, __COUNTER__)
+// following is code to include the body of this file pow(2, 7) times
+#define RECURSIVE_INVOCATION 1
+#include "shader.cpp"
+#undef RECURSIVE_INVOCATION
+#define RECURSIVE_INVOCATION 1
+#include "shader.cpp"
+#elif RECURSIVE_INVOCATION == 1
+#undef RECURSIVE_INVOCATION
+#define RECURSIVE_INVOCATION 2
+#include "shader.cpp"
+#undef RECURSIVE_INVOCATION
+#define RECURSIVE_INVOCATION 2
+#include "shader.cpp"
+#elif RECURSIVE_INVOCATION == 2
+#undef RECURSIVE_INVOCATION
+#define RECURSIVE_INVOCATION 3
+#include "shader.cpp"
+#undef RECURSIVE_INVOCATION
+#define RECURSIVE_INVOCATION 3
+#include "shader.cpp"
+#elif RECURSIVE_INVOCATION == 3
+#undef RECURSIVE_INVOCATION
+#define RECURSIVE_INVOCATION 4
+#include "shader.cpp"
+#undef RECURSIVE_INVOCATION
+#define RECURSIVE_INVOCATION 4
+#include "shader.cpp"
+#elif RECURSIVE_INVOCATION == 4
+#undef RECURSIVE_INVOCATION
+#define RECURSIVE_INVOCATION 5
+#include "shader.cpp"
+#undef RECURSIVE_INVOCATION
+#define RECURSIVE_INVOCATION 5
+#include "shader.cpp"
+#elif RECURSIVE_INVOCATION == 5
+#undef RECURSIVE_INVOCATION
+#define RECURSIVE_INVOCATION 6
+#include "shader.cpp"
+#undef RECURSIVE_INVOCATION
+#define RECURSIVE_INVOCATION 6
+#include "shader.cpp"
+#elif RECURSIVE_INVOCATION == 6
+#undef RECURSIVE_INVOCATION
+#define RECURSIVE_INVOCATION 7
+#include "shader.cpp"
+#undef RECURSIVE_INVOCATION
+#define RECURSIVE_INVOCATION 7
+#include "shader.cpp"
+#elif RECURSIVE_INVOCATION == 7
 #include <cstdint>
 #include <cmath>
 #include <limits>
 
-namespace shader
+namespace UNIQUEIFY(shader)
 {
 constexpr float max(float a, float b) noexcept
 {
@@ -540,7 +593,7 @@ static void loop(int i,
     SHb += DirToSh(RSM_to_RH_dir, color.b());
 }
 
-extern "C" void shader_main(void) noexcept
+void shader_main(void) noexcept
 {
     vec3 normalizedRHCenter = 2.f * vec3(gl_FragCoord.xy(), slice) / resolution - 1.f;
     vec3 RHcenter = (RHMatrix * vec4(normalizedRHCenter * extents, 1.f)).xyz();
@@ -555,8 +608,8 @@ extern "C" void shader_main(void) noexcept
     vec4  SHg = vec4(0.f);
     vec4  SHb = vec4(0.f);
 
-    int x = int(gl_FragCoord.x), y = int(gl_FragCoord.y);
-    float phi = 30.f * (x ^ y) + 10.f * x * y;
+    //int x = int(gl_FragCoord.x), y = int(gl_FragCoord.y);
+    //float phi = 30.f * (x ^ y) + 10.f * x * y;
 
     loop(0, RHcenter, RHCellSize, RHuv, RHdepth, SHr, SHg, SHb);
     loop(1, RHcenter, RHCellSize, RHuv, RHdepth, SHr, SHg, SHb);
@@ -584,3 +637,4 @@ extern "C" void shader_main(void) noexcept
     SHBlue = SHb;
 }
 }
+#endif