mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[Aaru.Checksums] Reformat and cleanup.
This commit is contained in:
@@ -37,19 +37,19 @@ static class Clmul
|
||||
};
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static void ShiftRight128(Vector128<ulong> initial, uint n, out Vector128<ulong> outLeft,
|
||||
static void ShiftRight128(Vector128<ulong> initial, uint n, out Vector128<ulong> outLeft,
|
||||
out Vector128<ulong> outRight)
|
||||
{
|
||||
uint maskPos = 16 - n;
|
||||
|
||||
Vector128<byte> maskA = Vector128.Create(_shuffleMasks[maskPos], _shuffleMasks[maskPos + 1],
|
||||
_shuffleMasks[maskPos + 2], _shuffleMasks[maskPos + 3],
|
||||
_shuffleMasks[maskPos + 4], _shuffleMasks[maskPos + 5],
|
||||
_shuffleMasks[maskPos + 6], _shuffleMasks[maskPos + 7],
|
||||
_shuffleMasks[maskPos + 8], _shuffleMasks[maskPos + 9],
|
||||
_shuffleMasks[maskPos + 10], _shuffleMasks[maskPos + 11],
|
||||
_shuffleMasks[maskPos + 12], _shuffleMasks[maskPos + 13],
|
||||
_shuffleMasks[maskPos + 14], _shuffleMasks[maskPos + 15]);
|
||||
var maskA = Vector128.Create(_shuffleMasks[maskPos], _shuffleMasks[maskPos + 1],
|
||||
_shuffleMasks[maskPos + 2], _shuffleMasks[maskPos + 3],
|
||||
_shuffleMasks[maskPos + 4], _shuffleMasks[maskPos + 5],
|
||||
_shuffleMasks[maskPos + 6], _shuffleMasks[maskPos + 7],
|
||||
_shuffleMasks[maskPos + 8], _shuffleMasks[maskPos + 9],
|
||||
_shuffleMasks[maskPos + 10], _shuffleMasks[maskPos + 11],
|
||||
_shuffleMasks[maskPos + 12], _shuffleMasks[maskPos + 13],
|
||||
_shuffleMasks[maskPos + 14], _shuffleMasks[maskPos + 15]);
|
||||
|
||||
Vector128<byte> maskB = Sse2.Xor(maskA, Sse2.CompareEqual(Vector128<byte>.Zero, Vector128<byte>.Zero));
|
||||
|
||||
@@ -64,28 +64,33 @@ static class Clmul
|
||||
|
||||
internal static ulong Step(ulong crc, byte[] data, uint length)
|
||||
{
|
||||
int bufPos = 16;
|
||||
const ulong k1 = 0xe05dd497ca393ae4;
|
||||
const ulong k2 = 0xdabe95afc7875f40;
|
||||
const ulong mu = 0x9c3e466c172963d5;
|
||||
const ulong pol = 0x92d8af2baf0e1e85;
|
||||
Vector128<ulong> foldConstants1 = Vector128.Create(k1, k2);
|
||||
Vector128<ulong> foldConstants2 = Vector128.Create(mu, pol);
|
||||
Vector128<ulong> initialCrc = Vector128.Create(~crc, 0);
|
||||
var bufPos = 16;
|
||||
const ulong k1 = 0xe05dd497ca393ae4;
|
||||
const ulong k2 = 0xdabe95afc7875f40;
|
||||
const ulong mu = 0x9c3e466c172963d5;
|
||||
const ulong pol = 0x92d8af2baf0e1e85;
|
||||
var foldConstants1 = Vector128.Create(k1, k2);
|
||||
var foldConstants2 = Vector128.Create(mu, pol);
|
||||
var initialCrc = Vector128.Create(~crc, 0);
|
||||
length -= 16;
|
||||
|
||||
// Initial CRC can simply be added to data
|
||||
ShiftRight128(initialCrc, 0, out Vector128<ulong> crc0, out Vector128<ulong> crc1);
|
||||
|
||||
Vector128<ulong> accumulator =
|
||||
Sse2.Xor(Fold(Sse2.Xor(crc0, Vector128.Create(BitConverter.ToUInt64(data, 0), BitConverter.ToUInt64(data, 8))), foldConstants1),
|
||||
crc1);
|
||||
Sse2.Xor(
|
||||
Fold(Sse2.Xor(crc0, Vector128.Create(BitConverter.ToUInt64(data, 0), BitConverter.ToUInt64(data, 8))),
|
||||
foldConstants1),
|
||||
crc1);
|
||||
|
||||
while(length >= 32)
|
||||
{
|
||||
accumulator =
|
||||
Fold(Sse2.Xor(Vector128.Create(BitConverter.ToUInt64(data, bufPos), BitConverter.ToUInt64(data, bufPos + 8)), accumulator),
|
||||
foldConstants1);
|
||||
Fold(
|
||||
Sse2.Xor(
|
||||
Vector128.Create(BitConverter.ToUInt64(data, bufPos), BitConverter.ToUInt64(data, bufPos + 8)),
|
||||
accumulator),
|
||||
foldConstants1);
|
||||
|
||||
length -= 16;
|
||||
bufPos += 16;
|
||||
@@ -102,9 +107,10 @@ static class Clmul
|
||||
Vector128<ulong> t1 = Pclmulqdq.CarrylessMultiply(r, foldConstants2, 0x00);
|
||||
|
||||
Vector128<ulong> t2 =
|
||||
Sse2.Xor(Sse2.Xor(Pclmulqdq.CarrylessMultiply(t1, foldConstants2, 0x10), Sse2.ShiftLeftLogical128BitLane(t1, 8)),
|
||||
r);
|
||||
Sse2.Xor(
|
||||
Sse2.Xor(Pclmulqdq.CarrylessMultiply(t1, foldConstants2, 0x10), Sse2.ShiftLeftLogical128BitLane(t1, 8)),
|
||||
r);
|
||||
|
||||
return ~(((ulong)Sse41.Extract(t2.AsUInt32(), 3) << 32) | Sse41.Extract(t2.AsUInt32(), 2));
|
||||
return ~((ulong)Sse41.Extract(t2.AsUInt32(), 3) << 32 | Sse41.Extract(t2.AsUInt32(), 2));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user