Lines Matching refs:p

18 #define U2I(nu) (p->Units2Indx[(nu) - 1])
19 #define I2U(indx) (p->Indx2Units[indx])
24 #define REF(ptr) ((UInt32)((Byte *)(ptr) - (p)->Base))
29 #define CTX(ref) ((CPpmd7_Context *)Ppmd7_GetContext(p, ref))
30 #define STATS(ctx) Ppmd7_GetStats(p, ctx)
57 #define NODE(offs) ((CPpmd7_Node *)(p->Base + (offs)))
60 void Ppmd7_Construct(CPpmd7 *p) in Ppmd7_Construct() argument
64 p->Base = 0; in Ppmd7_Construct()
69 do { p->Units2Indx[k++] = (Byte)i; } while(--step); in Ppmd7_Construct()
70 p->Indx2Units[i] = (Byte)k; in Ppmd7_Construct()
73 p->NS2BSIndx[0] = (0 << 1); in Ppmd7_Construct()
74 p->NS2BSIndx[1] = (1 << 1); in Ppmd7_Construct()
75 memset(p->NS2BSIndx + 2, (2 << 1), 9); in Ppmd7_Construct()
76 memset(p->NS2BSIndx + 11, (3 << 1), 256 - 11); in Ppmd7_Construct()
79 p->NS2Indx[i] = (Byte)i; in Ppmd7_Construct()
82 p->NS2Indx[i] = (Byte)m; in Ppmd7_Construct()
87 memset(p->HB2Flag, 0, 0x40); in Ppmd7_Construct()
88 memset(p->HB2Flag + 0x40, 8, 0x100 - 0x40); in Ppmd7_Construct()
91 void Ppmd7_Free(CPpmd7 *p, ISzAlloc *alloc) in Ppmd7_Free() argument
93 alloc->Free(alloc, p->Base); in Ppmd7_Free()
94 p->Size = 0; in Ppmd7_Free()
95 p->Base = 0; in Ppmd7_Free()
98 Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc) in Ppmd7_Alloc() argument
100 if (p->Base == 0 || p->Size != size) in Ppmd7_Alloc()
102 Ppmd7_Free(p, alloc); in Ppmd7_Alloc()
103 p->AlignOffset = in Ppmd7_Alloc()
109 if ((p->Base = (Byte *)alloc->Alloc(alloc, p->AlignOffset + size in Ppmd7_Alloc()
115 p->Size = size; in Ppmd7_Alloc()
120 static void InsertNode(CPpmd7 *p, void *node, unsigned indx) in InsertNode() argument
122 *((CPpmd_Void_Ref *)node) = p->FreeList[indx]; in InsertNode()
123 p->FreeList[indx] = REF(node); in InsertNode()
126 static void *RemoveNode(CPpmd7 *p, unsigned indx) in RemoveNode() argument
128 CPpmd_Void_Ref *node = (CPpmd_Void_Ref *)Ppmd7_GetPtr(p, p->FreeList[indx]); in RemoveNode()
129 p->FreeList[indx] = *node; in RemoveNode()
133 static void SplitBlock(CPpmd7 *p, void *ptr, unsigned oldIndx, unsigned newIndx) in SplitBlock() argument
140 InsertNode(p, ((Byte *)ptr) + U2B(k), nu - k - 1); in SplitBlock()
142 InsertNode(p, ptr, i); in SplitBlock()
145 static void GlueFreeBlocks(CPpmd7 *p) in GlueFreeBlocks() argument
151 CPpmd7_Node_Ref head = p->AlignOffset + p->Size; in GlueFreeBlocks()
157 p->GlueCount = 255; in GlueFreeBlocks()
163 CPpmd7_Node_Ref next = (CPpmd7_Node_Ref)p->FreeList[i]; in GlueFreeBlocks()
164 p->FreeList[i] = 0; in GlueFreeBlocks()
178 if (p->LoUnit != p->HiUnit) in GlueFreeBlocks()
179 ((CPpmd7_Node *)p->LoUnit)->Stamp = 1; in GlueFreeBlocks()
206 InsertNode(p, node, PPMD_NUM_INDEXES - 1); in GlueFreeBlocks()
210 InsertNode(p, node + k, nu - k - 1); in GlueFreeBlocks()
212 InsertNode(p, node, i); in GlueFreeBlocks()
217 static void *AllocUnitsRare(CPpmd7 *p, unsigned indx) in AllocUnitsRare() argument
221 if (p->GlueCount == 0) in AllocUnitsRare()
223 GlueFreeBlocks(p); in AllocUnitsRare()
224 if (p->FreeList[indx] != 0) in AllocUnitsRare()
225 return RemoveNode(p, indx); in AllocUnitsRare()
233 p->GlueCount--; in AllocUnitsRare()
234 return ((UInt32)(p->UnitsStart - p->Text) > numBytes) ? (p->UnitsStart -= numBytes) : (NULL); in AllocUnitsRare()
237 while (p->FreeList[i] == 0); in AllocUnitsRare()
238 retVal = RemoveNode(p, i); in AllocUnitsRare()
239 SplitBlock(p, retVal, i, indx); in AllocUnitsRare()
243 static void *AllocUnits(CPpmd7 *p, unsigned indx) in AllocUnits() argument
246 if (p->FreeList[indx] != 0) in AllocUnits()
247 return RemoveNode(p, indx); in AllocUnits()
249 if (numBytes <= (UInt32)(p->HiUnit - p->LoUnit)) in AllocUnits()
251 void *retVal = p->LoUnit; in AllocUnits()
252 p->LoUnit += numBytes; in AllocUnits()
255 return AllocUnitsRare(p, indx); in AllocUnits()
262 static void *ShrinkUnits(CPpmd7 *p, void *oldPtr, unsigned oldNU, unsigned newNU) in ShrinkUnits() argument
268 if (p->FreeList[i1] != 0) in ShrinkUnits()
270 void *ptr = RemoveNode(p, i1); in ShrinkUnits()
272 InsertNode(p, oldPtr, i0); in ShrinkUnits()
275 SplitBlock(p, oldPtr, i0, i1); in ShrinkUnits()
279 #define SUCCESSOR(p) ((CPpmd_Void_Ref)((p)->SuccessorLow | ((UInt32)(p)->SuccessorHigh << 16))) argument
281 static void SetSuccessor(CPpmd_State *p, CPpmd_Void_Ref v) in SetSuccessor() argument
283 (p)->SuccessorLow = (UInt16)((UInt32)(v) & 0xFFFF); in SetSuccessor()
284 (p)->SuccessorHigh = (UInt16)(((UInt32)(v) >> 16) & 0xFFFF); in SetSuccessor()
287 static void RestartModel(CPpmd7 *p) in RestartModel() argument
291 memset(p->FreeList, 0, sizeof(p->FreeList)); in RestartModel()
292 p->Text = p->Base + p->AlignOffset; in RestartModel()
293 p->HiUnit = p->Text + p->Size; in RestartModel()
294 p->LoUnit = p->UnitsStart = p->HiUnit - p->Size / 8 / UNIT_SIZE * 7 * UNIT_SIZE; in RestartModel()
295 p->GlueCount = 0; in RestartModel()
297 p->OrderFall = p->MaxOrder; in RestartModel()
298 p->RunLength = p->InitRL = -(Int32)((p->MaxOrder < 12) ? p->MaxOrder : 12) - 1; in RestartModel()
299 p->PrevSuccess = 0; in RestartModel()
301 p->MinContext = p->MaxContext = (CTX_PTR)(p->HiUnit -= UNIT_SIZE); /* AllocContext(p); */ in RestartModel()
302 p->MinContext->Suffix = 0; in RestartModel()
303 p->MinContext->NumStats = 256; in RestartModel()
304 p->MinContext->SummFreq = 256 + 1; in RestartModel()
305 p->FoundState = (CPpmd_State *)p->LoUnit; /* AllocUnits(p, PPMD_NUM_INDEXES - 1); */ in RestartModel()
306 p->LoUnit += U2B(256 / 2); in RestartModel()
307 p->MinContext->Stats = REF(p->FoundState); in RestartModel()
310 CPpmd_State *s = &p->FoundState[i]; in RestartModel()
319 UInt16 *dest = p->BinSumm[i] + k; in RestartModel()
328 CPpmd_See *s = &p->See[i][k]; in RestartModel()
334 void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder) in Ppmd7_Init() argument
336 p->MaxOrder = maxOrder; in Ppmd7_Init()
337 RestartModel(p); in Ppmd7_Init()
338 p->DummySee.Shift = PPMD_PERIOD_BITS; in Ppmd7_Init()
339 p->DummySee.Summ = 0; /* unused */ in Ppmd7_Init()
340 p->DummySee.Count = 64; /* unused */ in Ppmd7_Init()
343 static CTX_PTR CreateSuccessors(CPpmd7 *p, Bool skip) in CreateSuccessors() argument
346 CTX_PTR c = p->MinContext; in CreateSuccessors()
347 CPpmd_Byte_Ref upBranch = (CPpmd_Byte_Ref)SUCCESSOR(p->FoundState); in CreateSuccessors()
352 ps[numPs++] = p->FoundState; in CreateSuccessors()
361 for (s = STATS(c); s->Symbol != p->FoundState->Symbol; s++); in CreateSuccessors()
376 upState.Symbol = *(const Byte *)Ppmd7_GetPtr(p, upBranch); in CreateSuccessors()
395 if (p->HiUnit != p->LoUnit) in CreateSuccessors()
396 c1 = (CTX_PTR)(p->HiUnit -= UNIT_SIZE); in CreateSuccessors()
397 else if (p->FreeList[0] != 0) in CreateSuccessors()
398 c1 = (CTX_PTR)RemoveNode(p, 0); in CreateSuccessors()
401 c1 = (CTX_PTR)AllocUnitsRare(p, 0); in CreateSuccessors()
423 static void UpdateModel(CPpmd7 *p) in UpdateModel() argument
425 CPpmd_Void_Ref successor, fSuccessor = SUCCESSOR(p->FoundState); in UpdateModel()
429 if (p->FoundState->Freq < MAX_FREQ / 4 && p->MinContext->Suffix != 0) in UpdateModel()
431 c = SUFFIX(p->MinContext); in UpdateModel()
442 if (s->Symbol != p->FoundState->Symbol) in UpdateModel()
444 do { s++; } while (s->Symbol != p->FoundState->Symbol); in UpdateModel()
459 if (p->OrderFall == 0) in UpdateModel()
461 p->MinContext = p->MaxContext = CreateSuccessors(p, True); in UpdateModel()
462 if (p->MinContext == 0) in UpdateModel()
464 RestartModel(p); in UpdateModel()
467 SetSuccessor(p->FoundState, REF(p->MinContext)); in UpdateModel()
471 *p->Text++ = p->FoundState->Symbol; in UpdateModel()
472 successor = REF(p->Text); in UpdateModel()
473 if (p->Text >= p->UnitsStart) in UpdateModel()
475 RestartModel(p); in UpdateModel()
483 CTX_PTR cs = CreateSuccessors(p, False); in UpdateModel()
486 RestartModel(p); in UpdateModel()
491 if (--p->OrderFall == 0) in UpdateModel()
494 p->Text -= (p->MaxContext != p->MinContext); in UpdateModel()
499 SetSuccessor(p->FoundState, successor); in UpdateModel()
500 fSuccessor = REF(p->MinContext); in UpdateModel()
503 s0 = p->MinContext->SummFreq - (ns = p->MinContext->NumStats) - (p->FoundState->Freq - 1); in UpdateModel()
505 for (c = p->MaxContext; c != p->MinContext; c = SUFFIX(c)) in UpdateModel()
518 void *ptr = AllocUnits(p, i + 1); in UpdateModel()
522 RestartModel(p); in UpdateModel()
527 InsertNode(p, oldPtr, i); in UpdateModel()
535 CPpmd_State *s = (CPpmd_State*)AllocUnits(p, 0); in UpdateModel()
538 RestartModel(p); in UpdateModel()
547 c->SummFreq = (UInt16)(s->Freq + p->InitEsc + (ns > 3)); in UpdateModel()
549 cf = 2 * (UInt32)p->FoundState->Freq * (c->SummFreq + 6); in UpdateModel()
564 s->Symbol = p->FoundState->Symbol; in UpdateModel()
569 p->MaxContext = p->MinContext = CTX(fSuccessor); in UpdateModel()
572 static void Rescale(CPpmd7 *p) in Rescale() argument
575 CPpmd_State *stats = STATS(p->MinContext); in Rescale()
576 CPpmd_State *s = p->FoundState; in Rescale()
583 escFreq = p->MinContext->SummFreq - s->Freq; in Rescale()
585 adder = (p->OrderFall != 0); in Rescale()
589 i = p->MinContext->NumStats - 1; in Rescale()
609 unsigned numStats = p->MinContext->NumStats; in Rescale()
613 p->MinContext->NumStats = (UInt16)(p->MinContext->NumStats - i); in Rescale()
614 if (p->MinContext->NumStats == 1) in Rescale()
623 InsertNode(p, stats, U2I(((numStats + 1) >> 1))); in Rescale()
624 *(p->FoundState = ONE_STATE(p->MinContext)) = tmp; in Rescale()
628 n1 = (p->MinContext->NumStats + 1) >> 1; in Rescale()
630 p->MinContext->Stats = STATS_REF(ShrinkUnits(p, stats, n0, n1)); in Rescale()
632 p->MinContext->SummFreq = (UInt16)(sumFreq + escFreq - (escFreq >> 1)); in Rescale()
633 p->FoundState = STATS(p->MinContext); in Rescale()
636 CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *escFreq) in Ppmd7_MakeEscFreq() argument
639 unsigned nonMasked = p->MinContext->NumStats - numMasked; in Ppmd7_MakeEscFreq()
640 if (p->MinContext->NumStats != 256) in Ppmd7_MakeEscFreq()
642 see = p->See[p->NS2Indx[nonMasked - 1]] + in Ppmd7_MakeEscFreq()
643 (nonMasked < (unsigned)SUFFIX(p->MinContext)->NumStats - p->MinContext->NumStats) + in Ppmd7_MakeEscFreq()
644 2 * (p->MinContext->SummFreq < 11 * p->MinContext->NumStats) + in Ppmd7_MakeEscFreq()
646 p->HiBitsFlag; in Ppmd7_MakeEscFreq()
655 see = &p->DummySee; in Ppmd7_MakeEscFreq()
661 static void NextContext(CPpmd7 *p) in NextContext() argument
663 CTX_PTR c = CTX(SUCCESSOR(p->FoundState)); in NextContext()
664 if (p->OrderFall == 0 && (Byte *)c > p->Text) in NextContext()
665 p->MinContext = p->MaxContext = c; in NextContext()
667 UpdateModel(p); in NextContext()
670 void Ppmd7_Update1(CPpmd7 *p) in Ppmd7_Update1() argument
672 CPpmd_State *s = p->FoundState; in Ppmd7_Update1()
674 p->MinContext->SummFreq += 4; in Ppmd7_Update1()
678 p->FoundState = --s; in Ppmd7_Update1()
680 Rescale(p); in Ppmd7_Update1()
682 NextContext(p); in Ppmd7_Update1()
685 void Ppmd7_Update1_0(CPpmd7 *p) in Ppmd7_Update1_0() argument
687 p->PrevSuccess = (2 * p->FoundState->Freq > p->MinContext->SummFreq); in Ppmd7_Update1_0()
688 p->RunLength += p->PrevSuccess; in Ppmd7_Update1_0()
689 p->MinContext->SummFreq += 4; in Ppmd7_Update1_0()
690 if ((p->FoundState->Freq += 4) > MAX_FREQ) in Ppmd7_Update1_0()
691 Rescale(p); in Ppmd7_Update1_0()
692 NextContext(p); in Ppmd7_Update1_0()
695 void Ppmd7_UpdateBin(CPpmd7 *p) in Ppmd7_UpdateBin() argument
697 p->FoundState->Freq = (Byte)(p->FoundState->Freq + (p->FoundState->Freq < 128 ? 1: 0)); in Ppmd7_UpdateBin()
698 p->PrevSuccess = 1; in Ppmd7_UpdateBin()
699 p->RunLength++; in Ppmd7_UpdateBin()
700 NextContext(p); in Ppmd7_UpdateBin()
703 void Ppmd7_Update2(CPpmd7 *p) in Ppmd7_Update2() argument
705 p->MinContext->SummFreq += 4; in Ppmd7_Update2()
706 if ((p->FoundState->Freq += 4) > MAX_FREQ) in Ppmd7_Update2()
707 Rescale(p); in Ppmd7_Update2()
708 p->RunLength = p->InitRL; in Ppmd7_Update2()
709 UpdateModel(p); in Ppmd7_Update2()