1 /* XzCrc64Opt.c -- CRC64 calculation
2 2017-06-30 : Igor Pavlov : Public domain */
10 #define CRC64_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
12 UInt64 MY_FAST_CALL
XzCrc64UpdateT4(UInt64 v
, const void *data
, size_t size
, const UInt64
*table
)
14 const Byte
*p
= (const Byte
*)data
;
15 for (; size
> 0 && ((unsigned)(ptrdiff_t)p
& 3) != 0; size
--, p
++)
16 v
= CRC64_UPDATE_BYTE_2(v
, *p
);
17 for (; size
>= 4; size
-= 4, p
+= 4)
19 UInt32 d
= (UInt32
)v
^ *(const UInt32
*)p
;
21 ^ (table
+ 0x300)[((d
) & 0xFF)]
22 ^ (table
+ 0x200)[((d
>> 8) & 0xFF)]
23 ^ (table
+ 0x100)[((d
>> 16) & 0xFF)]
24 ^ (table
+ 0x000)[((d
>> 24))];
26 for (; size
> 0; size
--, p
++)
27 v
= CRC64_UPDATE_BYTE_2(v
, *p
);
36 #define CRC_UINT64_SWAP(v) \
38 | ((v >> 40) & ((UInt64)0xFF << 8)) \
39 | ((v >> 24) & ((UInt64)0xFF << 16)) \
40 | ((v >> 8) & ((UInt64)0xFF << 24)) \
41 | ((v << 8) & ((UInt64)0xFF << 32)) \
42 | ((v << 24) & ((UInt64)0xFF << 40)) \
43 | ((v << 40) & ((UInt64)0xFF << 48)) \
46 #define CRC64_UPDATE_BYTE_2_BE(crc, b) (table[(Byte)((crc) >> 56) ^ (b)] ^ ((crc) << 8))
48 UInt64 MY_FAST_CALL
XzCrc64UpdateT1_BeT4(UInt64 v
, const void *data
, size_t size
, const UInt64
*table
)
50 const Byte
*p
= (const Byte
*)data
;
52 v
= CRC_UINT64_SWAP(v
);
53 for (; size
> 0 && ((unsigned)(ptrdiff_t)p
& 3) != 0; size
--, p
++)
54 v
= CRC64_UPDATE_BYTE_2_BE(v
, *p
);
55 for (; size
>= 4; size
-= 4, p
+= 4)
57 UInt32 d
= (UInt32
)(v
>> 32) ^ *(const UInt32
*)p
;
59 ^ (table
+ 0x000)[((d
) & 0xFF)]
60 ^ (table
+ 0x100)[((d
>> 8) & 0xFF)]
61 ^ (table
+ 0x200)[((d
>> 16) & 0xFF)]
62 ^ (table
+ 0x300)[((d
>> 24))];
64 for (; size
> 0; size
--, p
++)
65 v
= CRC64_UPDATE_BYTE_2_BE(v
, *p
);
66 return CRC_UINT64_SWAP(v
);