diff options
Diffstat (limited to 'C/XzCrc64.c')
-rw-r--r-- | C/XzCrc64.c | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/C/XzCrc64.c b/C/XzCrc64.c index b6d02cb..c2fad6c 100644 --- a/C/XzCrc64.c +++ b/C/XzCrc64.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* XzCrc64.c -- CRC64 calculation | 1 | /* XzCrc64.c -- CRC64 calculation |
2 | 2017-05-23 : Igor Pavlov : Public domain */ | 2 | 2023-04-02 : Igor Pavlov : Public domain */ |
3 | 3 | ||
4 | #include "Precomp.h" | 4 | #include "Precomp.h" |
5 | 5 | ||
@@ -12,39 +12,30 @@ | |||
12 | #define CRC64_NUM_TABLES 4 | 12 | #define CRC64_NUM_TABLES 4 |
13 | #else | 13 | #else |
14 | #define CRC64_NUM_TABLES 5 | 14 | #define CRC64_NUM_TABLES 5 |
15 | #define CRC_UINT64_SWAP(v) \ | ||
16 | ((v >> 56) \ | ||
17 | | ((v >> 40) & ((UInt64)0xFF << 8)) \ | ||
18 | | ((v >> 24) & ((UInt64)0xFF << 16)) \ | ||
19 | | ((v >> 8) & ((UInt64)0xFF << 24)) \ | ||
20 | | ((v << 8) & ((UInt64)0xFF << 32)) \ | ||
21 | | ((v << 24) & ((UInt64)0xFF << 40)) \ | ||
22 | | ((v << 40) & ((UInt64)0xFF << 48)) \ | ||
23 | | ((v << 56))) | ||
24 | 15 | ||
25 | UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table); | 16 | UInt64 Z7_FASTCALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table); |
26 | #endif | 17 | #endif |
27 | 18 | ||
28 | #ifndef MY_CPU_BE | 19 | #ifndef MY_CPU_BE |
29 | UInt64 MY_FAST_CALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table); | 20 | UInt64 Z7_FASTCALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table); |
30 | #endif | 21 | #endif |
31 | 22 | ||
32 | typedef UInt64 (MY_FAST_CALL *CRC64_FUNC)(UInt64 v, const void *data, size_t size, const UInt64 *table); | 23 | typedef UInt64 (Z7_FASTCALL *CRC64_FUNC)(UInt64 v, const void *data, size_t size, const UInt64 *table); |
33 | 24 | ||
34 | static CRC64_FUNC g_Crc64Update; | 25 | static CRC64_FUNC g_Crc64Update; |
35 | UInt64 g_Crc64Table[256 * CRC64_NUM_TABLES]; | 26 | UInt64 g_Crc64Table[256 * CRC64_NUM_TABLES]; |
36 | 27 | ||
37 | UInt64 MY_FAST_CALL Crc64Update(UInt64 v, const void *data, size_t size) | 28 | UInt64 Z7_FASTCALL Crc64Update(UInt64 v, const void *data, size_t size) |
38 | { | 29 | { |
39 | return g_Crc64Update(v, data, size, g_Crc64Table); | 30 | return g_Crc64Update(v, data, size, g_Crc64Table); |
40 | } | 31 | } |
41 | 32 | ||
42 | UInt64 MY_FAST_CALL Crc64Calc(const void *data, size_t size) | 33 | UInt64 Z7_FASTCALL Crc64Calc(const void *data, size_t size) |
43 | { | 34 | { |
44 | return g_Crc64Update(CRC64_INIT_VAL, data, size, g_Crc64Table) ^ CRC64_INIT_VAL; | 35 | return g_Crc64Update(CRC64_INIT_VAL, data, size, g_Crc64Table) ^ CRC64_INIT_VAL; |
45 | } | 36 | } |
46 | 37 | ||
47 | void MY_FAST_CALL Crc64GenerateTable() | 38 | void Z7_FASTCALL Crc64GenerateTable(void) |
48 | { | 39 | { |
49 | UInt32 i; | 40 | UInt32 i; |
50 | for (i = 0; i < 256; i++) | 41 | for (i = 0; i < 256; i++) |
@@ -57,7 +48,7 @@ void MY_FAST_CALL Crc64GenerateTable() | |||
57 | } | 48 | } |
58 | for (i = 256; i < 256 * CRC64_NUM_TABLES; i++) | 49 | for (i = 256; i < 256 * CRC64_NUM_TABLES; i++) |
59 | { | 50 | { |
60 | UInt64 r = g_Crc64Table[(size_t)i - 256]; | 51 | const UInt64 r = g_Crc64Table[(size_t)i - 256]; |
61 | g_Crc64Table[i] = g_Crc64Table[r & 0xFF] ^ (r >> 8); | 52 | g_Crc64Table[i] = g_Crc64Table[r & 0xFF] ^ (r >> 8); |
62 | } | 53 | } |
63 | 54 | ||
@@ -76,11 +67,14 @@ void MY_FAST_CALL Crc64GenerateTable() | |||
76 | { | 67 | { |
77 | for (i = 256 * CRC64_NUM_TABLES - 1; i >= 256; i--) | 68 | for (i = 256 * CRC64_NUM_TABLES - 1; i >= 256; i--) |
78 | { | 69 | { |
79 | UInt64 x = g_Crc64Table[(size_t)i - 256]; | 70 | const UInt64 x = g_Crc64Table[(size_t)i - 256]; |
80 | g_Crc64Table[i] = CRC_UINT64_SWAP(x); | 71 | g_Crc64Table[i] = Z7_BSWAP64(x); |
81 | } | 72 | } |
82 | g_Crc64Update = XzCrc64UpdateT1_BeT4; | 73 | g_Crc64Update = XzCrc64UpdateT1_BeT4; |
83 | } | 74 | } |
84 | } | 75 | } |
85 | #endif | 76 | #endif |
86 | } | 77 | } |
78 | |||
79 | #undef kCrc64Poly | ||
80 | #undef CRC64_NUM_TABLES | ||