How can adding code to a loop make it faster?

前端 未结 5 1927
醉梦人生
醉梦人生 2020-12-03 17:13

I have a simple function with an inner loop - it scales the input value, looks up an output value in a lookup table, and copies it to the destination. (ftol_ambient is a tri

5条回答
  •  盖世英雄少女心
    2020-12-03 17:54

    My first guess is that the branch is being predicted better in the second case. Possibly because the nested if gives whatever algorithm the processor's using more information to guess from. Just out of curiousity, what happens when you remove the line

    if (((int *)SRGBCeiling)[iSRGB] <= *((int *)pSource))

    ?

提交回复
热议问题