From 65b13cb73e3297dc58ebe5d51b6566e01916766c Mon Sep 17 00:00:00 2001 From: dhewg Date: Thu, 5 Jul 2012 21:53:00 +0200 Subject: [PATCH] Use a more modern way to set the fpu precision --- neo/framework/Common.cpp | 3 +++ neo/sys/cpu.cpp | 13 +++++++++++++ neo/sys/posix/posix_main.cpp | 3 --- neo/sys/sys_public.h | 8 +------- neo/sys/win32/win_cpu.cpp | 24 ------------------------ neo/sys/win32/win_main.cpp | 1 - 6 files changed, 17 insertions(+), 35 deletions(-) diff --git a/neo/framework/Common.cpp b/neo/framework/Common.cpp index 2d3ccd73..f2224dc0 100644 --- a/neo/framework/Common.cpp +++ b/neo/framework/Common.cpp @@ -2805,6 +2805,9 @@ void idCommonLocal::Init( int argc, char **argv ) { // override cvars from command line StartupVariable( NULL, false ); + // set fpu double extended precision + Sys_FPU_SetPrecision(); + // initialize processor specific SIMD implementation InitSIMD(); diff --git a/neo/sys/cpu.cpp b/neo/sys/cpu.cpp index aaf64627..8e7e1599 100644 --- a/neo/sys/cpu.cpp +++ b/neo/sys/cpu.cpp @@ -26,6 +26,8 @@ If you have questions concerning this license or the applicable additional terms =========================================================================== */ +#include + #include // MSVC header intrin.h uses strcmp and errors out when not set @@ -221,3 +223,14 @@ int Sys_GetProcessorId( void ) { return flags; } + +/* +=============== +Sys_FPU_SetPrecision +=============== +*/ +void Sys_FPU_SetPrecision() { +#if defined(_MSC_VER) && defined(_M_IX86) + _controlfp(_PC_64, _MCW_PC); +#endif +} diff --git a/neo/sys/posix/posix_main.cpp b/neo/sys/posix/posix_main.cpp index d754206b..f36989e6 100644 --- a/neo/sys/posix/posix_main.cpp +++ b/neo/sys/posix/posix_main.cpp @@ -323,9 +323,6 @@ const char *Sys_FPU_GetState( void ) { return ""; } -void Sys_FPU_SetPrecision( int precision ) { -} - /* ================ Sys_LockMemory diff --git a/neo/sys/sys_public.h b/neo/sys/sys_public.h index d5679d1c..79d3297a 100644 --- a/neo/sys/sys_public.h +++ b/neo/sys/sys_public.h @@ -52,12 +52,6 @@ typedef enum { FPU_EXCEPTION_INEXACT_RESULT = 32 } fpuExceptions_t; -typedef enum { - FPU_PRECISION_SINGLE = 0, - FPU_PRECISION_DOUBLE = 1, - FPU_PRECISION_DOUBLE_EXTENDED = 2 -} fpuPrecision_t; - typedef enum { AXIS_SIDE, AXIS_FORWARD, @@ -158,7 +152,7 @@ const char * Sys_FPU_GetState( void ); void Sys_FPU_EnableExceptions( int exceptions ); // sets the FPU precision -void Sys_FPU_SetPrecision( int precision ); +void Sys_FPU_SetPrecision(); // sets Flush-To-Zero mode void Sys_FPU_SetFTZ( bool enable ); diff --git a/neo/sys/win32/win_cpu.cpp b/neo/sys/win32/win_cpu.cpp index 438d807e..7bbecffe 100644 --- a/neo/sys/win32/win_cpu.cpp +++ b/neo/sys/win32/win_cpu.cpp @@ -273,27 +273,3 @@ void Sys_FPU_EnableExceptions( int exceptions ) { } #endif } - -/* -=============== -Sys_FPU_SetPrecision -=============== -*/ -void Sys_FPU_SetPrecision( int precision ) { -#ifdef _MSC_VER - short precisionBitTable[4] = { 0, 1, 3, 0 }; - short precisionBits = precisionBitTable[precision & 3] << 8; - short precisionMask = ~( ( 1 << 9 ) | ( 1 << 8 ) ); - - __asm { - mov eax, statePtr - mov cx, precisionBits - fnstcw word ptr [eax] - mov bx, word ptr [eax] - and bx, precisionMask - or bx, cx - mov word ptr [eax], bx - fldcw word ptr [eax] - } -#endif -} diff --git a/neo/sys/win32/win_main.cpp b/neo/sys/win32/win_main.cpp index a00900ae..a63c8926 100644 --- a/neo/sys/win32/win_main.cpp +++ b/neo/sys/win32/win_main.cpp @@ -653,7 +653,6 @@ int main(int argc, char *argv[]) { #endif // Sys_FPU_EnableExceptions( TEST_FPU_EXCEPTIONS ); - Sys_FPU_SetPrecision( FPU_PRECISION_DOUBLE_EXTENDED ); if ( argc > 1 ) { common->Init( argc-1, &argv[1] );