All pastes #361957 Raw Edit

Subdino

public text v1 · immutable
·published 2007-02-18 13:00 UTC
rendered paste body
Index: lua/lua/src/lib/streflop_gateway.cpp
===================================================================
--- lua/lua/src/lib/streflop_gateway.cpp	(revision 3420)
+++ lua/lua/src/lib/streflop_gateway.cpp	(working copy)
@@ -1,107 +0,0 @@
-/*
-
-This file makes the streflop functions used by LUA visible from C using a C interface
-There is no corresponding .h, this file was made to work with lmathlib.c only.
-See lmathlib.c for details.
-
-*/
-
-#include "lib/streflop/streflop.h"
-
-// stolen from lua.h
-#ifndef LUA_NUMBER
-typedef float lua_Number;
-#else
-typedef LUA_NUMBER lua_Number;
-#endif
-
-extern "C" {
-
-lua_Number streflop_fabs(lua_Number x) {
-    return streflop::fabs(x);
-}
-
-lua_Number streflop_sin(lua_Number x) {
-    return streflop::sin(x);
-}
-
-lua_Number streflop_cos(lua_Number x) {
-    return streflop::cos(x);
-}
-
-lua_Number streflop_tan(lua_Number x) {
-    return streflop::tan(x);
-}
-
-lua_Number streflop_asin(lua_Number x) {
-    return streflop::asin(x);
-}
-
-lua_Number streflop_acos(lua_Number x) {
-    return streflop::acos(x);
-}
-
-lua_Number streflop_atan(lua_Number x) {
-    return streflop::atan(x);
-}
-
-lua_Number streflop_atan2(lua_Number x,lua_Number y) {
-    return streflop::atan2(x,y);
-}
-
-lua_Number streflop_ceil(lua_Number x) {
-    return streflop::ceil(x);
-}
-
-lua_Number streflop_floor(lua_Number x) {
-    return streflop::floor(x);
-}
-
-lua_Number streflop_fmod(lua_Number x,lua_Number y) {
-    return streflop::fmod(x,y);
-}
-
-lua_Number streflop_sqrt(lua_Number x) {
-    return streflop::sqrt(x);
-}
-
-lua_Number streflop_pow(lua_Number x,lua_Number y) {
-    return streflop::pow(x,y);
-}
-
-lua_Number streflop_log(lua_Number x) {
-    return streflop::log(x);
-}
-
-lua_Number streflop_log10(lua_Number x) {
-    return streflop::log10(x);
-}
-
-lua_Number streflop_exp(lua_Number x) {
-    return streflop::exp(x);
-}
-
-lua_Number streflop_frexp(lua_Number x, int* e) {
-    return streflop::frexp(x,e);
-}
-
-lua_Number streflop_ldexp(lua_Number x, int e) {
-    return streflop::ldexp(x,e);
-}
-
-static int lua_streflop_random_seed = 0;
-
-void streflop_seed(int s) {
-    streflop::RandomInit(s);
-}
-
-lua_Number streflop_random() {
-    // respect the original lua code that uses rand, and rand is auto-seeded always with the same value
-    if (lua_streflop_random_seed == 0) {
-        lua_streflop_random_seed = 1;
-        streflop::RandomInit(1);
-    }
-    return streflop::Random<true, false, lua_Number>(lua_Number(0.), lua_Number(1.));
-}
-
-}
Index: lua/lua/src/lib/lmathlib.c
===================================================================
--- lua/lua/src/lib/lmathlib.c	(revision 3420)
+++ lua/lua/src/lib/lmathlib.c	(working copy)
@@ -7,40 +7,36 @@
 
 #include <stdlib.h>
 
-/*
-Uses streflop for sync. purposes, not system library
-#include <math.h>
-*/
+#ifdef USING_STREFLOP
+  /*
+  Use streflop for sync. purposes, not system library.
+  LUA uses only a few math functions, no need to make a full-scale solution.
+  See streflop_gateway for the implementation of these functions.
+  */
 
+  #include "lib/streflop/streflop.h"
+  iusing namespace streflop;
+
+  void seed(int s) {
+    RandomInit(s);
+  }
+
+  lua_Number rand() {
+      // respect the original lua code that uses rand, and rand is auto-seeded always with the same value
+      if (lua_streflop_random_seed == 0) {
+          lua_streflop_random_seed = 1;
+          seed(1);
+      }
+      return Random<true, false, lua_Number>(lua_Number(0.), lua_Number(1.));
+  }
+#else
+  #include <math.h>
+#endif
+
 #define lmathlib_c
 
 #include "lua.h"
 
-/*
-LUA uses only a few math functions, no need to make a full-scale solution.
-See streflop_gateway for the implementation of these functions.
-*/
-extern lua_Number streflop_fabs(lua_Number);
-extern lua_Number streflop_sin(lua_Number);
-extern lua_Number streflop_cos(lua_Number);
-extern lua_Number streflop_tan(lua_Number);
-extern lua_Number streflop_asin(lua_Number);
-extern lua_Number streflop_acos(lua_Number);
-extern lua_Number streflop_atan(lua_Number);
-extern lua_Number streflop_atan2(lua_Number,lua_Number);
-extern lua_Number streflop_ceil(lua_Number);
-extern lua_Number streflop_floor(lua_Number);;
-extern lua_Number streflop_fmod(lua_Number,lua_Number);
-extern lua_Number streflop_sqrt(lua_Number);
-extern lua_Number streflop_pow(lua_Number,lua_Number);
-extern lua_Number streflop_log(lua_Number);
-extern lua_Number streflop_log10(lua_Number);
-extern lua_Number streflop_exp(lua_Number);
-extern lua_Number streflop_frexp(lua_Number, int*);
-extern lua_Number streflop_ldexp(lua_Number, int);
-extern void streflop_seed(int);
-extern lua_Number streflop_random();
-
 #include "lauxlib.h"
 #include "lualib.h"
 
@@ -65,82 +61,82 @@
 
 
 static int math_abs (lua_State *L) {
-  lua_pushnumber(L, streflop_fabs(luaL_checknumber(L, 1)));
+  lua_pushnumber(L, fabs(luaL_checknumber(L, 1)));
   return 1;
 }
 
 static int math_sin (lua_State *L) {
-  lua_pushnumber(L, streflop_sin(TORAD(luaL_checknumber(L, 1))));
+  lua_pushnumber(L, sin(TORAD(luaL_checknumber(L, 1))));
   return 1;
 }
 
 static int math_cos (lua_State *L) {
-  lua_pushnumber(L, streflop_cos(TORAD(luaL_checknumber(L, 1))));
+  lua_pushnumber(L, cos(TORAD(luaL_checknumber(L, 1))));
   return 1;
 }
 
 static int math_tan (lua_State *L) {
-  lua_pushnumber(L, streflop_tan(TORAD(luaL_checknumber(L, 1))));
+  lua_pushnumber(L, tan(TORAD(luaL_checknumber(L, 1))));
   return 1;
 }
 
 static int math_asin (lua_State *L) {
-  lua_pushnumber(L, FROMRAD(streflop_asin(luaL_checknumber(L, 1))));
+  lua_pushnumber(L, FROMRAD(asin(luaL_checknumber(L, 1))));
   return 1;
 }
 
 static int math_acos (lua_State *L) {
-  lua_pushnumber(L, FROMRAD(streflop_acos(luaL_checknumber(L, 1))));
+  lua_pushnumber(L, FROMRAD(acos(luaL_checknumber(L, 1))));
   return 1;
 }
 
 static int math_atan (lua_State *L) {
-  lua_pushnumber(L, FROMRAD(streflop_atan(luaL_checknumber(L, 1))));
+  lua_pushnumber(L, FROMRAD(atan(luaL_checknumber(L, 1))));
   return 1;
 }
 
 static int math_atan2 (lua_State *L) {
-  lua_pushnumber(L, FROMRAD(streflop_atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2))));
+  lua_pushnumber(L, FROMRAD(atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2))));
   return 1;
 }
 
 static int math_ceil (lua_State *L) {
-  lua_pushnumber(L, streflop_ceil(luaL_checknumber(L, 1)));
+  lua_pushnumber(L, ceil(luaL_checknumber(L, 1)));
   return 1;
 }
 
 static int math_floor (lua_State *L) {
-  lua_pushnumber(L, streflop_floor(luaL_checknumber(L, 1)));
+  lua_pushnumber(L, floor(luaL_checknumber(L, 1)));
   return 1;
 }
 
 static int math_mod (lua_State *L) {
-  lua_pushnumber(L, streflop_fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
+  lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
   return 1;
 }
 
 static int math_sqrt (lua_State *L) {
-  lua_pushnumber(L, streflop_sqrt(luaL_checknumber(L, 1)));
+  lua_pushnumber(L, sqrt(luaL_checknumber(L, 1)));
   return 1;
 }
 
 static int math_pow (lua_State *L) {
-  lua_pushnumber(L, streflop_pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
+  lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
   return 1;
 }
 
 static int math_log (lua_State *L) {
-  lua_pushnumber(L, streflop_log(luaL_checknumber(L, 1)));
+  lua_pushnumber(L, log(luaL_checknumber(L, 1)));
   return 1;
 }
 
 static int math_log10 (lua_State *L) {
-  lua_pushnumber(L, streflop_log10(luaL_checknumber(L, 1)));
+  lua_pushnumber(L, log10(luaL_checknumber(L, 1)));
   return 1;
 }
 
 static int math_exp (lua_State *L) {
-  lua_pushnumber(L, streflop_exp(luaL_checknumber(L, 1)));
+  lua_pushnumber(L, exp(luaL_checknumber(L, 1)));
   return 1;
 }
 
@@ -156,13 +152,13 @@
 
 static int math_frexp (lua_State *L) {
   int e;
-  lua_pushnumber(L, streflop_frexp(luaL_checknumber(L, 1), &e));
+  lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e));
   lua_pushnumber(L, e);
   return 2;
 }
 
 static int math_ldexp (lua_State *L) {
-  lua_pushnumber(L, streflop_ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2)));
+  lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2)));
   return 1;
 }
 
@@ -199,8 +195,7 @@
 static int math_random (lua_State *L) {
   /* the `%' avoids the (rare) case of r==1, and is needed also because on
      some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */
-  /*lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX;*/
-  lua_Number r = streflop_random();
+  lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX;
   switch (lua_gettop(L)) {  /* check number of arguments */
     case 0: {  /* no arguments */
       lua_pushnumber(L, r);  /* Number between 0 and 1 */
@@ -209,14 +204,14 @@
     case 1: {  /* only upper limit */
       int u = luaL_checkint(L, 1);
       luaL_argcheck(L, 1<=u, 1, "interval is empty");
-      lua_pushnumber(L, (int)streflop_floor(r*u)+1);  /* int between 1 and `u' */
+      lua_pushnumber(L, (int)floor(r*u)+1);  /* int between 1 and `u' */
       break;
     }
     case 2: {  /* lower and upper limits */
       int l = luaL_checkint(L, 1);
       int u = luaL_checkint(L, 2);
       luaL_argcheck(L, l<=u, 2, "interval is empty");
-      lua_pushnumber(L, (int)streflop_floor(r*(u-l+1))+l);  /* int between `l' and `u' */
+      lua_pushnumber(L, (int)floor(r*(u-l+1))+l);  /* int between `l' and `u' */
       break;
     }
     default: return luaL_error(L, "wrong number of arguments");
@@ -224,9 +219,9 @@
   return 1;
 }
 
+
 static int math_randomseed (lua_State *L) {
-  /*srand(luaL_checkint(L, 1));*/
-  streflop_seed(luaL_checkint(L, 1));
+  srand(luaL_checkint(L, 1));
   return 0;
 }
 
Index: SConstruct
===================================================================
--- SConstruct	(revision 3420)
+++ SConstruct	(working copy)
@@ -176,7 +176,8 @@
 		env.AddPostAction(lib, Action([['strip','$TARGET']]))
 
 # Build streflop (which has it's own Makefile-based build system)
-if not 'configure' in sys.argv and not 'test' in sys.argv and not 'install' in sys.argv:
+if not os.environ.has_key('SKIP_STREFLOP') and not 'configure' in sys.argv and not 'test' in sys.argv and not 'install' in sys.argv:
+	env['CCFLAGS'] += ['-DUSE_STREFLOP']
 	cmd = "CC=" + env['CC'] + " CXX=" + env['CXX'] + " --no-print-directory -C rts/lib/streflop"
 	if env['fpmath'] == 'sse':
 		cmd = "STREFLOP_SSE=1 " + cmd
Index: rts/build/scons/rts.py
===================================================================
--- rts/build/scons/rts.py	(revision 3420)
+++ rts/build/scons/rts.py	(working copy)
@@ -200,7 +200,9 @@
 		# Use single precision constants only.
 		# This should be redundant with the modifications done by tools/double_to_single_precision.sed.
 		# Other options copied from streflop makefiles.
-		env['CCFLAGS'] = ['-fsingle-precision-constant', '-frounding-math', '-fsignaling-nans', '-mieee-fp']
+		env['CCFLAGS'] = ['-fsingle-precision-constant', '-frounding-math', '-fsignaling-nans']
+		if not os.environ.has_key('SKIP_STREFLOP'):
+			env['CCFLAGS'].append('-mieee-fp')
 
 		# profile?
 		bool_opt('profile', False)
@@ -264,7 +266,8 @@
 		if env['syncdebug'] and env['synccheck']:
 			print "syncdebug and synccheck are mutually exclusive. Please choose one."
 			env.Exit(1)
-		string_opt('fpmath', '387')
+		if not os.environ.has_key('SKIP_STREFLOP'):
+			string_opt('fpmath', '387')
 
 		# If sync debugger is on, disable inlining, as it makes it much harder to follow backtraces.
 		if env['syncdebug']:
@@ -276,7 +279,7 @@
 			env['CCFLAGS'] += ['-fvisibility=hidden']
 
 		# Allow easy switching between 387 and SSE fpmath.
-		if env['fpmath']:
+		if not os.environ.has_key('SKIP_STREFLOP') and env['fpmath']:
 			env['CCFLAGS'] += ['-mfpmath='+env['fpmath']]
 			if env['fpmath'] == 'sse':
 				print "WARNING: SSE math vs X87 math is unsynced!"
@@ -316,7 +319,7 @@
 		spring_defines = ['DIRECT_CONTROL_ALLOWED']
 
 		# Add define specifying type of floating point math to use.
-		if env['fpmath']:
+		if not os.environ.has_key('SKIP_STREFLOP') and env['fpmath']:
 			if env['fpmath'] == 'sse':
 				spring_defines += ['STREFLOP_SSE']
 			if env['fpmath'] == '387':
Index: rts/System/Sound.cpp
===================================================================
--- rts/System/Sound.cpp	(revision 3420)
+++ rts/System/Sound.cpp	(working copy)
@@ -42,9 +42,11 @@
 		sound = SAFE_NEW CNullSound;
 	}
 
+#ifdef STREFLOP_H
 	// Something in DirectSoundCreate (sound drivers?) messes with the FPU control word.
 	// Set single precision floating point math.
 	streflop_init<streflop::Simple>();
+#endif
 
 	return sound;
 }
Index: rts/System/myMath.cpp
===================================================================
--- rts/System/myMath.cpp	(revision 3420)
+++ rts/System/myMath.cpp	(working copy)
@@ -16,10 +16,11 @@
 public:
 	CMyMath()
 	{
+#ifdef STREFLOP_H
 		// This must be put here too because it's executed before the streflop_init in main().
 		// Set single precision floating point math.
 		streflop_init<streflop::Simple>();
-
+#endif
 		for(int a=0;a<1024;++a){
 			float ang=(a-512)*2*PI/1024;
 			float2 v;
@@ -33,12 +34,14 @@
 			checksum *= 33;
 			checksum = 33 * checksum + *(unsigned*)&headingToVectorTable[a].y;
 		}
-// 		fprintf(stderr, "headingToVectorTable checksum: %08x\n", checksum);
+#ifdef STREFLOP_H
+//		fprintf(stderr, "headingToVectorTable checksum: %08x\n", checksum);
 		assert(checksum == 0x617a9968);
 
 		// release mode check
 		if (checksum != 0x617a9968)
 			handleerror(0, "invalid headingToVectorTable checksum", "Sync Error", 0);
+#endif
 	}
 };
 
Index: rts/System/Main.cpp
===================================================================
--- rts/System/Main.cpp	(revision 3420)
+++ rts/System/Main.cpp	(working copy)
@@ -439,9 +439,11 @@
 		return false;
 	}
 
+#ifdef STREFLOP_H
 	// Something in SDL_SetVideoMode (OpenGL drivers?) messes with the FPU control word.
 	// Set single precision floating point math.
 	streflop_init<streflop::Simple>();
+#endif
 
 	if (FSAA) {
  		FSAA = MultisampleVerify();
@@ -1036,8 +1038,10 @@
 	}
 #endif
 
+#ifdef STREFLOP_H
 	// Set single precision floating point math.
 	streflop_init<streflop::Simple>();
+#endif
 	good_fpu_control_registers("::Run");
 
 // It's nice to be able to disable catching when you're debugging
Index: rts/Sim/Units/UnitHandler.cpp
===================================================================
--- rts/Sim/Units/UnitHandler.cpp	(revision 3420)
+++ rts/Sim/Units/UnitHandler.cpp	(working copy)
@@ -260,7 +260,11 @@
 
 	if(!(gs->frameNum&15)){
 		if(diminishingMetalMakers)
+#ifdef STREFLOP_H
 			metalMakerEfficiency=8.0f/(8.0f+max(0.0f,sqrt(metalMakerIncome/gs->activeTeams)-4));
+#else
+			metalMakerEfficiency=8.0f/(8.0f+max(0.0f,sqrtf(metalMakerIncome/gs->activeTeams)-4));
+#endif
 		metalMakerIncome=0;
 	}
 
Index: rts/Game/GameServer.cpp
===================================================================
--- rts/Game/GameServer.cpp	(revision 3420)
+++ rts/Game/GameServer.cpp	(working copy)
@@ -66,10 +66,12 @@
 	fakeDesync = false;
 #endif
 
+#ifdef STREFLOP_H
 	// Something in CGameServer::CGameServer borks the FPU control word
 	// maybe the threading, or something in CNet::InitServer() ??
 	// Set single precision floating point math.
 	streflop_init<streflop::Simple>();
+#endif
 }
 
 CGameServer::~CGameServer()
Index: rts/Rendering/UnitModels/UnitDrawer.cpp
===================================================================
--- rts/Rendering/UnitModels/UnitDrawer.cpp	(revision 3420)
+++ rts/Rendering/UnitModels/UnitDrawer.cpp	(working copy)
@@ -947,7 +947,11 @@
 			float dot=vec.dot(sundir);
 			if(dot<0)
 				dot=0;
+#ifdef STREFLOP_H
 			float exp=min(1.f,pow(dot,exponent)+pow(dot,3)*0.25f);
+#else
+			float exp=min(1.f,powf(dot,exponent)+powf(dot,3)*0.25f);
+#endif
 			buf[(y*size+x)*4+0]=(unsigned char)(suncolor.x*exp*255);
 			buf[(y*size+x)*4+1]=(unsigned char)(suncolor.y*exp*255);
 			buf[(y*size+x)*4+2]=(unsigned char)(suncolor.z*exp*255);