Skip to content

Fix floating point <-> integer conversions #116236

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

Merged
merged 1 commit into from
Jun 3, 2025

Conversation

janvorli
Copy link
Member

@janvorli janvorli commented Jun 2, 2025

This change uses JIT helpers to implement the floating point to integer and vice versa conversions.

This change uses JIT helpers to implement the floating point to
integer and vice versa conversions.
@janvorli janvorli added this to the 10.0.0 milestone Jun 2, 2025
@janvorli janvorli self-assigned this Jun 2, 2025
@Copilot Copilot AI review requested due to automatic review settings June 2, 2025 23:02
@janvorli janvorli requested review from BrzVlad and kg as code owners June 2, 2025 23:02
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 2, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR aims to fix and standardize the floating point to integer (and vice versa) conversion logic by leveraging JIT helper functions.

  • Introduced new FCDECL helper calls for various conversion scenarios.
  • Replaced traditional cast-based conversions with helper calls via HCCALL1.
  • Implemented previously unhandled conversion cases (e.g., UINT conversions) by replacing assert(0) with helper calls.
Comments suppressed due to low confidence (3)

src/coreclr/vm/interpexec.cpp:250

  • The conversion now employs HCCALL1(JIT_Dbl2Int, ...) for converting a float to int, replacing a direct cast. Please verify that the helper function preserves the intended conversion semantics compared to the previous implementation.
LOCAL_VAR(ip[1], int32_t) = (int8_t)HCCALL1(JIT_Dbl2Int, (double)LOCAL_VAR(ip[2], float));

src/coreclr/vm/interpexec.cpp:318

  • Replacing the previous assert(0) with a helper call for INTOP_CONV_U4_R8 alters the behavior. Please ensure that JIT_Dbl2UInt correctly handles the conversion edge cases that were originally unimplemented.
LOCAL_VAR(ip[1], uint32_t) = HCCALL1(JIT_Dbl2UInt, LOCAL_VAR(ip[2], double));

src/coreclr/vm/interpexec.cpp:366

  • Replacing the TODO and assert(0) in INTOP_CONV_U8_R8 with a helper call changes the conversion behavior. Confirm that JIT_Dbl2ULng implements the intended logic for converting a double to an unsigned long.
LOCAL_VAR(ip[1], uint64_t) = HCCALL1(JIT_Dbl2ULng, LOCAL_VAR(ip[2], double));

@janvorli
Copy link
Member Author

janvorli commented Jun 3, 2025

/ba-g #116261

@janvorli janvorli merged commit 1a7d466 into dotnet:main Jun 3, 2025
95 of 97 checks passed
@janvorli janvorli deleted the fix-floating-point-conversions branch June 3, 2025 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants