Skip to content

Commit

Permalink
JIT: fix 32-bit non-Mac stack alignment
Browse files Browse the repository at this point in the history
Fix function-call setup to align the stack to a 16-byte boundary on
all platforms.
  • Loading branch information
mflatt committed Nov 23, 2019
1 parent 0bb23c3 commit c611f12
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions racket/src/racket/src/jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ END_XFORM_ARITH;
# define _jit_epilog scheme_jit_epilog
#endif

/* The ABI for _CALL_DARWIN or JIT_X86_64 requires alignment. Even
when it's not required, it's better for performance when flonums
are stored on the stack. */
#define JIT_X86_ALIGN_STACK 1

#ifndef DEFINE_LIGHTNING_FUNCS
# define SUPPRESS_LIGHTNING_FUNCS
#endif
Expand Down Expand Up @@ -936,11 +941,7 @@ void scheme_jit_prolog_again(mz_jit_state *jitter, int n, int ret_addr_reg)
# define mz_get_local_p_x(x, l, FP) jit_ldxi_p((x), FP, (l))
# define mz_patch_branch_at(a, v) jit_patch_branch_at(a, v)
# define mz_patch_ucbranch_at(a, v) jit_patch_ucbranch_at(a, v)
/* The ABI for _CALL_DARWIN or JIT_X86_64 requires alignment. Even
when it's not required, it's better for performance when flonums
are stored on the stack. */
# define X86_ALIGN_STACK 1
# ifdef X86_ALIGN_STACK
# ifdef JIT_X86_ALIGN_STACK
/* Maintain 16-byte stack alignment. */
# ifdef JIT_X86_64
# define STACK_ALIGN_WORDS 1
Expand Down
6 changes: 3 additions & 3 deletions racket/src/racket/src/jitcommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static int save_struct_temp(mz_jit_state *jitter, int reg)
jit_movr_p(JIT_V(3), reg);
#endif
#ifdef MZ_USE_JIT_I386
# ifdef X86_ALIGN_STACK
# ifdef JIT_X86_ALIGN_STACK
mz_set_local_p(reg, JIT_LOCAL3);
# else
jit_pushr_p(reg);
Expand All @@ -101,7 +101,7 @@ static int restore_struct_temp(mz_jit_state *jitter, int reg)
jit_movr_p(reg, JIT_V(3));
#endif
#ifdef MZ_USE_JIT_I386
# ifdef X86_ALIGN_STACK
# ifdef JIT_X86_ALIGN_STACK
mz_get_local_p(reg, JIT_LOCAL3);
# else
jit_popr_p(reg);
Expand Down Expand Up @@ -1714,7 +1714,7 @@ int scheme_generate_struct_op(mz_jit_state *jitter, int kind, int for_branch,
} else {
mz_patch_ucbranch(bref_true);
#ifdef MZ_USE_JIT_I386
# ifndef X86_ALIGN_STACK
# ifndef JIT_X86_ALIGN_STACK
jit_popr_p(JIT_V1);
# endif
#endif
Expand Down
2 changes: 1 addition & 1 deletion racket/src/racket/src/lightning/i386/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ struct jit_local_state {
/* Stack isn't used for arguments: */
# define jit_prepare_i(ni) (_jitl.argssize = (ni), _jitl.argpushes = _jitl.argssize)
#else
# ifdef _CALL_DARWIN
# if defined(_CALL_DARWIN) || defined(JIT_X86_ALIGN_STACK)
/* Stack must stay 16-byte aligned: */
# define jit_prepare_i(ni) (((ni & 0x3) \
? SUBLir(4 * ((((ni) + 3) & ~(0x3)) - (ni)), JIT_SP) \
Expand Down

1 comment on commit c611f12

@pmatos
Copy link
Collaborator

@pmatos pmatos commented on c611f12 Nov 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably related to #2921, right?

Please sign in to comment.