From 6a96d262e751cb1ca4abba4d774a75f920c1fce0 Mon Sep 17 00:00:00 2001 From: Grant Dickinson Date: Mon, 28 Jan 2019 18:50:57 -0800 Subject: [PATCH 1/2] Update call sites for https://github.com/dotnet/corert/pull/6911 --- .../AccountManagement/Utils.cs | 4 ++-- .../Internal/Utilities/BitArithmetic.cs | 17 +++-------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/Utils.cs b/src/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/Utils.cs index bf66ae06960d..5619e2036788 100644 --- a/src/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/Utils.cs +++ b/src/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/Utils.cs @@ -45,12 +45,12 @@ internal static bool AreBytesEqual(byte[] src, byte[] tgt) internal static void ClearBit(ref int value, uint bitmask) { - value = (int)(((uint)value) & ((uint)(~bitmask))); + BitOps.ClearBit(ref value, (int)bitmask); } internal static void SetBit(ref int value, uint bitmask) { - value = (int)(((uint)value) | ((uint)bitmask)); + BitOps.InsertBit(ref value, (uint)bitmask); } // {0xa2, 0x3f,...} --> "a23f..." diff --git a/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BitArithmetic.cs b/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BitArithmetic.cs index bbf3d81370e8..1721856f6f6d 100644 --- a/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BitArithmetic.cs +++ b/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BitArithmetic.cs @@ -10,28 +10,17 @@ internal static class BitArithmetic { internal static int CountBits(int v) { - return CountBits(unchecked((uint)v)); + return BitOps.PopCount(v); } internal static int CountBits(uint v) { - unchecked - { - v = v - ((v >> 1) & 0x55555555u); - v = (v & 0x33333333u) + ((v >> 2) & 0x33333333u); - return (int)((v + (v >> 4) & 0xF0F0F0Fu) * 0x1010101u) >> 24; - } + return BitOps.PopCount(v); } internal static int CountBits(ulong v) { - const ulong Mask01010101 = 0x5555555555555555UL; - const ulong Mask00110011 = 0x3333333333333333UL; - const ulong Mask00001111 = 0x0F0F0F0F0F0F0F0FUL; - const ulong Mask00000001 = 0x0101010101010101UL; - v = v - ((v >> 1) & Mask01010101); - v = (v & Mask00110011) + ((v >> 2) & Mask00110011); - return (int)(unchecked(((v + (v >> 4)) & Mask00001111) * Mask00000001) >> 56); + return BitOps.PopCount(v); } internal static uint Align(uint position, uint alignment) From 6485bf12c1eb7a415a74b4cf147dfb95154a7ea6 Mon Sep 17 00:00:00 2001 From: Grant Dickinson Date: Mon, 28 Jan 2019 20:30:14 -0800 Subject: [PATCH 2/2] Another callsite --- src/Common/src/System/Net/WebSockets/ManagedWebSocket.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Common/src/System/Net/WebSockets/ManagedWebSocket.cs b/src/Common/src/System/Net/WebSockets/ManagedWebSocket.cs index 86c5ba9e50ae..0f9898bc6c28 100644 --- a/src/Common/src/System/Net/WebSockets/ManagedWebSocket.cs +++ b/src/Common/src/System/Net/WebSockets/ManagedWebSocket.cs @@ -1262,7 +1262,7 @@ private static unsafe int ApplyMask(Span toMask, int mask, int maskIndex) Debug.Assert(maskIndex < sizeof(int)); int maskShift = maskIndex * 8; - int shiftedMask = (int)(((uint)mask >> maskShift) | ((uint)mask << (32 - maskShift))); + int shiftedMask = BitOps.RotateRight(mask, maskShift); // Try to use SIMD. We can if the number of bytes we're trying to mask is at least as much // as the width of a vector and if the width is an even multiple of the mask.