-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Remove unsafe bool
casts
#111024
base: main
Are you sure you want to change the base?
Remove unsafe bool
casts
#111024
Conversation
@@ -1075,17 +1075,15 @@ public static explicit operator float(Half value) | |||
// Extract exponent bits of value (BiasedExponent is not for here as it performs unnecessary shift) | |||
uint offsetExponent = bitValueInProcess & HalfExponentMask; | |||
// ~0u when value is subnormal, 0 otherwise | |||
uint subnormalMask = (uint)-Unsafe.BitCast<bool, byte>(offsetExponent == 0u); | |||
// ~0u when value is either Infinity or NaN, 0 otherwise |
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.
this comment is incorrect
@tannergooding Is this beneficial? 2 bytes higher in code size, but 0.75 lower PerfScore. ; 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) |
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/FormattingHelpers.CountDigits.cs
Show resolved
Hide resolved
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.
LGTM otherwise, thanks!. Wonder if we have more such bool <--> int unsafe conversions
These were the only conversions I found searching for:
|
Is this ready? |
@EgorBo I had a question about codegen: #111024 (comment) I'm guessing the diff codegen in that comment is preferable? |
Contributes to #94941.