Quellcode durchsuchen

Moved the call to "CallDelayedReleaseHooks" from the top of vm loop to inside _OP_RETURN opcode, this way there is no constant time penalty on the vm loop.

mingodad vor 12 Jahren
Ursprung
Commit
6541dc8331
2 geänderte Dateien mit 38 neuen und 45 gelöschten Zeilen
  1. 35 41
      SquiLu/samples/spectralnorm.nut
  2. 3 4
      SquiLu/squirrel/sqvm.cpp

+ 35 - 41
SquiLu/samples/spectralnorm.nut

@@ -1,58 +1,52 @@
 // The Computer Language Benchmarks Game
 // http://benchmarksgame.alioth.debian.org/
-//
-// contributed by Ian Osgood
-// modified by Isaac Gouy
+// contributed by Mike Pall
 
-local function A(i,j) {
-  local ij = i+j;
+local function A(i, j){
+  local ij = i+j
   return 1.0/(ij * (ij+1)/2.0+i+1);
 }
 
-local function Au(u,v, N) {
-  for (var i=0; i<N; ++i) {
-    var t = 0.0;
-    for (var j=0; j<N; ++j) t += A(i,j) * u[j];
-    v[i] = t;
+local function Av(x, y, N){
+  for(local i=0; i < N; ++i){
+    local a = 0
+    for(local j=0; j < N; ++j) a += x[j] * A(i, j)
+    y[i] = a
   }
 }
 
-local function Atu(u,v, N) {
-  for (var i=0; i<N; ++i) {
-    var t = 0.0;
-    for (var j=0; j<N; ++j) t += A(j,i) * u[j];
-    v[i] = t;
+local function Atv(x, y, N){
+  for(local i=0; i < N; ++i){
+    local a = 0
+    for(local j=0; j < N; ++j) a += x[j] * A(j, i)
+    y[i] = a
   }
 }
 
-local function AtAu(u,v,w, N) {
-  Au(u,w, N);
-  Atu(w,v, N);
+local function AtAv(x, y, t, N){
+  Av(x, t, N)
+  Atv(t, y, N)
 }
 
-local function spectralnorm(n) {
-  var i, u=array(n), v=array(n), w=array(n), vv=0.0, vBv=0.0;
-  for (i=0; i<n; ++i) {
-    u[i] = 1.0; v[i] = w[i] = 0.0; 
-  }
-  for (i=0; i<10; ++i) {
-    AtAu(u,v,w, n);
-    AtAu(v,u,w, n);
-  }
-  for (i=0; i<n; ++i) {
-    vBv += u[i]*v[i];
-    vv  += v[i]*v[i];
-  }
-  return math.sqrt(vBv/vv);
+local N = vargv.get(1, 500).tointeger();
+
+local start = os.clock()
+
+local u = array(N), v = array(N), t = array(N)
+for(local i=0; i < N; ++i) u[i] = 1
+
+for(local i=0; i < 10; ++i){
+	AtAv(u, v, t, N)
+	AtAv(v, u, t, N)
 }
 
-print(check_delayed_release_hooks());
-//check_delayed_release_hooks(false);
-call_delayed_release_hooks();
-print(check_delayed_release_hooks());
+local vBv = 0.0, vv = 0.0
+for(local i=0; i < N; ++i){
+  local ui = u[i], vi = v[i]
+  vBv += ui*vi
+  vv += vi*vi
+}
 
-local N = vargv.get(1, 500).tointeger();
-local start = os.clock();
-local result = spectralnorm(N);
-print("spectralnorm", N, os.clock()-start);
-print(format("%d = %0.9f\n", N, result));
+local result = math.sqrt(vBv / vv);
+print("spectralnorm", N, os.clock()-start)
+print(format("%0.9f\n", result))

+ 3 - 4
SquiLu/squirrel/sqvm.cpp

@@ -774,7 +774,6 @@ exception_restore:
 		{
 		    //if the last instruction was a call then check for release hooks
 		    //obs.: changing the order of comparison bellow with gcc makes the code slower
-		    if((ci->_ip->op == _OP_CALL) && _check_delayed_relase_hooks) _sharedstate->CallDelayedReleaseHooks(this);
 #ifdef PROFILE_SQVM
 			OpProfile &opp_last = _op_profile[ci->_ip->op];
 			_op_profile_timer.stop();
@@ -932,7 +931,8 @@ exception_restore:
 			case _OP_RETURN:
 				if((ci)->_generator) {
 					(ci)->_generator->Kill();
-				}
+				}
+				if(_check_delayed_relase_hooks) _sharedstate->CallDelayedReleaseHooks(this);
 				if(Return(arg0, arg1, temp_reg)){
 					assert(traps==0);
 					//outres = temp_reg;
@@ -1128,8 +1128,7 @@ exception_restore:
 			case _OP_CLOSE:
 				if(_openouters) CloseOuters(&(STK(arg1)));
 				continue;
-			}
-
+			}
 		}
 	}
 #endif