Просмотр исходного кода

A bit of performance improvement on Arithmetic operations, and remove code duplication.

mingodad 12 лет назад
Родитель
Сommit
f5b0f703b5
4 измененных файлов с 17 добавлено и 42 удалено
  1. 2 3
      SquiLu/samples/binary-tree.nut
  2. 2 2
      SquiLu/samples/spectralnorm.nut
  3. 2 19
      SquiLu/squilu.cbp
  4. 11 18
      SquiLu/squirrel/sqvm.cpp

+ 2 - 3
SquiLu/samples/binary-tree.nut

@@ -8,13 +8,12 @@ local function BottomUpTree(item, depth){
     --depth;
     return [ item, BottomUpTree(i-1, depth),  BottomUpTree(i, depth) ];
   }
-  else return [ item ];
+  return [ item ];
 }
 
 local function ItemCheck(tree){
   if (tree.get(1, false))  return tree[0] + ItemCheck(tree[1]) - ItemCheck(tree[2])
-  else
-    return tree[0]
+  return tree[0]
 }
 
 local start = os.clock()

+ 2 - 2
SquiLu/samples/spectralnorm.nut

@@ -3,8 +3,8 @@
 // contributed by Mike Pall
 
 local function A(i, j){
-  local ij = i+j
-  return 1.0/(ij * (ij+1)/2.0+i+1);
+  local ij = j + i++
+  return 1.0/(ij++ * ij/2.0+i);
 }
 
 local function Av(x, y, N){

+ 2 - 19
SquiLu/squilu.cbp

@@ -34,8 +34,6 @@
 				<Compiler>
 					<Add option="-O3" />
 					<Add option="-Wall" />
-					<Add option="-fno-rtti" />
-					<Add option="-fno-strict-aliasing" />
 					<Add option="-DNDEBUG=1" />
 					<Add option="-DWITH_FULL_DAD_EXTRAS=1" />
 					<Add directory="../../zeromq-3.2.2/include" />
@@ -82,8 +80,6 @@
 				<Compiler>
 					<Add option="-O3" />
 					<Add option="-Wall" />
-					<Add option="-fno-rtti" />
-					<Add option="-fno-strict-aliasing" />
 					<Add option="-DAS_STATIC_LIB=1" />
 					<Add option="-DINET_ATON=1" />
 					<Add option="-DNDEBUG=1" />
@@ -115,8 +111,6 @@
 					<Add option="-fexpensive-optimizations" />
 					<Add option="-O3" />
 					<Add option="-Wall" />
-					<Add option="-fno-rtti" />
-					<Add option="-fno-strict-aliasing" />
 					<Add option="-DWITH_FLTK=1" />
 					<Add option="-DNDEBUG=1" />
 					<Add option="-DWITH_FULL_DAD_EXTRAS=1" />
@@ -161,8 +155,6 @@
 					<Add option="-O2" />
 					<Add option="-Wall" />
 					<Add option="-g" />
-					<Add option="-fno-rtti" />
-					<Add option="-fno-strict-aliasing" />
 					<Add option="-DWITH_FLTK=1" />
 					<Add option="-DWITH_FULL_DAD_EXTRAS=1" />
 					<Add directory="../../zeromq-3.2.2/include" />
@@ -202,8 +194,6 @@
 				<Compiler>
 					<Add option="-O3" />
 					<Add option="-Wall" />
-					<Add option="-fno-rtti" />
-					<Add option="-fno-strict-aliasing" />
 					<Add option="-DAS_STATIC_LIB=1" />
 					<Add option="-DINET_ATON=1" />
 					<Add option="-DWITH_FLTK=1" />
@@ -252,8 +242,6 @@
 				<Compiler>
 					<Add option="-O3" />
 					<Add option="-Wall" />
-					<Add option="-fno-rtti" />
-					<Add option="-fno-strict-aliasing" />
 					<Add option="-DAS_STATIC_LIB=1" />
 					<Add option="-DINET_ATON=1" />
 					<Add option="-DWITH_FLTK=1" />
@@ -302,8 +290,6 @@
 				<Compiler>
 					<Add option="-Os" />
 					<Add option="-Wall" />
-					<Add option="-fno-rtti" />
-					<Add option="-fno-strict-aliasing" />
 					<Add option="-DNEED_SUBLATIN_C=1" />
 					<Add option="-DSQUILU_ALONE=1" />
 					<Add option="-DNDEBUG=1" />
@@ -331,8 +317,6 @@
 				<Compiler>
 					<Add option="-Os" />
 					<Add option="-Wall" />
-					<Add option="-fno-rtti" />
-					<Add option="-fno-strict-aliasing" />
 					<Add option="-DNEED_SUBLATIN_C=1" />
 					<Add option="-DSQUILU_ALONE=1" />
 					<Add option="-D_WIN32_WCE=1" />
@@ -358,8 +342,6 @@
 				<Compiler>
 					<Add option="-O3" />
 					<Add option="-Wall" />
-					<Add option="-fno-rtti" />
-					<Add option="-fno-strict-aliasing" />
 					<Add option="-DINET_ATON=1" />
 					<Add option="-DNDEBUG=1" />
 					<Add option="-DSQLITE_OMIT_WAL=1" />
@@ -372,6 +354,7 @@
 				</Compiler>
 				<Linker>
 					<Add option="-s" />
+					<Add option="-Wl,-static" />
 					<Add library="axtls-wince" />
 					<Add library="discount-wince" />
 					<Add library="coredll" />
@@ -385,6 +368,7 @@
 		<Compiler>
 			<Add option="-Wall" />
 			<Add option="-fno-strict-aliasing" />
+			<Add option="-fno-rtti" />
 			<Add option="-DONLY_ASCII=1" />
 			<Add option="-DPROFILE_SQVM0=1" />
 			<Add option="-DSQ_JIT_LLVM44=1" />
@@ -641,7 +625,6 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
-			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_mix.cpp">
 			<Option target="Debug" />

+ 11 - 18
SquiLu/squirrel/sqvm.cpp

@@ -42,30 +42,23 @@ bool SQVM::BW_OP(SQUnsignedInteger op,SQObjectPtr &trg,const SQObjectPtr &o1,con
 	return true;
 }
 
-#define _ARITH_(op,trg,o1,o2) \
+#define _ARITH_BASE_(op,trg,o1,o2, ARITH_INTEGER) \
 { \
-	SQInteger tmask = type(o1)|type(o2); \
-	switch(tmask) { \
-		case OT_INTEGER: trg = _integer(o1) op _integer(o2);break; \
-		case (OT_FLOAT|OT_INTEGER): \
-		case (OT_FLOAT): trg = tofloat(o1) op tofloat(o2); break;\
+	switch(type(o1)|type(o2)) { \
+		case OT_INTEGER: ARITH_INTEGER;break; \
+		case (OT_FLOAT): trg = _float(o1) op _float(o2); break;\
+		case (OT_FLOAT|OT_INTEGER): trg = tofloat(o1) op tofloat(o2); break;\
 		default: _GUARD(ARITH_OP((#op)[0],trg,o1,o2)); break;\
 	} \
 }
-
-#define _ARITH_NOZERO(op,trg,o1,o2,err) \
-{ \
-	SQInteger tmask = type(o1)|type(o2); \
-	switch(tmask) { \
-		case OT_INTEGER: { SQInteger i1 = _integer(o1); SQInteger i2 = _integer(o2);\
+
+#define _ARITH_(op,trg,o1,o2) _ARITH_BASE_(op,trg,o1,o2, trg = _integer(o1) op _integer(o2))
+
+#define _ARITH_NOZERO(op,trg,o1,o2,err) _ARITH_BASE_(op,trg,o1,o2, \
+		{ SQInteger i1 = _integer(o1); SQInteger i2 = _integer(o2);\
             if(i2 == 0) { Raise_Error(err); SQ_THROW(); } \
             else if(i2 == -1 && i1 == INT_MIN) { Raise_Error(_SC("integer overflow")); SQ_THROW(); }\
-            trg = i1 op i2; } break;\
-		case (OT_FLOAT|OT_INTEGER): \
-		case (OT_FLOAT): trg = tofloat(o1) op tofloat(o2); break;\
-		default: _GUARD(ARITH_OP((#op)[0],trg,o1,o2)); break;\
-	} \
-}
+            trg = i1 op i2; })
 
 bool SQVM::ARITH_OP(SQUnsignedInteger op,SQObjectPtr &trg,const SQObjectPtr &o1,const SQObjectPtr &o2)
 {