Use likely/unlikely to improve certain vector ops #66
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some compilers have special ways to indicate that a branch of an
if
is especially likely or unlikely to be taken, and can do some
micro-optimizations based on that. Establish IMATH_LIKELY and
IMATH_UNLIKELY macros to implement this. (In C++20 and beyond, there
will be standard attributes for this, but it'll be a while before we
can rely on those.)
For a few conditions in the length and normalize methods of vectors,
in OSL we had replaced these functions with our own modified versions
after analysis from Intel engineers that these hints really did help
generate more performant code in these specific places. In this PR,
I'm pushing those improvements back to the Imath project itself.
These new macros should be used with caution -- programmers
notoriously guess wrong and can hurt performance by using them
inappropriately. "My intuition is that it will take this branch most
of the time" is not good enough. Truly exceptional conditions (like
branches that handle very rarely encountered errors) can safely be
marked, but most ordinary control flow should not use these except in
response to clear indications from performance tests.
Signed-off-by: Larry Gritz lg@larrygritz.com