Skip to content

Commit

Permalink
Don't zero stuff on the tail call
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtbucher committed Oct 25, 2024
1 parent 64b198a commit 5791853
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions Tools/jit/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,39 @@

#include "ceval_macros.h"

#define CLOBBER_REGISTER(R, N) \
do { \
register __typeof__((R)) _reg __asm__ (#N); \
__asm__ inline ("":"=r"(_reg)); \
(R) = _reg; \
} while (0)

#if defined(__aarch64__) || defined(_M_ARM64)

#define CLEANUP() \
do { \
CLOBBER_REGISTER(_oparg, w3); \
CLOBBER_REGISTER(_operand, x4); \
} while (0)

#elif defined(__x86_64__) || defined(_M_X64)

#define CLEANUP() \
do { \
CLOBBER_REGISTER(_oparg, bx); \
CLOBBER_REGISTER(_operand, r14); \
} while (0)

#elif defined(_M_IX86)

#define CLEANUP() \
do { \
CLOBBER_REGISTER(_oparg, si); \
_operand = 0; \
} while (0)

#endif

#undef CURRENT_OPARG
#define CURRENT_OPARG() (_oparg)

Expand Down Expand Up @@ -48,8 +81,9 @@
#define GOTO_TIER_TWO(EXECUTOR) \
do { \
OPT_STAT_INC(traces_executed); \
CLEANUP(); \
__attribute__((musttail)) \
return ((jit_func)((EXECUTOR)->jit_side_entry))(frame, stack_pointer, tstate, 0, 0); \
return ((jit_func)((EXECUTOR)->jit_side_entry))(frame, stack_pointer, tstate, _oparg, _operand); \
} while (0)

#undef GOTO_TIER_ONE
Expand All @@ -71,8 +105,9 @@ do { \
#define PATCH_JUMP(ALIAS) \
do { \
PyAPI_DATA(void) ALIAS; \
CLEANUP(); \
__attribute__((musttail)) \
return ((jit_func)&ALIAS)(frame, stack_pointer, tstate, 0, 0); \
return ((jit_func)&ALIAS)(frame, stack_pointer, tstate, _oparg, _operand); \
} while (0)

#undef JUMP_TO_JUMP_TARGET
Expand Down

0 comments on commit 5791853

Please sign in to comment.