Force compiler to not optimize side-effect-less statements

前端 未结 11 1677
执念已碎
执念已碎 2021-01-11 11:25

I was reading some old game programming books and as some of you might know, back in that day it was usually faster to do bit hacks than do things the standard way. (Convert

11条回答
  •  滥情空心
    2021-01-11 12:14

    a function call incurs quite a bit of overhead, so I would remove this anyway.

    adding a dummy += i; is no problem, as long as you keep this same bit of code in the alternate profile too. (So the code you are comparing it against).

    Last but not least: generate asm code. Even if you can not code in asm, the generated code is typically understandable since it will have labels and commented C code behind it. So you know (sortoff) what happens, and which bits are kept.

    R

    p.s. found this too:

     inline float pslNegFabs32f(float x){
           __asm{
             fld  x //Push 'x' into st(0) of FPU stack
             fabs
             fchs   //change sign
             fstp x //Pop from st(0) of FPU stack
            }
           return x;
     } 
    

    supposedly also very fast. You might want to profile this too. (although it is hardly portable code)

提交回复
热议问题