Signed-off-by: Tomek Grabiec <tgrab...@gmail.com> --- arch/x86/insn-selector.brg | 30 ++++++++++++++++++++++++++++++ regression/jvm/DoubleArithmeticTest.java | 16 ++++++++++------ 2 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/arch/x86/insn-selector.brg b/arch/x86/insn-selector.brg index 8dfc6dd..dc5c582 100644 --- a/arch/x86/insn-selector.brg +++ b/arch/x86/insn-selector.brg @@ -1572,6 +1572,36 @@ reg: EXPR_CONVERSION_FROM_DOUBLE(freg) state->reg1 = get_var(s->b_parent, J_INT); select_insn(s, tree, reg_reg_insn(INSN_CONV_FPU64_TO_GPR, state->left->reg1, state->reg1)); + } else if (expr->vm_type == J_LONG) { + struct var_info *esp = get_fixed_var(s->b_parent, MACH_REG_ESP); + + state->reg1 = get_var(s->b_parent, J_INT); + state->reg2 = get_var(s->b_parent, J_INT); + + /* Reserve space for temporaries. */ + select_insn(s, tree, imm_reg_insn(INSN_SUB_IMM_REG, 16, esp)); + + /* + * (%esp) contains double value to be converted + * $8(%esp) contains saved FPU control word + * $12(%esp) contains modified FPU control word (RC flag set) + */ + + select_insn(s, tree, membase_insn(INSN_FNSTCW_MEMBASE, esp, 8)); + select_insn(s, tree, membase_insn(INSN_FNSTCW_MEMBASE, esp, 12)); + + select_insn(s, tree, reg_membase_insn(INSN_MOV_64_XMM_MEMBASE, state->left->reg1, esp, 0)); + select_insn(s, tree, membase_insn(INSN_FLD_64_MEMBASE, esp, 0)); + + select_insn(s, tree, imm_membase_insn(INSN_OR_IMM_MEMBASE, 0xc0, esp, 12)); + select_insn(s, tree, membase_insn(INSN_FLDCW_MEMBASE, esp, 12)); + select_insn(s, tree, membase_insn(INSN_FISTP_64_MEMBASE, esp, 0)); + select_insn(s, tree, membase_insn(INSN_FLDCW_MEMBASE, esp, 8)); + + select_insn(s, tree, membase_reg_insn(INSN_MOV_MEMBASE_REG, esp, 0, state->reg1)); + select_insn(s, tree, membase_reg_insn(INSN_MOV_MEMBASE_REG, esp, 4, state->reg2)); + + select_insn(s, tree, imm_reg_insn(INSN_ADD_IMM_REG, 16, esp)); } else { die("EXPR_CONVERSION_FROM_DOUBLE: no conversion from %d to %d", src->vm_type, expr->vm_type); } diff --git a/regression/jvm/DoubleArithmeticTest.java b/regression/jvm/DoubleArithmeticTest.java index 092cb85..0547b7e 100644 --- a/regression/jvm/DoubleArithmeticTest.java +++ b/regression/jvm/DoubleArithmeticTest.java @@ -126,6 +126,14 @@ public class DoubleArithmeticTest extends TestCase { return (int) val; } + public static double l2d(long val) { + return (double) val; + } + + public static long d2l(double val) { + return (long) val; + } + public static void testDoubleIntConversion() { assertEquals(2, d2i(2.5)); assertEquals(-1000, d2i(-1000.0101)); @@ -133,13 +141,9 @@ public class DoubleArithmeticTest extends TestCase { assertEquals(-3000, i2d(-3000)); } - public static double l2d(long val) { - return (double) val; - } - public static void testDoubleLongConversion() { -// assertEquals(2, d2l(2.)); -// assertEquals(-1000, d2l(-1000.0101)); + assertEquals(2, d2l(2.)); + assertEquals(-1000, d2l(-1000.0101)); assertEquals(2.0, l2d(2)); assertEquals(-3000, l2d(-3000)); } -- 1.6.0.6 ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel