aboutsummaryrefslogtreecommitdiff
path: root/C/LzFind.c
diff options
context:
space:
mode:
Diffstat (limited to 'C/LzFind.c')
-rw-r--r--C/LzFind.c127
1 files changed, 78 insertions, 49 deletions
diff --git a/C/LzFind.c b/C/LzFind.c
index 0fbd5aa..1ce4046 100644
--- a/C/LzFind.c
+++ b/C/LzFind.c
@@ -1,5 +1,5 @@
1/* LzFind.c -- Match finder for LZ algorithms 1/* LzFind.c -- Match finder for LZ algorithms
22023-03-14 : Igor Pavlov : Public domain */ 22024-03-01 : Igor Pavlov : Public domain */
3 3
4#include "Precomp.h" 4#include "Precomp.h"
5 5
@@ -108,9 +108,15 @@ static int LzInWindow_Create2(CMatchFinder *p, UInt32 blockSize, ISzAllocPtr all
108 return (p->bufBase != NULL); 108 return (p->bufBase != NULL);
109} 109}
110 110
111static const Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; } 111static const Byte *MatchFinder_GetPointerToCurrentPos(void *p)
112{
113 return ((CMatchFinder *)p)->buffer;
114}
112 115
113static UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return GET_AVAIL_BYTES(p); } 116static UInt32 MatchFinder_GetNumAvailableBytes(void *p)
117{
118 return GET_AVAIL_BYTES((CMatchFinder *)p);
119}
114 120
115 121
116Z7_NO_INLINE 122Z7_NO_INLINE
@@ -571,8 +577,9 @@ void MatchFinder_Init_4(CMatchFinder *p)
571#define CYC_TO_POS_OFFSET 0 577#define CYC_TO_POS_OFFSET 0
572// #define CYC_TO_POS_OFFSET 1 // for debug 578// #define CYC_TO_POS_OFFSET 1 // for debug
573 579
574void MatchFinder_Init(CMatchFinder *p) 580void MatchFinder_Init(void *_p)
575{ 581{
582 CMatchFinder *p = (CMatchFinder *)_p;
576 MatchFinder_Init_HighHash(p); 583 MatchFinder_Init_HighHash(p);
577 MatchFinder_Init_LowHash(p); 584 MatchFinder_Init_LowHash(p);
578 MatchFinder_Init_4(p); 585 MatchFinder_Init_4(p);
@@ -607,16 +614,16 @@ void MatchFinder_Init(CMatchFinder *p)
607 #endif 614 #endif
608 #endif 615 #endif
609 616
610// #elif defined(MY_CPU_ARM_OR_ARM64) 617#elif defined(MY_CPU_ARM64) \
611#elif defined(MY_CPU_ARM64) 618 /* || (defined(__ARM_ARCH) && (__ARM_ARCH >= 7)) */
612 619
613 #if defined(__clang__) && (__clang_major__ >= 8) \ 620 #if defined(Z7_CLANG_VERSION) && (Z7_CLANG_VERSION >= 30800) \
614 || defined(__GNUC__) && (__GNUC__ >= 8) 621 || defined(__GNUC__) && (__GNUC__ >= 6)
615 #define USE_LZFIND_SATUR_SUB_128 622 #define USE_LZFIND_SATUR_SUB_128
616 #ifdef MY_CPU_ARM64 623 #ifdef MY_CPU_ARM64
617 // #define LZFIND_ATTRIB_SSE41 __attribute__((__target__(""))) 624 // #define LZFIND_ATTRIB_SSE41 __attribute__((__target__("")))
618 #else 625 #else
619 // #define LZFIND_ATTRIB_SSE41 __attribute__((__target__("fpu=crypto-neon-fp-armv8"))) 626 #define LZFIND_ATTRIB_SSE41 __attribute__((__target__("fpu=neon")))
620 #endif 627 #endif
621 628
622 #elif defined(_MSC_VER) 629 #elif defined(_MSC_VER)
@@ -625,7 +632,7 @@ void MatchFinder_Init(CMatchFinder *p)
625 #endif 632 #endif
626 #endif 633 #endif
627 634
628 #if defined(_MSC_VER) && defined(MY_CPU_ARM64) 635 #if defined(Z7_MSC_VER_ORIGINAL) && defined(MY_CPU_ARM64)
629 #include <arm64_neon.h> 636 #include <arm64_neon.h>
630 #else 637 #else
631 #include <arm_neon.h> 638 #include <arm_neon.h>
@@ -1082,9 +1089,11 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const
1082 1089
1083 1090
1084#define MOVE_POS \ 1091#define MOVE_POS \
1085 ++p->cyclicBufferPos; \ 1092 p->cyclicBufferPos++; \
1086 p->buffer++; \ 1093 p->buffer++; \
1087 { const UInt32 pos1 = p->pos + 1; p->pos = pos1; if (pos1 == p->posLimit) MatchFinder_CheckLimits(p); } 1094 { const UInt32 pos1 = p->pos + 1; \
1095 p->pos = pos1; \
1096 if (pos1 == p->posLimit) MatchFinder_CheckLimits(p); }
1088 1097
1089#define MOVE_POS_RET MOVE_POS return distances; 1098#define MOVE_POS_RET MOVE_POS return distances;
1090 1099
@@ -1103,20 +1112,26 @@ static void MatchFinder_MovePos(CMatchFinder *p)
1103} 1112}
1104 1113
1105#define GET_MATCHES_HEADER2(minLen, ret_op) \ 1114#define GET_MATCHES_HEADER2(minLen, ret_op) \
1106 unsigned lenLimit; UInt32 hv; const Byte *cur; UInt32 curMatch; \ 1115 UInt32 hv; const Byte *cur; UInt32 curMatch; \
1107 lenLimit = (unsigned)p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \ 1116 UInt32 lenLimit = p->lenLimit; \
1117 if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; } \
1108 cur = p->buffer; 1118 cur = p->buffer;
1109 1119
1110#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return distances) 1120#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return distances)
1111#define SKIP_HEADER(minLen) do { GET_MATCHES_HEADER2(minLen, continue) 1121#define SKIP_HEADER(minLen) \
1122 do { GET_MATCHES_HEADER2(minLen, continue)
1112 1123
1113#define MF_PARAMS(p) lenLimit, curMatch, p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue 1124#define MF_PARAMS(p) lenLimit, curMatch, p->pos, p->buffer, p->son, \
1125 p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
1114 1126
1115#define SKIP_FOOTER SkipMatchesSpec(MF_PARAMS(p)); MOVE_POS } while (--num); 1127#define SKIP_FOOTER \
1128 SkipMatchesSpec(MF_PARAMS(p)); \
1129 MOVE_POS \
1130 } while (--num);
1116 1131
1117#define GET_MATCHES_FOOTER_BASE(_maxLen_, func) \ 1132#define GET_MATCHES_FOOTER_BASE(_maxLen_, func) \
1118 distances = func(MF_PARAMS(p), \ 1133 distances = func(MF_PARAMS(p), distances, (UInt32)_maxLen_); \
1119 distances, (UInt32)_maxLen_); MOVE_POS_RET 1134 MOVE_POS_RET
1120 1135
1121#define GET_MATCHES_FOOTER_BT(_maxLen_) \ 1136#define GET_MATCHES_FOOTER_BT(_maxLen_) \
1122 GET_MATCHES_FOOTER_BASE(_maxLen_, GetMatchesSpec1) 1137 GET_MATCHES_FOOTER_BASE(_maxLen_, GetMatchesSpec1)
@@ -1133,8 +1148,9 @@ static void MatchFinder_MovePos(CMatchFinder *p)
1133 for (; c != lim; c++) if (*(c + diff) != *c) break; \ 1148 for (; c != lim; c++) if (*(c + diff) != *c) break; \
1134 maxLen = (unsigned)(c - cur); } 1149 maxLen = (unsigned)(c - cur); }
1135 1150
1136static UInt32* Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) 1151static UInt32* Bt2_MatchFinder_GetMatches(void *_p, UInt32 *distances)
1137{ 1152{
1153 CMatchFinder *p = (CMatchFinder *)_p;
1138 GET_MATCHES_HEADER(2) 1154 GET_MATCHES_HEADER(2)
1139 HASH2_CALC 1155 HASH2_CALC
1140 curMatch = p->hash[hv]; 1156 curMatch = p->hash[hv];
@@ -1158,8 +1174,9 @@ UInt32* Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
1158 mmm = pos; 1174 mmm = pos;
1159 1175
1160 1176
1161static UInt32* Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) 1177static UInt32* Bt3_MatchFinder_GetMatches(void *_p, UInt32 *distances)
1162{ 1178{
1179 CMatchFinder *p = (CMatchFinder *)_p;
1163 UInt32 mmm; 1180 UInt32 mmm;
1164 UInt32 h2, d2, pos; 1181 UInt32 h2, d2, pos;
1165 unsigned maxLen; 1182 unsigned maxLen;
@@ -1199,8 +1216,9 @@ static UInt32* Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
1199} 1216}
1200 1217
1201 1218
1202static UInt32* Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) 1219static UInt32* Bt4_MatchFinder_GetMatches(void *_p, UInt32 *distances)
1203{ 1220{
1221 CMatchFinder *p = (CMatchFinder *)_p;
1204 UInt32 mmm; 1222 UInt32 mmm;
1205 UInt32 h2, h3, d2, d3, pos; 1223 UInt32 h2, h3, d2, d3, pos;
1206 unsigned maxLen; 1224 unsigned maxLen;
@@ -1267,10 +1285,12 @@ static UInt32* Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
1267} 1285}
1268 1286
1269 1287
1270static UInt32* Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) 1288static UInt32* Bt5_MatchFinder_GetMatches(void *_p, UInt32 *distances)
1271{ 1289{
1290 CMatchFinder *p = (CMatchFinder *)_p;
1272 UInt32 mmm; 1291 UInt32 mmm;
1273 UInt32 h2, h3, d2, d3, maxLen, pos; 1292 UInt32 h2, h3, d2, d3, pos;
1293 unsigned maxLen;
1274 UInt32 *hash; 1294 UInt32 *hash;
1275 GET_MATCHES_HEADER(5) 1295 GET_MATCHES_HEADER(5)
1276 1296
@@ -1339,8 +1359,9 @@ static UInt32* Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
1339} 1359}
1340 1360
1341 1361
1342static UInt32* Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) 1362static UInt32* Hc4_MatchFinder_GetMatches(void *_p, UInt32 *distances)
1343{ 1363{
1364 CMatchFinder *p = (CMatchFinder *)_p;
1344 UInt32 mmm; 1365 UInt32 mmm;
1345 UInt32 h2, h3, d2, d3, pos; 1366 UInt32 h2, h3, d2, d3, pos;
1346 unsigned maxLen; 1367 unsigned maxLen;
@@ -1407,10 +1428,12 @@ static UInt32* Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
1407} 1428}
1408 1429
1409 1430
1410static UInt32 * Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) 1431static UInt32 * Hc5_MatchFinder_GetMatches(void *_p, UInt32 *distances)
1411{ 1432{
1433 CMatchFinder *p = (CMatchFinder *)_p;
1412 UInt32 mmm; 1434 UInt32 mmm;
1413 UInt32 h2, h3, d2, d3, maxLen, pos; 1435 UInt32 h2, h3, d2, d3, pos;
1436 unsigned maxLen;
1414 UInt32 *hash; 1437 UInt32 *hash;
1415 GET_MATCHES_HEADER(5) 1438 GET_MATCHES_HEADER(5)
1416 1439
@@ -1466,7 +1489,7 @@ static UInt32 * Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
1466 if (*(cur - d2 + 3) != cur[3]) 1489 if (*(cur - d2 + 3) != cur[3])
1467 break; 1490 break;
1468 UPDATE_maxLen 1491 UPDATE_maxLen
1469 distances[-2] = maxLen; 1492 distances[-2] = (UInt32)maxLen;
1470 if (maxLen == lenLimit) 1493 if (maxLen == lenLimit)
1471 { 1494 {
1472 p->son[p->cyclicBufferPos] = curMatch; 1495 p->son[p->cyclicBufferPos] = curMatch;
@@ -1489,8 +1512,9 @@ UInt32* Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
1489} 1512}
1490 1513
1491 1514
1492static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num) 1515static void Bt2_MatchFinder_Skip(void *_p, UInt32 num)
1493{ 1516{
1517 CMatchFinder *p = (CMatchFinder *)_p;
1494 SKIP_HEADER(2) 1518 SKIP_HEADER(2)
1495 { 1519 {
1496 HASH2_CALC 1520 HASH2_CALC
@@ -1511,8 +1535,9 @@ void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
1511 SKIP_FOOTER 1535 SKIP_FOOTER
1512} 1536}
1513 1537
1514static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num) 1538static void Bt3_MatchFinder_Skip(void *_p, UInt32 num)
1515{ 1539{
1540 CMatchFinder *p = (CMatchFinder *)_p;
1516 SKIP_HEADER(3) 1541 SKIP_HEADER(3)
1517 { 1542 {
1518 UInt32 h2; 1543 UInt32 h2;
@@ -1526,8 +1551,9 @@ static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
1526 SKIP_FOOTER 1551 SKIP_FOOTER
1527} 1552}
1528 1553
1529static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) 1554static void Bt4_MatchFinder_Skip(void *_p, UInt32 num)
1530{ 1555{
1556 CMatchFinder *p = (CMatchFinder *)_p;
1531 SKIP_HEADER(4) 1557 SKIP_HEADER(4)
1532 { 1558 {
1533 UInt32 h2, h3; 1559 UInt32 h2, h3;
@@ -1542,8 +1568,9 @@ static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
1542 SKIP_FOOTER 1568 SKIP_FOOTER
1543} 1569}
1544 1570
1545static void Bt5_MatchFinder_Skip(CMatchFinder *p, UInt32 num) 1571static void Bt5_MatchFinder_Skip(void *_p, UInt32 num)
1546{ 1572{
1573 CMatchFinder *p = (CMatchFinder *)_p;
1547 SKIP_HEADER(5) 1574 SKIP_HEADER(5)
1548 { 1575 {
1549 UInt32 h2, h3; 1576 UInt32 h2, h3;
@@ -1589,8 +1616,9 @@ static void Bt5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
1589 }} while(num); \ 1616 }} while(num); \
1590 1617
1591 1618
1592static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) 1619static void Hc4_MatchFinder_Skip(void *_p, UInt32 num)
1593{ 1620{
1621 CMatchFinder *p = (CMatchFinder *)_p;
1594 HC_SKIP_HEADER(4) 1622 HC_SKIP_HEADER(4)
1595 1623
1596 UInt32 h2, h3; 1624 UInt32 h2, h3;
@@ -1604,8 +1632,9 @@ static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
1604} 1632}
1605 1633
1606 1634
1607static void Hc5_MatchFinder_Skip(CMatchFinder *p, UInt32 num) 1635static void Hc5_MatchFinder_Skip(void *_p, UInt32 num)
1608{ 1636{
1637 CMatchFinder *p = (CMatchFinder *)_p;
1609 HC_SKIP_HEADER(5) 1638 HC_SKIP_HEADER(5)
1610 1639
1611 UInt32 h2, h3; 1640 UInt32 h2, h3;
@@ -1634,41 +1663,41 @@ void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
1634 1663
1635void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder2 *vTable) 1664void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder2 *vTable)
1636{ 1665{
1637 vTable->Init = (Mf_Init_Func)MatchFinder_Init; 1666 vTable->Init = MatchFinder_Init;
1638 vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes; 1667 vTable->GetNumAvailableBytes = MatchFinder_GetNumAvailableBytes;
1639 vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos; 1668 vTable->GetPointerToCurrentPos = MatchFinder_GetPointerToCurrentPos;
1640 if (!p->btMode) 1669 if (!p->btMode)
1641 { 1670 {
1642 if (p->numHashBytes <= 4) 1671 if (p->numHashBytes <= 4)
1643 { 1672 {
1644 vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches; 1673 vTable->GetMatches = Hc4_MatchFinder_GetMatches;
1645 vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip; 1674 vTable->Skip = Hc4_MatchFinder_Skip;
1646 } 1675 }
1647 else 1676 else
1648 { 1677 {
1649 vTable->GetMatches = (Mf_GetMatches_Func)Hc5_MatchFinder_GetMatches; 1678 vTable->GetMatches = Hc5_MatchFinder_GetMatches;
1650 vTable->Skip = (Mf_Skip_Func)Hc5_MatchFinder_Skip; 1679 vTable->Skip = Hc5_MatchFinder_Skip;
1651 } 1680 }
1652 } 1681 }
1653 else if (p->numHashBytes == 2) 1682 else if (p->numHashBytes == 2)
1654 { 1683 {
1655 vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches; 1684 vTable->GetMatches = Bt2_MatchFinder_GetMatches;
1656 vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip; 1685 vTable->Skip = Bt2_MatchFinder_Skip;
1657 } 1686 }
1658 else if (p->numHashBytes == 3) 1687 else if (p->numHashBytes == 3)
1659 { 1688 {
1660 vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches; 1689 vTable->GetMatches = Bt3_MatchFinder_GetMatches;
1661 vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip; 1690 vTable->Skip = Bt3_MatchFinder_Skip;
1662 } 1691 }
1663 else if (p->numHashBytes == 4) 1692 else if (p->numHashBytes == 4)
1664 { 1693 {
1665 vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches; 1694 vTable->GetMatches = Bt4_MatchFinder_GetMatches;
1666 vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip; 1695 vTable->Skip = Bt4_MatchFinder_Skip;
1667 } 1696 }
1668 else 1697 else
1669 { 1698 {
1670 vTable->GetMatches = (Mf_GetMatches_Func)Bt5_MatchFinder_GetMatches; 1699 vTable->GetMatches = Bt5_MatchFinder_GetMatches;
1671 vTable->Skip = (Mf_Skip_Func)Bt5_MatchFinder_Skip; 1700 vTable->Skip = Bt5_MatchFinder_Skip;
1672 } 1701 }
1673} 1702}
1674 1703