Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating the x64 casting behavior to be IEEE 754 compliant and to use saturation for overflow #61761

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions docs/design/coreclr/botr/readytorun-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,8 @@ enum ReadyToRunHelper
READYTORUN_HELPER_LLsh = 0xC7,
READYTORUN_HELPER_LRsh = 0xC8,
READYTORUN_HELPER_LRsz = 0xC9,
READYTORUN_HELPER_Lng2Dbl = 0xCA,
READYTORUN_HELPER_ULng2Dbl = 0xCB,
READYTORUN_HELPER_Int64ToDouble = 0xCA,
READYTORUN_HELPER_UInt64ToDouble = 0xCB,

// 32-bit division helpers
READYTORUN_HELPER_Div = 0xCC,
Expand All @@ -753,14 +753,22 @@ enum ReadyToRunHelper
READYTORUN_HELPER_UMod = 0xCF,

// Floating point conversions
READYTORUN_HELPER_Dbl2Int = 0xD0,
READYTORUN_HELPER_Dbl2IntOvf = 0xD1,
READYTORUN_HELPER_Dbl2Lng = 0xD2,
READYTORUN_HELPER_Dbl2LngOvf = 0xD3,
READYTORUN_HELPER_Dbl2UInt = 0xD4,
READYTORUN_HELPER_Dbl2UIntOvf = 0xD5,
READYTORUN_HELPER_Dbl2ULng = 0xD6,
READYTORUN_HELPER_Dbl2ULngOvf = 0xD7,
READYTORUN_HELPER_DoubleToInt32 = 0xD0,
READYTORUN_HELPER_DoubleToInt32Ovf = 0xD1,
READYTORUN_HELPER_DoubleToInt64 = 0xD2,
READYTORUN_HELPER_DoubleToInt64Ovf = 0xD3,
READYTORUN_HELPER_DoubleToUInt32 = 0xD4,
READYTORUN_HELPER_DoubleToUInt32Ovf = 0xD5,
READYTORUN_HELPER_DoubleToUInt64 = 0xD6,
READYTORUN_HELPER_DoubleToUInt64Ovf = 0xD7,
READYTORUN_HELPER_DoubleToInt8 = 0xD8,
READYTORUN_HELPER_DoubleToInt8Ovf = 0xD9,
READYTORUN_HELPER_DoubleToInt16 = 0xDA,
READYTORUN_HELPER_DoubleToInt16Ovf = 0xDB,
READYTORUN_HELPER_DoubleToUInt8 = 0xDC,
READYTORUN_HELPER_DoubleToUInt8Ovf = 0xDD,
READYTORUN_HELPER_DoubleToUInt16 = 0xDE,
READYTORUN_HELPER_DoubleToUInt16Ovf = 0xDF,

// Floating point ops
READYTORUN_HELPER_DblRem = 0xE0,
Expand Down
28 changes: 18 additions & 10 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,16 +384,24 @@ enum CorInfoHelpFunc
CORINFO_HELP_LMOD,
CORINFO_HELP_ULDIV,
CORINFO_HELP_ULMOD,
CORINFO_HELP_LNG2DBL, // Convert a signed int64 to a double
CORINFO_HELP_ULNG2DBL, // Convert a unsigned int64 to a double
CORINFO_HELP_DBL2INT,
CORINFO_HELP_DBL2INT_OVF,
CORINFO_HELP_DBL2LNG,
CORINFO_HELP_DBL2LNG_OVF,
CORINFO_HELP_DBL2UINT,
CORINFO_HELP_DBL2UINT_OVF,
CORINFO_HELP_DBL2ULNG,
CORINFO_HELP_DBL2ULNG_OVF,
CORINFO_HELP_Int64ToDouble,
CORINFO_HELP_UInt64ToDouble,
CORINFO_HELP_DoubleToInt8,
CORINFO_HELP_DoubleToInt8_OVF,
CORINFO_HELP_DoubleToInt16,
CORINFO_HELP_DoubleToInt16_OVF,
CORINFO_HELP_DoubleToInt32,
CORINFO_HELP_DoubleToInt32_OVF,
CORINFO_HELP_DoubleToInt64,
CORINFO_HELP_DoubleToInt64_OVF,
CORINFO_HELP_DoubleToUInt8,
CORINFO_HELP_DoubleToUInt8_OVF,
CORINFO_HELP_DoubleToUInt16,
CORINFO_HELP_DoubleToUInt16_OVF,
CORINFO_HELP_DoubleToUInt32,
CORINFO_HELP_DoubleToUInt32_OVF,
CORINFO_HELP_DoubleToUInt64,
CORINFO_HELP_DoubleToUInt64_OVF,
CORINFO_HELP_FLTREM,
CORINFO_HELP_DBLREM,
CORINFO_HELP_FLTROUND,
Expand Down
52 changes: 29 additions & 23 deletions src/coreclr/inc/jithelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
JITHELPER(CORINFO_HELP_UDIV, JIT_UDiv, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_UMOD, JIT_UMod, CORINFO_HELP_SIG_8_STACK)

