summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorThilo Schulz <arny@ats.s.bawue.de>2011-06-13 09:56:39 +0000
committerTim Angus <tim@ngus.net>2013-01-09 23:15:55 +0000
commit6a71409a0622050f9a682d4e3b02419c444febe5 (patch)
tree7766ff71304d04c6e42de7dd7d48ed7e7e0fac59 /src/sys
parentb15804d39f71e9be202818288726777d1ca8ac09 (diff)
- Add MASM assembler files for MSVC x64 projects to support vm_x86 in x64 mode - Clean up ftol()/snapvector() mess - Make use of SSE instructions for ftol()/snapvector() if available - move ftol/snapvector pure assembler to inline assembler, this will add x86_64 and improve support for different calling conventions - Set FPU control word at program startup to get consistent behaviour on all platforms
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/sys_main.c4
-rw-r--r--src/sys/sys_unix.c32
-rw-r--r--src/sys/sys_win32.c70
3 files changed, 44 insertions, 62 deletions
diff --git a/src/sys/sys_main.c b/src/sys/sys_main.c
index 46a795eb..07e8e395 100644
--- a/src/sys/sys_main.c
+++ b/src/sys/sys_main.c
@@ -417,8 +417,8 @@ Used to load a development dll instead of a virtual machine
#2 look in fs_basepath
=================
*/
-void *Sys_LoadDll( const char *name,
- intptr_t (**entryPoint)(int, ...),
+void * QDECL Sys_LoadDll( const char *name,
+ intptr_t (QDECL **entryPoint)(int, ...),
intptr_t (*systemcalls)(intptr_t, ...) )
{
void *libHandle;
diff --git a/src/sys/sys_unix.c b/src/sys/sys_unix.c
index 4aad8b88..72ca8360 100644
--- a/src/sys/sys_unix.c
+++ b/src/sys/sys_unix.c
@@ -37,6 +37,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <pwd.h>
#include <libgen.h>
#include <fcntl.h>
+#include <fenv.h>
qboolean stdinIsATTY;
@@ -118,31 +119,6 @@ int Sys_Milliseconds (void)
return curtime;
}
-#if !id386
-/*
-==================
-fastftol
-==================
-*/
-long fastftol( float f )
-{
- return (long)f;
-}
-
-/*
-==================
-Sys_SnapVector
-==================
-*/
-void Sys_SnapVector( float *v )
-{
- v[0] = rint(v[0]);
- v[1] = rint(v[1]);
- v[2] = rint(v[2]);
-}
-#endif
-
-
/*
==================
Sys_RandomBytes
@@ -749,6 +725,12 @@ void Sys_GLimpInit( void )
// NOP
}
+void Sys_SetFloatEnv(void)
+{
+ // rounding towards 0
+ fesetround(FE_TOWARDZERO);
+}
+
/*
==============
Sys_PlatformInit
diff --git a/src/sys/sys_win32.c b/src/sys/sys_win32.c
index f91b26b1..4fddfdc0 100644
--- a/src/sys/sys_win32.c
+++ b/src/sys/sys_win32.c
@@ -39,6 +39,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <wincrypt.h>
#include <shlobj.h>
#include <psapi.h>
+#include <float.h>
// Used to determine where to store user-specific files
static char homePath[ MAX_OSPATH ] = { 0 };
@@ -47,14 +48,38 @@ static char homePath[ MAX_OSPATH ] = { 0 };
static UINT timerResolution = 0;
#endif
-#ifdef __WIN64__
-void Sys_SnapVector( float *v )
+/*
+================
+Sys_SetFPUCW
+Set FPU control word to default value
+================
+*/
+
+#ifndef _RC_CHOP
+// mingw doesn't seem to have these defined :(
+
+ #define _MCW_EM 0x0008001fU
+ #define _MCW_RC 0x00000300U
+ #define _MCW_PC 0x00030000U
+ #define _RC_CHOP 0x00000300U
+ #define _PC_53 0x00010000U
+
+ unsigned int _controlfp(unsigned int new, unsigned int mask);
+#endif
+
+#define FPUCWMASK1 (_MCW_RC | _MCW_EM)
+#define FPUCW (_RC_CHOP | _MCW_EM | _PC_53)
+
+#ifdef idx64
+#define FPUCWMASK (FPUCWMASK1)
+#else
+#define FPUCWMASK (FPUCWMASK1 | _MCW_PC)
+#endif
+
+void Sys_SetFloatEnv(void)
{
- v[0] = rint(v[0]);
- v[1] = rint(v[1]);
- v[2] = rint(v[2]);
+ _controlfp(FPUCW, FPUCWMASK);
}
-#endif
/*
================
@@ -136,34 +161,6 @@ int Sys_Milliseconds (void)
return sys_curtime;
}
-#ifndef __GNUC__ //see snapvectora.s
-/*
-================
-Sys_SnapVector
-================
-*/
-void Sys_SnapVector( float *v )
-{
- int i;
- float f;
-
- f = *v;
- __asm fld f;
- __asm fistp i;
- *v = i;
- v++;
- f = *v;
- __asm fld f;
- __asm fistp i;
- *v = i;
- v++;
- f = *v;
- __asm fld f;
- __asm fistp i;
- *v = i;
-}
-#endif
-
/*
================
Sys_RandomBytes
@@ -715,9 +712,12 @@ void Sys_PlatformInit( void )
{
#ifndef DEDICATED
TIMECAPS ptc;
-
const char *SDL_VIDEODRIVER = getenv( "SDL_VIDEODRIVER" );
+#endif
+
+ Sys_SetFloatEnv();
+#ifndef DEDICATED
if( SDL_VIDEODRIVER )
{
Com_Printf( "SDL_VIDEODRIVER is externally set to \"%s\", "