aboutsummaryrefslogtreecommitdiff
path: root/C/Ppmd8.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/Ppmd8.c
parent5b39dc76f1bc82f941d5c800ab9f34407a06b53a (diff)
download7zip-fc662341e6f85da78ada0e443f6116b978f79f22.tar.gz
7zip-fc662341e6f85da78ada0e443f6116b978f79f22.tar.bz2
7zip-fc662341e6f85da78ada0e443f6116b978f79f22.zip
24.0524.05
Diffstat (limited to 'C/Ppmd8.c')
-rw-r--r--C/Ppmd8.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/C/Ppmd8.c b/C/Ppmd8.c
index 28abf27..c6bdd86 100644
--- a/C/Ppmd8.c
+++ b/C/Ppmd8.c
@@ -1,5 +1,5 @@
1/* Ppmd8.c -- PPMdI codec 1/* Ppmd8.c -- PPMdI codec
22023-04-02 : Igor Pavlov : Public domain 22023-09-07 : Igor Pavlov : Public domain
3This code is based on PPMd var.I (2002): Dmitry Shkarin : Public domain */ 3This code is based on PPMd var.I (2002): Dmitry Shkarin : Public domain */
4 4
5#include "Precomp.h" 5#include "Precomp.h"
@@ -302,8 +302,17 @@ static void *Ppmd8_AllocUnits(CPpmd8 *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
@@ -1215,8 +1224,8 @@ void Ppmd8_UpdateModel(CPpmd8 *p)
1215 if ((ns1 & 1) != 0) 1224 if ((ns1 & 1) != 0)
1216 { 1225 {
1217 /* Expand for one UNIT */ 1226 /* Expand for one UNIT */
1218 unsigned oldNU = (ns1 + 1) >> 1; 1227 const unsigned oldNU = (ns1 + 1) >> 1;
1219 unsigned i = U2I(oldNU); 1228 const unsigned i = U2I(oldNU);
1220 if (i != U2I((size_t)oldNU + 1)) 1229 if (i != U2I((size_t)oldNU + 1))
1221 { 1230 {
1222 void *ptr = Ppmd8_AllocUnits(p, i + 1); 1231 void *ptr = Ppmd8_AllocUnits(p, i + 1);
@@ -1235,7 +1244,7 @@ void Ppmd8_UpdateModel(CPpmd8 *p)
1235 sum = c->Union2.SummFreq; 1244 sum = c->Union2.SummFreq;
1236 /* max increase of Escape_Freq is 1 here. 1245 /* max increase of Escape_Freq is 1 here.
1237 an average increase is 1/3 per symbol */ 1246 an average increase is 1/3 per symbol */
1238 sum += (3 * ns1 + 1 < ns); 1247 sum += (UInt32)(unsigned)(3 * ns1 + 1 < ns);
1239 /* original PPMdH uses 16-bit variable for (sum) here. 1248 /* original PPMdH uses 16-bit variable for (sum) here.
1240 But (sum < ???). Do we need to truncate (sum) to 16-bit */ 1249 But (sum < ???). Do we need to truncate (sum) to 16-bit */
1241 // sum = (UInt16)sum; 1250 // sum = (UInt16)sum;
@@ -1265,7 +1274,7 @@ void Ppmd8_UpdateModel(CPpmd8 *p)
1265 1274
1266 s->Freq = (Byte)freq; 1275 s->Freq = (Byte)freq;
1267 1276
1268 sum = freq + p->InitEsc + (ns > 2); // Ppmd8 (> 2) 1277 sum = (UInt32)(freq + p->InitEsc + (ns > 2)); // Ppmd8 (> 2)
1269 } 1278 }
1270 } 1279 }
1271 1280
@@ -1437,10 +1446,10 @@ CPpmd_See *Ppmd8_MakeEscFreq(CPpmd8 *p, unsigned numMasked1, UInt32 *escFreq)
1437 1446
1438 { 1447 {
1439 // if (see->Summ) field is larger than 16-bit, we need only low 16 bits of Summ 1448 // if (see->Summ) field is larger than 16-bit, we need only low 16 bits of Summ
1440 unsigned summ = (UInt16)see->Summ; // & 0xFFFF 1449 const unsigned summ = (UInt16)see->Summ; // & 0xFFFF
1441 unsigned r = (summ >> see->Shift); 1450 const unsigned r = (summ >> see->Shift);
1442 see->Summ = (UInt16)(summ - r); 1451 see->Summ = (UInt16)(summ - r);
1443 *escFreq = r + (r == 0); 1452 *escFreq = (UInt32)(r + (r == 0));
1444 } 1453 }
1445 } 1454 }
1446 else 1455 else
@@ -1485,9 +1494,9 @@ void Ppmd8_Update1_0(CPpmd8 *p)
1485 CPpmd_State *s = p->FoundState; 1494 CPpmd_State *s = p->FoundState;
1486 CPpmd8_Context *mc = p->MinContext; 1495 CPpmd8_Context *mc = p->MinContext;
1487 unsigned freq = s->Freq; 1496 unsigned freq = s->Freq;
1488 unsigned summFreq = mc->Union2.SummFreq; 1497 const unsigned summFreq = mc->Union2.SummFreq;
1489 p->PrevSuccess = (2 * freq >= summFreq); // Ppmd8 (>=) 1498 p->PrevSuccess = (2 * freq >= summFreq); // Ppmd8 (>=)
1490 p->RunLength += (int)p->PrevSuccess; 1499 p->RunLength += (Int32)p->PrevSuccess;
1491 mc->Union2.SummFreq = (UInt16)(summFreq + 4); 1500 mc->Union2.SummFreq = (UInt16)(summFreq + 4);
1492 freq += 4; 1501 freq += 4;
1493 s->Freq = (Byte)freq; 1502 s->Freq = (Byte)freq;