// CORINFO_HELP_DBL2INT, CORINFO_HELP_DBL2UINT, and CORINFO_HELP_DBL2LONG get
// patched for CPUs that support SSE2 (P4 and above).
#ifndef TARGET_64BIT
JITHELPER(CORINFO_HELP_LLSH, JIT_LLsh, CORINFO_HELP_SIG_REG_ONLY)
JITHELPER(CORINFO_HELP_LRSH, JIT_LRsh, CORINFO_HELP_SIG_REG_ONLY)
Expand All @@ -46,27 +44,35 @@
JITHELPER(CORINFO_HELP_LRSH, NULL, CORINFO_HELP_SIG_CANNOT_USE_ALIGN_STUB)
JITHELPER(CORINFO_HELP_LRSZ, NULL, CORINFO_HELP_SIG_CANNOT_USE_ALIGN_STUB)
#endif // TARGET_64BIT
JITHELPER(CORINFO_HELP_LMUL, JIT_LMul, CORINFO_HELP_SIG_16_STACK)
JITHELPER(CORINFO_HELP_LMUL_OVF, JIT_LMulOvf, CORINFO_HELP_SIG_16_STACK)
JITHELPER(CORINFO_HELP_ULMUL_OVF, JIT_ULMulOvf, CORINFO_HELP_SIG_16_STACK)
JITHELPER(CORINFO_HELP_LDIV, JIT_LDiv, CORINFO_HELP_SIG_16_STACK)
JITHELPER(CORINFO_HELP_LMOD, JIT_LMod, CORINFO_HELP_SIG_16_STACK)
JITHELPER(CORINFO_HELP_ULDIV, JIT_ULDiv, CORINFO_HELP_SIG_16_STACK)
JITHELPER(CORINFO_HELP_ULMOD, JIT_ULMod, CORINFO_HELP_SIG_16_STACK)
JITHELPER(CORINFO_HELP_LNG2DBL, JIT_Lng2Dbl, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_ULNG2DBL, JIT_ULng2Dbl, CORINFO_HELP_SIG_8_STACK)
DYNAMICJITHELPER(CORINFO_HELP_DBL2INT, JIT_Dbl2Lng, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DBL2INT_OVF, JIT_Dbl2IntOvf, CORINFO_HELP_SIG_8_STACK)
DYNAMICJITHELPER(CORINFO_HELP_DBL2LNG, JIT_Dbl2Lng, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DBL2LNG_OVF, JIT_Dbl2LngOvf, CORINFO_HELP_SIG_8_STACK)
DYNAMICJITHELPER(CORINFO_HELP_DBL2UINT, JIT_Dbl2Lng, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DBL2UINT_OVF, JIT_Dbl2UIntOvf, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DBL2ULNG, JIT_Dbl2ULng, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DBL2ULNG_OVF, JIT_Dbl2ULngOvf, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_FLTREM, JIT_FltRem, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DBLREM, JIT_DblRem, CORINFO_HELP_SIG_16_STACK)
JITHELPER(CORINFO_HELP_FLTROUND, JIT_FloatRound, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DBLROUND, JIT_DoubleRound, CORINFO_HELP_SIG_16_STACK)
JITHELPER(CORINFO_HELP_LMUL, JIT_LMul, CORINFO_HELP_SIG_16_STACK)
JITHELPER(CORINFO_HELP_LMUL_OVF, JIT_LMulOvf, CORINFO_HELP_SIG_16_STACK)
JITHELPER(CORINFO_HELP_ULMUL_OVF, JIT_ULMulOvf, CORINFO_HELP_SIG_16_STACK)
JITHELPER(CORINFO_HELP_LDIV, JIT_LDiv, CORINFO_HELP_SIG_16_STACK)
JITHELPER(CORINFO_HELP_LMOD, JIT_LMod, CORINFO_HELP_SIG_16_STACK)
JITHELPER(CORINFO_HELP_ULDIV, JIT_ULDiv, CORINFO_HELP_SIG_16_STACK)
JITHELPER(CORINFO_HELP_ULMOD, JIT_ULMod, CORINFO_HELP_SIG_16_STACK)
JITHELPER(CORINFO_HELP_Int64ToDouble, JIT_Int64ToDouble, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_UInt64ToDouble, JIT_UInt64ToDouble, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DoubleToInt8, JIT_DoubleToInt8, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DoubleToInt8_OVF, JIT_DoubleToInt8Ovf, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DoubleToInt16, JIT_DoubleToInt16, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DoubleToInt16_OVF, JIT_DoubleToInt16Ovf, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DoubleToInt32, JIT_DoubleToInt32, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DoubleToInt32_OVF, JIT_DoubleToInt32Ovf, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DoubleToInt64, JIT_DoubleToInt64, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DoubleToInt64_OVF, JIT_DoubleToInt64Ovf, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DoubleToUInt8, JIT_DoubleToUInt8, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DoubleToUInt8_OVF, JIT_DoubleToUInt8Ovf, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DoubleToUInt16, JIT_DoubleToUInt16, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DoubleToUInt16_OVF, JIT_DoubleToUInt16Ovf, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DoubleToUInt32, JIT_DoubleToUInt32, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DoubleToUInt32_OVF, JIT_DoubleToUInt32Ovf, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DoubleToUInt64, JIT_DoubleToUInt64, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DoubleToUInt64_OVF, JIT_DoubleToUInt64Ovf, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_FLTREM, JIT_FltRem, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DBLREM, JIT_DblRem, CORINFO_HELP_SIG_16_STACK)
JITHELPER(CORINFO_HELP_FLTROUND, JIT_FloatRound, CORINFO_HELP_SIG_8_STACK)
JITHELPER(CORINFO_HELP_DBLROUND, JIT_DoubleRound, CORINFO_HELP_SIG_16_STACK)

