steam-for-linux icon indicating copy to clipboard operation
steam-for-linux copied to clipboard

[HLDS] Compiler-level optimization issues

Open thecrock opened this issue 13 years ago • 1 comments

I've noticed that compiler generates slow code in some cases. For example, int => float conversion, engine_i486.so, SV_SetGlobalTrace:

.text:00077FF7  movd    xmm0, dword ptr [eax]  //load dword to 128 bit register zeroing remaining 96 bits
.text:00077FFB  movq    [esp+0Ch+var_C], xmm0  //move 64 bit int to stack
.text:00078000  fild    [esp+0Ch+var_C]  //load float from 64bit int from stack
.text:00078003  fstp    dword ptr ds:gGlobalVariables+4Ch //store it in some field of global variable

All int => float conversions in engine_i486.so are done in same way.

Two first instructions from code above do unnecessary conversion from int32 => int64 and just wastes CPU time. Code above may be written with only two instructions:

fild  dword ptr [eax]
fstp  dword ptr gGlobalVariables+4Ch

Please review optimization flags for compiler, it can generate faster code. Also consider moving from x87 to SSE math (-mfpmath=sse), it works faster than x87 for single floats since Core2 familty CPUs.

thecrock avatar Feb 02 '13 11:02 thecrock

WE need x87 math so that the game simulation matches between all platforms (and on windows we are using a very old compiler). So can't fix this.

alfred-valve avatar Feb 04 '13 22:02 alfred-valve