Skip to content

Commit

Permalink
Updating Mono casting behavior to be IEEE 754 compliant and to satura…
Browse files Browse the repository at this point in the history
…te on overflow
  • Loading branch information
tannergooding committed Mar 3, 2022
1 parent 188f44b commit 1e61a40
Show file tree
Hide file tree
Showing 18 changed files with 632 additions and 387 deletions.
9 changes: 9 additions & 0 deletions src/mono/mono/metadata/icall-signatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,22 @@ ICALL_SIG (1, (void)) \
ICALL_SIG (2, (double, double)) \
ICALL_SIG (2, (double, int32)) \
ICALL_SIG (2, (double, long)) \
ICALL_SIG (2, (double, uint32)) \
ICALL_SIG (2, (double, ulong)) \
ICALL_SIG (2, (double, ptr)) \
ICALL_SIG (2, (float, double)) \
ICALL_SIG (2, (float, int32)) \
ICALL_SIG (2, (float, long)) \
ICALL_SIG (2, (int, obj)) \
ICALL_SIG (2, (int16, double)) \
ICALL_SIG (2, (int32, double)) \
ICALL_SIG (2, (int16, float)) \
ICALL_SIG (2, (int32, float)) \
ICALL_SIG (2, (int32, obj)) \
ICALL_SIG (2, (int32, object)) \
ICALL_SIG (2, (int8, double)) \
ICALL_SIG (2, (long, double)) \
ICALL_SIG (2, (int8, float)) \
ICALL_SIG (2, (long, float)) \
ICALL_SIG (2, (obj, ptr)) \
ICALL_SIG (2, (object, int)) \
Expand All @@ -174,9 +181,11 @@ ICALL_SIG (2, (ptr, object)) \
ICALL_SIG (2, (ptr, ptr)) \
ICALL_SIG (2, (uint16, double)) \
ICALL_SIG (2, (uint32, double)) \
ICALL_SIG (2, (uint16, float)) \
ICALL_SIG (2, (uint32, float)) \
ICALL_SIG (2, (uint8, double)) \
ICALL_SIG (2, (ulong, double)) \
ICALL_SIG (2, (uint8, float)) \
ICALL_SIG (2, (ulong, float)) \
ICALL_SIG (2, (void, int)) \
ICALL_SIG (2, (void, int32)) \
Expand Down
29 changes: 24 additions & 5 deletions src/mono/mono/metadata/jit-icall-reg.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ MONO_JIT_ICALL (__emul_fconv_to_i1) \
MONO_JIT_ICALL (__emul_fconv_to_i2) \
MONO_JIT_ICALL (__emul_fconv_to_i4) \
MONO_JIT_ICALL (__emul_fconv_to_i8) \
MONO_JIT_ICALL (__emul_fconv_to_ovf_i1) \
MONO_JIT_ICALL (__emul_fconv_to_ovf_i2) \
MONO_JIT_ICALL (__emul_fconv_to_ovf_i4) \
MONO_JIT_ICALL (__emul_fconv_to_ovf_i8) \
MONO_JIT_ICALL (__emul_fconv_to_ovf_u1) \
MONO_JIT_ICALL (__emul_fconv_to_ovf_u2) \
MONO_JIT_ICALL (__emul_fconv_to_ovf_u4) \
MONO_JIT_ICALL (__emul_fconv_to_ovf_u8) \
MONO_JIT_ICALL (__emul_fconv_to_r4) \
MONO_JIT_ICALL (__emul_fconv_to_u) \
Expand All @@ -87,9 +93,9 @@ MONO_JIT_ICALL (__emul_fmul) \
MONO_JIT_ICALL (__emul_fneg) \
MONO_JIT_ICALL (__emul_frem) \
MONO_JIT_ICALL (__emul_fsub) \
MONO_JIT_ICALL (__emul_iconv_to_r_un) \
MONO_JIT_ICALL (__emul_iconv_to_r4) \
MONO_JIT_ICALL (__emul_iconv_to_r8) \
MONO_JIT_ICALL (__emul_iconv_to_r8_un) \
MONO_JIT_ICALL (__emul_lconv_to_r4) \
MONO_JIT_ICALL (__emul_lconv_to_r8) \
MONO_JIT_ICALL (__emul_lconv_to_r8_un) \
Expand All @@ -112,11 +118,24 @@ MONO_JIT_ICALL (__emul_op_imul_ovf_un) \
MONO_JIT_ICALL (__emul_op_imul_ovf_un_oom) \
MONO_JIT_ICALL (__emul_op_irem) \
MONO_JIT_ICALL (__emul_op_irem_un) \
MONO_JIT_ICALL (__emul_rconv_to_i8) \
MONO_JIT_ICALL (__emul_rconv_to_ovf_i8) \
MONO_JIT_ICALL (__emul_rconv_to_ovf_u8) \
MONO_JIT_ICALL (__emul_rconv_to_i) \
MONO_JIT_ICALL (__emul_rconv_to_i1) \
MONO_JIT_ICALL (__emul_rconv_to_i2) \
MONO_JIT_ICALL (__emul_rconv_to_i4) \
MONO_JIT_ICALL (__emul_rconv_to_i8) \
MONO_JIT_ICALL (__emul_rconv_to_ovf_i1) \
MONO_JIT_ICALL (__emul_rconv_to_ovf_i2) \
MONO_JIT_ICALL (__emul_rconv_to_ovf_i4) \
MONO_JIT_ICALL (__emul_rconv_to_ovf_i8) \
MONO_JIT_ICALL (__emul_rconv_to_ovf_u1) \
MONO_JIT_ICALL (__emul_rconv_to_ovf_u2) \
MONO_JIT_ICALL (__emul_rconv_to_ovf_u4) \
MONO_JIT_ICALL (__emul_rconv_to_ovf_u8) \
MONO_JIT_ICALL (__emul_rconv_to_u) \
MONO_JIT_ICALL (__emul_rconv_to_u1) \
MONO_JIT_ICALL (__emul_rconv_to_u2) \
MONO_JIT_ICALL (__emul_rconv_to_u4) \
MONO_JIT_ICALL (__emul_rconv_to_u8) \
MONO_JIT_ICALL (__emul_rconv_to_u8) \
MONO_JIT_ICALL (__emul_rrem) \
MONO_JIT_ICALL (cominterop_get_ccw) \
MONO_JIT_ICALL (cominterop_get_ccw_object) \
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/aot-runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "mini.h"