// Allocating a new object
JITHELPER(CORINFO_HELP_NEWFAST, JIT_New, CORINFO_HELP_SIG_REG_ONLY)
Expand Down
28 changes: 18 additions & 10 deletions src/coreclr/inc/readytorun.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ enum ReadyToRunHelper
READYTORUN_HELPER_LLsh = 0xC7,
READYTORUN_HELPER_LRsh = 0xC8,
READYTORUN_HELPER_LRsz = 0xC9,
READYTORUN_HELPER_Lng2Dbl = 0xCA,
READYTORUN_HELPER_ULng2Dbl = 0xCB,
READYTORUN_HELPER_Int64ToDouble = 0xCA,
READYTORUN_HELPER_UInt64ToDouble = 0xCB,

// 32-bit division helpers
READYTORUN_HELPER_Div = 0xCC,
Expand All @@ -330,14 +330,22 @@ enum ReadyToRunHelper
READYTORUN_HELPER_UMod = 0xCF,

// Floating point conversions
READYTORUN_HELPER_Dbl2Int = 0xD0,
READYTORUN_HELPER_Dbl2IntOvf = 0xD1,
READYTORUN_HELPER_Dbl2Lng = 0xD2,
READYTORUN_HELPER_Dbl2LngOvf = 0xD3,
READYTORUN_HELPER_Dbl2UInt = 0xD4,
READYTORUN_HELPER_Dbl2UIntOvf = 0xD5,
READYTORUN_HELPER_Dbl2ULng = 0xD6,
READYTORUN_HELPER_Dbl2ULngOvf = 0xD7,
READYTORUN_HELPER_DoubleToInt32 = 0xD0,
READYTORUN_HELPER_DoubleToInt32Ovf = 0xD1,
READYTORUN_HELPER_DoubleToInt64 = 0xD2,
READYTORUN_HELPER_DoubleToInt64Ovf = 0xD3,
READYTORUN_HELPER_DoubleToUInt32 = 0xD4,
READYTORUN_HELPER_DoubleToUInt32Ovf = 0xD5,
READYTORUN_HELPER_DoubleToUInt64 = 0xD6,
READYTORUN_HELPER_DoubleToUInt64Ovf = 0xD7,
READYTORUN_HELPER_DoubleToInt8 = 0xD8,
READYTORUN_HELPER_DoubleToInt8Ovf = 0xD9,
READYTORUN_HELPER_DoubleToInt16 = 0xDA,
READYTORUN_HELPER_DoubleToInt16Ovf = 0xDB,
READYTORUN_HELPER_DoubleToUInt8 = 0xDC,
READYTORUN_HELPER_DoubleToUInt8Ovf = 0xDD,
READYTORUN_HELPER_DoubleToUInt16 = 0xDE,
READYTORUN_HELPER_DoubleToUInt16Ovf = 0xDF,

