Floating point faster than fixed-point

Yeah, I know - sounds stupid, but it's true.

I'm still perfecting my voxel engine. One huge problem was that it requires quite a few linear and bi-linear interpolations. My first thought, stop using floats and switch to fixed point. So, I did that.

However my frame rate in 320x200x64K was near abysmal. Also, the viewing distance was not satisfactory.

**Function 1 - fixed point**

Code:

`int LI(int v1,int v2,long f1)`

{

return v1+(f1*(v2-v1)>>SHIFT);

}

**Function 2 - double**

Code:

`int LI(int v1,int v2,double f1)`

{

return (int)((double)v1+(double)f1*((double)v2-(double)v1));

}

Even with all of the typecasting (just to be sure, ugly but ensures correct result) function 2 is faster than 1.

**Function 3 - inline asm for FPU**

Code:

`int LI(int v1,int v2,double f1)`

{

int value=0;

asm

{

finit //init FPU - just to be sure

fild v2 //place v2 on FPU stack

fisub v1 //integer subtract v1

fmul f1 //real multiply f1

fiadd v1 //integer add v1

fistp value //store integer in value, pop ST

}

return value;

}

Function 3 is the fastest of these three. I even tried using fixed point in assembly, but since inline does not allow 32-bit registers, it was tedious and slower. Not sure if fixed point in 32-bit registers is faster. Someone with MASM, please try this out and let me know.

At least for inline asm, it looks like goodbye to fixed point. Never thought I would be saying that.

Still too slow for 640x480x64K, because of all of the bank switching. Protected mode would allow much faster bank switch or even linear frame buffer, but my copy of DJGPP got eaten by a virus.

Would like to see some DJGPP code for VBE 2.0+.