8000 py: Add MP_LIKELY(), MP_UNLIKELY() macros to help branch prediction. · garyaj/micropython@361909e · GitHub
[go: up one dir, main page]

Skip to content

Commit 361909e

Browse files
committed
py: Add MP_LIKELY(), MP_UNLIKELY() macros to help branch prediction.
1 parent 1ee1785 commit 361909e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

py/mpconfig.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,13 @@ typedef double mp_float_t;
562562
#ifndef MP_WEAK
563563
#define MP_WEAK __attribute__((weak))
564564
#endif
565+
566+
// Condition is likely to be true, to help branch prediction
567+
#ifndef MP_LIKELY
568+
#define MP_LIKELY(x) __builtin_expect((x), 1)
569+
#endif
570+
571+
// Condition is likely to be false, to help branch prediction
572+
#ifndef MP_UNLIKELY
573+
#define MP_UNLIKELY(x) __builtin_expect((x), 0)
574+
#endif

0 commit comments

Comments
 (0)
0