aboutsummaryrefslogtreecommitdiff
path: root/C/XzCrc64Opt.c
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2023-06-21 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2023-12-17 14:59:19 +0500
commit5b39dc76f1bc82f941d5c800ab9f34407a06b53a (patch)
treefe5e17420300b715021a76328444088d32047963 /C/XzCrc64Opt.c
parent93be7d4abfd4233228f58ee1fbbcd76d91be66a4 (diff)
download7zip-23.01.tar.gz
7zip-23.01.tar.bz2
7zip-23.01.zip
23.0123.01
Diffstat (limited to 'C/XzCrc64Opt.c')
-rw-r--r--C/XzCrc64Opt.c28
1 files changed, 9 insertions, 19 deletions
diff --git a/C/XzCrc64Opt.c b/C/XzCrc64Opt.c
index 93a9fff..d03374c 100644
--- a/C/XzCrc64Opt.c
+++ b/C/XzCrc64Opt.c
@@ -1,5 +1,5 @@
1/* XzCrc64Opt.c -- CRC64 calculation 1/* XzCrc64Opt.c -- CRC64 calculation
22021-02-09 : Igor Pavlov : Public domain */ 22023-04-02 : Igor Pavlov : Public domain */
3 3
4#include "Precomp.h" 4#include "Precomp.h"
5 5
@@ -9,15 +9,15 @@
9 9
10#define CRC64_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) 10#define CRC64_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
11 11
12UInt64 MY_FAST_CALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table); 12UInt64 Z7_FASTCALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table);
13UInt64 MY_FAST_CALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table) 13UInt64 Z7_FASTCALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table)
14{ 14{
15 const Byte *p = (const Byte *)data; 15 const Byte *p = (const Byte *)data;
16 for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++) 16 for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)
17 v = CRC64_UPDATE_BYTE_2(v, *p); 17 v = CRC64_UPDATE_BYTE_2(v, *p);
18 for (; size >= 4; size -= 4, p += 4) 18 for (; size >= 4; size -= 4, p += 4)
19 { 19 {
20 UInt32 d = (UInt32)v ^ *(const UInt32 *)(const void *)p; 20 const UInt32 d = (UInt32)v ^ *(const UInt32 *)(const void *)p;
21 v = (v >> 32) 21 v = (v >> 32)
22 ^ (table + 0x300)[((d ) & 0xFF)] 22 ^ (table + 0x300)[((d ) & 0xFF)]
23 ^ (table + 0x200)[((d >> 8) & 0xFF)] 23 ^ (table + 0x200)[((d >> 8) & 0xFF)]
@@ -34,29 +34,19 @@ UInt64 MY_FAST_CALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, con
34 34
35#ifndef MY_CPU_LE 35#ifndef MY_CPU_LE
36 36
37#define CRC_UINT64_SWAP(v) \
38 ((v >> 56) \
39 | ((v >> 40) & ((UInt64)0xFF << 8)) \
40 | ((v >> 24) & ((UInt64)0xFF << 16)) \
41 | ((v >> 8) & ((UInt64)0xFF << 24)) \
42 | ((v << 8) & ((UInt64)0xFF << 32)) \
43 | ((v << 24) & ((UInt64)0xFF << 40)) \
44 | ((v << 40) & ((UInt64)0xFF << 48)) \
45 | ((v << 56)))
46
47#define CRC64_UPDATE_BYTE_2_BE(crc, b) (table[(Byte)((crc) >> 56) ^ (b)] ^ ((crc) << 8)) 37#define CRC64_UPDATE_BYTE_2_BE(crc, b) (table[(Byte)((crc) >> 56) ^ (b)] ^ ((crc) << 8))
48 38
49UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table); 39UInt64 Z7_FASTCALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table);
50UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table) 40UInt64 Z7_FASTCALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table)
51{ 41{
52 const Byte *p = (const Byte *)data; 42 const Byte *p = (const Byte *)data;
53 table += 0x100; 43 table += 0x100;
54 v = CRC_UINT64_SWAP(v); 44 v = Z7_BSWAP64(v);
55 for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++) 45 for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)
56 v = CRC64_UPDATE_BYTE_2_BE(v, *p); 46 v = CRC64_UPDATE_BYTE_2_BE(v, *p);
57 for (; size >= 4; size -= 4, p += 4) 47 for (; size >= 4; size -= 4, p += 4)
58 { 48 {
59 UInt32 d = (UInt32)(v >> 32) ^ *(const UInt32 *)(const void *)p; 49 const UInt32 d = (UInt32)(v >> 32) ^ *(const UInt32 *)(const void *)p;
60 v = (v << 32) 50 v = (v << 32)
61 ^ (table + 0x000)[((d ) & 0xFF)] 51 ^ (table + 0x000)[((d ) & 0xFF)]
62 ^ (table + 0x100)[((d >> 8) & 0xFF)] 52 ^ (table + 0x100)[((d >> 8) & 0xFF)]
@@ -65,7 +55,7 @@ UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size
65 } 55 }
66 for (; size > 0; size--, p++) 56 for (; size > 0; size--, p++)
67 v = CRC64_UPDATE_BYTE_2_BE(v, *p); 57 v = CRC64_UPDATE_BYTE_2_BE(v, *p);
68 return CRC_UINT64_SWAP(v); 58 return Z7_BSWAP64(v);
69} 59}
70 60
71#endif 61#endif