aboutsummaryrefslogtreecommitdiff
path: root/util/cbfstool/lzma/C/LzFind.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/cbfstool/lzma/C/LzFind.c')
-rw-r--r--util/cbfstool/lzma/C/LzFind.c160
1 files changed, 80 insertions, 80 deletions
diff --git a/util/cbfstool/lzma/C/LzFind.c b/util/cbfstool/lzma/C/LzFind.c
index 8f204afb13..a0d01bfff2 100644
--- a/util/cbfstool/lzma/C/LzFind.c
+++ b/util/cbfstool/lzma/C/LzFind.c
@@ -7,10 +7,10 @@
#include "LzHash.h"
#define kEmptyHashValue 0
-#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)
+#define kMaxValForNormalize ((uint32_t)0xFFFFFFFF)
#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */
#define kNormalizeMask (~(kNormalizeStepMin - 1))
-#define kMaxHistorySize ((UInt32)3 << 30)
+#define kMaxHistorySize ((uint32_t)3 << 30)
#define kStartMaxLen 3
@@ -25,9 +25,9 @@ static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */
-static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)
+static int LzInWindow_Create(CMatchFinder *p, uint32_t keepSizeReserv, ISzAlloc *alloc)
{
- UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
+ uint32_t blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
if (p->directInput)
{
p->blockSize = blockSize;
@@ -37,17 +37,17 @@ static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *a
{
LzInWindow_Free(p, alloc);
p->blockSize = blockSize;
- p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);
+ p->bufferBase = (uint8_t *)alloc->Alloc(alloc, (size_t)blockSize);
}
return (p->bufferBase != 0);
}
-Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
-static Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 bindex) { return p->buffer[bindex]; }
+uint8_t *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
+static uint8_t MatchFinder_GetIndexByte(CMatchFinder *p, int32_t bindex) { return p->buffer[bindex]; }
-static UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
+static uint32_t MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
-void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
+void MatchFinder_ReduceOffsets(CMatchFinder *p, uint32_t subValue)
{
p->posLimit -= subValue;
p->pos -= subValue;
@@ -60,9 +60,9 @@ static void MatchFinder_ReadBlock(CMatchFinder *p)
return;
if (p->directInput)
{
- UInt32 curSize = 0xFFFFFFFF - p->streamPos;
+ uint32_t curSize = 0xFFFFFFFF - p->streamPos;
if (curSize > p->directInputRem)
- curSize = (UInt32)p->directInputRem;
+ curSize = (uint32_t)p->directInputRem;
p->directInputRem -= curSize;
p->streamPos += curSize;
if (p->directInputRem == 0)
@@ -71,7 +71,7 @@ static void MatchFinder_ReadBlock(CMatchFinder *p)
}
for (;;)
{
- Byte *dest = p->buffer + (p->streamPos - p->pos);
+ uint8_t *dest = p->buffer + (p->streamPos - p->pos);
size_t size = (p->bufferBase + p->blockSize - dest);
if (size == 0)
return;
@@ -83,7 +83,7 @@ static void MatchFinder_ReadBlock(CMatchFinder *p)
p->streamEndWasReached = 1;
return;
}
- p->streamPos += (UInt32)size;
+ p->streamPos += (uint32_t)size;
if (p->streamPos - p->pos > p->keepSizeAfter)
return;
}
@@ -132,7 +132,7 @@ static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
void MatchFinder_Construct(CMatchFinder *p)
{
- UInt32 i;
+ uint32_t i;
p->bufferBase = 0;
p->directInput = 0;
p->hash = 0;
@@ -140,7 +140,7 @@ void MatchFinder_Construct(CMatchFinder *p)
for (i = 0; i < 256; i++)
{
- UInt32 r = i;
+ uint32_t r = i;
int j;
for (j = 0; j < 8; j++)
r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
@@ -160,26 +160,26 @@ void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)
LzInWindow_Free(p, alloc);
}
-static CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)
+static CLzRef* AllocRefs(uint32_t num, ISzAlloc *alloc)
{
- size_t sizeInBytes = (size_t)num * sizeof(CLzRef);
- if (sizeInBytes / sizeof(CLzRef) != num)
+ size_t sizeInuint8_ts = (size_t)num * sizeof(CLzRef);
+ if (sizeInuint8_ts / sizeof(CLzRef) != num)
return 0;
- return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);
+ return (CLzRef *)alloc->Alloc(alloc, sizeInuint8_ts);
}
-int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
- UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
+int MatchFinder_Create(CMatchFinder *p, uint32_t historySize,
+ uint32_t keepAddBufferBefore, uint32_t matchMaxLen, uint32_t keepAddBufferAfter,
ISzAlloc *alloc)
{
- UInt32 sizeReserv;
+ uint32_t sizeReserv;
if (historySize > kMaxHistorySize)
{
MatchFinder_Free(p, alloc);
return 0;
}
sizeReserv = historySize >> 1;
- if (historySize > ((UInt32)2 << 30))
+ if (historySize > ((uint32_t)2 << 30))
sizeReserv = historySize >> 2;
sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);
@@ -188,8 +188,8 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
/* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */
if (LzInWindow_Create(p, sizeReserv, alloc))
{
- UInt32 newCyclicBufferSize = historySize + 1;
- UInt32 hs;
+ uint32_t newCyclicBufferSize = historySize + 1;
+ uint32_t hs;
p->matchMaxLen = matchMaxLen;
{
p->fixedHashSize = 0;
@@ -221,8 +221,8 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
}
{
- UInt32 prevSize = p->hashSizeSum + p->numSons;
- UInt32 newSize;
+ uint32_t prevSize = p->hashSizeSum + p->numSons;
+ uint32_t newSize;
p->historySize = historySize;
p->hashSizeSum = hs;
p->cyclicBufferSize = newCyclicBufferSize;
@@ -245,8 +245,8 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
static void MatchFinder_SetLimits(CMatchFinder *p)
{
- UInt32 limit = kMaxValForNormalize - p->pos;
- UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;
+ uint32_t limit = kMaxValForNormalize - p->pos;
+ uint32_t limit2 = p->cyclicBufferSize - p->cyclicBufferPos;
if (limit2 < limit)
limit = limit2;
limit2 = p->streamPos - p->pos;
@@ -260,7 +260,7 @@ static void MatchFinder_SetLimits(CMatchFinder *p)
if (limit2 < limit)
limit = limit2;
{
- UInt32 lenLimit = p->streamPos - p->pos;
+ uint32_t lenLimit = p->streamPos - p->pos;
if (lenLimit > p->matchMaxLen)
lenLimit = p->matchMaxLen;
p->lenLimit = lenLimit;
@@ -270,7 +270,7 @@ static void MatchFinder_SetLimits(CMatchFinder *p)
void MatchFinder_Init(CMatchFinder *p)
{
- UInt32 i;
+ uint32_t i;
for (i = 0; i < p->hashSizeSum; i++)
p->hash[i] = kEmptyHashValue;
p->cyclicBufferPos = 0;
@@ -282,17 +282,17 @@ void MatchFinder_Init(CMatchFinder *p)
MatchFinder_SetLimits(p);
}
-static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
+static uint32_t MatchFinder_GetSubValue(CMatchFinder *p)
{
return (p->pos - p->historySize - 1) & kNormalizeMask;
}
-void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
+void MatchFinder_Normalize3(uint32_t subValue, CLzRef *items, uint32_t numItems)
{
- UInt32 i;
+ uint32_t i;
for (i = 0; i < numItems; i++)
{
- UInt32 value = items[i];
+ uint32_t value = items[i];
if (value <= subValue)
value = kEmptyHashValue;
else
@@ -303,7 +303,7 @@ void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
static void MatchFinder_Normalize(CMatchFinder *p)
{
- UInt32 subValue = MatchFinder_GetSubValue(p);
+ uint32_t subValue = MatchFinder_GetSubValue(p);
MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);
MatchFinder_ReduceOffsets(p, subValue);
}
@@ -319,22 +319,22 @@ static void MatchFinder_CheckLimits(CMatchFinder *p)
MatchFinder_SetLimits(p);
}
-static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
- UInt32 *distances, UInt32 maxLen)
+static uint32_t * Hc_GetMatchesSpec(uint32_t lenLimit, uint32_t curMatch, uint32_t pos, const uint8_t *cur, CLzRef *son,
+ uint32_t _cyclicBufferPos, uint32_t _cyclicBufferSize, uint32_t cutValue,
+ uint32_t *distances, uint32_t maxLen)
{
son[_cyclicBufferPos] = curMatch;
for (;;)
{
- UInt32 delta = pos - curMatch;
+ uint32_t delta = pos - curMatch;
if (cutValue-- == 0 || delta >= _cyclicBufferSize)
return distances;
{
- const Byte *pb = cur - delta;
+ const uint8_t *pb = cur - delta;
curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
if (pb[maxLen] == cur[maxLen] && *pb == *cur)
{
- UInt32 len = 0;
+ uint32_t len = 0;
while (++len != lenLimit)
if (pb[len] != cur[len])
break;
@@ -350,16 +350,16 @@ static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos,
}
}
-UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
- UInt32 *distances, UInt32 maxLen)
+uint32_t * GetMatchesSpec1(uint32_t lenLimit, uint32_t curMatch, uint32_t pos, const uint8_t *cur, CLzRef *son,
+ uint32_t _cyclicBufferPos, uint32_t _cyclicBufferSize, uint32_t cutValue,
+ uint32_t *distances, uint32_t maxLen)
{
CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
- UInt32 len0 = 0, len1 = 0;
+ uint32_t len0 = 0, len1 = 0;
for (;;)
{
- UInt32 delta = pos - curMatch;
+ uint32_t delta = pos - curMatch;
if (cutValue-- == 0 || delta >= _cyclicBufferSize)
{
*ptr0 = *ptr1 = kEmptyHashValue;
@@ -367,8 +367,8 @@ UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byt
}
{
CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
- const Byte *pb = cur - delta;
- UInt32 len = (len0 < len1 ? len0 : len1);
+ const uint8_t *pb = cur - delta;
+ uint32_t len = (len0 < len1 ? len0 : len1);
if (pb[len] == cur[len])
{
if (++len != lenLimit && pb[len] == cur[len])
@@ -405,15 +405,15 @@ UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byt
}
}
-static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)
+static void SkipMatchesSpec(uint32_t lenLimit, uint32_t curMatch, uint32_t pos, const uint8_t *cur, CLzRef *son,
+ uint32_t _cyclicBufferPos, uint32_t _cyclicBufferSize, uint32_t cutValue)
{
CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
- UInt32 len0 = 0, len1 = 0;
+ uint32_t len0 = 0, len1 = 0;
for (;;)
{
- UInt32 delta = pos - curMatch;
+ uint32_t delta = pos - curMatch;
if (cutValue-- == 0 || delta >= _cyclicBufferSize)
{
*ptr0 = *ptr1 = kEmptyHashValue;
@@ -421,8 +421,8 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const
}
{
CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
- const Byte *pb = cur - delta;
- UInt32 len = (len0 < len1 ? len0 : len1);
+ const uint8_t *pb = cur - delta;
+ uint32_t len = (len0 < len1 ? len0 : len1);
if (pb[len] == cur[len])
{
while (++len != lenLimit)
@@ -465,7 +465,7 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const
static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
#define GET_MATCHES_HEADER2(minLen, ret_op) \
- UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \
+ uint32_t lenLimit; uint32_t hashValue; const uint8_t *cur; uint32_t curMatch; \
lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
cur = p->buffer;
@@ -475,15 +475,15 @@ static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
#define GET_MATCHES_FOOTER(offset, maxLen) \
- offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \
+ offset = (uint32_t)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \
distances + offset, maxLen) - distances); MOVE_POS_RET;
#define SKIP_FOOTER \
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
-static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+static uint32_t Bt2_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances)
{
- UInt32 offset;
+ uint32_t offset;
GET_MATCHES_HEADER(2)
HASH2_CALC;
curMatch = p->hash[hashValue];
@@ -492,9 +492,9 @@ static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
GET_MATCHES_FOOTER(offset, 1)
}
-UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+uint32_t Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances)
{
- UInt32 offset;
+ uint32_t offset;
GET_MATCHES_HEADER(3)
HASH_ZIP_CALC;
curMatch = p->hash[hashValue];
@@ -503,9 +503,9 @@ UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
GET_MATCHES_FOOTER(offset, 2)
}
-static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+static uint32_t Bt3_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances)
{
- UInt32 hash2Value, delta2, maxLen, offset;
+ uint32_t hash2Value, delta2, maxLen, offset;
GET_MATCHES_HEADER(3)
HASH3_CALC;
@@ -536,9 +536,9 @@ static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
GET_MATCHES_FOOTER(offset, maxLen)
}
-static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+static uint32_t Bt4_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances)
{
- UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
+ uint32_t hash2Value, hash3Value, delta2, delta3, maxLen, offset;
GET_MATCHES_HEADER(4)
HASH4_CALC;
@@ -583,9 +583,9 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
GET_MATCHES_FOOTER(offset, maxLen)
}
-static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+static uint32_t Hc4_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances)
{
- UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
+ uint32_t hash2Value, hash3Value, delta2, delta3, maxLen, offset;
GET_MATCHES_HEADER(4)
HASH4_CALC;
@@ -627,24 +627,24 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
}
if (maxLen < 3)
maxLen = 3;
- offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
+ offset = (uint32_t)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
distances + offset, maxLen) - (distances));
MOVE_POS_RET
}
-UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+uint32_t Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances)
{
- UInt32 offset;
+ uint32_t offset;
GET_MATCHES_HEADER(3)
HASH_ZIP_CALC;
curMatch = p->hash[hashValue];
p->hash[hashValue] = p->pos;
- offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
+ offset = (uint32_t)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
distances, 2) - (distances));
MOVE_POS_RET
}
-static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+static void Bt2_MatchFinder_Skip(CMatchFinder *p, uint32_t num)
{
do
{
@@ -657,7 +657,7 @@ static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
while (--num != 0);
}
-void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, uint32_t num)
{
do
{
@@ -670,11 +670,11 @@ void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
while (--num != 0);
}
-static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+static void Bt3_MatchFinder_Skip(CMatchFinder *p, uint32_t num)
{
do
{
- UInt32 hash2Value;
+ uint32_t hash2Value;
SKIP_HEADER(3)
HASH3_CALC;
curMatch = p->hash[kFix3HashSize + hashValue];
@@ -685,11 +685,11 @@ static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
while (--num != 0);
}
-static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+static void Bt4_MatchFinder_Skip(CMatchFinder *p, uint32_t num)
{
do
{
- UInt32 hash2Value, hash3Value;
+ uint32_t hash2Value, hash3Value;
SKIP_HEADER(4)
HASH4_CALC;
curMatch = p->hash[kFix4HashSize + hashValue];
@@ -701,11 +701,11 @@ static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
while (--num != 0);
}
-static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+static void Hc4_MatchFinder_Skip(CMatchFinder *p, uint32_t num)
{
do
{
- UInt32 hash2Value, hash3Value;
+ uint32_t hash2Value, hash3Value;
SKIP_HEADER(4)
HASH4_CALC;
curMatch = p->hash[kFix4HashSize + hashValue];
@@ -718,7 +718,7 @@ static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
while (--num != 0);
}
-void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, uint32_t num)
{
do
{