Skip to content

Commit c5e3af0

Browse files
committed
Ensure the mono interpreter also handles ConvertToIntegerNative for double and single
1 parent e90351f commit c5e3af0

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

src/mono/mono/mini/interp/transform.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2676,7 +2676,56 @@ interp_handle_intrinsics (TransformData *td, MonoMethod *target_method, MonoClas
26762676
!strncmp ("Vector", klass_name, 6) &&
26772677
!strcmp (tm, "get_IsHardwareAccelerated"))) {
26782678
*op = MINT_LDC_I4_0;
2679-
}
2679+
} else if ((target_method->klass == mono_defaults.double_class) || (target_method->klass == mono_defaults.single_class)) {
2680+
MonoGenericContext *method_context = mono_method_get_context (cmethod);
2681+
bool isDouble = target_method->klass == mono_defaults.double_class;
2682+
if (!strcmp (tm, "ConvertToIntegerNative") &&
2683+
method_context != NULL &&
2684+
method_context->method_inst->type_argc == 1) {
2685+
int opcode = 0;
2686+
MonoTypeEnum tto_type = method_context->method_inst->type_argv [0]->type;
2687+
MonoStackType tto_stack = STACK_I4;
2688+
switch (tto_type) {
2689+
case MONO_TYPE_I1:
2690+
*op = isDouble ? MINT_CONV_I1_R8 : MINT_CONV_I1_R4;
2691+
break;
2692+
case MONO_TYPE_I2:
2693+
*op = isDouble ? MINT_CONV_I2_R8 : MINT_CONV_I2_R4;
2694+
break;
2695+
#if TARGET_SIZEOF_VOID_P == 4
2696+
case MONO_TYPE_I:
2697+
#endif
2698+
case MONO_TYPE_I4:
2699+
*op = isDouble ? MINT_CONV_I4_R8 : MINT_CONV_I4_R4;
2700+
break;
2701+
#if TARGET_SIZEOF_VOID_P == 8
2702+
case MONO_TYPE_I:
2703+
#endif
2704+
case MONO_TYPE_I8:
2705+
*op = isDouble ? MINT_CONV_I8_R8 : MINT_CONV_I8_R4;
2706+
break;
2707+
case MONO_TYPE_U1:
2708+
*op = isDouble ? MINT_CONV_U1_R8 : MINT_CONV_U1_R4;
2709+
break;
2710+
case MONO_TYPE_U2:
2711+
*op = isDouble ? MINT_CONV_U2_R8 : MINT_CONV_U2_R4;
2712+
break;
2713+
#if TARGET_SIZEOF_VOID_P == 4
2714+
case MONO_TYPE_U:
2715+
#endif
2716+
case MONO_TYPE_U4:
2717+
*op = isDouble ? MINT_CONV_U4_R8 : MINT_CONV_U4_R4;
2718+
break;
2719+
#if TARGET_SIZEOF_VOID_P == 8
2720+
case MONO_TYPE_U:
2721+
#endif
2722+
case MONO_TYPE_U8:
2723+
*op = isDouble ? MINT_CONV_U8_R8 : MINT_CONV_U8_R4;
2724+
break;
2725+
default: return FALSE;
2726+
}
2727+
}
2728+
}
26802729

26812730
return FALSE;
26822731
}

0 commit comments

Comments
 (0)