diff options
author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2023-06-21 00:00:00 +0000 |
---|---|---|
committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2023-12-17 14:59:19 +0500 |
commit | 5b39dc76f1bc82f941d5c800ab9f34407a06b53a (patch) | |
tree | fe5e17420300b715021a76328444088d32047963 /C/Ppmd8.c | |
parent | 93be7d4abfd4233228f58ee1fbbcd76d91be66a4 (diff) | |
download | 7zip-5b39dc76f1bc82f941d5c800ab9f34407a06b53a.tar.gz 7zip-5b39dc76f1bc82f941d5c800ab9f34407a06b53a.tar.bz2 7zip-5b39dc76f1bc82f941d5c800ab9f34407a06b53a.zip |
23.0123.01
Diffstat (limited to 'C/Ppmd8.c')
-rw-r--r-- | C/Ppmd8.c | 248 |
1 files changed, 138 insertions, 110 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* Ppmd8.c -- PPMdI codec | 1 | /* Ppmd8.c -- PPMdI codec |
2 | 2021-04-13 : Igor Pavlov : Public domain | 2 | 2023-04-02 : Igor Pavlov : Public domain |
3 | This code is based on PPMd var.I (2002): Dmitry Shkarin : Public domain */ | 3 | This code is based on PPMd var.I (2002): Dmitry Shkarin : Public domain */ |
4 | 4 | ||
5 | #include "Precomp.h" | 5 | #include "Precomp.h" |
@@ -14,7 +14,7 @@ This code is based on PPMd var.I (2002): Dmitry Shkarin : Public domain */ | |||
14 | MY_ALIGN(16) | 14 | MY_ALIGN(16) |
15 | static const Byte PPMD8_kExpEscape[16] = { 25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 }; | 15 | static const Byte PPMD8_kExpEscape[16] = { 25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 }; |
16 | MY_ALIGN(16) | 16 | MY_ALIGN(16) |
17 | static const UInt16 kInitBinEsc[] = { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051}; | 17 | static const UInt16 PPMD8_kInitBinEsc[] = { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051}; |
18 | 18 | ||
19 | #define MAX_FREQ 124 | 19 | #define MAX_FREQ 124 |
20 | #define UNIT_SIZE 12 | 20 | #define UNIT_SIZE 12 |
@@ -33,7 +33,7 @@ static const UInt16 kInitBinEsc[] = { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x | |||
33 | #define ONE_STATE(ctx) Ppmd8Context_OneState(ctx) | 33 | #define ONE_STATE(ctx) Ppmd8Context_OneState(ctx) |
34 | #define SUFFIX(ctx) CTX((ctx)->Suffix) | 34 | #define SUFFIX(ctx) CTX((ctx)->Suffix) |
35 | 35 | ||
36 | typedef CPpmd8_Context * CTX_PTR; | 36 | typedef CPpmd8_Context * PPMD8_CTX_PTR; |
37 | 37 | ||
38 | struct CPpmd8_Node_; | 38 | struct CPpmd8_Node_; |
39 | 39 | ||
@@ -114,7 +114,7 @@ BoolInt Ppmd8_Alloc(CPpmd8 *p, UInt32 size, ISzAllocPtr alloc) | |||
114 | #define EMPTY_NODE 0xFFFFFFFF | 114 | #define EMPTY_NODE 0xFFFFFFFF |
115 | 115 | ||
116 | 116 | ||
117 | static void InsertNode(CPpmd8 *p, void *node, unsigned indx) | 117 | static void Ppmd8_InsertNode(CPpmd8 *p, void *node, unsigned indx) |
118 | { | 118 | { |
119 | ((CPpmd8_Node *)node)->Stamp = EMPTY_NODE; | 119 | ((CPpmd8_Node *)node)->Stamp = EMPTY_NODE; |
120 | ((CPpmd8_Node *)node)->Next = (CPpmd8_Node_Ref)p->FreeList[indx]; | 120 | ((CPpmd8_Node *)node)->Next = (CPpmd8_Node_Ref)p->FreeList[indx]; |
@@ -124,7 +124,7 @@ static void InsertNode(CPpmd8 *p, void *node, unsigned indx) | |||
124 | } | 124 | } |
125 | 125 | ||
126 | 126 | ||
127 | static void *RemoveNode(CPpmd8 *p, unsigned indx) | 127 | static void *Ppmd8_RemoveNode(CPpmd8 *p, unsigned indx) |
128 | { | 128 | { |
129 | CPpmd8_Node *node = NODE((CPpmd8_Node_Ref)p->FreeList[indx]); | 129 | CPpmd8_Node *node = NODE((CPpmd8_Node_Ref)p->FreeList[indx]); |
130 | p->FreeList[indx] = node->Next; | 130 | p->FreeList[indx] = node->Next; |
@@ -134,16 +134,16 @@ static void *RemoveNode(CPpmd8 *p, unsigned indx) | |||
134 | } | 134 | } |
135 | 135 | ||
136 | 136 | ||
137 | static void SplitBlock(CPpmd8 *p, void *ptr, unsigned oldIndx, unsigned newIndx) | 137 | static void Ppmd8_SplitBlock(CPpmd8 *p, void *ptr, unsigned oldIndx, unsigned newIndx) |
138 | { | 138 | { |
139 | unsigned i, nu = I2U(oldIndx) - I2U(newIndx); | 139 | unsigned i, nu = I2U(oldIndx) - I2U(newIndx); |
140 | ptr = (Byte *)ptr + U2B(I2U(newIndx)); | 140 | ptr = (Byte *)ptr + U2B(I2U(newIndx)); |
141 | if (I2U(i = U2I(nu)) != nu) | 141 | if (I2U(i = U2I(nu)) != nu) |
142 | { | 142 | { |
143 | unsigned k = I2U(--i); | 143 | unsigned k = I2U(--i); |
144 | InsertNode(p, ((Byte *)ptr) + U2B(k), nu - k - 1); | 144 | Ppmd8_InsertNode(p, ((Byte *)ptr) + U2B(k), nu - k - 1); |
145 | } | 145 | } |
146 | InsertNode(p, ptr, i); | 146 | Ppmd8_InsertNode(p, ptr, i); |
147 | } | 147 | } |
148 | 148 | ||
149 | 149 | ||
@@ -159,7 +159,7 @@ static void SplitBlock(CPpmd8 *p, void *ptr, unsigned oldIndx, unsigned newIndx) | |||
159 | 159 | ||
160 | 160 | ||
161 | 161 | ||
162 | static void GlueFreeBlocks(CPpmd8 *p) | 162 | static void Ppmd8_GlueFreeBlocks(CPpmd8 *p) |
163 | { | 163 | { |
164 | /* | 164 | /* |
165 | we use first UInt32 field of 12-bytes UNITs as record type stamp | 165 | we use first UInt32 field of 12-bytes UNITs as record type stamp |
@@ -239,27 +239,27 @@ static void GlueFreeBlocks(CPpmd8 *p) | |||
239 | if (nu == 0) | 239 | if (nu == 0) |
240 | continue; | 240 | continue; |
241 | for (; nu > 128; nu -= 128, node += 128) | 241 | for (; nu > 128; nu -= 128, node += 128) |
242 | InsertNode(p, node, PPMD_NUM_INDEXES - 1); | 242 | Ppmd8_InsertNode(p, node, PPMD_NUM_INDEXES - 1); |
243 | if (I2U(i = U2I(nu)) != nu) | 243 | if (I2U(i = U2I(nu)) != nu) |
244 | { | 244 | { |
245 | unsigned k = I2U(--i); | 245 | unsigned k = I2U(--i); |
246 | InsertNode(p, node + k, (unsigned)nu - k - 1); | 246 | Ppmd8_InsertNode(p, node + k, (unsigned)nu - k - 1); |
247 | } | 247 | } |
248 | InsertNode(p, node, i); | 248 | Ppmd8_InsertNode(p, node, i); |
249 | } | 249 | } |
250 | } | 250 | } |
251 | 251 | ||
252 | 252 | ||
253 | MY_NO_INLINE | 253 | Z7_NO_INLINE |
254 | static void *AllocUnitsRare(CPpmd8 *p, unsigned indx) | 254 | static void *Ppmd8_AllocUnitsRare(CPpmd8 *p, unsigned indx) |
255 | { | 255 | { |
256 | unsigned i; | 256 | unsigned i; |
257 | 257 | ||
258 | if (p->GlueCount == 0) | 258 | if (p->GlueCount == 0) |
259 | { | 259 | { |
260 | GlueFreeBlocks(p); | 260 | Ppmd8_GlueFreeBlocks(p); |
261 | if (p->FreeList[indx] != 0) | 261 | if (p->FreeList[indx] != 0) |
262 | return RemoveNode(p, indx); | 262 | return Ppmd8_RemoveNode(p, indx); |
263 | } | 263 | } |
264 | 264 | ||
265 | i = indx; | 265 | i = indx; |
@@ -277,17 +277,17 @@ static void *AllocUnitsRare(CPpmd8 *p, unsigned indx) | |||
277 | while (p->FreeList[i] == 0); | 277 | while (p->FreeList[i] == 0); |
278 | 278 | ||
279 | { | 279 | { |
280 | void *block = RemoveNode(p, i); | 280 | void *block = Ppmd8_RemoveNode(p, i); |
281 | SplitBlock(p, block, i, indx); | 281 | Ppmd8_SplitBlock(p, block, i, indx); |
282 | return block; | 282 | return block; |
283 | } | 283 | } |
284 | } | 284 | } |
285 | 285 | ||
286 | 286 | ||
287 | static void *AllocUnits(CPpmd8 *p, unsigned indx) | 287 | static void *Ppmd8_AllocUnits(CPpmd8 *p, unsigned indx) |
288 | { | 288 | { |
289 | if (p->FreeList[indx] != 0) | 289 | if (p->FreeList[indx] != 0) |
290 | return RemoveNode(p, indx); | 290 | return Ppmd8_RemoveNode(p, indx); |
291 | { | 291 | { |
292 | UInt32 numBytes = U2B(I2U(indx)); | 292 | UInt32 numBytes = U2B(I2U(indx)); |
293 | Byte *lo = p->LoUnit; | 293 | Byte *lo = p->LoUnit; |
@@ -297,11 +297,11 @@ static void *AllocUnits(CPpmd8 *p, unsigned indx) | |||
297 | return lo; | 297 | return lo; |
298 | } | 298 | } |
299 | } | 299 | } |
300 | return AllocUnitsRare(p, indx); | 300 | return Ppmd8_AllocUnitsRare(p, indx); |
301 | } | 301 | } |
302 | 302 | ||
303 | 303 | ||
304 | #define MyMem12Cpy(dest, src, num) \ | 304 | #define MEM_12_CPY(dest, src, num) \ |
305 | { UInt32 *d = (UInt32 *)dest; const UInt32 *z = (const UInt32 *)src; UInt32 n = num; \ | 305 | { UInt32 *d = (UInt32 *)dest; const UInt32 *z = (const UInt32 *)src; UInt32 n = num; \ |
306 | do { d[0] = z[0]; d[1] = z[1]; d[2] = z[2]; z += 3; d += 3; } while (--n); } | 306 | do { d[0] = z[0]; d[1] = z[1]; d[2] = z[2]; z += 3; d += 3; } while (--n); } |
307 | 307 | ||
@@ -315,26 +315,26 @@ static void *ShrinkUnits(CPpmd8 *p, void *oldPtr, unsigned oldNU, unsigned newNU | |||
315 | return oldPtr; | 315 | return oldPtr; |
316 | if (p->FreeList[i1] != 0) | 316 | if (p->FreeList[i1] != 0) |
317 | { | 317 | { |
318 | void *ptr = RemoveNode(p, i1); | 318 | void *ptr = Ppmd8_RemoveNode(p, i1); |
319 | MyMem12Cpy(ptr, oldPtr, newNU); | 319 | MEM_12_CPY(ptr, oldPtr, newNU) |
320 | InsertNode(p, oldPtr, i0); | 320 | Ppmd8_InsertNode(p, oldPtr, i0); |
321 | return ptr; | 321 | return ptr; |
322 | } | 322 | } |
323 | SplitBlock(p, oldPtr, i0, i1); | 323 | Ppmd8_SplitBlock(p, oldPtr, i0, i1); |
324 | return oldPtr; | 324 | return oldPtr; |
325 | } | 325 | } |
326 | 326 | ||
327 | 327 | ||
328 | static void FreeUnits(CPpmd8 *p, void *ptr, unsigned nu) | 328 | static void FreeUnits(CPpmd8 *p, void *ptr, unsigned nu) |
329 | { | 329 | { |
330 | InsertNode(p, ptr, U2I(nu)); | 330 | Ppmd8_InsertNode(p, ptr, U2I(nu)); |
331 | } | 331 | } |
332 | 332 | ||
333 | 333 | ||
334 | static void SpecialFreeUnit(CPpmd8 *p, void *ptr) | 334 | static void SpecialFreeUnit(CPpmd8 *p, void *ptr) |
335 | { | 335 | { |
336 | if ((Byte *)ptr != p->UnitsStart) | 336 | if ((Byte *)ptr != p->UnitsStart) |
337 | InsertNode(p, ptr, 0); | 337 | Ppmd8_InsertNode(p, ptr, 0); |
338 | else | 338 | else |
339 | { | 339 | { |
340 | #ifdef PPMD8_FREEZE_SUPPORT | 340 | #ifdef PPMD8_FREEZE_SUPPORT |
@@ -352,10 +352,10 @@ static void *MoveUnitsUp(CPpmd8 *p, void *oldPtr, unsigned nu) | |||
352 | void *ptr; | 352 | void *ptr; |
353 | if ((Byte *)oldPtr > p->UnitsStart + (1 << 14) || REF(oldPtr) > p->FreeList[indx]) | 353 | if ((Byte *)oldPtr > p->UnitsStart + (1 << 14) || REF(oldPtr) > p->FreeList[indx]) |
354 | return oldPtr; | 354 | return oldPtr; |
355 | ptr = RemoveNode(p, indx); | 355 | ptr = Ppmd8_RemoveNode(p, indx); |
356 | MyMem12Cpy(ptr, oldPtr, nu); | 356 | MEM_12_CPY(ptr, oldPtr, nu) |
357 | if ((Byte *)oldPtr != p->UnitsStart) | 357 | if ((Byte *)oldPtr != p->UnitsStart) |
358 | InsertNode(p, oldPtr, indx); | 358 | Ppmd8_InsertNode(p, oldPtr, indx); |
359 | else | 359 | else |
360 | p->UnitsStart += U2B(I2U(indx)); | 360 | p->UnitsStart += U2B(I2U(indx)); |
361 | return ptr; | 361 | return ptr; |
@@ -411,22 +411,22 @@ static void ExpandTextArea(CPpmd8 *p) | |||
411 | 411 | ||
412 | 412 | ||
413 | #define SUCCESSOR(p) Ppmd_GET_SUCCESSOR(p) | 413 | #define SUCCESSOR(p) Ppmd_GET_SUCCESSOR(p) |
414 | static void SetSuccessor(CPpmd_State *p, CPpmd_Void_Ref v) | 414 | static void Ppmd8State_SetSuccessor(CPpmd_State *p, CPpmd_Void_Ref v) |
415 | { | 415 | { |
416 | Ppmd_SET_SUCCESSOR(p, v); | 416 | Ppmd_SET_SUCCESSOR(p, v) |
417 | } | 417 | } |
418 | 418 | ||
419 | #define RESET_TEXT(offs) { p->Text = p->Base + p->AlignOffset + (offs); } | 419 | #define RESET_TEXT(offs) { p->Text = p->Base + p->AlignOffset + (offs); } |
420 | 420 | ||
421 | MY_NO_INLINE | 421 | Z7_NO_INLINE |
422 | static | 422 | static |
423 | void RestartModel(CPpmd8 *p) | 423 | void Ppmd8_RestartModel(CPpmd8 *p) |
424 | { | 424 | { |
425 | unsigned i, k, m; | 425 | unsigned i, k, m; |
426 | 426 | ||
427 | memset(p->FreeList, 0, sizeof(p->FreeList)); | 427 | memset(p->FreeList, 0, sizeof(p->FreeList)); |
428 | memset(p->Stamps, 0, sizeof(p->Stamps)); | 428 | memset(p->Stamps, 0, sizeof(p->Stamps)); |
429 | RESET_TEXT(0); | 429 | RESET_TEXT(0) |
430 | p->HiUnit = p->Text + p->Size; | 430 | p->HiUnit = p->Text + p->Size; |
431 | p->LoUnit = p->UnitsStart = p->HiUnit - p->Size / 8 / UNIT_SIZE * 7 * UNIT_SIZE; | 431 | p->LoUnit = p->UnitsStart = p->HiUnit - p->Size / 8 / UNIT_SIZE * 7 * UNIT_SIZE; |
432 | p->GlueCount = 0; | 432 | p->GlueCount = 0; |
@@ -436,8 +436,8 @@ void RestartModel(CPpmd8 *p) | |||
436 | p->PrevSuccess = 0; | 436 | p->PrevSuccess = 0; |
437 | 437 | ||
438 | { | 438 | { |
439 | CPpmd8_Context *mc = (CTX_PTR)(void *)(p->HiUnit -= UNIT_SIZE); /* AllocContext(p); */ | 439 | CPpmd8_Context *mc = (PPMD8_CTX_PTR)(void *)(p->HiUnit -= UNIT_SIZE); /* AllocContext(p); */ |
440 | CPpmd_State *s = (CPpmd_State *)p->LoUnit; /* AllocUnits(p, PPMD_NUM_INDEXES - 1); */ | 440 | CPpmd_State *s = (CPpmd_State *)p->LoUnit; /* Ppmd8_AllocUnits(p, PPMD_NUM_INDEXES - 1); */ |
441 | 441 | ||
442 | p->LoUnit += U2B(256 / 2); | 442 | p->LoUnit += U2B(256 / 2); |
443 | p->MaxContext = p->MinContext = mc; | 443 | p->MaxContext = p->MinContext = mc; |
@@ -452,7 +452,7 @@ void RestartModel(CPpmd8 *p) | |||
452 | { | 452 | { |
453 | s->Symbol = (Byte)i; | 453 | s->Symbol = (Byte)i; |
454 | s->Freq = 1; | 454 | s->Freq = 1; |
455 | SetSuccessor(s, 0); | 455 | Ppmd8State_SetSuccessor(s, 0); |
456 | } | 456 | } |
457 | } | 457 | } |
458 | 458 | ||
@@ -475,7 +475,7 @@ void RestartModel(CPpmd8 *p) | |||
475 | { | 475 | { |
476 | unsigned r; | 476 | unsigned r; |
477 | UInt16 *dest = p->BinSumm[m] + k; | 477 | UInt16 *dest = p->BinSumm[m] + k; |
478 | UInt16 val = (UInt16)(PPMD_BIN_SCALE - kInitBinEsc[k] / (i + 1)); | 478 | const UInt16 val = (UInt16)(PPMD_BIN_SCALE - PPMD8_kInitBinEsc[k] / (i + 1)); |
479 | for (r = 0; r < 64; r += 8) | 479 | for (r = 0; r < 64; r += 8) |
480 | dest[r] = val; | 480 | dest[r] = val; |
481 | } | 481 | } |
@@ -507,7 +507,7 @@ void Ppmd8_Init(CPpmd8 *p, unsigned maxOrder, unsigned restoreMethod) | |||
507 | { | 507 | { |
508 | p->MaxOrder = maxOrder; | 508 | p->MaxOrder = maxOrder; |
509 | p->RestoreMethod = restoreMethod; | 509 | p->RestoreMethod = restoreMethod; |
510 | RestartModel(p); | 510 | Ppmd8_RestartModel(p); |
511 | } | 511 | } |
512 | 512 | ||
513 | 513 | ||
@@ -531,7 +531,7 @@ Refresh() is called when we remove some symbols (successors) in context. | |||
531 | It increases Escape_Freq for sum of all removed symbols. | 531 | It increases Escape_Freq for sum of all removed symbols. |
532 | */ | 532 | */ |
533 | 533 | ||
534 | static void Refresh(CPpmd8 *p, CTX_PTR ctx, unsigned oldNU, unsigned scale) | 534 | static void Refresh(CPpmd8 *p, PPMD8_CTX_PTR ctx, unsigned oldNU, unsigned scale) |
535 | { | 535 | { |
536 | unsigned i = ctx->NumStats, escFreq, sumFreq, flags; | 536 | unsigned i = ctx->NumStats, escFreq, sumFreq, flags; |
537 | CPpmd_State *s = (CPpmd_State *)ShrinkUnits(p, STATS(ctx), oldNU, (i + 2) >> 1); | 537 | CPpmd_State *s = (CPpmd_State *)ShrinkUnits(p, STATS(ctx), oldNU, (i + 2) >> 1); |
@@ -581,7 +581,7 @@ static void Refresh(CPpmd8 *p, CTX_PTR ctx, unsigned oldNU, unsigned scale) | |||
581 | } | 581 | } |
582 | 582 | ||
583 | 583 | ||
584 | static void SwapStates(CPpmd_State *t1, CPpmd_State *t2) | 584 | static void SWAP_STATES(CPpmd_State *t1, CPpmd_State *t2) |
585 | { | 585 | { |
586 | CPpmd_State tmp = *t1; | 586 | CPpmd_State tmp = *t1; |
587 | *t1 = *t2; | 587 | *t1 = *t2; |
@@ -597,7 +597,7 @@ CutOff() reduces contexts: | |||
597 | if the (Union4.Stats) is close to (UnitsStart), it moves it up. | 597 | if the (Union4.Stats) is close to (UnitsStart), it moves it up. |
598 | */ | 598 | */ |
599 | 599 | ||
600 | static CPpmd_Void_Ref CutOff(CPpmd8 *p, CTX_PTR ctx, unsigned order) | 600 | static CPpmd_Void_Ref CutOff(CPpmd8 *p, PPMD8_CTX_PTR ctx, unsigned order) |
601 | { | 601 | { |
602 | int ns = ctx->NumStats; | 602 | int ns = ctx->NumStats; |
603 | unsigned nu; | 603 | unsigned nu; |
@@ -613,7 +613,7 @@ static CPpmd_Void_Ref CutOff(CPpmd8 *p, CTX_PTR ctx, unsigned order) | |||
613 | successor = CutOff(p, CTX(successor), order + 1); | 613 | successor = CutOff(p, CTX(successor), order + 1); |
614 | else | 614 | else |
615 | successor = 0; | 615 | successor = 0; |
616 | SetSuccessor(s, successor); | 616 | Ppmd8State_SetSuccessor(s, successor); |
617 | if (successor || order <= 9) /* O_BOUND */ | 617 | if (successor || order <= 9) /* O_BOUND */ |
618 | return REF(ctx); | 618 | return REF(ctx); |
619 | } | 619 | } |
@@ -630,11 +630,11 @@ static CPpmd_Void_Ref CutOff(CPpmd8 *p, CTX_PTR ctx, unsigned order) | |||
630 | if ((UInt32)((Byte *)stats - p->UnitsStart) <= (1 << 14) | 630 | if ((UInt32)((Byte *)stats - p->UnitsStart) <= (1 << 14) |
631 | && (CPpmd_Void_Ref)ctx->Union4.Stats <= p->FreeList[indx]) | 631 | && (CPpmd_Void_Ref)ctx->Union4.Stats <= p->FreeList[indx]) |
632 | { | 632 | { |
633 | void *ptr = RemoveNode(p, indx); | 633 | void *ptr = Ppmd8_RemoveNode(p, indx); |
634 | ctx->Union4.Stats = STATS_REF(ptr); | 634 | ctx->Union4.Stats = STATS_REF(ptr); |
635 | MyMem12Cpy(ptr, (const void *)stats, nu); | 635 | MEM_12_CPY(ptr, (const void *)stats, nu) |
636 | if ((Byte *)stats != p->UnitsStart) | 636 | if ((Byte *)stats != p->UnitsStart) |
637 | InsertNode(p, stats, indx); | 637 | Ppmd8_InsertNode(p, stats, indx); |
638 | else | 638 | else |
639 | p->UnitsStart += U2B(I2U(indx)); | 639 | p->UnitsStart += U2B(I2U(indx)); |
640 | stats = ptr; | 640 | stats = ptr; |
@@ -656,16 +656,16 @@ static CPpmd_Void_Ref CutOff(CPpmd8 *p, CTX_PTR ctx, unsigned order) | |||
656 | } | 656 | } |
657 | else | 657 | else |
658 | { | 658 | { |
659 | SwapStates(s, s2); | 659 | SWAP_STATES(s, s2); |
660 | SetSuccessor(s2, 0); | 660 | Ppmd8State_SetSuccessor(s2, 0); |
661 | } | 661 | } |
662 | } | 662 | } |
663 | else | 663 | else |
664 | { | 664 | { |
665 | if (order < p->MaxOrder) | 665 | if (order < p->MaxOrder) |
666 | SetSuccessor(s, CutOff(p, CTX(successor), order + 1)); | 666 | Ppmd8State_SetSuccessor(s, CutOff(p, CTX(successor), order + 1)); |
667 | else | 667 | else |
668 | SetSuccessor(s, 0); | 668 | Ppmd8State_SetSuccessor(s, 0); |
669 | } | 669 | } |
670 | } | 670 | } |
671 | while (--s >= stats); | 671 | while (--s >= stats); |
@@ -711,7 +711,7 @@ RemoveBinContexts() | |||
711 | removes Bin Context without Successor, if suffix of that context is also binary. | 711 | removes Bin Context without Successor, if suffix of that context is also binary. |
712 | */ | 712 | */ |
713 | 713 | ||
714 | static CPpmd_Void_Ref RemoveBinContexts(CPpmd8 *p, CTX_PTR ctx, unsigned order) | 714 | static CPpmd_Void_Ref RemoveBinContexts(CPpmd8 *p, PPMD8_CTX_PTR ctx, unsigned order) |
715 | { | 715 | { |
716 | if (!ctx->NumStats) | 716 | if (!ctx->NumStats) |
717 | { | 717 | { |
@@ -721,7 +721,7 @@ static CPpmd_Void_Ref RemoveBinContexts(CPpmd8 *p, CTX_PTR ctx, unsigned order) | |||
721 | successor = RemoveBinContexts(p, CTX(successor), order + 1); | 721 | successor = RemoveBinContexts(p, CTX(successor), order + 1); |
722 | else | 722 | else |
723 | successor = 0; | 723 | successor = 0; |
724 | SetSuccessor(s, successor); | 724 | Ppmd8State_SetSuccessor(s, successor); |
725 | /* Suffix context can be removed already, since different (high-order) | 725 | /* Suffix context can be removed already, since different (high-order) |
726 | Successors may refer to same context. So we check Flags == 0xFF (Stamp == EMPTY_NODE) */ | 726 | Successors may refer to same context. So we check Flags == 0xFF (Stamp == EMPTY_NODE) */ |
727 | if (!successor && (!SUFFIX(ctx)->NumStats || SUFFIX(ctx)->Flags == 0xFF)) | 727 | if (!successor && (!SUFFIX(ctx)->NumStats || SUFFIX(ctx)->Flags == 0xFF)) |
@@ -737,9 +737,9 @@ static CPpmd_Void_Ref RemoveBinContexts(CPpmd8 *p, CTX_PTR ctx, unsigned order) | |||
737 | { | 737 | { |
738 | CPpmd_Void_Ref successor = SUCCESSOR(s); | 738 | CPpmd_Void_Ref successor = SUCCESSOR(s); |
739 | if ((Byte *)Ppmd8_GetPtr(p, successor) >= p->UnitsStart && order < p->MaxOrder) | 739 | if ((Byte *)Ppmd8_GetPtr(p, successor) >= p->UnitsStart && order < p->MaxOrder) |
740 | SetSuccessor(s, RemoveBinContexts(p, CTX(successor), order + 1)); | 740 | Ppmd8State_SetSuccessor(s, RemoveBinContexts(p, CTX(successor), order + 1)); |
741 | else | 741 | else |
742 | SetSuccessor(s, 0); | 742 | Ppmd8State_SetSuccessor(s, 0); |
743 | } | 743 | } |
744 | while (--s >= STATS(ctx)); | 744 | while (--s >= STATS(ctx)); |
745 | } | 745 | } |
@@ -767,15 +767,15 @@ static UInt32 GetUsedMemory(const CPpmd8 *p) | |||
767 | #endif | 767 | #endif |
768 | 768 | ||
769 | 769 | ||
770 | static void RestoreModel(CPpmd8 *p, CTX_PTR ctxError | 770 | static void RestoreModel(CPpmd8 *p, PPMD8_CTX_PTR ctxError |
771 | #ifdef PPMD8_FREEZE_SUPPORT | 771 | #ifdef PPMD8_FREEZE_SUPPORT |
772 | , CTX_PTR fSuccessor | 772 | , PPMD8_CTX_PTR fSuccessor |
773 | #endif | 773 | #endif |
774 | ) | 774 | ) |
775 | { | 775 | { |
776 | CTX_PTR c; | 776 | PPMD8_CTX_PTR c; |
777 | CPpmd_State *s; | 777 | CPpmd_State *s; |
778 | RESET_TEXT(0); | 778 | RESET_TEXT(0) |
779 | 779 | ||
780 | // we go here in cases of error of allocation for context (c1) | 780 | // we go here in cases of error of allocation for context (c1) |
781 | // Order(MinContext) < Order(ctxError) <= Order(MaxContext) | 781 | // Order(MinContext) < Order(ctxError) <= Order(MaxContext) |
@@ -831,7 +831,7 @@ static void RestoreModel(CPpmd8 *p, CTX_PTR ctxError | |||
831 | else | 831 | else |
832 | #endif | 832 | #endif |
833 | if (p->RestoreMethod == PPMD8_RESTORE_METHOD_RESTART || GetUsedMemory(p) < (p->Size >> 1)) | 833 | if (p->RestoreMethod == PPMD8_RESTORE_METHOD_RESTART || GetUsedMemory(p) < (p->Size >> 1)) |
834 | RestartModel(p); | 834 | Ppmd8_RestartModel(p); |
835 | else | 835 | else |
836 | { | 836 | { |
837 | while (p->MaxContext->Suffix) | 837 | while (p->MaxContext->Suffix) |
@@ -850,8 +850,8 @@ static void RestoreModel(CPpmd8 *p, CTX_PTR ctxError | |||
850 | 850 | ||
851 | 851 | ||
852 | 852 | ||
853 | MY_NO_INLINE | 853 | Z7_NO_INLINE |
854 | static CTX_PTR CreateSuccessors(CPpmd8 *p, BoolInt skip, CPpmd_State *s1, CTX_PTR c) | 854 | static PPMD8_CTX_PTR Ppmd8_CreateSuccessors(CPpmd8 *p, BoolInt skip, CPpmd_State *s1, PPMD8_CTX_PTR c) |
855 | { | 855 | { |
856 | 856 | ||
857 | CPpmd_Byte_Ref upBranch = (CPpmd_Byte_Ref)SUCCESSOR(p->FoundState); | 857 | CPpmd_Byte_Ref upBranch = (CPpmd_Byte_Ref)SUCCESSOR(p->FoundState); |
@@ -927,15 +927,15 @@ static CTX_PTR CreateSuccessors(CPpmd8 *p, BoolInt skip, CPpmd_State *s1, CTX_PT | |||
927 | 927 | ||
928 | do | 928 | do |
929 | { | 929 | { |
930 | CTX_PTR c1; | 930 | PPMD8_CTX_PTR c1; |
931 | /* = AllocContext(p); */ | 931 | /* = AllocContext(p); */ |
932 | if (p->HiUnit != p->LoUnit) | 932 | if (p->HiUnit != p->LoUnit) |
933 | c1 = (CTX_PTR)(void *)(p->HiUnit -= UNIT_SIZE); | 933 | c1 = (PPMD8_CTX_PTR)(void *)(p->HiUnit -= UNIT_SIZE); |
934 | else if (p->FreeList[0] != 0) | 934 | else if (p->FreeList[0] != 0) |
935 | c1 = (CTX_PTR)RemoveNode(p, 0); | 935 | c1 = (PPMD8_CTX_PTR)Ppmd8_RemoveNode(p, 0); |
936 | else | 936 | else |
937 | { | 937 | { |
938 | c1 = (CTX_PTR)AllocUnitsRare(p, 0); | 938 | c1 = (PPMD8_CTX_PTR)Ppmd8_AllocUnitsRare(p, 0); |
939 | if (!c1) | 939 | if (!c1) |
940 | return NULL; | 940 | return NULL; |
941 | } | 941 | } |
@@ -943,9 +943,9 @@ static CTX_PTR CreateSuccessors(CPpmd8 *p, BoolInt skip, CPpmd_State *s1, CTX_PT | |||
943 | c1->NumStats = 0; | 943 | c1->NumStats = 0; |
944 | c1->Union2.State2.Symbol = newSym; | 944 | c1->Union2.State2.Symbol = newSym; |
945 | c1->Union2.State2.Freq = newFreq; | 945 | c1->Union2.State2.Freq = newFreq; |
946 | SetSuccessor(ONE_STATE(c1), upBranch); | 946 | Ppmd8State_SetSuccessor(ONE_STATE(c1), upBranch); |
947 | c1->Suffix = REF(c); | 947 | c1->Suffix = REF(c); |
948 | SetSuccessor(ps[--numPs], REF(c1)); | 948 | Ppmd8State_SetSuccessor(ps[--numPs], REF(c1)); |
949 | c = c1; | 949 | c = c1; |
950 | } | 950 | } |
951 | while (numPs != 0); | 951 | while (numPs != 0); |
@@ -954,10 +954,10 @@ static CTX_PTR CreateSuccessors(CPpmd8 *p, BoolInt skip, CPpmd_State *s1, CTX_PT | |||
954 | } | 954 | } |
955 | 955 | ||
956 | 956 | ||
957 | static CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, CTX_PTR c) | 957 | static PPMD8_CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, PPMD8_CTX_PTR c) |
958 | { | 958 | { |
959 | CPpmd_State *s = NULL; | 959 | CPpmd_State *s = NULL; |
960 | CTX_PTR c1 = c; | 960 | PPMD8_CTX_PTR c1 = c; |
961 | CPpmd_Void_Ref upBranch = REF(p->Text); | 961 | CPpmd_Void_Ref upBranch = REF(p->Text); |
962 | 962 | ||
963 | #ifdef PPMD8_FREEZE_SUPPORT | 963 | #ifdef PPMD8_FREEZE_SUPPORT |
@@ -967,7 +967,7 @@ static CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, CTX_PTR c) | |||
967 | ps[numPs++] = p->FoundState; | 967 | ps[numPs++] = p->FoundState; |
968 | #endif | 968 | #endif |
969 | 969 | ||
970 | SetSuccessor(p->FoundState, upBranch); | 970 | Ppmd8State_SetSuccessor(p->FoundState, upBranch); |
971 | p->OrderFall++; | 971 | p->OrderFall++; |
972 | 972 | ||
973 | for (;;) | 973 | for (;;) |
@@ -985,8 +985,8 @@ static CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, CTX_PTR c) | |||
985 | #ifdef PPMD8_FREEZE_SUPPORT | 985 | #ifdef PPMD8_FREEZE_SUPPORT |
986 | if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE) | 986 | if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE) |
987 | { | 987 | { |
988 | do { SetSuccessor(ps[--numPs], REF(c)); } while (numPs); | 988 | do { Ppmd8State_SetSuccessor(ps[--numPs], REF(c)); } while (numPs); |
989 | RESET_TEXT(1); | 989 | RESET_TEXT(1) |
990 | p->OrderFall = 1; | 990 | p->OrderFall = 1; |
991 | } | 991 | } |
992 | #endif | 992 | #endif |
@@ -1014,7 +1014,7 @@ static CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, CTX_PTR c) | |||
1014 | #ifdef PPMD8_FREEZE_SUPPORT | 1014 | #ifdef PPMD8_FREEZE_SUPPORT |
1015 | ps[numPs++] = s; | 1015 | ps[numPs++] = s; |
1016 | #endif | 1016 | #endif |
1017 | SetSuccessor(s, upBranch); | 1017 | Ppmd8State_SetSuccessor(s, upBranch); |
1018 | p->OrderFall++; | 1018 | p->OrderFall++; |
1019 | } | 1019 | } |
1020 | 1020 | ||
@@ -1022,8 +1022,8 @@ static CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, CTX_PTR c) | |||
1022 | if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE) | 1022 | if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE) |
1023 | { | 1023 | { |
1024 | c = CTX(SUCCESSOR(s)); | 1024 | c = CTX(SUCCESSOR(s)); |
1025 | do { SetSuccessor(ps[--numPs], REF(c)); } while (numPs); | 1025 | do { Ppmd8State_SetSuccessor(ps[--numPs], REF(c)); } while (numPs); |
1026 | RESET_TEXT(1); | 1026 | RESET_TEXT(1) |
1027 | p->OrderFall = 1; | 1027 | p->OrderFall = 1; |
1028 | return c; | 1028 | return c; |
1029 | } | 1029 | } |
@@ -1031,15 +1031,15 @@ static CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, CTX_PTR c) | |||
1031 | #endif | 1031 | #endif |
1032 | if (SUCCESSOR(s) <= upBranch) | 1032 | if (SUCCESSOR(s) <= upBranch) |
1033 | { | 1033 | { |
1034 | CTX_PTR successor; | 1034 | PPMD8_CTX_PTR successor; |
1035 | CPpmd_State *s2 = p->FoundState; | 1035 | CPpmd_State *s2 = p->FoundState; |
1036 | p->FoundState = s; | 1036 | p->FoundState = s; |
1037 | 1037 | ||
1038 | successor = CreateSuccessors(p, False, NULL, c); | 1038 | successor = Ppmd8_CreateSuccessors(p, False, NULL, c); |
1039 | if (!successor) | 1039 | if (!successor) |
1040 | SetSuccessor(s, 0); | 1040 | Ppmd8State_SetSuccessor(s, 0); |
1041 | else | 1041 | else |
1042 | SetSuccessor(s, REF(successor)); | 1042 | Ppmd8State_SetSuccessor(s, REF(successor)); |
1043 | p->FoundState = s2; | 1043 | p->FoundState = s2; |
1044 | } | 1044 | } |
1045 | 1045 | ||
@@ -1047,7 +1047,7 @@ static CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, CTX_PTR c) | |||
1047 | CPpmd_Void_Ref successor = SUCCESSOR(s); | 1047 | CPpmd_Void_Ref successor = SUCCESSOR(s); |
1048 | if (p->OrderFall == 1 && c1 == p->MaxContext) | 1048 | if (p->OrderFall == 1 && c1 == p->MaxContext) |
1049 | { | 1049 | { |
1050 | SetSuccessor(p->FoundState, successor); | 1050 | Ppmd8State_SetSuccessor(p->FoundState, successor); |
1051 | p->Text--; | 1051 | p->Text--; |
1052 | } | 1052 | } |
1053 | if (successor == 0) | 1053 | if (successor == 0) |
@@ -1059,11 +1059,11 @@ static CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, CTX_PTR c) | |||
1059 | 1059 | ||
1060 | 1060 | ||
1061 | void Ppmd8_UpdateModel(CPpmd8 *p); | 1061 | void Ppmd8_UpdateModel(CPpmd8 *p); |
1062 | MY_NO_INLINE | 1062 | Z7_NO_INLINE |
1063 | void Ppmd8_UpdateModel(CPpmd8 *p) | 1063 | void Ppmd8_UpdateModel(CPpmd8 *p) |
1064 | { | 1064 | { |
1065 | CPpmd_Void_Ref maxSuccessor, minSuccessor = SUCCESSOR(p->FoundState); | 1065 | CPpmd_Void_Ref maxSuccessor, minSuccessor = SUCCESSOR(p->FoundState); |
1066 | CTX_PTR c; | 1066 | PPMD8_CTX_PTR c; |
1067 | unsigned s0, ns, fFreq = p->FoundState->Freq; | 1067 | unsigned s0, ns, fFreq = p->FoundState->Freq; |
1068 | Byte flag, fSymbol = p->FoundState->Symbol; | 1068 | Byte flag, fSymbol = p->FoundState->Symbol; |
1069 | { | 1069 | { |
@@ -1096,7 +1096,7 @@ void Ppmd8_UpdateModel(CPpmd8 *p) | |||
1096 | 1096 | ||
1097 | if (s[0].Freq >= s[-1].Freq) | 1097 | if (s[0].Freq >= s[-1].Freq) |
1098 | { | 1098 | { |
1099 | SwapStates(&s[0], &s[-1]); | 1099 | SWAP_STATES(&s[0], &s[-1]); |
1100 | s--; | 1100 | s--; |
1101 | } | 1101 | } |
1102 | } | 1102 | } |
@@ -1112,14 +1112,14 @@ void Ppmd8_UpdateModel(CPpmd8 *p) | |||
1112 | c = p->MaxContext; | 1112 | c = p->MaxContext; |
1113 | if (p->OrderFall == 0 && minSuccessor) | 1113 | if (p->OrderFall == 0 && minSuccessor) |
1114 | { | 1114 | { |
1115 | CTX_PTR cs = CreateSuccessors(p, True, s, p->MinContext); | 1115 | PPMD8_CTX_PTR cs = Ppmd8_CreateSuccessors(p, True, s, p->MinContext); |
1116 | if (!cs) | 1116 | if (!cs) |
1117 | { | 1117 | { |
1118 | SetSuccessor(p->FoundState, 0); | 1118 | Ppmd8State_SetSuccessor(p->FoundState, 0); |
1119 | RESTORE_MODEL(c, CTX(minSuccessor)); | 1119 | RESTORE_MODEL(c, CTX(minSuccessor)); |
1120 | return; | 1120 | return; |
1121 | } | 1121 | } |
1122 | SetSuccessor(p->FoundState, REF(cs)); | 1122 | Ppmd8State_SetSuccessor(p->FoundState, REF(cs)); |
1123 | p->MinContext = p->MaxContext = cs; | 1123 | p->MinContext = p->MaxContext = cs; |
1124 | return; | 1124 | return; |
1125 | } | 1125 | } |
@@ -1141,7 +1141,7 @@ void Ppmd8_UpdateModel(CPpmd8 *p) | |||
1141 | 1141 | ||
1142 | if (!minSuccessor) | 1142 | if (!minSuccessor) |
1143 | { | 1143 | { |
1144 | CTX_PTR cs = ReduceOrder(p, s, p->MinContext); | 1144 | PPMD8_CTX_PTR cs = ReduceOrder(p, s, p->MinContext); |
1145 | if (!cs) | 1145 | if (!cs) |
1146 | { | 1146 | { |
1147 | RESTORE_MODEL(c, NULL); | 1147 | RESTORE_MODEL(c, NULL); |
@@ -1151,7 +1151,7 @@ void Ppmd8_UpdateModel(CPpmd8 *p) | |||
1151 | } | 1151 | } |
1152 | else if ((Byte *)Ppmd8_GetPtr(p, minSuccessor) < p->UnitsStart) | 1152 | else if ((Byte *)Ppmd8_GetPtr(p, minSuccessor) < p->UnitsStart) |
1153 | { | 1153 | { |
1154 | CTX_PTR cs = CreateSuccessors(p, False, s, p->MinContext); | 1154 | PPMD8_CTX_PTR cs = Ppmd8_CreateSuccessors(p, False, s, p->MinContext); |
1155 | if (!cs) | 1155 | if (!cs) |
1156 | { | 1156 | { |
1157 | RESTORE_MODEL(c, NULL); | 1157 | RESTORE_MODEL(c, NULL); |
@@ -1169,7 +1169,7 @@ void Ppmd8_UpdateModel(CPpmd8 *p) | |||
1169 | else if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE) | 1169 | else if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE) |
1170 | { | 1170 | { |
1171 | maxSuccessor = minSuccessor; | 1171 | maxSuccessor = minSuccessor; |
1172 | RESET_TEXT(0); | 1172 | RESET_TEXT(0) |
1173 | p->OrderFall = 0; | 1173 | p->OrderFall = 0; |
1174 | } | 1174 | } |
1175 | #endif | 1175 | #endif |
@@ -1219,7 +1219,7 @@ void Ppmd8_UpdateModel(CPpmd8 *p) | |||
1219 | unsigned i = U2I(oldNU); | 1219 | unsigned i = U2I(oldNU); |
1220 | if (i != U2I((size_t)oldNU + 1)) | 1220 | if (i != U2I((size_t)oldNU + 1)) |
1221 | { | 1221 | { |
1222 | void *ptr = AllocUnits(p, i + 1); | 1222 | void *ptr = Ppmd8_AllocUnits(p, i + 1); |
1223 | void *oldPtr; | 1223 | void *oldPtr; |
1224 | if (!ptr) | 1224 | if (!ptr) |
1225 | { | 1225 | { |
@@ -1227,8 +1227,8 @@ void Ppmd8_UpdateModel(CPpmd8 *p) | |||
1227 | return; | 1227 | return; |
1228 | } | 1228 | } |
1229 | oldPtr = STATS(c); | 1229 | oldPtr = STATS(c); |
1230 | MyMem12Cpy(ptr, oldPtr, oldNU); | 1230 | MEM_12_CPY(ptr, oldPtr, oldNU) |
1231 | InsertNode(p, oldPtr, i); | 1231 | Ppmd8_InsertNode(p, oldPtr, i); |
1232 | c->Union4.Stats = STATS_REF(ptr); | 1232 | c->Union4.Stats = STATS_REF(ptr); |
1233 | } | 1233 | } |
1234 | } | 1234 | } |
@@ -1243,7 +1243,7 @@ void Ppmd8_UpdateModel(CPpmd8 *p) | |||
1243 | else | 1243 | else |
1244 | { | 1244 | { |
1245 | 1245 | ||
1246 | CPpmd_State *s = (CPpmd_State*)AllocUnits(p, 0); | 1246 | CPpmd_State *s = (CPpmd_State*)Ppmd8_AllocUnits(p, 0); |
1247 | if (!s) | 1247 | if (!s) |
1248 | { | 1248 | { |
1249 | RESTORE_MODEL(c, CTX(minSuccessor)); | 1249 | RESTORE_MODEL(c, CTX(minSuccessor)); |
@@ -1255,7 +1255,7 @@ void Ppmd8_UpdateModel(CPpmd8 *p) | |||
1255 | s->Symbol = c->Union2.State2.Symbol; | 1255 | s->Symbol = c->Union2.State2.Symbol; |
1256 | s->Successor_0 = c->Union4.State4.Successor_0; | 1256 | s->Successor_0 = c->Union4.State4.Successor_0; |
1257 | s->Successor_1 = c->Union4.State4.Successor_1; | 1257 | s->Successor_1 = c->Union4.State4.Successor_1; |
1258 | // SetSuccessor(s, c->Union4.Stats); // call it only for debug purposes to check the order of | 1258 | // Ppmd8State_SetSuccessor(s, c->Union4.Stats); // call it only for debug purposes to check the order of |
1259 | // (Successor_0 and Successor_1) in LE/BE. | 1259 | // (Successor_0 and Successor_1) in LE/BE. |
1260 | c->Union4.Stats = REF(s); | 1260 | c->Union4.Stats = REF(s); |
1261 | if (freq < MAX_FREQ / 4 - 1) | 1261 | if (freq < MAX_FREQ / 4 - 1) |
@@ -1275,7 +1275,7 @@ void Ppmd8_UpdateModel(CPpmd8 *p) | |||
1275 | UInt32 sf = (UInt32)s0 + sum; | 1275 | UInt32 sf = (UInt32)s0 + sum; |
1276 | s->Symbol = fSymbol; | 1276 | s->Symbol = fSymbol; |
1277 | c->NumStats = (Byte)(ns1 + 1); | 1277 | c->NumStats = (Byte)(ns1 + 1); |
1278 | SetSuccessor(s, maxSuccessor); | 1278 | Ppmd8State_SetSuccessor(s, maxSuccessor); |
1279 | c->Flags |= flag; | 1279 | c->Flags |= flag; |
1280 | if (cf < 6 * sf) | 1280 | if (cf < 6 * sf) |
1281 | { | 1281 | { |
@@ -1299,8 +1299,8 @@ void Ppmd8_UpdateModel(CPpmd8 *p) | |||
1299 | 1299 | ||
1300 | 1300 | ||
1301 | 1301 | ||
1302 | MY_NO_INLINE | 1302 | Z7_NO_INLINE |
1303 | static void Rescale(CPpmd8 *p) | 1303 | static void Ppmd8_Rescale(CPpmd8 *p) |
1304 | { | 1304 | { |
1305 | unsigned i, adder, sumFreq, escFreq; | 1305 | unsigned i, adder, sumFreq, escFreq; |
1306 | CPpmd_State *stats = STATS(p->MinContext); | 1306 | CPpmd_State *stats = STATS(p->MinContext); |
@@ -1389,7 +1389,7 @@ static void Rescale(CPpmd8 *p) | |||
1389 | *s = *stats; | 1389 | *s = *stats; |
1390 | s->Freq = (Byte)freq; | 1390 | s->Freq = (Byte)freq; |
1391 | p->FoundState = s; | 1391 | p->FoundState = s; |
1392 | InsertNode(p, stats, U2I(n0)); | 1392 | Ppmd8_InsertNode(p, stats, U2I(n0)); |
1393 | return; | 1393 | return; |
1394 | } | 1394 | } |
1395 | 1395 | ||
@@ -1452,9 +1452,9 @@ CPpmd_See *Ppmd8_MakeEscFreq(CPpmd8 *p, unsigned numMasked1, UInt32 *escFreq) | |||
1452 | } | 1452 | } |
1453 | 1453 | ||
1454 | 1454 | ||
1455 | static void NextContext(CPpmd8 *p) | 1455 | static void Ppmd8_NextContext(CPpmd8 *p) |
1456 | { | 1456 | { |
1457 | CTX_PTR c = CTX(SUCCESSOR(p->FoundState)); | 1457 | PPMD8_CTX_PTR c = CTX(SUCCESSOR(p->FoundState)); |
1458 | if (p->OrderFall == 0 && (const Byte *)c >= p->UnitsStart) | 1458 | if (p->OrderFall == 0 && (const Byte *)c >= p->UnitsStart) |
1459 | p->MaxContext = p->MinContext = c; | 1459 | p->MaxContext = p->MinContext = c; |
1460 | else | 1460 | else |
@@ -1471,12 +1471,12 @@ void Ppmd8_Update1(CPpmd8 *p) | |||
1471 | s->Freq = (Byte)freq; | 1471 | s->Freq = (Byte)freq; |
1472 | if (freq > s[-1].Freq) | 1472 | if (freq > s[-1].Freq) |
1473 | { | 1473 | { |
1474 | SwapStates(s, &s[-1]); | 1474 | SWAP_STATES(s, &s[-1]); |
1475 | p->FoundState = --s; | 1475 | p->FoundState = --s; |
1476 | if (freq > MAX_FREQ) | 1476 | if (freq > MAX_FREQ) |
1477 | Rescale(p); | 1477 | Ppmd8_Rescale(p); |
1478 | } | 1478 | } |
1479 | NextContext(p); | 1479 | Ppmd8_NextContext(p); |
1480 | } | 1480 | } |
1481 | 1481 | ||
1482 | 1482 | ||
@@ -1492,8 +1492,8 @@ void Ppmd8_Update1_0(CPpmd8 *p) | |||
1492 | freq += 4; | 1492 | freq += 4; |
1493 | s->Freq = (Byte)freq; | 1493 | s->Freq = (Byte)freq; |
1494 | if (freq > MAX_FREQ) | 1494 | if (freq > MAX_FREQ) |
1495 | Rescale(p); | 1495 | Ppmd8_Rescale(p); |
1496 | NextContext(p); | 1496 | Ppmd8_NextContext(p); |
1497 | } | 1497 | } |
1498 | 1498 | ||
1499 | 1499 | ||
@@ -1504,7 +1504,7 @@ void Ppmd8_UpdateBin(CPpmd8 *p) | |||
1504 | p->FoundState->Freq = (Byte)(freq + (freq < 196)); // Ppmd8 (196) | 1504 | p->FoundState->Freq = (Byte)(freq + (freq < 196)); // Ppmd8 (196) |
1505 | p->PrevSuccess = 1; | 1505 | p->PrevSuccess = 1; |
1506 | p->RunLength++; | 1506 | p->RunLength++; |
1507 | NextContext(p); | 1507 | Ppmd8_NextContext(p); |
1508 | } | 1508 | } |
1509 | */ | 1509 | */ |
1510 | 1510 | ||
@@ -1517,7 +1517,7 @@ void Ppmd8_Update2(CPpmd8 *p) | |||
1517 | p->MinContext->Union2.SummFreq = (UInt16)(p->MinContext->Union2.SummFreq + 4); | 1517 | p->MinContext->Union2.SummFreq = (UInt16)(p->MinContext->Union2.SummFreq + 4); |
1518 | s->Freq = (Byte)freq; | 1518 | s->Freq = (Byte)freq; |
1519 | if (freq > MAX_FREQ) | 1519 | if (freq > MAX_FREQ) |
1520 | Rescale(p); | 1520 | Ppmd8_Rescale(p); |
1521 | Ppmd8_UpdateModel(p); | 1521 | Ppmd8_UpdateModel(p); |
1522 | } | 1522 | } |
1523 | 1523 | ||
@@ -1526,7 +1526,7 @@ void Ppmd8_Update2(CPpmd8 *p) | |||
1526 | GlueCount, and Glue method | 1526 | GlueCount, and Glue method |
1527 | BinSum | 1527 | BinSum |
1528 | See / EscFreq | 1528 | See / EscFreq |
1529 | CreateSuccessors updates more suffix contexts | 1529 | Ppmd8_CreateSuccessors updates more suffix contexts |
1530 | Ppmd8_UpdateModel consts. | 1530 | Ppmd8_UpdateModel consts. |
1531 | PrevSuccess Update | 1531 | PrevSuccess Update |
1532 | 1532 | ||
@@ -1535,3 +1535,31 @@ Flags: | |||
1535 | (1 << 3) - there is symbol in Stats with (sym >= 0x40) in | 1535 | (1 << 3) - there is symbol in Stats with (sym >= 0x40) in |
1536 | (1 << 4) - main symbol of context is (sym >= 0x40) | 1536 | (1 << 4) - main symbol of context is (sym >= 0x40) |
1537 | */ | 1537 | */ |
1538 | |||
1539 | #undef RESET_TEXT | ||
1540 | #undef FLAG_RESCALED | ||
1541 | #undef FLAG_PREV_HIGH | ||
1542 | #undef HiBits_Prepare | ||
1543 | #undef HiBits_Convert_3 | ||
1544 | #undef HiBits_Convert_4 | ||
1545 | #undef PPMD8_HiBitsFlag_3 | ||
1546 | #undef PPMD8_HiBitsFlag_4 | ||
1547 | #undef RESTORE_MODEL | ||
1548 | |||
1549 | #undef MAX_FREQ | ||
1550 | #undef UNIT_SIZE | ||
1551 | #undef U2B | ||
1552 | #undef U2I | ||
1553 | #undef I2U | ||
1554 | |||
1555 | #undef REF | ||
1556 | #undef STATS_REF | ||
1557 | #undef CTX | ||
1558 | #undef STATS | ||
1559 | #undef ONE_STATE | ||
1560 | #undef SUFFIX | ||
1561 | #undef NODE | ||
1562 | #undef EMPTY_NODE | ||
1563 | #undef MEM_12_CPY | ||
1564 | #undef SUCCESSOR | ||
1565 | #undef SWAP_STATES | ||