// Floating point ops
READYTORUN_HELPER_DblRem = 0xE0,
Expand Down
28 changes: 18 additions & 10 deletions src/coreclr/inc/readytorunhelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,30 @@ HELPER(READYTORUN_HELPER_ULMod, CORINFO_HELP_ULMOD,
HELPER(READYTORUN_HELPER_LLsh, CORINFO_HELP_LLSH, )
HELPER(READYTORUN_HELPER_LRsh, CORINFO_HELP_LRSH, )
HELPER(READYTORUN_HELPER_LRsz, CORINFO_HELP_LRSZ, )
HELPER(READYTORUN_HELPER_Lng2Dbl, CORINFO_HELP_LNG2DBL, )
HELPER(READYTORUN_HELPER_ULng2Dbl, CORINFO_HELP_ULNG2DBL, )
HELPER(READYTORUN_HELPER_Int64ToDouble, CORINFO_HELP_Int64ToDouble, )
HELPER(READYTORUN_HELPER_UInt64ToDouble, CORINFO_HELP_UInt64ToDouble, )

HELPER(READYTORUN_HELPER_Div, CORINFO_HELP_DIV, )
HELPER(READYTORUN_HELPER_Mod, CORINFO_HELP_MOD, )
HELPER(READYTORUN_HELPER_UDiv, CORINFO_HELP_UDIV, )
HELPER(READYTORUN_HELPER_UMod, CORINFO_HELP_UMOD, )

HELPER(READYTORUN_HELPER_Dbl2Int, CORINFO_HELP_DBL2INT, )
HELPER(READYTORUN_HELPER_Dbl2IntOvf, CORINFO_HELP_DBL2INT_OVF, )
HELPER(READYTORUN_HELPER_Dbl2Lng, CORINFO_HELP_DBL2LNG, )
HELPER(READYTORUN_HELPER_Dbl2LngOvf, CORINFO_HELP_DBL2LNG_OVF, )
HELPER(READYTORUN_HELPER_Dbl2UInt, CORINFO_HELP_DBL2UINT, )
HELPER(READYTORUN_HELPER_Dbl2UIntOvf, CORINFO_HELP_DBL2UINT_OVF, )
HELPER(READYTORUN_HELPER_Dbl2ULng, CORINFO_HELP_DBL2ULNG, )
HELPER(READYTORUN_HELPER_Dbl2ULngOvf, CORINFO_HELP_DBL2ULNG_OVF, )
HELPER(READYTORUN_HELPER_DoubleToInt32, CORINFO_HELP_DoubleToInt32, )
HELPER(READYTORUN_HELPER_DoubleToInt32Ovf, CORINFO_HELP_DoubleToInt32_OVF, )
HELPER(READYTORUN_HELPER_DoubleToInt64, CORINFO_HELP_DoubleToInt64, )
HELPER(READYTORUN_HELPER_DoubleToInt64Ovf, CORINFO_HELP_DoubleToInt64_OVF, )
HELPER(READYTORUN_HELPER_DoubleToUInt32, CORINFO_HELP_DoubleToUInt32, )
HELPER(READYTORUN_HELPER_DoubleToUInt32Ovf, CORINFO_HELP_DoubleToUInt32_OVF, )
HELPER(READYTORUN_HELPER_DoubleToUInt64, CORINFO_HELP_DoubleToUInt64, )
HELPER(READYTORUN_HELPER_DoubleToUInt64Ovf, CORINFO_HELP_DoubleToUInt64_OVF, )
HELPER(READYTORUN_HELPER_DoubleToInt8, CORINFO_HELP_DoubleToInt8, )
HELPER(READYTORUN_HELPER_DoubleToInt8Ovf, CORINFO_HELP_DoubleToInt8_OVF, )
HELPER(READYTORUN_HELPER_DoubleToInt16, CORINFO_HELP_DoubleToInt16, )
HELPER(READYTORUN_HELPER_DoubleToInt16Ovf, CORINFO_HELP_DoubleToInt16_OVF, )
HELPER(READYTORUN_HELPER_DoubleToUInt8, CORINFO_HELP_DoubleToUInt8, )
HELPER(READYTORUN_HELPER_DoubleToUInt8Ovf, CORINFO_HELP_DoubleToUInt8_OVF, )
HELPER(READYTORUN_HELPER_DoubleToUInt16, CORINFO_HELP_DoubleToUInt16, )
HELPER(READYTORUN_HELPER_DoubleToUInt16Ovf, CORINFO_HELP_DoubleToUInt16_OVF, )

HELPER(READYTORUN_HELPER_FltRem, CORINFO_HELP_FLTREM, )
HELPER(READYTORUN_HELPER_DblRem, CORINFO_HELP_DBLREM, )
Expand Down
Loading