/* Version number of the AOT file format */
#define MONO_AOT_FILE_VERSION 183
#define MONO_AOT_FILE_VERSION 184

#define MONO_AOT_TRAMP_PAGE_SIZE 16384

Expand Down
17 changes: 0 additions & 17 deletions src/mono/mono/mini/decompose.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,8 @@ mono_decompose_opcode (MonoCompile *cfg, MonoInst *ins)
}
break;
case OP_ICONV_TO_R_UN:
#ifdef MONO_ARCH_EMULATE_CONV_R8_UN
if (!COMPILE_LLVM (cfg))
emulate = TRUE;
#endif
break;
default:
emulate = TRUE;
Expand Down Expand Up @@ -698,21 +696,6 @@ mono_decompose_long_opts (MonoCompile *cfg)
case OP_LCONV_TO_U:
MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, tree->dreg, MONO_LVREG_LS (tree->sreg1));
break;
#ifndef MONO_ARCH_EMULATE_LCONV_TO_R8
case OP_LCONV_TO_R8:
MONO_EMIT_NEW_BIALU (cfg, OP_LCONV_TO_R8_2, tree->dreg, MONO_LVREG_LS (tree->sreg1), MONO_LVREG_MS (tree->sreg1));
break;
#endif
#ifndef MONO_ARCH_EMULATE_LCONV_TO_R4
case OP_LCONV_TO_R4:
MONO_EMIT_NEW_BIALU (cfg, OP_LCONV_TO_R4_2, tree->dreg, MONO_LVREG_LS (tree->sreg1), MONO_LVREG_MS (tree->sreg1));
break;
#endif
#ifndef MONO_ARCH_EMULATE_LCONV_TO_R8_UN
case OP_LCONV_TO_R_UN:
MONO_EMIT_NEW_BIALU (cfg, OP_LCONV_TO_R_UN_2, tree->dreg, MONO_LVREG_LS (tree->sreg1), MONO_LVREG_MS (tree->sreg1));
break;
#endif
case OP_LCONV_TO_OVF_I1: {
MonoBasicBlock *is_negative, *end_label;

Expand Down

0 comments on commit 1e61a40

Please sign in to comment.