168 lines
2.2 KiB
C++
168 lines
2.2 KiB
C++
unsigned int myrand()
|
|
{
|
|
static int i= 0;
|
|
i*= 78547803;
|
|
i+= 1747627;
|
|
return i;
|
|
}
|
|
|
|
extern const float c_2PI= 6.2831853f;
|
|
extern const float c_PI= 3.1415927f;
|
|
|
|
#ifdef SUPERSMALL
|
|
extern "C" int _fltused;
|
|
int _fltused;
|
|
#endif
|
|
|
|
extern "C" int ____security_cookie;
|
|
int ____security_cookie;
|
|
|
|
#ifdef SUPERSMALL
|
|
/*extern "C"
|
|
{
|
|
__declspec(naked) void _ftol2()
|
|
{
|
|
__asm
|
|
{
|
|
fistp DWORD PTR [esp-12]
|
|
mov eax, DWORD PTR [esp-12]
|
|
mov ecx, DWORD PTR [esp-8]
|
|
|
|
ret
|
|
}
|
|
}
|
|
__declspec(naked) void _ftol2_sse()
|
|
{
|
|
__asm
|
|
{
|
|
fistp DWORD PTR [esp-12]
|
|
mov eax, DWORD PTR [esp-12]
|
|
mov ecx, DWORD PTR [esp-8]
|
|
|
|
ret
|
|
}
|
|
}
|
|
}*/
|
|
|
|
float mypow( float a, float b)
|
|
{
|
|
// faster pow based on code by agner fog
|
|
__asm
|
|
{
|
|
fld b;
|
|
fld a;
|
|
|
|
// ftst;
|
|
// fstsw ax;
|
|
// sahf;
|
|
// jz zero;
|
|
|
|
fyl2x;
|
|
fist dword ptr [a];
|
|
sub esp, 12;
|
|
mov dword ptr [esp],0;
|
|
mov dword ptr [esp+4],0x80000000;
|
|
fisub dword ptr [a];
|
|
mov eax, dword ptr [a];
|
|
add eax, 0x3fff;
|
|
mov [esp+8], eax;
|
|
// jle underflow;
|
|
// cmp eax, 0x8000;
|
|
// jge overflow;
|
|
f2xm1;
|
|
fld1;
|
|
fadd;
|
|
fld tbyte ptr [esp];
|
|
add esp, 12;
|
|
fmul;
|
|
//jmp end;
|
|
|
|
// underflow:
|
|
// fstp st;
|
|
// fldz;
|
|
// add esp, 12;
|
|
// jmp end;
|
|
|
|
//overflow:
|
|
// push 0x7f800000;
|
|
// fstp st;
|
|
// fld dword ptr [esp];
|
|
// add esp, 16;
|
|
// jmp end;
|
|
|
|
//zero:
|
|
// fstp st(1);
|
|
|
|
//end:
|
|
}
|
|
//return st;
|
|
}
|
|
#endif
|
|
|
|
|
|
|
|
extern "C"
|
|
{
|
|
double __cdecl sin(double);
|
|
double __cdecl cos(double);
|
|
double __cdecl sqrt(double);
|
|
double __cdecl fabs(double);
|
|
|
|
void* __cdecl memcpy( void* dest, const void* src, size_t count );
|
|
}
|
|
|
|
#pragma intrinsic ( sin, cos, sqrt, fabs ) // true intrinsic
|
|
#pragma intrinsic ( memcpy ) // true intrinsic
|
|
|
|
/*
|
|
__forceinline double sin(double v)
|
|
{
|
|
__asm fld v;
|
|
__asm fsin;
|
|
__asm fstp v;
|
|
return v;
|
|
}
|
|
|
|
|
|
float cos(float v)
|
|
{
|
|
__asm fld v;
|
|
__asm fcos;
|
|
__asm fstp v;
|
|
return v;
|
|
}
|
|
*/
|
|
/*float sqrt(float v)
|
|
{
|
|
__asm finit;
|
|
__asm fld v;
|
|
__asm fsqrt;
|
|
__asm fstp v;
|
|
return v;
|
|
}*/
|
|
|
|
/*float abs(float X)
|
|
{
|
|
if(X < 0.0f)
|
|
return -X;
|
|
|
|
return X;
|
|
}*/
|
|
|
|
float maximum(float X, float Y)
|
|
{
|
|
if(X < Y)
|
|
return Y;
|
|
|
|
return X;
|
|
}
|
|
|
|
float minimum(float X, float Y)
|
|
{
|
|
if(X > Y)
|
|
return Y;
|
|
|
|
return X;
|
|
}
|
|
|