You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried code example from a youtube video and found out,
that the OW does not detect the branchless code
and always uses a branch in the other examples.
Original source was a branchless version and a version with if.
I added an often used code-style with a conditional:
/* original example: branchless code */
int smaller_branchless(int a, int b)
{
return a* (a<b) + b*(b<=a);
}
/* my extension: A very common usage with a conditional */
int smaller_cond(int a, int b)
{
return (a < b) ? a : b;
}
/* original example: with if */
int smaller_if(int a, int b)
{
if (a < b)
return a;
else
return b;
}
clang (-O2/-O3) detects the branchless version and produces the same code for all 3 variants:
OpenWatcom has a small advantage here, because of the selected register calling convention (-6r)
but does not detect, what the branchless code is doing
and for the conditional source example and the "if" source example,
the code produced by OW (owcc -mtune=i686 with -O2 or with -O3) has always a branch:
I expect, that the impact of running the branching code produced by OW
is smaller on recent CPUs (speculative execution, register renaming, branch prediction, ...)
compared to the Pentium Pro processor generation (when the "cmov" family of commands appeared)
but when a branch can be avoided easily, it should be done (see clang and gcc).
The text was updated successfully, but these errors were encountered:
I used Compiler explorer and verified, that icc (2021.10) and msvc (17.10)
create similar branchless code for the conditional example and the "if" example.
I tried code example from a youtube video and found out,
that the OW does not detect the branchless code
and always uses a branch in the other examples.
Original source was a branchless version and a version with if.
I added an often used code-style with a conditional:
clang (-O2/-O3) detects the branchless version and produces the same code for all 3 variants:
The branchless version of gcc (-O2/-O3) is a bit longer,
but gcc creates the same code for the conditional and the "if" version.
OpenWatcom has a small advantage here, because of the selected register calling convention (-6r)
but does not detect, what the branchless code is doing
and for the conditional source example and the "if" source example,
the code produced by OW (owcc -mtune=i686 with -O2 or with -O3) has always a branch:
I expect, that the impact of running the branching code produced by OW
is smaller on recent CPUs (speculative execution, register renaming, branch prediction, ...)
compared to the Pentium Pro processor generation (when the "cmov" family of commands appeared)
but when a branch can be avoided easily, it should be done (see clang and gcc).
The text was updated successfully, but these errors were encountered: