-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from koculu/46-enhancement-x86-support
Add Crc32 x86 support.
- Loading branch information
Showing
3 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.Intrinsics.X86; | ||
|
||
namespace Tenray.ZoneTree.WAL; | ||
|
||
public sealed class Crc32Computer_SSE42_X86 | ||
{ | ||
public static bool IsSupported => Sse42.IsSupported; | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static uint Compute(uint crc, ulong data) | ||
{ | ||
var result = (uint)Sse42.Crc32(crc, (uint)data); | ||
return Sse42.Crc32(crc, (uint)(data >> 32)); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static uint Compute(uint crc, uint data) | ||
{ | ||
return Sse42.Crc32(crc, data); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static uint Compute(uint crc, int data) | ||
{ | ||
return Sse42.Crc32(crc, (uint)data); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static uint Compute(uint crc, byte[] data) | ||
{ | ||
var off = 0; | ||
var len = data.Length; | ||
while (len >= 4) | ||
{ | ||
crc = (uint)Sse42.X64.Crc32(crc, BitConverter.ToUInt32(data, off)); | ||
off += 4; | ||
len -= 4; | ||
} | ||
|
||
while (len > 0) | ||
{ | ||
crc = Sse42.Crc32(crc, data[off]); | ||
off++; | ||
len--; | ||
} | ||
return crc; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters