aboutsummaryrefslogtreecommitdiff
path: root/C/Ppmd7.c
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2024-05-14 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2024-05-15 23:55:04 +0500
commitfc662341e6f85da78ada0e443f6116b978f79f22 (patch)
tree1be1cc402a7a9cbc18d4eeea6b141354c2d559e3 /C/Ppmd7.c
parent5b39dc76f1bc82f941d5c800ab9f34407a06b53a (diff)
download7zip-fc662341e6f85da78ada0e443f6116b978f79f22.tar.gz
7zip-fc662341e6f85da78ada0e443f6116b978f79f22.tar.bz2
7zip-fc662341e6f85da78ada0e443f6116b978f79f22.zip
24.0524.05
Diffstat (limited to 'C/Ppmd7.c')
-rw-r--r--C/Ppmd7.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/C/Ppmd7.c b/C/Ppmd7.c
index 6e1307e..efcc5d8 100644
--- a/C/Ppmd7.c
+++ b/C/Ppmd7.c
@@ -1,5 +1,5 @@
1/* Ppmd7.c -- PPMdH codec 1/* Ppmd7.c -- PPMdH codec
22023-04-02 : Igor Pavlov : Public domain 22023-09-07 : Igor Pavlov : Public domain
3This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ 3This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
4 4
5#include "Precomp.h" 5#include "Precomp.h"
@@ -302,8 +302,17 @@ static void *Ppmd7_AllocUnits(CPpmd7 *p, unsigned indx)
302 302
303 303
304#define MEM_12_CPY(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); \
306 do { d[0] = z[0]; d[1] = z[1]; d[2] = z[2]; z += 3; d += 3; } while (--n); } 306 const UInt32 *z = (const UInt32 *)(src); \
307 unsigned n = (num); \
308 do { \
309 d[0] = z[0]; \
310 d[1] = z[1]; \
311 d[2] = z[2]; \
312 z += 3; \
313 d += 3; \
314 } while (--n); \
315 }
307 316
308 317
309/* 318/*
@@ -711,8 +720,8 @@ void Ppmd7_UpdateModel(CPpmd7 *p)
711 if ((ns1 & 1) == 0) 720 if ((ns1 & 1) == 0)
712 { 721 {
713 /* Expand for one UNIT */ 722 /* Expand for one UNIT */
714 unsigned oldNU = ns1 >> 1; 723 const unsigned oldNU = ns1 >> 1;
715 unsigned i = U2I(oldNU); 724 const unsigned i = U2I(oldNU);
716 if (i != U2I((size_t)oldNU + 1)) 725 if (i != U2I((size_t)oldNU + 1))
717 { 726 {
718 void *ptr = Ppmd7_AllocUnits(p, i + 1); 727 void *ptr = Ppmd7_AllocUnits(p, i + 1);
@@ -731,7 +740,7 @@ void Ppmd7_UpdateModel(CPpmd7 *p)
731 sum = c->Union2.SummFreq; 740 sum = c->Union2.SummFreq;
732 /* max increase of Escape_Freq is 3 here. 741 /* max increase of Escape_Freq is 3 here.
733 total increase of Union2.SummFreq for all symbols is less than 256 here */ 742 total increase of Union2.SummFreq for all symbols is less than 256 here */
734 sum += (UInt32)(2 * ns1 < ns) + 2 * ((unsigned)(4 * ns1 <= ns) & (sum <= 8 * ns1)); 743 sum += (UInt32)(unsigned)((2 * ns1 < ns) + 2 * ((unsigned)(4 * ns1 <= ns) & (sum <= 8 * ns1)));
735 /* original PPMdH uses 16-bit variable for (sum) here. 744 /* original PPMdH uses 16-bit variable for (sum) here.
736 But (sum < 0x9000). So we don't truncate (sum) to 16-bit */ 745 But (sum < 0x9000). So we don't truncate (sum) to 16-bit */
737 // sum = (UInt16)sum; 746 // sum = (UInt16)sum;
@@ -761,7 +770,7 @@ void Ppmd7_UpdateModel(CPpmd7 *p)
761 // (max(s->freq) == 120), when we convert from 1-symbol into 2-symbol context 770 // (max(s->freq) == 120), when we convert from 1-symbol into 2-symbol context
762 s->Freq = (Byte)freq; 771 s->Freq = (Byte)freq;
763 // max(InitEsc = PPMD7_kExpEscape[*]) is 25. So the max(escapeFreq) is 26 here 772 // max(InitEsc = PPMD7_kExpEscape[*]) is 25. So the max(escapeFreq) is 26 here
764 sum = freq + p->InitEsc + (ns > 3); 773 sum = (UInt32)(freq + p->InitEsc + (ns > 3));
765 } 774 }
766 } 775 }
767 776
@@ -933,10 +942,10 @@ CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *escFreq)
933 p->HiBitsFlag; 942 p->HiBitsFlag;
934 { 943 {
935 // if (see->Summ) field is larger than 16-bit, we need only low 16 bits of Summ 944 // if (see->Summ) field is larger than 16-bit, we need only low 16 bits of Summ
936 unsigned summ = (UInt16)see->Summ; // & 0xFFFF 945 const unsigned summ = (UInt16)see->Summ; // & 0xFFFF
937 unsigned r = (summ >> see->Shift); 946 const unsigned r = (summ >> see->Shift);
938 see->Summ = (UInt16)(summ - r); 947 see->Summ = (UInt16)(summ - r);
939 *escFreq = r + (r == 0); 948 *escFreq = (UInt32)(r + (r == 0));
940 } 949 }
941 } 950 }
942 else 951 else
@@ -981,9 +990,9 @@ void Ppmd7_Update1_0(CPpmd7 *p)
981 CPpmd_State *s = p->FoundState; 990 CPpmd_State *s = p->FoundState;
982 CPpmd7_Context *mc = p->MinContext; 991 CPpmd7_Context *mc = p->MinContext;
983 unsigned freq = s->Freq; 992 unsigned freq = s->Freq;
984 unsigned summFreq = mc->Union2.SummFreq; 993 const unsigned summFreq = mc->Union2.SummFreq;
985 p->PrevSuccess = (2 * freq > summFreq); 994 p->PrevSuccess = (2 * freq > summFreq);
986 p->RunLength += (int)p->PrevSuccess; 995 p->RunLength += (Int32)p->PrevSuccess;
987 mc->Union2.SummFreq = (UInt16)(summFreq + 4); 996 mc->Union2.SummFreq = (UInt16)(summFreq + 4);
988 freq += 4; 997 freq += 4;
989 s->Freq = (Byte)freq; 998 s->Freq = (Byte)freq;