-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Make System.Double/Single.ConvertToInteger intrinsic #122424
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
Open
janvorli
wants to merge
1
commit into
dotnet:main
Choose a base branch
from
janvorli:make-converttointeger-intrinsic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, I might've misunderstood or misexplained a bit when we talked on teams.
ConvertToIntegerandConvertToIntegerNativedo not have the same behavior, and this is intentional., so this fix isn't necessarily correct/valid.The former,
ConvertToInteger, does a deterministic conversion that should be correctly handling all types includingbyte,sbyte, and others. That is, it should always be done using saturation and sodouble.MinValue -> sbyteshould produce-128.The latter,
ConvertToIntegerNative, does not strictly guarantee the edge case handling and may do things like simply emitcvtss2siwhich returns a sentinel value (0x8000_0000) instead. This may also end up doing something likedouble -> int -> sbytefor the conversion.However, the former has a known issue in its intrinsic handling on RyuJIT where it may also do
double -> int -> sbyteinstead of directly doingdouble -> sbyte. This is a bug in that handling and really needs to be fixed to ensure the direct (intrinsic) and indirect (managed) implementations are aligned with eachother.This bug stems from the historical IR handling for cast nodes and is more complex to resolve. That is,
(sbyte)someDoubleisconv.i1and is effectively doingdouble -> int -> sbyte. And while it could be argued this is fine for the cast behavior, is not correct forConvertToInteger.To then answer @davidwrighton's question, users probably aren't complaining because most are doing
(sbyte)someDouble, they aren't doingdouble.ConvertToInteger<sbyte>(someDouble)and really aren't comparing that to delegate or reflection based invocation so it all looks consistent to them.I would expect that for the interpreter, we also need to ensure consistency between the various functions. That is, we need
directandindirectinvocations ofConvertToIntegerto be consistent. The same needs to be true forConvertToIntegerNative, but the two of these do not need to be consistent with eachother.If the interpreter can rollover to jitting at some point, then it is important that these also match the JIT behavior, so that users don't experience change in results mid compilation.
I can work on getting a fix up for the
conv.i1/u1/i2/u2issue on the JIT side.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The interpreter is expected to be mixed-and-matched with R2R code in .NET 11, so this problem exists today.
The problem with
ConvertToIntegerNativeconsistency is very similar to hardware intrinsics. The strategy that we use for hardware intrinsics is:<typename>.IsSupportedreturns false)We may want to use the same strategy for
ConvertToIntegerNativeand other similar JIT intrinsics.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, would it be preferrable to drop this PR a keep the two respective tests failing until we fix the JIT?