- 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
This commit is contained in:
Thilo Schulz 2011-06-13 09:56:39 +00:00
parent 471182cba0
commit 03201aff22
22 changed files with 540 additions and 460 deletions

View file

@ -37,6 +37,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 };
@ -45,15 +46,39 @@ static char homePath[ MAX_OSPATH ] = { 0 };
static UINT timerResolution = 0;
#endif
#ifdef __WIN64__
void Sys_SnapVector( float *v )
{
v[0] = rint(v[0]);
v[1] = rint(v[1]);
v[2] = rint(v[2]);
}
/*
================
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)
{
_controlfp(FPUCW, FPUCWMASK);
}
/*
================
Sys_DefaultHomePath
@ -140,34 +165,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
@ -719,9 +716,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\", "