Skip to content

Commit

Permalink
Fix operator precedence consistency in ASCIIUtility.GetIndexOfFirstNo…
Browse files Browse the repository at this point in the history
…nAsciiByte (dotnet#64814)

The `&&` operator takes precedence over `||`, make it explicit by wrapping in parenthesis which also makes it consistent with other usages like https://github.com/dotnet/runtime/blob/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8Utility.Transcoding.cs#L887

Sse2 implies little endian so the check only needs to apply to AdvSimd.
  • Loading branch information
akoeplinger authored Feb 6, 2022
1 parent 207f2b6 commit 3610ac1
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static unsafe nuint GetIndexOfFirstNonAsciiByte(byte* pBuffer, nuint buff
// pmovmskb which we know are optimized, and (b) we can avoid downclocking the processor while
// this method is running.

return (Sse2.IsSupported || AdvSimd.Arm64.IsSupported && BitConverter.IsLittleEndian)
return (Sse2.IsSupported || (AdvSimd.Arm64.IsSupported && BitConverter.IsLittleEndian))
? GetIndexOfFirstNonAsciiByte_Intrinsified(pBuffer, bufferLength)
: GetIndexOfFirstNonAsciiByte_Default(pBuffer, bufferLength);
}
Expand Down Expand Up @@ -1614,7 +1614,7 @@ public static unsafe nuint WidenAsciiToUtf16(byte* pAsciiBuffer, char* pUtf16Buf
// pmovmskb which we know are optimized, and (b) we can avoid downclocking the processor while
// this method is running.

if (BitConverter.IsLittleEndian && (Sse2.IsSupported || AdvSimd.Arm64.IsSupported))
if (Sse2.IsSupported || (AdvSimd.Arm64.IsSupported && BitConverter.IsLittleEndian))
{
if (elementCount >= 2 * (uint)Unsafe.SizeOf<Vector128<byte>>())
{
Expand Down

0 comments on commit 3610ac1

Please sign in to comment.