• Home
  • Raw
  • Download

Lines Matching +full:- +full:p

1 /* Bcj2Enc.c -- BCJ2 Encoder (Converter for x86 code)
2 2018-07-04 : Igor Pavlov : Public domain */
27 void Bcj2Enc_Init(CBcj2Enc *p) in Bcj2Enc_Init() argument
31 p->state = BCJ2_ENC_STATE_OK; in Bcj2Enc_Init()
32 p->finishMode = BCJ2_ENC_FINISH_MODE_CONTINUE; in Bcj2Enc_Init()
34 p->prevByte = 0; in Bcj2Enc_Init()
36 p->cache = 0; in Bcj2Enc_Init()
37 p->range = 0xFFFFFFFF; in Bcj2Enc_Init()
38 p->low = 0; in Bcj2Enc_Init()
39 p->cacheSize = 1; in Bcj2Enc_Init()
41 p->ip = 0; in Bcj2Enc_Init()
43 p->fileIp = 0; in Bcj2Enc_Init()
44 p->fileSize = 0; in Bcj2Enc_Init()
45 p->relatLimit = BCJ2_RELAT_LIMIT; in Bcj2Enc_Init()
47 p->tempPos = 0; in Bcj2Enc_Init()
49 p->flushPos = 0; in Bcj2Enc_Init()
51 for (i = 0; i < sizeof(p->probs) / sizeof(p->probs[0]); i++) in Bcj2Enc_Init()
52 p->probs[i] = kBitModelTotal >> 1; in Bcj2Enc_Init()
55 static BoolInt MY_FAST_CALL RangeEnc_ShiftLow(CBcj2Enc *p) in RangeEnc_ShiftLow() argument
57 if ((UInt32)p->low < (UInt32)0xFF000000 || (UInt32)(p->low >> 32) != 0) in RangeEnc_ShiftLow()
59 Byte *buf = p->bufs[BCJ2_STREAM_RC]; in RangeEnc_ShiftLow()
62 if (buf == p->lims[BCJ2_STREAM_RC]) in RangeEnc_ShiftLow()
64 p->state = BCJ2_STREAM_RC; in RangeEnc_ShiftLow()
65 p->bufs[BCJ2_STREAM_RC] = buf; in RangeEnc_ShiftLow()
68 *buf++ = (Byte)(p->cache + (Byte)(p->low >> 32)); in RangeEnc_ShiftLow()
69 p->cache = 0xFF; in RangeEnc_ShiftLow()
71 while (--p->cacheSize); in RangeEnc_ShiftLow()
72 p->bufs[BCJ2_STREAM_RC] = buf; in RangeEnc_ShiftLow()
73 p->cache = (Byte)((UInt32)p->low >> 24); in RangeEnc_ShiftLow()
75 p->cacheSize++; in RangeEnc_ShiftLow()
76 p->low = (UInt32)p->low << 8; in RangeEnc_ShiftLow()
80 static void Bcj2Enc_Encode_2(CBcj2Enc *p) in Bcj2Enc_Encode_2() argument
82 if (BCJ2_IS_32BIT_STREAM(p->state)) in Bcj2Enc_Encode_2()
84 Byte *cur = p->bufs[p->state]; in Bcj2Enc_Encode_2()
85 if (cur == p->lims[p->state]) in Bcj2Enc_Encode_2()
87 SetBe32(cur, p->tempTarget); in Bcj2Enc_Encode_2()
88 p->bufs[p->state] = cur + 4; in Bcj2Enc_Encode_2()
91 p->state = BCJ2_ENC_STATE_ORIG; in Bcj2Enc_Encode_2()
95 if (p->range < kTopValue) in Bcj2Enc_Encode_2()
97 if (RangeEnc_ShiftLow(p)) in Bcj2Enc_Encode_2()
99 p->range <<= 8; in Bcj2Enc_Encode_2()
104 const Byte *src = p->src; in Bcj2Enc_Encode_2()
107 SizeT num = p->srcLim - src; in Bcj2Enc_Encode_2()
109 if (p->finishMode == BCJ2_ENC_FINISH_MODE_CONTINUE) in Bcj2Enc_Encode_2()
113 num -= 4; in Bcj2Enc_Encode_2()
118 dest = p->bufs[BCJ2_STREAM_MAIN]; in Bcj2Enc_Encode_2()
119 if (num > (SizeT)(p->lims[BCJ2_STREAM_MAIN] - dest)) in Bcj2Enc_Encode_2()
121 num = p->lims[BCJ2_STREAM_MAIN] - dest; in Bcj2Enc_Encode_2()
124 p->state = BCJ2_STREAM_MAIN; in Bcj2Enc_Encode_2()
131 if (p->prevByte == 0x0F && (src[0] & 0xF0) == 0x80) in Bcj2Enc_Encode_2()
155 num = src - p->src; in Bcj2Enc_Encode_2()
159 p->prevByte = src[-1]; in Bcj2Enc_Encode_2()
160 p->bufs[BCJ2_STREAM_MAIN] = dest; in Bcj2Enc_Encode_2()
161 p->src = src; in Bcj2Enc_Encode_2()
162 p->ip += (UInt32)num; in Bcj2Enc_Encode_2()
167 Byte context = (Byte)(num == 0 ? p->prevByte : src[-1]); in Bcj2Enc_Encode_2()
170 p->bufs[BCJ2_STREAM_MAIN] = dest + 1; in Bcj2Enc_Encode_2()
171 p->ip += (UInt32)num + 1; in Bcj2Enc_Encode_2()
176 if ((SizeT)(p->srcLim - src) >= 4) in Bcj2Enc_Encode_2()
179 if ((p->fileSize == 0 || (UInt32)(p->ip + 4 + relatVal - p->fileIp) < p->fileSize) in Bcj2Enc_Encode_2()
180 && ((relatVal + p->relatLimit) >> 1) < p->relatLimit) in Bcj2Enc_Encode_2()
187 Byte b = src[-1]; in Bcj2Enc_Encode_2()
188 … CProb *prob = p->probs + (unsigned)(b == 0xE8 ? 2 + (unsigned)context : (b == 0xE9 ? 1 : 0)); in Bcj2Enc_Encode_2()
191 bound = (p->range >> kNumModelBits) * ttt; in Bcj2Enc_Encode_2()
195 p->range = bound; in Bcj2Enc_Encode_2()
196 *prob = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); in Bcj2Enc_Encode_2()
197 p->src = src; in Bcj2Enc_Encode_2()
198 p->prevByte = b; in Bcj2Enc_Encode_2()
202 p->low += bound; in Bcj2Enc_Encode_2()
203 p->range -= bound; in Bcj2Enc_Encode_2()
204 *prob = (CProb)(ttt - (ttt >> kNumMoveBits)); in Bcj2Enc_Encode_2()
209 p->ip += 4; in Bcj2Enc_Encode_2()
210 absVal = p->ip + relatVal; in Bcj2Enc_Encode_2()
211 p->prevByte = src[3]; in Bcj2Enc_Encode_2()
213 p->src = src; in Bcj2Enc_Encode_2()
216 Byte *cur = p->bufs[cj]; in Bcj2Enc_Encode_2()
217 if (cur == p->lims[cj]) in Bcj2Enc_Encode_2()
219 p->state = cj; in Bcj2Enc_Encode_2()
220 p->tempTarget = absVal; in Bcj2Enc_Encode_2()
224 p->bufs[cj] = cur + 4; in Bcj2Enc_Encode_2()
233 if (p->finishMode != BCJ2_ENC_FINISH_MODE_END_STREAM) in Bcj2Enc_Encode_2()
236 for (; p->flushPos < 5; p->flushPos++) in Bcj2Enc_Encode_2()
237 if (RangeEnc_ShiftLow(p)) in Bcj2Enc_Encode_2()
239 p->state = BCJ2_ENC_STATE_OK; in Bcj2Enc_Encode_2()
243 void Bcj2Enc_Encode(CBcj2Enc *p) in Bcj2Enc_Encode() argument
246 PRF(printf("---- ip = %8d tempPos = %8d src = %8d\n", p->ip, p->tempPos, p->srcLim - p->src)); in Bcj2Enc_Encode()
248 if (p->tempPos != 0) in Bcj2Enc_Encode()
254 const Byte *src = p->src; in Bcj2Enc_Encode()
255 const Byte *srcLim = p->srcLim; in Bcj2Enc_Encode()
256 unsigned finishMode = p->finishMode; in Bcj2Enc_Encode()
258 p->src = p->temp; in Bcj2Enc_Encode()
259 p->srcLim = p->temp + p->tempPos; in Bcj2Enc_Encode()
261 p->finishMode = BCJ2_ENC_FINISH_MODE_CONTINUE; in Bcj2Enc_Encode()
263 … PRF(printf(" ip = %8d tempPos = %8d src = %8d\n", p->ip, p->tempPos, p->srcLim - p->src)); in Bcj2Enc_Encode()
265 Bcj2Enc_Encode_2(p); in Bcj2Enc_Encode()
268 unsigned num = (unsigned)(p->src - p->temp); in Bcj2Enc_Encode()
269 unsigned tempPos = p->tempPos - num; in Bcj2Enc_Encode()
271 p->tempPos = tempPos; in Bcj2Enc_Encode()
273 p->temp[i] = p->temp[(size_t)i + num]; in Bcj2Enc_Encode()
275 p->src = src; in Bcj2Enc_Encode()
276 p->srcLim = srcLim; in Bcj2Enc_Encode()
277 p->finishMode = finishMode; in Bcj2Enc_Encode()
279 if (p->state != BCJ2_ENC_STATE_ORIG || src == srcLim) in Bcj2Enc_Encode()
284 p->src = src - tempPos; in Bcj2Enc_Encode()
285 p->tempPos = 0; in Bcj2Enc_Encode()
289 p->temp[tempPos] = src[0]; in Bcj2Enc_Encode()
290 p->tempPos = tempPos + 1; in Bcj2Enc_Encode()
291 p->src = src + 1; in Bcj2Enc_Encode()
297 PRF(printf("++++ ip = %8d tempPos = %8d src = %8d\n", p->ip, p->tempPos, p->srcLim - p->src)); in Bcj2Enc_Encode()
299 Bcj2Enc_Encode_2(p); in Bcj2Enc_Encode()
301 if (p->state == BCJ2_ENC_STATE_ORIG) in Bcj2Enc_Encode()
303 const Byte *src = p->src; in Bcj2Enc_Encode()
304 unsigned rem = (unsigned)(p->srcLim - src); in Bcj2Enc_Encode()
307 p->temp[i] = src[i]; in Bcj2Enc_Encode()
308 p->tempPos = rem; in Bcj2Enc_Encode()
309 p->src = src + rem; in Bcj2Enc_Encode()