This calls the C function fmodf() as the VM Spec suggests. Signed-off-by: Arthur Huillet <arthur.huil...@free.fr> --- arch/x86/insn-selector_32.brg | 21 +++++++++++++++++++++ regression/jvm/FloatArithmeticTest.java | 9 +++++++-- 2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/arch/x86/insn-selector_32.brg b/arch/x86/insn-selector_32.brg index 1ba67b9..0e8e84f 100644 --- a/arch/x86/insn-selector_32.brg +++ b/arch/x86/insn-selector_32.brg @@ -22,6 +22,7 @@ #include <assert.h> #include <errno.h> +#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -447,6 +448,26 @@ reg: OP_REM(reg, reg) 1 select_insn(s, tree, reg_reg_insn(INSN_DIV_REG_REG, state->right->reg1, eax)); } +freg: OP_FREM(freg, freg) 1 +{ + struct var_info *esp, *eax; + + state->reg1 = get_fpu_var(s->b_parent); + + esp = get_fixed_var(s->b_parent, REG_ESP); + eax = get_fixed_var(s->b_parent, REG_EAX); + + select_insn(s, tree, reg_membase_insn(INSN_MOV_XMM_MEMBASE, state->left->reg1, esp, -8)); + select_insn(s, tree, reg_membase_insn(INSN_MOV_XMM_MEMBASE, state->right->reg1, esp, -4)); + select_insn(s, tree, imm_reg_insn(INSN_SUB_IMM_REG, 8, esp)); + + select_insn(s, tree, rel_insn(INSN_CALL_REL, (unsigned long)fmodf)); + method_args_cleanup(s, tree, 2); + + select_insn(s, tree, membase_insn(INSN_FSTP_MEMBASE, esp, -4)); + select_insn(s, tree, membase_reg_insn(INSN_MOV_MEMBASE_XMM, esp, -4, state->reg1)); +} + reg: OP_REM_64(reg, reg) 1 { emulate_op_64(state, s, tree, emulate_lrem, J_LONG); diff --git a/regression/jvm/FloatArithmeticTest.java b/regression/jvm/FloatArithmeticTest.java index 711710a..3a44995 100644 --- a/regression/jvm/FloatArithmeticTest.java +++ b/regression/jvm/FloatArithmeticTest.java @@ -97,6 +97,12 @@ public class FloatArithmeticTest extends TestCase { return dividend / divisor; } + public static void testFloatRemainder() { + assertEquals(2.0f, rem(6.0f, 4.0f)); + assertEquals(10000.5f, rem(10000.5f, 10001.5f)); + assertEquals(1.0f, rem(10002.5f, 10001.5f)); + } + public static float rem(float dividend, float divisor) { return dividend % divisor; } @@ -133,8 +139,7 @@ public class FloatArithmeticTest extends TestCase { testFloatSubtractionImmediateLocal(); testFloatMultiplication(); testFloatDivision(); -// FIXME -// testFloatRemainder(); + testFloatRemainder(); testFloatNegation(); testFloatIntConversion(); exit(); -- 1.6.3.3 ------------------------------------------------------------------------------ _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel