Replace:
Code: Select all
inline DWORD F2DW( FLOAT f ) { return *((DWORD*)&f); }
Code: Select all
__inline DWORD F2DW(float f)
{
DWORD retval = 0;
_asm {
fld f
lea eax, [retval]
fistp dword ptr[eax]
}
return retval;
}
Code: Select all
inline DWORD F2DW( FLOAT f ) { return *((DWORD*)&f); }
Code: Select all
__inline DWORD F2DW(float f)
{
DWORD retval = 0;
_asm {
fld f
lea eax, [retval]
fistp dword ptr[eax]
}
return retval;
}
Well...it's good practice to initalize all your variables. I can't count how many times I ran into an issue and wasted 4 hours debugging it only to find out it was an uninitialized variable. In this case, if the float to DWORD conversion fails for some reason, the function will return 0 instead of 0xcccccccc. As for the extra instruction, every little bit counts. Genesis and RF are not built for speed. All game engines and shells should be built for speed. For example, the structs in Genesis and RF are not 4 byte aligned. This makes the processor very angry because it has to work harder. Struct sizes should be in multiples of 4. For example:@paradoxnj: just a question out of interest: Would it matter if you didn't initalize the variable at the beginning? (It does only save 1 machine code instruction and would not matter in the end, i know) I mean the variable's value would be set to the 'float' value anyways... Or is this not advisable, because the value is set by the assembler code?
Code: Select all
struct Test
{
float a; // 8 bytes
DWORD b; // 4 bytes
char c; // 1 byte
} Test;
Code: Select all
struct Test
{
float a; // 8 bytes
DWORD b; // 4 bytes
int c; // 4 bytes
} Test;
Code: Select all
class MyClass
{
public:
int my_var;
inline MyClass::GetMyVar()
{
return my_var;
}
};
MyClass cls;
cls.GetMyVar() = 0;
Code: Select all
class MyClass
{
public:
int my_var;
}
MyClass cls;
cls.my_var = 0;
Code: Select all
inline DWORD F2DW( FLOAT f ) { return *((DWORD*)&f); }