Commit 7b19a49b by Geoff Lang Committed by Commit Bot

Use LIKELY and UNLIKELY macros to wrap error generation.

BUG=609673 Change-Id: I247f561712e30aa10bad77fabf614501d596915e Reviewed-on: https://chromium-review.googlesource.com/1021995Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent 629bb259
......@@ -101,4 +101,15 @@
// We will undef the macro so that the function name does not get replaced
#undef MemoryBarrier
// Macro for hinting that an expression is likely to be true/false.
#if !defined(ANGLE_LIKELY) || !defined(ANGLE_UNLIKELY)
#if defined(__GNUC__) || defined(__clang__)
#define ANGLE_LIKELY(x) __builtin_expect(!!(x), 1)
#define ANGLE_UNLIKELY(x) __builtin_expect(!!(x), 0)
#else
#define ANGLE_LIKELY(x) (x)
#define ANGLE_UNLIKELY(x) (x)
#endif // defined(__GNUC__) || defined(__clang__)
#endif // !defined(ANGLE_LIKELY) || !defined(ANGLE_UNLIKELY)
#endif // COMMON_PLATFORM_H_
......@@ -2453,7 +2453,7 @@ void Context::getProgramInterfaceivRobust(GLuint program,
void Context::handleError(const Error &error) const
{
if (error.isError())
if (ANGLE_UNLIKELY(error.isError()))
{
GLenum code = error.getCode();
mErrors.insert(code);
......
......@@ -223,35 +223,35 @@ inline Error NoError()
#define ANGLE_CONCAT2(x, y) ANGLE_CONCAT1(x, y)
#define ANGLE_LOCAL_VAR ANGLE_CONCAT2(_localVar, __LINE__)
#define ANGLE_TRY_TEMPLATE(EXPR, FUNC) \
{ \
auto ANGLE_LOCAL_VAR = EXPR; \
if (ANGLE_LOCAL_VAR.isError()) \
{ \
FUNC(ANGLE_LOCAL_VAR); \
} \
} \
#define ANGLE_TRY_TEMPLATE(EXPR, FUNC) \
{ \
auto ANGLE_LOCAL_VAR = EXPR; \
if (ANGLE_UNLIKELY(ANGLE_LOCAL_VAR.isError())) \
{ \
FUNC(ANGLE_LOCAL_VAR); \
} \
} \
ANGLE_EMPTY_STATEMENT
#define ANGLE_RETURN(X) return X;
#define ANGLE_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_RETURN);
#define ANGLE_TRY_RESULT(EXPR, RESULT) \
{ \
auto ANGLE_LOCAL_VAR = EXPR; \
if (ANGLE_LOCAL_VAR.isError()) \
{ \
return ANGLE_LOCAL_VAR.getError(); \
} \
RESULT = ANGLE_LOCAL_VAR.getResult(); \
} \
#define ANGLE_TRY_RESULT(EXPR, RESULT) \
{ \
auto ANGLE_LOCAL_VAR = EXPR; \
if (ANGLE_UNLIKELY(ANGLE_LOCAL_VAR.isError())) \
{ \
return ANGLE_LOCAL_VAR.getError(); \
} \
RESULT = ANGLE_LOCAL_VAR.getResult(); \
} \
ANGLE_EMPTY_STATEMENT
// TODO(jmadill): Introduce way to store errors to a const Context.
#define ANGLE_SWALLOW_ERR(EXPR) \
{ \
auto ANGLE_LOCAL_VAR = EXPR; \
if (ANGLE_LOCAL_VAR.isError()) \
if (ANGLE_UNLIKELY(ANGLE_LOCAL_VAR.isError())) \
{ \
ERR() << "Unhandled internal error: " << ANGLE_LOCAL_VAR; \
} \
......
......@@ -667,7 +667,7 @@ VkImageViewType GetImageViewType(gl::TextureType textureType);
#define ANGLE_VK_TRY(command) \
{ \
auto ANGLE_LOCAL_VAR = command; \
if (ANGLE_LOCAL_VAR != VK_SUCCESS) \
if (ANGLE_UNLIKELY(ANGLE_LOCAL_VAR != VK_SUCCESS)) \
{ \
return rx::vk::Error(ANGLE_LOCAL_VAR, __FILE__, __LINE__); \
} \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment