2004-05-08 03:11:51 +02:00
|
|
|
#include "precompiled.h"
|
2004-03-03 00:56:51 +01:00
|
|
|
|
2005-01-25 00:08:30 +01:00
|
|
|
#include "lib.h"
|
2004-03-03 00:56:51 +01:00
|
|
|
#include "sysdep.h"
|
2005-09-10 16:28:55 +02:00
|
|
|
#if CPU_IA32
|
|
|
|
# include "ia32.h"
|
|
|
|
#endif
|
2005-09-14 18:58:10 +02:00
|
|
|
#if OS_WIN
|
|
|
|
# include "win/wcpu.h"
|
|
|
|
#endif
|
2005-09-10 16:28:55 +02:00
|
|
|
|
|
|
|
|
2004-07-15 21:59:27 +02:00
|
|
|
#include <memory.h>
|
2004-07-25 13:30:05 +02:00
|
|
|
#include <stdarg.h>
|
2004-03-03 00:56:51 +01:00
|
|
|
|
2004-06-03 03:43:33 +02:00
|
|
|
|
2005-08-09 18:23:19 +02:00
|
|
|
#if !HAVE_C99
|
2004-06-03 03:43:33 +02:00
|
|
|
|
2006-02-23 08:55:32 +01:00
|
|
|
// note: stupid VC7 gets arguments wrong when using __declspec(naked);
|
|
|
|
// we need to use DWORD PTR and esp-relative addressing.
|
|
|
|
|
|
|
|
#if HAVE_MS_ASM
|
|
|
|
__declspec(naked) float fminf(float, float)
|
|
|
|
{
|
|
|
|
__asm
|
|
|
|
{
|
|
|
|
fld DWORD PTR [esp+4]
|
|
|
|
fld DWORD PTR [esp+8]
|
|
|
|
fcomi st(0), st(1)
|
|
|
|
fcmovnb st(0), st(1)
|
|
|
|
fxch
|
|
|
|
fstp st(0)
|
|
|
|
ret
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2004-06-03 03:43:33 +02:00
|
|
|
float fminf(float a, float b)
|
|
|
|
{
|
|
|
|
return (a < b)? a : b;
|
|
|
|
}
|
2006-02-23 08:55:32 +01:00
|
|
|
#endif
|
2004-06-03 03:43:33 +02:00
|
|
|
|
2006-02-23 08:55:32 +01:00
|
|
|
#if HAVE_MS_ASM
|
|
|
|
__declspec(naked) float fmaxf(float, float)
|
|
|
|
{
|
|
|
|
__asm
|
|
|
|
{
|
|
|
|
fld DWORD PTR [esp+4]
|
|
|
|
fld DWORD PTR [esp+8]
|
|
|
|
fcomi st(0), st(1)
|
|
|
|
fcmovb st(0), st(1)
|
|
|
|
fxch
|
|
|
|
fstp st(0)
|
|
|
|
ret
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2004-06-03 03:43:33 +02:00
|
|
|
float fmaxf(float a, float b)
|
|
|
|
{
|
|
|
|
return (a > b)? a : b;
|
|
|
|
}
|
2005-11-07 03:45:25 +01:00
|
|
|
#endif
|
|
|
|
|
2006-02-23 08:55:32 +01:00
|
|
|
#endif // #if !HAVE_C99
|
|
|
|
|
2005-10-19 22:26:53 +02:00
|
|
|
|
2005-11-07 03:45:25 +01:00
|
|
|
// no C99, and not running on IA-32 (where this is defined to ia32_rint)
|
|
|
|
// => need to implement our fallback version.
|
|
|
|
#if !HAVE_C99 && !defined(rint)
|
2005-10-19 22:26:53 +02:00
|
|
|
|
|
|
|
inline float rintf(float f)
|
|
|
|
{
|
|
|
|
return (float)(int)f;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline double rint(double d)
|
|
|
|
{
|
|
|
|
return (double)(int)d;
|
|
|
|
}
|
|
|
|
|
2004-06-03 03:43:33 +02:00
|
|
|
#endif
|
2005-09-10 16:28:55 +02:00
|
|
|
|
|
|
|
|
2005-11-07 03:45:25 +01:00
|
|
|
// float->int conversion: not using the ia32 version; just implement as a
|
|
|
|
// cast. (see USE_IA32_FLOAT_TO_INT definition for details)
|
2005-11-07 03:04:28 +01:00
|
|
|
#if !USE_IA32_FLOAT_TO_INT
|
|
|
|
|
|
|
|
i32 i32_from_float(float f)
|
|
|
|
{
|
|
|
|
return (i32)f;
|
|
|
|
}
|
|
|
|
|
|
|
|
i32 i32_from_double(double d)
|
|
|
|
{
|
|
|
|
return (i32)d;
|
|
|
|
}
|
|
|
|
|
|
|
|
i64 i64_from_double(double d)
|
|
|
|
{
|
|
|
|
return (i64)d;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|