wingo pushed a commit to branch lightning
in repository guile.
commit 0b0d63d89293475409161e86ae727087a14d99b1
Author: pcpa <[email protected]>
Date: Tue Dec 3 15:09:48 2013 -0200
x86: Ensure the x87 stack is empty when calling a function.
* lib/jit_x86-cpu.c: Use the emms instruction before
calling any function. This is particularly important
when using c99 complex functions as it can easily
overflow the x87 stack due to the way lightning uses
the x87 stack as a flat register file.
---
ChangeLog | 8 ++++++++
lib/jit_x86-cpu.c | 5 +++++
2 files changed, 13 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index eef5617..8eaed7a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2013-12-03 Paulo Andrade <[email protected]>
+
+ * lib/jit_x86-cpu.c: Use the emms instruction before
+ calling any function. This is particularly important
+ when using c99 complex functions as it can easily
+ overflow the x87 stack due to the way lightning uses
+ the x87 stack as a flat register file.
+
2013-12-02 Paulo Andrade <[email protected]>
* lib/jit_x86-x87.c: Correct wrong code generation due
diff --git a/lib/jit_x86-cpu.c b/lib/jit_x86-cpu.c
index 4cf16c1..e79697a 100644
--- a/lib/jit_x86-cpu.c
+++ b/lib/jit_x86-cpu.c
@@ -139,6 +139,7 @@ static void
_rx(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t);
# define nop(n) _nop(_jit, n)
static void _nop(jit_state_t*, jit_int32_t);
+# define emms() is(0x770f)
# define lea(md, rb, ri, ms, rd) _lea(_jit, md, rb, ri, ms, rd)
static void
_lea(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t,jit_int32_t);
@@ -3258,6 +3259,9 @@ _bxsubi_u(jit_state_t *_jit, jit_word_t i0, jit_int32_t
r0, jit_word_t i1)
static void
_callr(jit_state_t *_jit, jit_int32_t r0)
{
+#if __WORDSIZE == 32
+ emms();
+#endif
rex(0, 0, _NOREG, _NOREG, r0);
ic(0xff);
mrm(0x03, 0x02, r7(r0));
@@ -3276,6 +3280,7 @@ _calli(jit_state_t *_jit, jit_word_t i0)
jit_unget_reg(reg);
#else
jit_word_t w;
+ emms();
ic(0xe8);
w = i0 - (_jit->pc.w + 4);
ii(w);