From d0fd6ded4ed5764a1763387fd7715ea79818dd14 Mon Sep 17 00:00:00 2001 From: Frode Solheim Date: Thu, 24 Sep 2015 20:19:40 +0200 Subject: [PATCH] Fix ESP/RSP stack pointer manipulation in more functions (x86-64) --- jit/codegen_x86.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/jit/codegen_x86.cpp b/jit/codegen_x86.cpp index 2637c6ab..5b824e02 100644 --- a/jit/codegen_x86.cpp +++ b/jit/codegen_x86.cpp @@ -4733,9 +4733,16 @@ LOWFUNC(NONE,NONE,2,raw_ftan_rr,(FW d, FR s)) } LENDFUNC(NONE,NONE,2,raw_ftan_rr,(FW d, FR s)) +#ifdef CPU_x86_64 +#define REX64 emit_byte(0x48); +#else +#define REX64 +#endif + LOWFUNC(NONE,NONE,1,raw_fcuts_r,(FRW r)) { make_tos(r); /* TOS = r */ + REX64 emit_byte(0x83); emit_byte(0xc4); emit_byte(0xfc); /* add -4 to esp */ @@ -4746,6 +4753,7 @@ LOWFUNC(NONE,NONE,1,raw_fcuts_r,(FRW r)) emit_byte(0x04); emit_byte(0x24); /* fld load r as SINGLE from [esp] */ emit_byte(0x9b); /* let the CPU wait on FPU exceptions */ + REX64 emit_byte(0x83); emit_byte(0xc4); emit_byte(0x04); /* add +4 to esp */ @@ -4755,6 +4763,7 @@ LENDFUNC(NONE,NONE,1,raw_fcuts_r,(FRW r)) LOWFUNC(NONE,NONE,1,raw_fcut_r,(FRW r)) { make_tos(r); /* TOS = r */ + REX64 emit_byte(0x83); emit_byte(0xc4); emit_byte(0xf8); /* add -8 to esp */ @@ -4765,6 +4774,7 @@ LOWFUNC(NONE,NONE,1,raw_fcut_r,(FRW r)) emit_byte(0x04); emit_byte(0x24); /* fld load r as DOUBLE from [esp] */ emit_byte(0x9b); /* let the CPU wait on FPU exceptions */ + REX64 emit_byte(0x83); emit_byte(0xc4); emit_byte(0x08); /* add +8 to esp */ @@ -5016,9 +5026,7 @@ LOWFUNC(NONE,NONE,2,raw_fsinh_rr,(FW d, FR s)) if (tr>=0) { emit_byte(0xd9); emit_byte(0xca); /* fxch swap with temp-reg */ -#ifdef CPU_x86_64 - emit_byte(0x48); /* Use rsp register */ -#endif + REX64 emit_byte(0x83); emit_byte(0xc4); emit_byte(0xf4); /* add -12 to esp */ @@ -5066,9 +5074,7 @@ LOWFUNC(NONE,NONE,2,raw_fsinh_rr,(FW d, FR s)) emit_byte(0xca); /* fxch swap temp-reg with e^-x in tr */ emit_byte(0xde); emit_byte(0xe9); /* fsubp (e^x)-(e^-x) */ -#ifdef CPU_x86_64 - emit_byte(0x48); /* Use rsp register */ -#endif + REX64 emit_byte(0x83); emit_byte(0xc4); emit_byte(0x0c); /* delayed add +12 to esp */ @@ -5113,6 +5119,7 @@ LOWFUNC(NONE,NONE,2,raw_fcosh_rr,(FW d, FR s)) if (tr>=0) { emit_byte(0xd9); emit_byte(0xca); /* fxch swap with temp-reg */ + REX64 emit_byte(0x83); emit_byte(0xc4); emit_byte(0xf4); /* add -12 to esp */ @@ -5158,6 +5165,7 @@ LOWFUNC(NONE,NONE,2,raw_fcosh_rr,(FW d, FR s)) emit_byte(0x24); /* fld load temp-reg from [esp] */ emit_byte(0xd9); emit_byte(0xca); /* fxch swap temp-reg with e^-x in tr */ + REX64 emit_byte(0x83); emit_byte(0xc4); emit_byte(0x0c); /* delayed add +12 to esp */ @@ -5200,6 +5208,7 @@ LOWFUNC(NONE,NONE,2,raw_ftanh_rr,(FW d, FR s)) if (tr>=0) { emit_byte(0xd9); emit_byte(0xca); /* fxch swap with temp-reg */ + REX64 emit_byte(0x83); emit_byte(0xc4); emit_byte(0xf4); /* add -12 to esp */ @@ -5253,6 +5262,7 @@ LOWFUNC(NONE,NONE,2,raw_ftanh_rr,(FW d, FR s)) emit_byte(0xca); /* fxch swap temp-reg with e^-x in tr */ emit_byte(0xde); emit_byte(0xf9); /* fdivp ((e^x)-(e^-x))/((e^x)+(e^-x)) */ + REX64 emit_byte(0x83); emit_byte(0xc4); emit_byte(0x0c); /* delayed add +12 to esp */ -- 2.47.3