Replies: 1 comment
-
Also a "manual" pre-i686 compatible
It can be slower than branches if the prediction is easy. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I remember playing around a while back with min and max function that had to be used a lot. in the end I used branches because on modern CPU well predicted branches are often faster than branch-less equivalent. For min and max I remember using those old funcs I read somewhere...
On 386/486 the following will be maybe faster:
In Doom those min and max functions are not common, however with a bit of rewriting, branches can often be avoided like in the case of your last commit (just checked after having started to write) where the line:
With a branchless min you get some potential benefit.
Of course you have to be careful because on 386/486 the branch is always assumed NOT to be taken which can lead to faster code. but for the cases where you have 50:50% odds then this kind of tricks are really worth it.
WC default min and max are just
min(a,b) (((a) < (b)) ? (a) : (b))
andmax(a,b) (((a) > (b)) ? (a) : (b))
instdlib.h
, like usual.EDIT I just found a third version:
Beta Was this translation helpful? Give feedback.
All reactions