Skip to content

Remove unsafe bool casts - #111024

Merged
EgorBo merged 4 commits into
dotnet:mainfrom
xtqqczze:avoid-Unsafe-BitCast
Jan 28, 2025
Merged

Remove unsafe bool casts#111024
EgorBo merged 4 commits into
dotnet:mainfrom
xtqqczze:avoid-Unsafe-BitCast

Conversation

@xtqqczze

@xtqqczzextqqczze commented Jan 2, 2025

Copy link
Copy Markdown
Contributor

Contributes to #94941.

@xtqqczze

Copy link
Copy Markdown
ContributorAuthor

@MihuBot

Comment threadsrc/libraries/System.Private.CoreLib/src/System/Half.cs
@xtqqczze

xtqqczze commented Jan 2, 2025

Copy link
Copy Markdown
ContributorAuthor

@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)

@EgorBoEgorBo left a comment

Copy link
Copy Markdown
Member

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

xtqqczze commented Jan 3, 2025

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
Member

Is this ready?

@xtqqczze

xtqqczze commented Jan 10, 2025

Copy link
Copy Markdown
ContributorAuthor

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
@EgorBoEgorBo mentioned this pull request Jan 13, 2025
15 tasks
@EgorBoEgorBo 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
@dotnet-policy-service

Copy link
Copy Markdown
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:mainJan 28, 2025
@EgorBo

Copy link
Copy Markdown
Member

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-actionsgithub-actionsBot locked and limited conversation to collaborators Feb 28, 2025
@xtqqczze
xtqqczze deleted the avoid-Unsafe-BitCast branch October 4, 2025 11:32
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Runtimecommunity-contributionIndicates that the PR has been added by a community memberreduce-unsafe

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@xtqqczze@EgorBo