Implement Linux-style likely()/unlikely() macros

This implement branch prediction macros likely() and unlikely() like in
Linux. When using these macros please ensure that when you use them the
condition in the branch really is very, very likely or unlikely. Think
90+% of the time. Primarily useful for error checking. (And I implement
these macros for all our error checking macros now)

See this article for more information:
https://kernelnewbies.org/FAQ/LikelyUnlikely

There are more places where these macros may make sense in renderer and
physics engine. Placing them will come in another commit down the line.
This commit is contained in:
Hein-Pieter van Braam 2017-09-20 11:04:50 +02:00
parent 4664d03a0e
commit 22358babda
4 changed files with 24 additions and 15 deletions

View file

@ -42,7 +42,7 @@ Variant *GDFunction::_get_variant(int p_address, GDInstance *p_instance, GDScrip
case ADDR_TYPE_SELF: {
if (!p_instance) {
if (unlikely(!p_instance)) {
r_error = "Cannot access self without instance.";
return NULL;
}
@ -54,7 +54,7 @@ Variant *GDFunction::_get_variant(int p_address, GDInstance *p_instance, GDScrip
} break;
case ADDR_TYPE_MEMBER: {
//member indexing is O(1)
if (!p_instance) {
if (unlikely(!p_instance)) {
r_error = "Cannot access member without instance.";
return NULL;
}
@ -279,7 +279,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a
#define GET_VARIANT_PTR(m_v, m_code_ofs) \
Variant *m_v; \
m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, _class, self, stack, err_text); \
if (!m_v) \
if (unlikely(!m_v)) \
break;
#else