Skip to content

Remove unsafe bool casts #111024

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 4 commits into from
Jan 28, 2025
Merged

Remove unsafe bool casts #111024

merged 4 commits into from
Jan 28, 2025

Conversation

xtqqczze
Copy link
Contributor

@xtqqczze xtqqczze commented Jan 2, 2025

Contributes to #94941.

@xtqqczze
Copy link
Contributor Author

xtqqczze commented Jan 2, 2025

@MihuBot

@xtqqczze
Copy link
Contributor Author

xtqqczze commented Jan 2, 2025

@tannergooding Is this beneficial? 2 bytes higher in code size, but 0.75 lower PerfScore.

MihuBot/runtime-utils#854

 ; Assembly listing for method System.Half:op_Explicit(float):System.Half (FullOpts)
+       xor      ecx, ecx
+       mov      edx, -1
        vucomiss xmm0, xmm0
-       setp     cl
-       movzx    rcx, cl
-       dec      ecx
+       cmovnp   ecx, edx

Related: #61761 (comment)

Copy link
Member

@EgorBo EgorBo left a comment

Choose a reason for hiding this comment

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

LGTM otherwise, thanks!. Wonder if we have more such bool <--> int unsafe conversions

@xtqqczze
Copy link
Contributor Author

xtqqczze commented Jan 3, 2025

LGTM otherwise, thanks!. Wonder if we have more such bool <--> int unsafe conversions

These were the only conversions I found searching for:

  • Unsafe.As<bool
  • Unsafe.BitCast<bool
  • *(byte*)&
  • *(sbyte*)&

@EgorBo
Copy link
Member

EgorBo commented Jan 10, 2025

Is this ready?

@xtqqczze
Copy link
Contributor Author

xtqqczze commented Jan 10, 2025

Is this ready?

@EgorBo I had a question about codegen: #111024 (comment)

I'm guessing the diff codegen in that comment is preferable?

@xtqqczze xtqqczze marked this pull request as ready for review January 11, 2025 00:32
@EgorBo EgorBo mentioned this pull request Jan 13, 2025
15 tasks
@EgorBo EgorBo added area-System.Runtime and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jan 28, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

@EgorBo EgorBo merged commit 21ab780 into dotnet:main Jan 28, 2025
138 of 142 checks passed
@EgorBo
Copy link
Member

EgorBo commented Jan 28, 2025

Thanks!

grendello added a commit to grendello/runtime that referenced this pull request Jan 30, 2025
* main:
  Make cdac APIs public but experimental (dotnet#111180)
  JIT: Enable inlining for late devirtualization (dotnet#110827)
  Remove unsafe `bool` casts (dotnet#111024)
  Fix shimmed implementation of TryGetHashAndReset to handle HMAC.
@github-actions github-actions bot locked and limited conversation to collaborators Feb 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime community-contribution Indicates that the PR has been added by a community member reduce-unsafe
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants