Created
October 31, 2016 15:26
-
-
Save doug65536/e676b7eb344d3e5723dedf352119f21d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BranchlessCompare | |
{ | |
public: | |
using T = int; | |
BranchlessCompare() | |
{ | |
reset(); | |
} | |
void reset() noexcept | |
{ | |
force_false = 0; | |
force_true = 0; | |
} | |
template<typename A> | |
void compare(A const& lhs, A const& rhs) noexcept | |
{ | |
// Force T if we are not forcing F and we would return T | |
// Force F if we are not forcing T and we would return F | |
force_true |= (force_false^1) & T(lhs < rhs); | |
force_false |= (force_true^1) & T(rhs < lhs); | |
} | |
bool get() const noexcept | |
{ | |
return (force_true & (force_false^1) & 1); | |
} | |
operator bool() const noexcept | |
{ | |
return get(); | |
} | |
private: | |
T force_true; | |
T force_false; | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool InstancingManager::Instance::operator <(Instance const& r) const | |
{ | |
BranchlessCompare cmp; | |
cmp.compare(shaderState, r.shaderState); | |
cmp.compare(textureState, r.textureState); | |
cmp.compare(geometryState, r.geometryState); | |
cmp.compare(drawCall.mode, r.drawCall.mode); | |
cmp.compare(drawCall.count, r.drawCall.count); | |
cmp.compare(drawCall.count, r.drawCall.count); | |
cmp.compare(drawCall.indices, r.drawCall.indices); | |
cmp.compare(mvMatrix, r.mvMatrix); | |
return cmp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment