[clr-interp] Fix conversion from unsigned integer to float#122369
Merged
davidwrighton merged 1 commit intodotnet:mainfrom Dec 10, 2025
Merged
[clr-interp] Fix conversion from unsigned integer to float#122369davidwrighton merged 1 commit intodotnet:mainfrom
davidwrighton merged 1 commit intodotnet:mainfrom
Conversation
- There isn't a single instruction for this, but the jit recognizes the conv.r.un + conv.r4 pattern as meaning convert directly from unsigned integer to float. Per ECMA it is valid to do processing at a higher intermediate precision, but RyuJit/interpreter follows tighter rules which result in more less loss of precision.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes the conversion from unsigned integers to float (R4) in the CLR interpreter. The JIT recognizes the conv.r.un + conv.r4 pattern as a direct unsigned-to-float conversion, and the interpreter now properly implements this pattern with distinct opcodes for R4 (float) versus R8 (double) conversions.
- Renamed existing
INTOP_CONV_R_UN_*opcodes toINTOP_CONV_R8_UN_*to clarify they convert to double - Added new
INTOP_CONV_R4_UN_*opcodes for direct unsigned-to-float conversion - Implemented a peephole optimization to recognize and properly handle the
conv.r.un + conv.r4pattern
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/interpreter/inc/intops.def | Renamed CONV_R_UN opcodes to CONV_R8_UN for clarity and added new CONV_R4_UN opcodes for unsigned-to-float conversions |
| src/coreclr/vm/interpexec.cpp | Updated case labels to use renamed R8 opcodes and added execution logic for new R4 unsigned conversion opcodes |
| src/coreclr/interpreter/compiler.h | Added declarations for the new ConvRUnR4 peephole optimization methods |
| src/coreclr/interpreter/compiler.cpp | Implemented ConvRUnR4 peephole to recognize conv.r.un + conv.r4 pattern, updated Peeps array size, and updated opcode references to use renamed CONV_R8_UN opcodes |
This was referenced Dec 10, 2025
Open
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes Runtime_106338 test.