1 /* XzCrc64Opt.c -- CRC64 calculation
2 2023-04-02 : Igor Pavlov : Public domain */
3
4 #include "Precomp.h"
5
6 #include "CpuArch.h"
7
8 #ifndef MY_CPU_BE
9
10 #define CRC64_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
11
12 UInt64 Z7_FASTCALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table);
XzCrc64UpdateT4(UInt64 v,const void * data,size_t size,const UInt64 * table)13 UInt64 Z7_FASTCALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table)
14 {
15 const Byte *p = (const Byte *)data;
16 for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)
17 v = CRC64_UPDATE_BYTE_2(v, *p);
18 for (; size >= 4; size -= 4, p += 4)
19 {
20 const UInt32 d = (UInt32)v ^ *(const UInt32 *)(const void *)p;
21 v = (v >> 32)
22 ^ (table + 0x300)[((d ) & 0xFF)]
23 ^ (table + 0x200)[((d >> 8) & 0xFF)]
24 ^ (table + 0x100)[((d >> 16) & 0xFF)]
25 ^ (table + 0x000)[((d >> 24))];
26 }
27 for (; size > 0; size--, p++)
28 v = CRC64_UPDATE_BYTE_2(v, *p);
29 return v;
30 }
31
32 #endif
33
34
35 #ifndef MY_CPU_LE
36
37 #define CRC64_UPDATE_BYTE_2_BE(crc, b) (table[(Byte)((crc) >> 56) ^ (b)] ^ ((crc) << 8))
38
39 UInt64 Z7_FASTCALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table);
XzCrc64UpdateT1_BeT4(UInt64 v,const void * data,size_t size,const UInt64 * table)40 UInt64 Z7_FASTCALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table)
41 {
42 const Byte *p = (const Byte *)data;
43 table += 0x100;
44 v = Z7_BSWAP64(v);
45 for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)
46 v = CRC64_UPDATE_BYTE_2_BE(v, *p);
47 for (; size >= 4; size -= 4, p += 4)
48 {
49 const UInt32 d = (UInt32)(v >> 32) ^ *(const UInt32 *)(const void *)p;
50 v = (v << 32)
51 ^ (table + 0x000)[((d ) & 0xFF)]
52 ^ (table + 0x100)[((d >> 8) & 0xFF)]
53 ^ (table + 0x200)[((d >> 16) & 0xFF)]
54 ^ (table + 0x300)[((d >> 24))];
55 }
56 for (; size > 0; size--, p++)
57 v = CRC64_UPDATE_BYTE_2_BE(v, *p);
58 return Z7_BSWAP64(v);
59 }
60
61 #endif
62