Skip to content

Commit

Permalink
add likely-unlikely to JIT
Browse files Browse the repository at this point in the history
  • Loading branch information
Fidget-Spinner committed Jan 28, 2025
1 parent 5c9a63f commit 2b26797
Show file tree
Hide file tree
Showing 4 changed files with 293 additions and 277 deletions.
10 changes: 9 additions & 1 deletion Python/ceval_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,16 @@ GETITEM(PyObject *v, Py_ssize_t i) {
#define UPDATE_MISS_STATS(INSTNAME) ((void)0)
#endif

#if defined(__GNUC__) || defined(__clang__)
#define Py_UNLIKELY(x) (__builtin_expect(!!(x),false))
#elif (defined(__cplusplus) && (__cplusplus >= 202002L)) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
#define Py_UNLIKELY(x) (x) [[unlikely]]
#else
#define Py_UNLIKELY(x) (x)
#endif

#define DEOPT_IF(COND, INSTNAME) \
if ((COND)) { \
if (Py_UNLIKELY(COND)) { \
/* This is only a single jump on release builds! */ \
UPDATE_MISS_STATS((INSTNAME)); \
assert(_PyOpcode_Deopt[opcode] == (INSTNAME)); \
Expand Down
Loading

0 comments on commit 2b26797

Please sign in to comment.