From e01ed457ab3500d18749d1f44e812e859215cfcc Mon Sep 17 00:00:00 2001 From: Mike Danes Date: Sun, 11 Sep 2016 15:49:12 +0300 Subject: [PATCH] Implement long to float cast for x86 Convert long to float/double casts to helper calls. Despite the call this version is 2x faster than JIT32's FILD implementation which suffers a significant store forwarding stall penalty. Commit migrated from https://github.com/dotnet/coreclr/commit/398317d18b0845681671ba449b8d8d9ca2cd505c --- src/coreclr/src/jit/codegenxarch.cpp | 3 ++- src/coreclr/src/jit/morph.cpp | 9 +++++++++ src/coreclr/src/vm/jithelpers.cpp | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/coreclr/src/jit/codegenxarch.cpp b/src/coreclr/src/jit/codegenxarch.cpp index 3f05348..4820257 100644 --- a/src/coreclr/src/jit/codegenxarch.cpp +++ b/src/coreclr/src/jit/codegenxarch.cpp @@ -8018,7 +8018,8 @@ void CodeGen::genIntToFloatCast(GenTreePtr treeNode) assert(!varTypeIsFloating(srcType) && varTypeIsFloating(dstType)); #if !defined(_TARGET_64BIT_) - NYI_IF(varTypeIsLong(srcType), "Conversion from long to float"); + // We expect morph to replace long to float/double casts with helper calls + noway_assert(!varTypeIsLong(srcType)); #endif // !defined(_TARGET_64BIT_) // Since xarch emitter doesn't handle reporting gc-info correctly while casting away gc-ness we diff --git a/src/coreclr/src/jit/morph.cpp b/src/coreclr/src/jit/morph.cpp index 00df17b..1423bc9 100644 --- a/src/coreclr/src/jit/morph.cpp +++ b/src/coreclr/src/jit/morph.cpp @@ -360,8 +360,17 @@ GenTreePtr Compiler::fgMorphCast(GenTreePtr tree) oper = gtNewCastNode(TYP_LONG, oper, TYP_LONG); oper->gtFlags |= (tree->gtFlags & (GTF_OVERFLOW | GTF_EXCEPT | GTF_UNSIGNED)); tree->gtFlags &= ~GTF_UNSIGNED; +#ifndef LEGACY_BACKEND + return fgMorphCastIntoHelper(tree, CORINFO_HELP_LNG2DBL, oper); +#endif } } +#ifndef LEGACY_BACKEND + else if (((tree->gtFlags & GTF_UNSIGNED) == 0) && (srcType == TYP_LONG) && varTypeIsFloating(dstType)) + { + return fgMorphCastIntoHelper(tree, CORINFO_HELP_LNG2DBL, oper); + } +#endif #endif //_TARGET_XARCH_ else if (varTypeIsGC(srcType) != varTypeIsGC(dstType)) { diff --git a/src/coreclr/src/vm/jithelpers.cpp b/src/coreclr/src/vm/jithelpers.cpp index 276c2d6..b578e6f 100644 --- a/src/coreclr/src/vm/jithelpers.cpp +++ b/src/coreclr/src/vm/jithelpers.cpp @@ -513,7 +513,7 @@ HCIMPL1_V(double, JIT_ULng2Dbl, UINT64 val) HCIMPLEND /*********************************************************************/ -// needed for ARM +// needed for ARM and RyuJIT-x86 HCIMPL1_V(double, JIT_Lng2Dbl, INT64 val) { FCALL_CONTRACT; -- 2.7.4