From ba1adc39a29afc0f19692f18be2b432c0d528c61 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Sat, 3 Sep 2022 09:44:25 +0200 Subject: [PATCH] Use BitOperations directly. --- src/ImageSharp/Common/Helpers/Numerics.cs | 26 ------------------- .../Helpers/Shuffle/IComponentShuffle.cs | 7 ++--- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/Numerics.cs b/src/ImageSharp/Common/Helpers/Numerics.cs index 9f81de1c20..8be59ca9a1 100644 --- a/src/ImageSharp/Common/Helpers/Numerics.cs +++ b/src/ImageSharp/Common/Helpers/Numerics.cs @@ -836,14 +836,6 @@ namespace SixLabors.ImageSharp return Sse2.ConvertToInt32(vsum); } - /// - /// Calculates floored log of the specified value, base 2. - /// Note that by convention, input value 0 returns 0 since Log(0) is undefined. - /// - /// The value. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Log2(uint value) => BitOperations.Log2(value); - /// /// Fast division with ceiling for numbers. /// @@ -852,24 +844,6 @@ namespace SixLabors.ImageSharp /// Ceiled division result. public static uint DivideCeil(uint value, uint divisor) => (value + divisor - 1) / divisor; - /// - /// Rotates the specified value left by the specified number of bits. - /// - /// The value to rotate. - /// The number of bits to rotate with. - /// The rotated value. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint RotateLeft(uint value, int offset) => BitOperations.RotateLeft(value, offset); - - /// - /// Rotates the specified value right by the specified number of bits. - /// - /// The value to rotate. - /// The number of bits to rotate with. - /// The rotated value. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint RotateRight(uint value, int offset) => BitOperations.RotateRight(value, offset); - /// /// Tells whether input value is outside of the given range. /// diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs index 0d27ea437f..9cd7db10d4 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs @@ -3,6 +3,7 @@ using System; using System.Buffers.Binary; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -157,7 +158,7 @@ namespace SixLabors.ImageSharp // packed = [W Z Y X] // ROTR(8, packedArgb) = [Y Z W X] - Unsafe.Add(ref dBase, i) = Numerics.RotateRight(packed, 8); + Unsafe.Add(ref dBase, i) = BitOperations.RotateRight(packed, 8); } } } @@ -188,7 +189,7 @@ namespace SixLabors.ImageSharp // tmp1 + tmp3 = [W X Y Z] uint tmp1 = packed & 0xFF00FF00; uint tmp2 = packed & 0x00FF00FF; - uint tmp3 = Numerics.RotateLeft(tmp2, 16); + uint tmp3 = BitOperations.RotateLeft(tmp2, 16); Unsafe.Add(ref dBase, i) = tmp1 + tmp3; } @@ -221,7 +222,7 @@ namespace SixLabors.ImageSharp // tmp1 + tmp3 = [Y Z W X] uint tmp1 = packed & 0x00FF00FF; uint tmp2 = packed & 0xFF00FF00; - uint tmp3 = Numerics.RotateLeft(tmp2, 16); + uint tmp3 = BitOperations.RotateLeft(tmp2, 16); Unsafe.Add(ref dBase, i) = tmp1 + tmp3; }