This is done by extending the HIR with two new EXPR_CONVERSION : EXPR_CONVERSION_{TO,FROM}_FLOAT.
Signed-off-by: Arthur Huillet <arthur.huil...@free.fr> --- arch/x86/insn-selector_32.brg | 38 ++++++++++++++++++++++++++---- include/jit/expression.h | 4 +++ jit/expression.c | 22 ++++++++++++++++++ jit/tree-printer.c | 2 + jit/typeconv-bc.c | 8 +++++- regression/jvm/FloatArithmeticTest.java | 2 +- 6 files changed, 69 insertions(+), 7 deletions(-) diff --git a/arch/x86/insn-selector_32.brg b/arch/x86/insn-selector_32.brg index 3103aa7..86d81b9 100644 --- a/arch/x86/insn-selector_32.brg +++ b/arch/x86/insn-selector_32.brg @@ -1164,12 +1164,40 @@ reg: EXPR_CONVERSION(reg) state->reg1 = get_var(s->b_parent); select_insn(s, tree, reg_reg_insn(INSN_MOVSX_REG_REG, state->left->reg1, state->reg1)); - } else if (src->vm_type == J_INT && expr->vm_type == J_FLOAT) { - NOT_IMPLEMENTED; - state->reg1 = get_var(s->b_parent); - } else if (src->vm_type == J_FLOAT && expr->vm_type == J_INT) { - NOT_IMPLEMENTED; + } else { + printf("%d to %d\n", src->vm_type, expr->vm_type); + assert(!"conversion not implemented"); + } +} + +freg: EXPR_CONVERSION_TO_FLOAT(reg) +{ + struct expression *expr, *src; + + expr = to_expr(tree); + src = to_expr(expr->from_expression); + + if (src->vm_type == J_INT && expr->vm_type == J_FLOAT) { + state->reg1 = get_fpu_var(s->b_parent); + + select_insn(s, tree, reg_reg_insn(INSN_CONV_GPR_TO_FPU, state->left->reg1, state->reg1)); + } else { + printf("%d to %d\n", src->vm_type, expr->vm_type); + assert(!"conversion not implemented"); + } +} + +reg: EXPR_CONVERSION_FROM_FLOAT(freg) +{ + struct expression *expr, *src; + + expr = to_expr(tree); + src = to_expr(expr->from_expression); + + if (src->vm_type == J_FLOAT && expr->vm_type == J_INT) { state->reg1 = get_var(s->b_parent); + + select_insn(s, tree, reg_reg_insn(INSN_CONV_FPU_TO_GPR, state->left->reg1, state->reg1)); } else { printf("%d to %d\n", src->vm_type, expr->vm_type); assert(!"conversion not implemented"); diff --git a/include/jit/expression.h b/include/jit/expression.h index d9c0b71..8f179c2 100644 --- a/include/jit/expression.h +++ b/include/jit/expression.h @@ -23,6 +23,8 @@ enum expression_type { EXPR_BINOP, EXPR_UNARY_OP, EXPR_CONVERSION, + EXPR_CONVERSION_FROM_FLOAT, + EXPR_CONVERSION_TO_FLOAT, EXPR_CLASS_FIELD, EXPR_INSTANCE_FIELD, EXPR_INVOKE, @@ -301,6 +303,8 @@ struct expression *array_deref_expr(enum vm_type, struct expression *, struct ex struct expression *binop_expr(enum vm_type, enum binary_operator, struct expression *, struct expression *); struct expression *unary_op_expr(enum vm_type, enum unary_operator, struct expression *); struct expression *conversion_expr(enum vm_type, struct expression *); +struct expression *conversion_from_float_expr(enum vm_type, struct expression *); +struct expression *conversion_to_float_expr(enum vm_type, struct expression *); struct expression *class_field_expr(enum vm_type, struct vm_field *); struct expression *instance_field_expr(enum vm_type, struct vm_field *, struct expression *); struct expression *invoke_expr(struct vm_method *); diff --git a/jit/expression.c b/jit/expression.c index a660f05..1f6727a 100644 --- a/jit/expression.c +++ b/jit/expression.c @@ -28,6 +28,8 @@ int expr_nr_kids(struct expression *expr) return 2; case EXPR_UNARY_OP: case EXPR_CONVERSION: + case EXPR_CONVERSION_TO_FLOAT: + case EXPR_CONVERSION_FROM_FLOAT: case EXPR_INSTANCE_FIELD: case EXPR_INVOKE: case EXPR_INVOKEVIRTUAL: @@ -75,6 +77,8 @@ int expr_is_pure(struct expression *expr) case EXPR_ARGS_LIST: case EXPR_UNARY_OP: case EXPR_CONVERSION: + case EXPR_CONVERSION_TO_FLOAT: + case EXPR_CONVERSION_FROM_FLOAT: case EXPR_ARG: case EXPR_ARRAYLENGTH: case EXPR_INSTANCEOF: @@ -263,6 +267,24 @@ struct expression *conversion_expr(enum vm_type vm_type, return expr; } +struct expression *conversion_to_float_expr(enum vm_type vm_type, + struct expression *from_expression) +{ + struct expression *expr = alloc_expression(EXPR_CONVERSION_TO_FLOAT, vm_type); + if (expr) + expr->from_expression = &from_expression->node; + return expr; +} + +struct expression *conversion_from_float_expr(enum vm_type vm_type, + struct expression *from_expression) +{ + struct expression *expr = alloc_expression(EXPR_CONVERSION_FROM_FLOAT, vm_type); + if (expr) + expr->from_expression = &from_expression->node; + return expr; +} + struct expression *class_field_expr(enum vm_type vm_type, struct vm_field *class_field) { struct expression *expr = alloc_expression(EXPR_CLASS_FIELD, vm_type); diff --git a/jit/tree-printer.c b/jit/tree-printer.c index 55b3adb..2c7c4c6 100644 --- a/jit/tree-printer.c +++ b/jit/tree-printer.c @@ -870,6 +870,8 @@ static print_expr_fn expr_printers[] = { [EXPR_BINOP] = print_binop_expr, [EXPR_UNARY_OP] = print_unary_op_expr, [EXPR_CONVERSION] = print_conversion_expr, + [EXPR_CONVERSION_FROM_FLOAT] = print_conversion_expr, + [EXPR_CONVERSION_TO_FLOAT] = print_conversion_expr, [EXPR_CLASS_FIELD] = print_class_field_expr, [EXPR_INSTANCE_FIELD] = print_instance_field_expr, [EXPR_INVOKE] = print_invoke_expr, diff --git a/jit/typeconv-bc.c b/jit/typeconv-bc.c index 5acc172..b6d846a 100644 --- a/jit/typeconv-bc.c +++ b/jit/typeconv-bc.c @@ -22,7 +22,13 @@ static int convert_conversion(struct parse_context *ctx, enum vm_type to_type) from_expression = stack_pop(ctx->bb->mimic_stack); - conversion_expression = conversion_expr(to_type, from_expression); + if (to_type == J_FLOAT) + conversion_expression = conversion_to_float_expr(to_type, from_expression); + else if (from_expression->vm_type == J_FLOAT) + conversion_expression = conversion_from_float_expr(to_type, from_expression); + else + conversion_expression = conversion_expr(to_type, from_expression); + if (!conversion_expression) return -ENOMEM; diff --git a/regression/jvm/FloatArithmeticTest.java b/regression/jvm/FloatArithmeticTest.java index 30ac318..8b3dfa7 100644 --- a/regression/jvm/FloatArithmeticTest.java +++ b/regression/jvm/FloatArithmeticTest.java @@ -136,7 +136,7 @@ public class FloatArithmeticTest extends TestCase { testFloatDivision(); //TODO testFloatRemainder(); testFloatNegation(); -// testFloatIntConversion(); + testFloatIntConversion(); exit(); } } -- 1.6.3.3 ------------------------------------------------------------------------------ _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel