Selaa lähdekoodia

bench with gcc

Nicolas Cannasse 10 vuotta sitten
vanhempi
commit
ef1c55482f
9 muutettua tiedostoa jossa 76 lisäystä ja 51 poistoa
  1. 2 6
      .gitignore
  2. 67 45
      bench/Bench.hx
  3. 1 0
      bench/ffib/main.c
  4. 1 0
      bench/ffib/out.txt
  5. 1 0
      bench/fib/main.c
  6. 1 0
      bench/fib/out.txt
  7. 1 0
      bench/ofib/main.c
  8. 1 0
      bench/ofib/out.txt
  9. 1 0
      src/jit.c

+ 2 - 6
.gitignore

@@ -1,18 +1,14 @@
 /Debug
-
 *.opensdf
-
 *.sdf
-
 *.suo
 *.ipch
-
 *.filters
-
 *.user
 Release
 x64
 /bench/Bench.n
-/bench/main.exe
 /bench/main.hl
 *.obj
+/bench/*.exe
+/bench/*.dll

+ 67 - 45
bench/Bench.hx

@@ -2,8 +2,8 @@ class Bench {
 
 	static var BENCH_COUNT = 2;
 
-	static function bestTime( cmd : String, args : Array<String> ) {
-		var out = null, bestTime = 1e9;
+	static function bestTime( cmd : String, args : Array<String>, out ) {
+		var bestTime = 1e9;
 		var targs = args.copy();
 		targs.unshift("./"+cmd);
 		targs.unshift("%e");
@@ -18,15 +18,12 @@ class Bench {
 			}
 			var o = StringTools.trim(p.stdout.readAll().toString());
 			var t = Std.parseFloat(p.stderr.readAll().toString());
-			if( out == null ) {
-				out = o;
-				bestTime = t;
-			} else {
-				if( out != o )
-					Sys.println("Varying output " + o + " != " + out);
-				if( t < bestTime )
-					bestTime = t;
+			if( out != o ) {
+				Sys.println("Bad ouput : " + o + " should be " + out);
+				return null;
 			}
+			if( t < bestTime )
+				bestTime = t;
 			p.close();
 		}
 		return { t : bestTime, out : out };
@@ -36,35 +33,64 @@ class Bench {
 		var count = 0;
 		for( f in sys.FileSystem.readDirectory(".") ) {
 			if( !sys.FileSystem.isDirectory(f) ) continue;
-			if( !sys.FileSystem.exists(f + "/main.c") || !sys.FileSystem.exists(f + "/Main.hx") ) continue;
+			if( !sys.FileSystem.exists(f + "/out.txt") || !sys.FileSystem.exists(f + "/Main.hx") ) continue;
 			Sys.println(f);
+			
+			var out = StringTools.trim(sys.io.File.getContent(f+"/out.txt"));
+			var c32 = null, c64 = null;
 
-			// C32
-			var p = new sys.io.Process("cl.exe", ["/nologo", "/Ot", "/arch:SSE2", "/fp:fast", f + "/main.c"]);
-			var code = p.exitCode();
-			if( code != 0 ) {
-				Sys.println("C32 Compilation failed with code " + code);
-				continue;
-			}
-			var c32 = bestTime("main.exe", []);
-			if( c32 == null ) continue;
-			Sys.println("  C-32 " + c32.t);
+			if( sys.FileSystem.exists(f+"/main.c") ) {
+				// MSVC32
+				var p = new sys.io.Process("cl.exe", ["/nologo", "/Ot", "/arch:SSE2", "/fp:fast", f + "/main.c"]);
+				var code = p.exitCode();
+				if( code != 0 ) {
+					Sys.println("MSVC32 Compilation failed with code " + code);
+					continue;
+				}
+				c32 = bestTime("main.exe", [], out);
+				if( c32 != null )
+					Sys.println("  MSVC-32 " + c32.t);
+	
+				// C64
+				var lib = Sys.getEnv("LIB");
+				Sys.putEnv("LIB", "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\lib\\amd64;C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Lib\\x64;" + lib);
+				var p = new sys.io.Process("C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\bin\\amd64\\cl.exe", ["/nologo", "/Ot", "/fp:fast", f + "/main.c"]);
+				var code = p.exitCode();
+				Sys.putEnv("LIB", lib); // restore
+				if( code != 0 ) {
+					Sys.println("C64 Compilation failed with code " + code);
+					continue;
+				}
+				c64 = bestTime("main.exe", [], out);
+				if( c64 != null )
+					Sys.println("  MSVC-64 " + c64.t);
 
-			// C64
-			var lib = Sys.getEnv("LIB");
-			Sys.putEnv("LIB", "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\lib\\amd64;C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Lib\\x64;" + lib);
- 			var p = new sys.io.Process("C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\bin\\amd64\\cl.exe", ["/nologo", "/Ot", "/fp:fast", f + "/main.c"]);
-			var code = p.exitCode();
-			Sys.putEnv("LIB", lib); // restore
-			if( code != 0 ) {
-				Sys.println("C64 Compilation failed with code " + code);
-				continue;
+				// GCC32
+				var p = new sys.io.Process("i686-pc-cygwin-gcc", ["-m32", "-msse2", "-mfpmath=sse", "-O3", f + "/main.c"]);
+				var code = p.exitCode();
+				if( code != 0 ) {
+					Sys.println("GCC32 Compilation failed with code " + code);
+					continue;
+				}
+				var gc32 = bestTime("a.exe", [], out);
+				if( gc32 != null ) {
+					Sys.println("  GCC-32 " + gc32.t);
+					if( c32 == null || c32.t > gc32.t ) c32 = gc32;
+				}
+				
+				// GCC64
+				var p = new sys.io.Process("gcc", ["-m64", "-msse2", "-mfpmath=sse", "-O3", f + "/main.c"]);
+				var code = p.exitCode();
+				if( code != 0 ) {
+					Sys.println("GCC64 Compilation failed with code " + code);
+					continue;
+				}
+				var gc64 = bestTime("a.exe", [], out);
+				if( gc64 != null ) {
+					Sys.println("  GCC-64 " + gc64.t);
+					if( c64 == null || c64.t > gc64.t ) c64 = gc64;
+				}
 			}
-			var c64 = bestTime("main.exe", []);
-			if( c64 == null ) continue;
-			if( c32.out != c64.out )
-				Sys.println("32/64 output vary : " + c32.out + " != " + c64.out);
-			Sys.println("  C-64 " + c64.t);
 
 			// HAXE
 			var p = new sys.io.Process("haxe", ["-cp", f, "-dce", "full", "-hl", "main.hl", "-main", "Main"]);
@@ -76,18 +102,14 @@ class Bench {
 			}
 
 			// HL32
-			var h32 = bestTime("../Release/hl.exe", ["main.hl"]);
-			if( h32 == null ) continue;
-			if( h32.out != c32.out )
-				Sys.println("Bad HL ouput : " + h32.out + " should be " + c32.out);
-			Sys.println("  HL-32 " + h32.t + " " + Math.round(c32.t * 100 / h32.t) + "%");
+			var h32 = bestTime("../Release/hl.exe", ["main.hl"], out);
+			if( h32 != null )
+				Sys.println("  HL-32 " + h32.t + (c32 == null ? "" : " " + Math.round(c32.t * 100 / h32.t) + "%"));
 
 			// HL64
-			var h64 = bestTime("../x64/Release/hl.exe", ["main.hl"]);
-			if( h64 == null ) continue;
-			if( h64.out != c64.out )
-				Sys.println("Bad HL ouput : " + h64.out + " should be " + c64.out);
-			Sys.println("  HL-64 " + h64.t + " " + Math.round(c64.t * 100 / h64.t) + "%");
+			var h64 = bestTime("../x64/Release/hl.exe", ["main.hl"], out);
+			if( h64 != null )
+				Sys.println("  HL-64 " + h64.t + (c64 == null ? "" : " " + Math.round(c64.t * 100 / h64.t) + "%"));
 
 			count++;
 		}

+ 1 - 0
bench/ffib/main.c

@@ -8,4 +8,5 @@ double ffib( double n ) {
 
 int main() {
 	printf("%.19gf\n", ffib(39));
+	return 0;
 }

+ 1 - 0
bench/ffib/out.txt

@@ -0,0 +1 @@
+102334155f

+ 1 - 0
bench/fib/main.c

@@ -8,4 +8,5 @@ int fib( int n ) {
 
 int main() {
 	printf("%di\n", fib(39));
+	return 0;
 }

+ 1 - 0
bench/fib/out.txt

@@ -0,0 +1 @@
+102334155i

+ 1 - 0
bench/ofib/main.c

@@ -38,4 +38,5 @@ int main() {
 	c->o = o;
 	p->fib = ofib;
 	printf("%di\n",o->p->fib(o,40));
+	return 0;
 }

+ 1 - 0
bench/ofib/out.txt

@@ -0,0 +1 @@
+102334155i

+ 1 - 0
src/jit.c

@@ -904,6 +904,7 @@ static int prepare_call_args( jit_ctx *ctx, int count, int *args, vreg *vregs, b
 					ASSERT(v->size);
 					break;
 				}
+				scratch(r);
 			}
 			LOCK(r);
 		}