diff --git a/src/Neo/Cryptography/Helper.cs b/src/Neo/Cryptography/Helper.cs index 5b3595785a..e276ef76a7 100644 --- a/src/Neo/Cryptography/Helper.cs +++ b/src/Neo/Cryptography/Helper.cs @@ -322,29 +322,5 @@ internal static bool Test(this BloomFilter filter, Transaction tx) return true; return false; } - - /// - /// Rotates the specified value left by the specified number of bits. - /// Similar in behavior to the x86 instruction ROL. - /// - /// The value to rotate. - /// The number of bits to rotate by. - /// Any value outside the range [0..31] is treated as congruent mod 32. - /// The rotated value. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint RotateLeft(uint value, int offset) - => (value << offset) | (value >> (32 - offset)); - - /// - /// Rotates the specified value left by the specified number of bits. - /// Similar in behavior to the x86 instruction ROL. - /// - /// The value to rotate. - /// The number of bits to rotate by. - /// Any value outside the range [0..63] is treated as congruent mod 64. - /// The rotated value. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ulong RotateLeft(ulong value, int offset) - => (value << offset) | (value >> (64 - offset)); } } diff --git a/src/Neo/Cryptography/Murmur128.cs b/src/Neo/Cryptography/Murmur128.cs index 607d845cf3..32024ac1b9 100644 --- a/src/Neo/Cryptography/Murmur128.cs +++ b/src/Neo/Cryptography/Murmur128.cs @@ -12,6 +12,7 @@ using System; using System.Buffers.Binary; using System.IO.Hashing; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -103,8 +104,8 @@ protected override void GetCurrentHashCore(Span destination) var tail = _tail.AsSpan(); ulong k1 = BinaryPrimitives.ReadUInt64LittleEndian(tail); ulong k2 = BinaryPrimitives.ReadUInt64LittleEndian(tail[8..]); - H2 ^= Helper.RotateLeft(k2 * c2, r2) * c1; - H1 ^= Helper.RotateLeft(k1 * c1, r1) * c2; + H2 ^= BitOperations.RotateLeft(k2 * c2, r2) * c1; + H1 ^= BitOperations.RotateLeft(k1 * c1, r1) * c2; } H1 ^= (ulong)_length; @@ -139,12 +140,12 @@ private void Mix(ReadOnlySpan source) ulong k1 = BinaryPrimitives.ReadUInt64LittleEndian(source); ulong k2 = BinaryPrimitives.ReadUInt64LittleEndian(source[8..]); - H1 ^= Helper.RotateLeft(k1 * c1, r1) * c2; - H1 = Helper.RotateLeft(H1, 27) + H2; + H1 ^= BitOperations.RotateLeft(k1 * c1, r1) * c2; + H1 = BitOperations.RotateLeft(H1, 27) + H2; H1 = H1 * m + n1; - H2 ^= Helper.RotateLeft(k2 * c2, r2) * c1; - H2 = Helper.RotateLeft(H2, 31) + H1; + H2 ^= BitOperations.RotateLeft(k2 * c2, r2) * c1; + H2 = BitOperations.RotateLeft(H2, 31) + H1; H2 = H2 * m + n2; } diff --git a/src/Neo/Cryptography/Murmur32.cs b/src/Neo/Cryptography/Murmur32.cs index e102900a34..80bc43ae4f 100644 --- a/src/Neo/Cryptography/Murmur32.cs +++ b/src/Neo/Cryptography/Murmur32.cs @@ -12,6 +12,7 @@ using System; using System.Buffers.Binary; using System.IO.Hashing; +using System.Numerics; using System.Runtime.CompilerServices; namespace Neo.Cryptography @@ -109,7 +110,7 @@ protected override void GetCurrentHashCore(Span destination) internal uint GetCurrentHashUInt32() { if (_tailLength > 0) - _hash ^= Helper.RotateLeft(_tail * c1, r1) * c2; + _hash ^= BitOperations.RotateLeft(_tail * c1, r1) * c2; var state = _hash ^ (uint)_length; state ^= state >> 16; @@ -124,10 +125,10 @@ internal uint GetCurrentHashUInt32() private void Mix(uint k) { k *= c1; - k = Helper.RotateLeft(k, r1); + k = BitOperations.RotateLeft(k, r1); k *= c2; _hash ^= k; - _hash = Helper.RotateLeft(_hash, r2); + _hash = BitOperations.RotateLeft(_hash, r2); _hash = _hash * m + n; }