Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPAssume macro usage in few places for optimisation (mostly -O3 benefits #1045

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions Sources/Core/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ namespace spades {
#define __PRETTY_FUNCTION__ __FUNCDNAME__
#endif

#if defined(__GNUC__) && defined(__GNUC_MINOR__)
#define GCCVERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
#else
#define GCCVERSION 0
#endif

#define SPADES_MARK_FUNCTION() \
static constexpr ::spades::reflection::Function thisFunction{__PRETTY_FUNCTION__, __FILE__, \
__LINE__}; \
Expand All @@ -124,6 +130,23 @@ namespace spades {
#define SPAssert(cond) ((!(cond)) ? SPRaise("SPAssertion failed: %s", #cond) : (void)0)
#endif

#if NDEBUG
#ifdef _MSC_VER
#define SPAssume(cond) __assume(cond)
#elif defined(__clang__) && __clang_major__ > 3
#define SPAssume(cond) __builtin_assume(cond)
#elif defined(__GNUC__) && GCCVERSION >= 4005
#define SPAssume(cond) \
do { \
if (!(cond)) __builtin_unreachable(); \
} while (0)
#else
#define SPAssume(cond)
#endif
#else
#define SPAssume(cond) SPAssert(cond)
#endif

#ifdef _MSC_VER
#define SPLog(format, ...) ::spades::LogMessage(__FILE__, __LINE__, format, __VA_ARGS__)
#else
Expand Down
2 changes: 1 addition & 1 deletion Sources/Draw/SWImageRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ namespace spades {
if (depthTest) {
depthOut = depthBuffer + (y * fbW);
}
SPAssert(x1 < x2);
SPAssume(x1 < x2);
int width = x2 - x1;
SWImageGouraudInterpolator<level> vary(vary1, vary2, width);
int minX = std::max(x1, 0);
Expand Down
2 changes: 1 addition & 1 deletion Sources/Draw/SWModelRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ namespace spades {
uint32_t normal = *(mp++);
int z = static_cast<int>(data >> 24);
// SPAssert(z < d);
SPAssert(z >= 0);
SPAssume(z >= 0);

auto vv = v2 + tAxis3 * zvals[z];
if (vv.z < zNear)
Expand Down
8 changes: 4 additions & 4 deletions Sources/Draw/SWRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ namespace spades {
int maxY = light.maxY;
int lightHeight = maxY - minY;

SPAssert(minX >= 0);
SPAssert(minY >= 0);
SPAssert(maxX <= fw);
SPAssert(maxY <= fh);
SPAssume(minX >= 0);
SPAssume(minY >= 0);
SPAssume(maxX <= fw);
SPAssume(maxY <= fh);

Vector3 lightCenter;
Vector3 diff = light.param.origin - sceneDef.viewOrigin;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Draw/SWUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace spades {
int GetNumSWRendererThreads();

template <class F> static void InvokeParallel(F f, unsigned int numThreads) {
SPAssert(numThreads <= 32);
SPAssume(numThreads <= 32);
std::array<std::unique_ptr<ConcurrentDispatch>, 32> disp;
for (auto i = 1U; i < numThreads; i++) {
auto ff = [i, &f]() { f(i); };
Expand Down