Browse Source

Use BitOperations directly.

pull/2189/head
Dirk Lemstra 4 years ago
parent
commit
ba1adc39a2
No known key found for this signature in database GPG Key ID: 40B84DE7D6271D30
  1. 26
      src/ImageSharp/Common/Helpers/Numerics.cs
  2. 7
      src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs

26
src/ImageSharp/Common/Helpers/Numerics.cs

@ -836,14 +836,6 @@ namespace SixLabors.ImageSharp
return Sse2.ConvertToInt32(vsum);
}
/// <summary>
/// Calculates floored log of the specified value, base 2.
/// Note that by convention, input value 0 returns 0 since Log(0) is undefined.
/// </summary>
/// <param name="value">The value.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Log2(uint value) => BitOperations.Log2(value);
/// <summary>
/// Fast division with ceiling for <see cref="uint"/> numbers.
/// </summary>
@ -852,24 +844,6 @@ namespace SixLabors.ImageSharp
/// <returns>Ceiled division result.</returns>
public static uint DivideCeil(uint value, uint divisor) => (value + divisor - 1) / divisor;
/// <summary>
/// Rotates the specified value left by the specified number of bits.
/// </summary>
/// <param name="value">The value to rotate.</param>
/// <param name="offset">The number of bits to rotate with.</param>
/// <returns>The rotated value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint RotateLeft(uint value, int offset) => BitOperations.RotateLeft(value, offset);
/// <summary>
/// Rotates the specified value right by the specified number of bits.
/// </summary>
/// <param name="value">The value to rotate.</param>
/// <param name="offset">The number of bits to rotate with.</param>
/// <returns>The rotated value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint RotateRight(uint value, int offset) => BitOperations.RotateRight(value, offset);
/// <summary>
/// Tells whether input value is outside of the given range.
/// </summary>

7
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;
}

Loading…
Cancel
Save