mirror of
https://github.com/SabreTools/SabreTools.Hashing.git
synced 2026-09-24 07:45:02 +00:00
Consolidate cases in fast transform
This commit is contained in:
@@ -168,25 +168,21 @@ namespace SabreTools.Hashing.Crc
|
||||
if (_processBitwise)
|
||||
return false;
|
||||
|
||||
// Check for optimizable transformations
|
||||
if (_definition.Width == 16 && _definition.ReflectIn)
|
||||
{
|
||||
TransformBlockFastReflect(ref hash, data, offset, length);
|
||||
return true;
|
||||
}
|
||||
if (_definition.Width == 32 && _definition.ReflectIn)
|
||||
// Only certain widths can be optimized
|
||||
if (System.Array.IndexOf([16, 32, 64], _definition.Width) == -1)
|
||||
return false;
|
||||
|
||||
// All reflection-in implementations share an optimized path
|
||||
if (_definition.ReflectIn)
|
||||
{
|
||||
TransformBlockFastReflect(ref hash, data, offset, length);
|
||||
return true;
|
||||
}
|
||||
|
||||
// CRC-32 with no reflection-in has can be optimized
|
||||
if (_definition.Width == 32 && !_definition.ReflectIn)
|
||||
{
|
||||
TransformBlockFast32NoReflect(ref hash, data, offset, length);
|
||||
return true;
|
||||
}
|
||||
if (_definition.Width == 64 && _definition.ReflectIn)
|
||||
{
|
||||
TransformBlockFastReflect(ref hash, data, offset, length);
|
||||
TransformBlockFastNoReflect(ref hash, data, offset, length);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -237,16 +233,16 @@ namespace SabreTools.Hashing.Crc
|
||||
/// <summary>
|
||||
/// Optimized transformation for 32-bit CRC with no reflection
|
||||
/// </summary>
|
||||
private void TransformBlockFast32NoReflect(ref ulong hash, byte[] data, int offset, int length)
|
||||
private void TransformBlockFastNoReflect(ref ulong hash, byte[] data, int offset, int length)
|
||||
{
|
||||
// Process on a copy of the hash
|
||||
ulong local = hash;
|
||||
|
||||
// Process aligned data
|
||||
if (length > 8)
|
||||
if (length > 4)
|
||||
{
|
||||
long end = offset + (length & ~(uint)7);
|
||||
length &= 7;
|
||||
long end = offset + (length & ~(uint)3);
|
||||
length &= 3;
|
||||
|
||||
while (offset < end)
|
||||
{
|
||||
@@ -255,21 +251,12 @@ namespace SabreTools.Hashing.Crc
|
||||
+ (data[offset + 2] << 8 )
|
||||
+ (data[offset + 1] << 16)
|
||||
+ (data[offset + 0] << 24));
|
||||
ulong high = (uint)(
|
||||
+ (data[offset + 7] << 32)
|
||||
+ (data[offset + 6] << 40)
|
||||
+ (data[offset + 5] << 48)
|
||||
+ (data[offset + 4] << 56));
|
||||
offset += 8;
|
||||
offset += 4;
|
||||
|
||||
local = _table[4, (byte)(low )]
|
||||
^ _table[5, (byte)(low >> 8 )]
|
||||
^ _table[6, (byte)(low >> 16 )]
|
||||
^ _table[7, (byte)(low >> 24 )]
|
||||
^ _table[0, (byte)(high )]
|
||||
^ _table[1, (byte)(high >> 8 )]
|
||||
^ _table[2, (byte)(high >> 16)]
|
||||
^ _table[3, (byte)(high >> 24)];
|
||||
local = _table[0, (byte)(low )]
|
||||
^ _table[1, (byte)(low >> 8 )]
|
||||
^ _table[2, (byte)(low >> 16)]
|
||||
^ _table[3, (byte)(low >> 24)];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user