Skip to content

Commit

Permalink
[mono] Fix conversions from float to integer (#57048)
Browse files Browse the repository at this point in the history
* [interp] Fix conversions from float to integer

.un prefix is ignored for these conversions

* [mini] Fix conversions from float to integer

.un prefix is ignored for these conversions

* Re-enable test
  • Loading branch information
BrzVlad authored Aug 9, 2021
1 parent 2be518a commit 1bd4e4b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 79 deletions.
55 changes: 0 additions & 55 deletions src/mono/mono/mini/interp/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -5445,14 +5445,6 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK;
ip += 4;
MINT_IN_BREAK;
}
MINT_IN_CASE(MINT_CONV_OVF_I4_UN_R8) {
double val = LOCAL_VAR (ip [2], double);
if (val < 0 || val > G_MAXINT32)
THROW_EX (mono_get_exception_overflow (), ip);
LOCAL_VAR (ip [1], gint32) = (gint32)val;
ip += 3;
MINT_IN_BREAK;
}
MINT_IN_CASE(MINT_CONV_OVF_U8_I4) {
gint32 val = LOCAL_VAR (ip [2], gint32);
if (val < 0)
Expand Down Expand Up @@ -5493,22 +5485,6 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK;
ip += 3;
MINT_IN_BREAK;
}
MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R8) {
double val = LOCAL_VAR (ip [2], double);
if (val < 0 || mono_isnan (val) || mono_trunc (val) != (gint64)val)
THROW_EX (mono_get_exception_overflow (), ip);
LOCAL_VAR (ip [1], gint64) = (gint64)val;
ip += 3;
MINT_IN_BREAK;
}
MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R4) {
float val = LOCAL_VAR (ip [2], float);
if (val < 0 || mono_isnan (val) || mono_trunc (val) != (gint64)val)
THROW_EX (mono_get_exception_overflow (), ip);
LOCAL_VAR (ip [1], gint64) = (gint64)val;
ip += 3;
MINT_IN_BREAK;
}
MINT_IN_CASE(MINT_CONV_OVF_I8_R4) {
float val = LOCAL_VAR (ip [2], float);
if (mono_isnan (val) || mono_trunc (val) != (gint64)val)
Expand Down Expand Up @@ -5917,21 +5893,6 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK;
ip += 3;
MINT_IN_BREAK;
}
MINT_IN_CASE(MINT_CONV_OVF_I2_UN_R4) {
float val = LOCAL_VAR (ip [2], float);
if (val < 0 || val > G_MAXINT16 || isnan (val))
THROW_EX (mono_get_exception_overflow (), ip);
LOCAL_VAR (ip [1], gint32) = (gint16) val;
ip += 3;
MINT_IN_BREAK;
}
MINT_IN_CASE(MINT_CONV_OVF_I2_UN_R8) {
double val = LOCAL_VAR (ip [2], double);
if (val < 0 || val > G_MAXINT16 || isnan (val))
THROW_EX (mono_get_exception_overflow (), ip);
LOCAL_VAR (ip [1], gint32) = (gint16) val;
MINT_IN_BREAK;
}
MINT_IN_CASE(MINT_CONV_OVF_U2_I4) {
gint32 val = LOCAL_VAR (ip [2], gint32);
if (val < 0 || val > G_MAXUINT16)
Expand Down Expand Up @@ -6012,22 +5973,6 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK;
ip += 3;
MINT_IN_BREAK;
}
MINT_IN_CASE(MINT_CONV_OVF_I1_UN_R4) {
float val = LOCAL_VAR (ip [2], float);
if (val < 0 || val > G_MAXINT8 || isnan (val))
THROW_EX (mono_get_exception_overflow (), ip);
LOCAL_VAR (ip [1], gint32) = (gint8) val;
ip += 3;
MINT_IN_BREAK;
}
MINT_IN_CASE(MINT_CONV_OVF_I1_UN_R8) {
double val = LOCAL_VAR (ip [2], double);
if (val < 0 || val > G_MAXINT8 || isnan (val))
THROW_EX (mono_get_exception_overflow (), ip);
LOCAL_VAR (ip [1], gint32) = (gint8) val;
ip += 3;
MINT_IN_BREAK;
}
MINT_IN_CASE(MINT_CONV_OVF_U1_I4) {
gint32 val = LOCAL_VAR (ip [2], gint32);
if (val < 0 || val > G_MAXUINT8)
Expand Down
9 changes: 0 additions & 9 deletions src/mono/mono/mini/interp/mintops.def
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,6 @@ OPDEF(MINT_CONV_OVF_I1_R8, "conv.ovf.i1.r8", 3, 1, 1, MintOpNoArgs)

OPDEF(MINT_CONV_OVF_I1_U4, "conv.ovf.i1.u4", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_CONV_OVF_I1_U8, "conv.ovf.i1.u8", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_CONV_OVF_I1_UN_R4, "conv.ovf.i1.un.r4", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_CONV_OVF_I1_UN_R8, "conv.ovf.i1.un.r8", 3, 1, 1, MintOpNoArgs)

OPDEF(MINT_CONV_OVF_U1_I4, "conv.ovf.u1.i4", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_CONV_OVF_U1_I8, "conv.ovf.u1.i8", 3, 1, 1, MintOpNoArgs)
Expand All @@ -598,8 +596,6 @@ OPDEF(MINT_CONV_OVF_I2_R8, "conv.ovf.i2.r8", 3, 1, 1, MintOpNoArgs)

OPDEF(MINT_CONV_OVF_I2_U4, "conv.ovf.i2.u4", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_CONV_OVF_I2_U8, "conv.ovf.i2.u8", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_CONV_OVF_I2_UN_R4, "conv.ovf.i2.un.r4", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_CONV_OVF_I2_UN_R8, "conv.ovf.i2.un.r8", 3, 1, 1, MintOpNoArgs)

OPDEF(MINT_CONV_OVF_U2_I4, "conv.ovf.u2.i4", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_CONV_OVF_U2_I8, "conv.ovf.u2.i8", 3, 1, 1, MintOpNoArgs)
Expand All @@ -612,8 +608,6 @@ OPDEF(MINT_CONV_OVF_I4_U8, "conv.ovf.i4.u8", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_CONV_OVF_I4_R4, "conv.ovf.i4.r4", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_CONV_OVF_I4_R8, "conv.ovf.i4.r8", 3, 1, 1, MintOpNoArgs)

OPDEF(MINT_CONV_OVF_I4_UN_R8, "conv.ovf.i4.un.r8", 3, 1, 1, MintOpNoArgs)

OPDEF(MINT_CONV_OVF_U4_I4, "conv.ovf.u4.i4", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_CONV_OVF_U4_I8, "conv.ovf.u4.i8", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_CONV_OVF_U4_R4, "conv.ovf.u4.r4", 3, 1, 1, MintOpNoArgs)
Expand All @@ -623,9 +617,6 @@ OPDEF(MINT_CONV_OVF_I8_U8, "conv.ovf.i8.u8", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_CONV_OVF_I8_R4, "conv.ovf.i8.r4", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_CONV_OVF_I8_R8, "conv.ovf.i8.r8", 3, 1, 1, MintOpNoArgs)

OPDEF(MINT_CONV_OVF_I8_UN_R8, "conv.ovf.i8.un.r8", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_CONV_OVF_I8_UN_R4, "conv.ovf.i8.un.r4", 3, 1, 1, MintOpNoArgs)

OPDEF(MINT_CONV_OVF_U8_I4, "conv.ovf.u8.i4", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_CONV_OVF_U8_I8, "conv.ovf.u8.i8", 3, 1, 1, MintOpNoArgs)
OPDEF(MINT_CONV_OVF_U8_R4, "conv.ovf.u8.r4", 3, 1, 1, MintOpNoArgs)
Expand Down
42 changes: 31 additions & 11 deletions src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -6141,24 +6141,44 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
}
#if SIZEOF_VOID_P == 8
case CEE_CONV_OVF_I_UN:
case CEE_CONV_OVF_U_UN:
#endif
case CEE_CONV_OVF_I8_UN:
case CEE_CONV_OVF_U8_UN:
CHECK_STACK (td, 1);
switch (td->sp [-1].type) {
case STACK_TYPE_R4:
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I8, MINT_CONV_OVF_I8_R4);
break;
case STACK_TYPE_R8:
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I8, MINT_CONV_OVF_I8_UN_R8);
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I8, MINT_CONV_OVF_I8_R8);
break;
case STACK_TYPE_I4:
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I8, MINT_CONV_I8_U4);
break;
case STACK_TYPE_I8:
if (*td->ip == CEE_CONV_OVF_I8_UN || *td->ip == CEE_CONV_OVF_I_UN)
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I8, MINT_CONV_OVF_I8_U8);
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I8, MINT_CONV_OVF_I8_U8);
break;
default:
g_assert_not_reached ();
break;
}
++td->ip;
break;
#if SIZEOF_VOID_P == 8
case CEE_CONV_OVF_U_UN:
#endif
case CEE_CONV_OVF_U8_UN:
CHECK_STACK (td, 1);
switch (td->sp [-1].type) {
case STACK_TYPE_R4:
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I8, MINT_CONV_OVF_U8_R4);
break;
case STACK_TYPE_R8:
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I8, MINT_CONV_OVF_U8_R8);
break;
case STACK_TYPE_I4:
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I8, MINT_CONV_I8_U4);
break;
case STACK_TYPE_R4:
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I8, MINT_CONV_OVF_I8_UN_R4);
case STACK_TYPE_I8:
break;
default:
g_assert_not_reached ();
Expand Down Expand Up @@ -6515,10 +6535,10 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
CHECK_STACK (td, 1);
switch (td->sp [-1].type) {
case STACK_TYPE_R4:
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I4, is_un ? MINT_CONV_OVF_I1_UN_R4 : MINT_CONV_OVF_I1_R4);
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I4, MINT_CONV_OVF_I1_R4);
break;
case STACK_TYPE_R8:
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I4, is_un ? MINT_CONV_OVF_I1_UN_R8 : MINT_CONV_OVF_I1_R8);
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I4, MINT_CONV_OVF_I1_R8);
break;
case STACK_TYPE_I4:
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I4, is_un ? MINT_CONV_OVF_I1_U4 : MINT_CONV_OVF_I1_I4);
Expand Down Expand Up @@ -6559,10 +6579,10 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
CHECK_STACK (td, 1);
switch (td->sp [-1].type) {
case STACK_TYPE_R4:
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I4, is_un ? MINT_CONV_OVF_I2_UN_R4 : MINT_CONV_OVF_I2_R4);
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I4, MINT_CONV_OVF_I2_R4);
break;
case STACK_TYPE_R8:
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I4, is_un ? MINT_CONV_OVF_I2_UN_R8 : MINT_CONV_OVF_I2_R8);
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I4, MINT_CONV_OVF_I2_R8);
break;
case STACK_TYPE_I4:
interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I4, is_un ? MINT_CONV_OVF_I2_U4 : MINT_CONV_OVF_I2_I4);
Expand Down
11 changes: 10 additions & 1 deletion src/mono/mono/mini/method-to-ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -8493,7 +8493,16 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
if (sp [-1]->type == STACK_R8 || sp [-1]->type == STACK_R4) {
/* floats are always signed, _UN has no effect */
ADD_UNOP (CEE_CONV_OVF_I8);
ADD_UNOP (il_op);
if (il_op == MONO_CEE_CONV_OVF_I1_UN)
ADD_UNOP (MONO_CEE_CONV_OVF_I1);
else if (il_op == MONO_CEE_CONV_OVF_I2_UN)
ADD_UNOP (MONO_CEE_CONV_OVF_I2);
else if (il_op == MONO_CEE_CONV_OVF_I4_UN)
ADD_UNOP (MONO_CEE_CONV_OVF_I4);
else if (il_op == MONO_CEE_CONV_OVF_I8_UN)
;
else
ADD_UNOP (il_op);
} else {
ADD_UNOP (il_op);
}
Expand Down
3 changes: 0 additions & 3 deletions src/tests/issues.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1646,9 +1646,6 @@
<ExcludeList Include = "$(XunitTestBinBase)/JIT/Directed/debugging/poison/**">
<Issue>Tests coreclr JIT's debug poisoning of address taken variables</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/JIT/IL_Conformance/TestConvertFromIntegral/**">
<Issue>https://github.com/dotnet/runtime/issues/56784</Issue>
</ExcludeList>
</ItemGroup>

<!-- Known failures for mono runtime on *all* architectures/operating systems in interpreter runtime mode -->
Expand Down

0 comments on commit 1bd4e4b

Please sign in to comment.