zstd_opt.h 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  1. /* SPDX-License-Identifier: (GPL-2.0 or BSD-3-Clause-Clear) */
  2. /**
  3. * Copyright (c) 2016-present, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
  4. * All rights reserved.
  5. */
  6. /* Note : this file is intended to be included within zstd_compress.c */
  7. #ifndef ZSTD_OPT_H_91842398743
  8. #define ZSTD_OPT_H_91842398743
  9. #define ZSTD_LITFREQ_ADD 2
  10. #define ZSTD_FREQ_DIV 4
  11. #define ZSTD_MAX_PRICE (1 << 30)
  12. /*-*************************************
  13. * Price functions for optimal parser
  14. ***************************************/
  15. FORCE_INLINE void ZSTD_setLog2Prices(seqStore_t *ssPtr)
  16. {
  17. ssPtr->log2matchLengthSum = ZSTD_highbit32(ssPtr->matchLengthSum + 1);
  18. ssPtr->log2litLengthSum = ZSTD_highbit32(ssPtr->litLengthSum + 1);
  19. ssPtr->log2litSum = ZSTD_highbit32(ssPtr->litSum + 1);
  20. ssPtr->log2offCodeSum = ZSTD_highbit32(ssPtr->offCodeSum + 1);
  21. ssPtr->factor = 1 + ((ssPtr->litSum >> 5) / ssPtr->litLengthSum) + ((ssPtr->litSum << 1) / (ssPtr->litSum + ssPtr->matchSum));
  22. }
  23. ZSTD_STATIC void ZSTD_rescaleFreqs(seqStore_t *ssPtr, const BYTE *src, size_t srcSize)
  24. {
  25. unsigned u;
  26. ssPtr->cachedLiterals = NULL;
  27. ssPtr->cachedPrice = ssPtr->cachedLitLength = 0;
  28. ssPtr->staticPrices = 0;
  29. if (ssPtr->litLengthSum == 0) {
  30. if (srcSize <= 1024)
  31. ssPtr->staticPrices = 1;
  32. for (u = 0; u <= MaxLit; u++)
  33. ssPtr->litFreq[u] = 0;
  34. for (u = 0; u < srcSize; u++)
  35. ssPtr->litFreq[src[u]]++;
  36. ssPtr->litSum = 0;
  37. ssPtr->litLengthSum = MaxLL + 1;
  38. ssPtr->matchLengthSum = MaxML + 1;
  39. ssPtr->offCodeSum = (MaxOff + 1);
  40. ssPtr->matchSum = (ZSTD_LITFREQ_ADD << Litbits);
  41. for (u = 0; u <= MaxLit; u++) {
  42. ssPtr->litFreq[u] = 1 + (ssPtr->litFreq[u] >> ZSTD_FREQ_DIV);
  43. ssPtr->litSum += ssPtr->litFreq[u];
  44. }
  45. for (u = 0; u <= MaxLL; u++)
  46. ssPtr->litLengthFreq[u] = 1;
  47. for (u = 0; u <= MaxML; u++)
  48. ssPtr->matchLengthFreq[u] = 1;
  49. for (u = 0; u <= MaxOff; u++)
  50. ssPtr->offCodeFreq[u] = 1;
  51. } else {
  52. ssPtr->matchLengthSum = 0;
  53. ssPtr->litLengthSum = 0;
  54. ssPtr->offCodeSum = 0;
  55. ssPtr->matchSum = 0;
  56. ssPtr->litSum = 0;
  57. for (u = 0; u <= MaxLit; u++) {
  58. ssPtr->litFreq[u] = 1 + (ssPtr->litFreq[u] >> (ZSTD_FREQ_DIV + 1));
  59. ssPtr->litSum += ssPtr->litFreq[u];
  60. }
  61. for (u = 0; u <= MaxLL; u++) {
  62. ssPtr->litLengthFreq[u] = 1 + (ssPtr->litLengthFreq[u] >> (ZSTD_FREQ_DIV + 1));
  63. ssPtr->litLengthSum += ssPtr->litLengthFreq[u];
  64. }
  65. for (u = 0; u <= MaxML; u++) {
  66. ssPtr->matchLengthFreq[u] = 1 + (ssPtr->matchLengthFreq[u] >> ZSTD_FREQ_DIV);
  67. ssPtr->matchLengthSum += ssPtr->matchLengthFreq[u];
  68. ssPtr->matchSum += ssPtr->matchLengthFreq[u] * (u + 3);
  69. }
  70. ssPtr->matchSum *= ZSTD_LITFREQ_ADD;
  71. for (u = 0; u <= MaxOff; u++) {
  72. ssPtr->offCodeFreq[u] = 1 + (ssPtr->offCodeFreq[u] >> ZSTD_FREQ_DIV);
  73. ssPtr->offCodeSum += ssPtr->offCodeFreq[u];
  74. }
  75. }
  76. ZSTD_setLog2Prices(ssPtr);
  77. }
  78. FORCE_INLINE U32 ZSTD_getLiteralPrice(seqStore_t *ssPtr, U32 litLength, const BYTE *literals)
  79. {
  80. U32 price, u;
  81. if (ssPtr->staticPrices)
  82. return ZSTD_highbit32((U32)litLength + 1) + (litLength * 6);
  83. if (litLength == 0)
  84. return ssPtr->log2litLengthSum - ZSTD_highbit32(ssPtr->litLengthFreq[0] + 1);
  85. /* literals */
  86. if (ssPtr->cachedLiterals == literals) {
  87. U32 const additional = litLength - ssPtr->cachedLitLength;
  88. const BYTE *literals2 = ssPtr->cachedLiterals + ssPtr->cachedLitLength;
  89. price = ssPtr->cachedPrice + additional * ssPtr->log2litSum;
  90. for (u = 0; u < additional; u++)
  91. price -= ZSTD_highbit32(ssPtr->litFreq[literals2[u]] + 1);
  92. ssPtr->cachedPrice = price;
  93. ssPtr->cachedLitLength = litLength;
  94. } else {
  95. price = litLength * ssPtr->log2litSum;
  96. for (u = 0; u < litLength; u++)
  97. price -= ZSTD_highbit32(ssPtr->litFreq[literals[u]] + 1);
  98. if (litLength >= 12) {
  99. ssPtr->cachedLiterals = literals;
  100. ssPtr->cachedPrice = price;
  101. ssPtr->cachedLitLength = litLength;
  102. }
  103. }
  104. /* literal Length */
  105. {
  106. const BYTE LL_deltaCode = 19;
  107. const BYTE llCode = (litLength > 63) ? (BYTE)ZSTD_highbit32(litLength) + LL_deltaCode : LL_Code[litLength];
  108. price += LL_bits[llCode] + ssPtr->log2litLengthSum - ZSTD_highbit32(ssPtr->litLengthFreq[llCode] + 1);
  109. }
  110. return price;
  111. }
  112. FORCE_INLINE U32 ZSTD_getPrice(seqStore_t *seqStorePtr, U32 litLength, const BYTE *literals, U32 offset, U32 matchLength, const int ultra)
  113. {
  114. /* offset */
  115. U32 price;
  116. BYTE const offCode = (BYTE)ZSTD_highbit32(offset + 1);
  117. if (seqStorePtr->staticPrices)
  118. return ZSTD_getLiteralPrice(seqStorePtr, litLength, literals) + ZSTD_highbit32((U32)matchLength + 1) + 16 + offCode;
  119. price = offCode + seqStorePtr->log2offCodeSum - ZSTD_highbit32(seqStorePtr->offCodeFreq[offCode] + 1);
  120. if (!ultra && offCode >= 20)
  121. price += (offCode - 19) * 2;
  122. /* match Length */
  123. {
  124. const BYTE ML_deltaCode = 36;
  125. const BYTE mlCode = (matchLength > 127) ? (BYTE)ZSTD_highbit32(matchLength) + ML_deltaCode : ML_Code[matchLength];
  126. price += ML_bits[mlCode] + seqStorePtr->log2matchLengthSum - ZSTD_highbit32(seqStorePtr->matchLengthFreq[mlCode] + 1);
  127. }
  128. return price + ZSTD_getLiteralPrice(seqStorePtr, litLength, literals) + seqStorePtr->factor;
  129. }
  130. ZSTD_STATIC void ZSTD_updatePrice(seqStore_t *seqStorePtr, U32 litLength, const BYTE *literals, U32 offset, U32 matchLength)
  131. {
  132. U32 u;
  133. /* literals */
  134. seqStorePtr->litSum += litLength * ZSTD_LITFREQ_ADD;
  135. for (u = 0; u < litLength; u++)
  136. seqStorePtr->litFreq[literals[u]] += ZSTD_LITFREQ_ADD;
  137. /* literal Length */
  138. {
  139. const BYTE LL_deltaCode = 19;
  140. const BYTE llCode = (litLength > 63) ? (BYTE)ZSTD_highbit32(litLength) + LL_deltaCode : LL_Code[litLength];
  141. seqStorePtr->litLengthFreq[llCode]++;
  142. seqStorePtr->litLengthSum++;
  143. }
  144. /* match offset */
  145. {
  146. BYTE const offCode = (BYTE)ZSTD_highbit32(offset + 1);
  147. seqStorePtr->offCodeSum++;
  148. seqStorePtr->offCodeFreq[offCode]++;
  149. }
  150. /* match Length */
  151. {
  152. const BYTE ML_deltaCode = 36;
  153. const BYTE mlCode = (matchLength > 127) ? (BYTE)ZSTD_highbit32(matchLength) + ML_deltaCode : ML_Code[matchLength];
  154. seqStorePtr->matchLengthFreq[mlCode]++;
  155. seqStorePtr->matchLengthSum++;
  156. }
  157. ZSTD_setLog2Prices(seqStorePtr);
  158. }
  159. #define SET_PRICE(pos, mlen_, offset_, litlen_, price_) \
  160. { \
  161. while (last_pos < pos) { \
  162. opt[last_pos + 1].price = ZSTD_MAX_PRICE; \
  163. last_pos++; \
  164. } \
  165. opt[pos].mlen = mlen_; \
  166. opt[pos].off = offset_; \
  167. opt[pos].litlen = litlen_; \
  168. opt[pos].price = price_; \
  169. }
  170. /* Update hashTable3 up to ip (excluded)
  171. Assumption : always within prefix (i.e. not within extDict) */
  172. FORCE_INLINE
  173. U32 ZSTD_insertAndFindFirstIndexHash3(ZSTD_CCtx *zc, const BYTE *ip)
  174. {
  175. U32 *const hashTable3 = zc->hashTable3;
  176. U32 const hashLog3 = zc->hashLog3;
  177. const BYTE *const base = zc->base;
  178. U32 idx = zc->nextToUpdate3;
  179. const U32 target = zc->nextToUpdate3 = (U32)(ip - base);
  180. const size_t hash3 = ZSTD_hash3Ptr(ip, hashLog3);
  181. while (idx < target) {
  182. hashTable3[ZSTD_hash3Ptr(base + idx, hashLog3)] = idx;
  183. idx++;
  184. }
  185. return hashTable3[hash3];
  186. }
  187. /*-*************************************
  188. * Binary Tree search
  189. ***************************************/
  190. static U32 ZSTD_insertBtAndGetAllMatches(ZSTD_CCtx *zc, const BYTE *const ip, const BYTE *const iLimit, U32 nbCompares, const U32 mls, U32 extDict,
  191. ZSTD_match_t *matches, const U32 minMatchLen)
  192. {
  193. const BYTE *const base = zc->base;
  194. const U32 curr = (U32)(ip - base);
  195. const U32 hashLog = zc->params.cParams.hashLog;
  196. const size_t h = ZSTD_hashPtr(ip, hashLog, mls);
  197. U32 *const hashTable = zc->hashTable;
  198. U32 matchIndex = hashTable[h];
  199. U32 *const bt = zc->chainTable;
  200. const U32 btLog = zc->params.cParams.chainLog - 1;
  201. const U32 btMask = (1U << btLog) - 1;
  202. size_t commonLengthSmaller = 0, commonLengthLarger = 0;
  203. const BYTE *const dictBase = zc->dictBase;
  204. const U32 dictLimit = zc->dictLimit;
  205. const BYTE *const dictEnd = dictBase + dictLimit;
  206. const BYTE *const prefixStart = base + dictLimit;
  207. const U32 btLow = btMask >= curr ? 0 : curr - btMask;
  208. const U32 windowLow = zc->lowLimit;
  209. U32 *smallerPtr = bt + 2 * (curr & btMask);
  210. U32 *largerPtr = bt + 2 * (curr & btMask) + 1;
  211. U32 matchEndIdx = curr + 8;
  212. U32 dummy32; /* to be nullified at the end */
  213. U32 mnum = 0;
  214. const U32 minMatch = (mls == 3) ? 3 : 4;
  215. size_t bestLength = minMatchLen - 1;
  216. if (minMatch == 3) { /* HC3 match finder */
  217. U32 const matchIndex3 = ZSTD_insertAndFindFirstIndexHash3(zc, ip);
  218. if (matchIndex3 > windowLow && (curr - matchIndex3 < (1 << 18))) {
  219. const BYTE *match;
  220. size_t currMl = 0;
  221. if ((!extDict) || matchIndex3 >= dictLimit) {
  222. match = base + matchIndex3;
  223. if (match[bestLength] == ip[bestLength])
  224. currMl = ZSTD_count(ip, match, iLimit);
  225. } else {
  226. match = dictBase + matchIndex3;
  227. if (ZSTD_readMINMATCH(match, MINMATCH) ==
  228. ZSTD_readMINMATCH(ip, MINMATCH)) /* assumption : matchIndex3 <= dictLimit-4 (by table construction) */
  229. currMl = ZSTD_count_2segments(ip + MINMATCH, match + MINMATCH, iLimit, dictEnd, prefixStart) + MINMATCH;
  230. }
  231. /* save best solution */
  232. if (currMl > bestLength) {
  233. bestLength = currMl;
  234. matches[mnum].off = ZSTD_REP_MOVE_OPT + curr - matchIndex3;
  235. matches[mnum].len = (U32)currMl;
  236. mnum++;
  237. if (currMl > ZSTD_OPT_NUM)
  238. goto update;
  239. if (ip + currMl == iLimit)
  240. goto update; /* best possible, and avoid read overflow*/
  241. }
  242. }
  243. }
  244. hashTable[h] = curr; /* Update Hash Table */
  245. while (nbCompares-- && (matchIndex > windowLow)) {
  246. U32 *nextPtr = bt + 2 * (matchIndex & btMask);
  247. size_t matchLength = MIN(commonLengthSmaller, commonLengthLarger); /* guaranteed minimum nb of common bytes */
  248. const BYTE *match;
  249. if ((!extDict) || (matchIndex + matchLength >= dictLimit)) {
  250. match = base + matchIndex;
  251. if (match[matchLength] == ip[matchLength]) {
  252. matchLength += ZSTD_count(ip + matchLength + 1, match + matchLength + 1, iLimit) + 1;
  253. }
  254. } else {
  255. match = dictBase + matchIndex;
  256. matchLength += ZSTD_count_2segments(ip + matchLength, match + matchLength, iLimit, dictEnd, prefixStart);
  257. if (matchIndex + matchLength >= dictLimit)
  258. match = base + matchIndex; /* to prepare for next usage of match[matchLength] */
  259. }
  260. if (matchLength > bestLength) {
  261. if (matchLength > matchEndIdx - matchIndex)
  262. matchEndIdx = matchIndex + (U32)matchLength;
  263. bestLength = matchLength;
  264. matches[mnum].off = ZSTD_REP_MOVE_OPT + curr - matchIndex;
  265. matches[mnum].len = (U32)matchLength;
  266. mnum++;
  267. if (matchLength > ZSTD_OPT_NUM)
  268. break;
  269. if (ip + matchLength == iLimit) /* equal : no way to know if inf or sup */
  270. break; /* drop, to guarantee consistency (miss a little bit of compression) */
  271. }
  272. if (match[matchLength] < ip[matchLength]) {
  273. /* match is smaller than curr */
  274. *smallerPtr = matchIndex; /* update smaller idx */
  275. commonLengthSmaller = matchLength; /* all smaller will now have at least this guaranteed common length */
  276. if (matchIndex <= btLow) {
  277. smallerPtr = &dummy32;
  278. break;
  279. } /* beyond tree size, stop the search */
  280. smallerPtr = nextPtr + 1; /* new "smaller" => larger of match */
  281. matchIndex = nextPtr[1]; /* new matchIndex larger than previous (closer to curr) */
  282. } else {
  283. /* match is larger than curr */
  284. *largerPtr = matchIndex;
  285. commonLengthLarger = matchLength;
  286. if (matchIndex <= btLow) {
  287. largerPtr = &dummy32;
  288. break;
  289. } /* beyond tree size, stop the search */
  290. largerPtr = nextPtr;
  291. matchIndex = nextPtr[0];
  292. }
  293. }
  294. *smallerPtr = *largerPtr = 0;
  295. update:
  296. zc->nextToUpdate = (matchEndIdx > curr + 8) ? matchEndIdx - 8 : curr + 1;
  297. return mnum;
  298. }
  299. /** Tree updater, providing best match */
  300. static U32 ZSTD_BtGetAllMatches(ZSTD_CCtx *zc, const BYTE *const ip, const BYTE *const iLimit, const U32 maxNbAttempts, const U32 mls, ZSTD_match_t *matches,
  301. const U32 minMatchLen)
  302. {
  303. if (ip < zc->base + zc->nextToUpdate)
  304. return 0; /* skipped area */
  305. ZSTD_updateTree(zc, ip, iLimit, maxNbAttempts, mls);
  306. return ZSTD_insertBtAndGetAllMatches(zc, ip, iLimit, maxNbAttempts, mls, 0, matches, minMatchLen);
  307. }
  308. static U32 ZSTD_BtGetAllMatches_selectMLS(ZSTD_CCtx *zc, /* Index table will be updated */
  309. const BYTE *ip, const BYTE *const iHighLimit, const U32 maxNbAttempts, const U32 matchLengthSearch,
  310. ZSTD_match_t *matches, const U32 minMatchLen)
  311. {
  312. switch (matchLengthSearch) {
  313. case 3: return ZSTD_BtGetAllMatches(zc, ip, iHighLimit, maxNbAttempts, 3, matches, minMatchLen);
  314. default:
  315. case 4: return ZSTD_BtGetAllMatches(zc, ip, iHighLimit, maxNbAttempts, 4, matches, minMatchLen);
  316. case 5: return ZSTD_BtGetAllMatches(zc, ip, iHighLimit, maxNbAttempts, 5, matches, minMatchLen);
  317. case 7:
  318. case 6: return ZSTD_BtGetAllMatches(zc, ip, iHighLimit, maxNbAttempts, 6, matches, minMatchLen);
  319. }
  320. }
  321. /** Tree updater, providing best match */
  322. static U32 ZSTD_BtGetAllMatches_extDict(ZSTD_CCtx *zc, const BYTE *const ip, const BYTE *const iLimit, const U32 maxNbAttempts, const U32 mls,
  323. ZSTD_match_t *matches, const U32 minMatchLen)
  324. {
  325. if (ip < zc->base + zc->nextToUpdate)
  326. return 0; /* skipped area */
  327. ZSTD_updateTree_extDict(zc, ip, iLimit, maxNbAttempts, mls);
  328. return ZSTD_insertBtAndGetAllMatches(zc, ip, iLimit, maxNbAttempts, mls, 1, matches, minMatchLen);
  329. }
  330. static U32 ZSTD_BtGetAllMatches_selectMLS_extDict(ZSTD_CCtx *zc, /* Index table will be updated */
  331. const BYTE *ip, const BYTE *const iHighLimit, const U32 maxNbAttempts, const U32 matchLengthSearch,
  332. ZSTD_match_t *matches, const U32 minMatchLen)
  333. {
  334. switch (matchLengthSearch) {
  335. case 3: return ZSTD_BtGetAllMatches_extDict(zc, ip, iHighLimit, maxNbAttempts, 3, matches, minMatchLen);
  336. default:
  337. case 4: return ZSTD_BtGetAllMatches_extDict(zc, ip, iHighLimit, maxNbAttempts, 4, matches, minMatchLen);
  338. case 5: return ZSTD_BtGetAllMatches_extDict(zc, ip, iHighLimit, maxNbAttempts, 5, matches, minMatchLen);
  339. case 7:
  340. case 6: return ZSTD_BtGetAllMatches_extDict(zc, ip, iHighLimit, maxNbAttempts, 6, matches, minMatchLen);
  341. }
  342. }
  343. /*-*******************************
  344. * Optimal parser
  345. *********************************/
  346. FORCE_INLINE
  347. void ZSTD_compressBlock_opt_generic(ZSTD_CCtx *ctx, const void *src, size_t srcSize, const int ultra)
  348. {
  349. seqStore_t *seqStorePtr = &(ctx->seqStore);
  350. const BYTE *const istart = (const BYTE *)src;
  351. const BYTE *ip = istart;
  352. const BYTE *anchor = istart;
  353. const BYTE *const iend = istart + srcSize;
  354. const BYTE *const ilimit = iend - 8;
  355. const BYTE *const base = ctx->base;
  356. const BYTE *const prefixStart = base + ctx->dictLimit;
  357. const U32 maxSearches = 1U << ctx->params.cParams.searchLog;
  358. const U32 sufficient_len = ctx->params.cParams.targetLength;
  359. const U32 mls = ctx->params.cParams.searchLength;
  360. const U32 minMatch = (ctx->params.cParams.searchLength == 3) ? 3 : 4;
  361. ZSTD_optimal_t *opt = seqStorePtr->priceTable;
  362. ZSTD_match_t *matches = seqStorePtr->matchTable;
  363. const BYTE *inr;
  364. U32 offset, rep[ZSTD_REP_NUM];
  365. /* init */
  366. ctx->nextToUpdate3 = ctx->nextToUpdate;
  367. ZSTD_rescaleFreqs(seqStorePtr, (const BYTE *)src, srcSize);
  368. ip += (ip == prefixStart);
  369. {
  370. U32 i;
  371. for (i = 0; i < ZSTD_REP_NUM; i++)
  372. rep[i] = ctx->rep[i];
  373. }
  374. /* Match Loop */
  375. while (ip < ilimit) {
  376. U32 cur, match_num, last_pos, litlen, price;
  377. U32 u, mlen, best_mlen, best_off, litLength;
  378. memset(opt, 0, sizeof(ZSTD_optimal_t));
  379. last_pos = 0;
  380. litlen = (U32)(ip - anchor);
  381. /* check repCode */
  382. {
  383. U32 i, last_i = ZSTD_REP_CHECK + (ip == anchor);
  384. for (i = (ip == anchor); i < last_i; i++) {
  385. const S32 repCur = (i == ZSTD_REP_MOVE_OPT) ? (rep[0] - 1) : rep[i];
  386. if ((repCur > 0) && (repCur < (S32)(ip - prefixStart)) &&
  387. (ZSTD_readMINMATCH(ip, minMatch) == ZSTD_readMINMATCH(ip - repCur, minMatch))) {
  388. mlen = (U32)ZSTD_count(ip + minMatch, ip + minMatch - repCur, iend) + minMatch;
  389. if (mlen > sufficient_len || mlen >= ZSTD_OPT_NUM) {
  390. best_mlen = mlen;
  391. best_off = i;
  392. cur = 0;
  393. last_pos = 1;
  394. goto _storeSequence;
  395. }
  396. best_off = i - (ip == anchor);
  397. do {
  398. price = ZSTD_getPrice(seqStorePtr, litlen, anchor, best_off, mlen - MINMATCH, ultra);
  399. if (mlen > last_pos || price < opt[mlen].price)
  400. SET_PRICE(mlen, mlen, i, litlen, price); /* note : macro modifies last_pos */
  401. mlen--;
  402. } while (mlen >= minMatch);
  403. }
  404. }
  405. }
  406. match_num = ZSTD_BtGetAllMatches_selectMLS(ctx, ip, iend, maxSearches, mls, matches, minMatch);
  407. if (!last_pos && !match_num) {
  408. ip++;
  409. continue;
  410. }
  411. if (match_num && (matches[match_num - 1].len > sufficient_len || matches[match_num - 1].len >= ZSTD_OPT_NUM)) {
  412. best_mlen = matches[match_num - 1].len;
  413. best_off = matches[match_num - 1].off;
  414. cur = 0;
  415. last_pos = 1;
  416. goto _storeSequence;
  417. }
  418. /* set prices using matches at position = 0 */
  419. best_mlen = (last_pos) ? last_pos : minMatch;
  420. for (u = 0; u < match_num; u++) {
  421. mlen = (u > 0) ? matches[u - 1].len + 1 : best_mlen;
  422. best_mlen = matches[u].len;
  423. while (mlen <= best_mlen) {
  424. price = ZSTD_getPrice(seqStorePtr, litlen, anchor, matches[u].off - 1, mlen - MINMATCH, ultra);
  425. if (mlen > last_pos || price < opt[mlen].price)
  426. SET_PRICE(mlen, mlen, matches[u].off, litlen, price); /* note : macro modifies last_pos */
  427. mlen++;
  428. }
  429. }
  430. if (last_pos < minMatch) {
  431. ip++;
  432. continue;
  433. }
  434. /* initialize opt[0] */
  435. {
  436. U32 i;
  437. for (i = 0; i < ZSTD_REP_NUM; i++)
  438. opt[0].rep[i] = rep[i];
  439. }
  440. opt[0].mlen = 1;
  441. opt[0].litlen = litlen;
  442. /* check further positions */
  443. for (cur = 1; cur <= last_pos; cur++) {
  444. inr = ip + cur;
  445. if (opt[cur - 1].mlen == 1) {
  446. litlen = opt[cur - 1].litlen + 1;
  447. if (cur > litlen) {
  448. price = opt[cur - litlen].price + ZSTD_getLiteralPrice(seqStorePtr, litlen, inr - litlen);
  449. } else
  450. price = ZSTD_getLiteralPrice(seqStorePtr, litlen, anchor);
  451. } else {
  452. litlen = 1;
  453. price = opt[cur - 1].price + ZSTD_getLiteralPrice(seqStorePtr, litlen, inr - 1);
  454. }
  455. if (cur > last_pos || price <= opt[cur].price)
  456. SET_PRICE(cur, 1, 0, litlen, price);
  457. if (cur == last_pos)
  458. break;
  459. if (inr > ilimit) /* last match must start at a minimum distance of 8 from oend */
  460. continue;
  461. mlen = opt[cur].mlen;
  462. if (opt[cur].off > ZSTD_REP_MOVE_OPT) {
  463. opt[cur].rep[2] = opt[cur - mlen].rep[1];
  464. opt[cur].rep[1] = opt[cur - mlen].rep[0];
  465. opt[cur].rep[0] = opt[cur].off - ZSTD_REP_MOVE_OPT;
  466. } else {
  467. opt[cur].rep[2] = (opt[cur].off > 1) ? opt[cur - mlen].rep[1] : opt[cur - mlen].rep[2];
  468. opt[cur].rep[1] = (opt[cur].off > 0) ? opt[cur - mlen].rep[0] : opt[cur - mlen].rep[1];
  469. opt[cur].rep[0] =
  470. ((opt[cur].off == ZSTD_REP_MOVE_OPT) && (mlen != 1)) ? (opt[cur - mlen].rep[0] - 1) : (opt[cur - mlen].rep[opt[cur].off]);
  471. }
  472. best_mlen = minMatch;
  473. {
  474. U32 i, last_i = ZSTD_REP_CHECK + (mlen != 1);
  475. for (i = (opt[cur].mlen != 1); i < last_i; i++) { /* check rep */
  476. const S32 repCur = (i == ZSTD_REP_MOVE_OPT) ? (opt[cur].rep[0] - 1) : opt[cur].rep[i];
  477. if ((repCur > 0) && (repCur < (S32)(inr - prefixStart)) &&
  478. (ZSTD_readMINMATCH(inr, minMatch) == ZSTD_readMINMATCH(inr - repCur, minMatch))) {
  479. mlen = (U32)ZSTD_count(inr + minMatch, inr + minMatch - repCur, iend) + minMatch;
  480. if (mlen > sufficient_len || cur + mlen >= ZSTD_OPT_NUM) {
  481. best_mlen = mlen;
  482. best_off = i;
  483. last_pos = cur + 1;
  484. goto _storeSequence;
  485. }
  486. best_off = i - (opt[cur].mlen != 1);
  487. if (mlen > best_mlen)
  488. best_mlen = mlen;
  489. do {
  490. if (opt[cur].mlen == 1) {
  491. litlen = opt[cur].litlen;
  492. if (cur > litlen) {
  493. price = opt[cur - litlen].price + ZSTD_getPrice(seqStorePtr, litlen, inr - litlen,
  494. best_off, mlen - MINMATCH, ultra);
  495. } else
  496. price = ZSTD_getPrice(seqStorePtr, litlen, anchor, best_off, mlen - MINMATCH, ultra);
  497. } else {
  498. litlen = 0;
  499. price = opt[cur].price + ZSTD_getPrice(seqStorePtr, 0, NULL, best_off, mlen - MINMATCH, ultra);
  500. }
  501. if (cur + mlen > last_pos || price <= opt[cur + mlen].price)
  502. SET_PRICE(cur + mlen, mlen, i, litlen, price);
  503. mlen--;
  504. } while (mlen >= minMatch);
  505. }
  506. }
  507. }
  508. match_num = ZSTD_BtGetAllMatches_selectMLS(ctx, inr, iend, maxSearches, mls, matches, best_mlen);
  509. if (match_num > 0 && (matches[match_num - 1].len > sufficient_len || cur + matches[match_num - 1].len >= ZSTD_OPT_NUM)) {
  510. best_mlen = matches[match_num - 1].len;
  511. best_off = matches[match_num - 1].off;
  512. last_pos = cur + 1;
  513. goto _storeSequence;
  514. }
  515. /* set prices using matches at position = cur */
  516. for (u = 0; u < match_num; u++) {
  517. mlen = (u > 0) ? matches[u - 1].len + 1 : best_mlen;
  518. best_mlen = matches[u].len;
  519. while (mlen <= best_mlen) {
  520. if (opt[cur].mlen == 1) {
  521. litlen = opt[cur].litlen;
  522. if (cur > litlen)
  523. price = opt[cur - litlen].price + ZSTD_getPrice(seqStorePtr, litlen, ip + cur - litlen,
  524. matches[u].off - 1, mlen - MINMATCH, ultra);
  525. else
  526. price = ZSTD_getPrice(seqStorePtr, litlen, anchor, matches[u].off - 1, mlen - MINMATCH, ultra);
  527. } else {
  528. litlen = 0;
  529. price = opt[cur].price + ZSTD_getPrice(seqStorePtr, 0, NULL, matches[u].off - 1, mlen - MINMATCH, ultra);
  530. }
  531. if (cur + mlen > last_pos || (price < opt[cur + mlen].price))
  532. SET_PRICE(cur + mlen, mlen, matches[u].off, litlen, price);
  533. mlen++;
  534. }
  535. }
  536. }
  537. best_mlen = opt[last_pos].mlen;
  538. best_off = opt[last_pos].off;
  539. cur = last_pos - best_mlen;
  540. /* store sequence */
  541. _storeSequence: /* cur, last_pos, best_mlen, best_off have to be set */
  542. opt[0].mlen = 1;
  543. while (1) {
  544. mlen = opt[cur].mlen;
  545. offset = opt[cur].off;
  546. opt[cur].mlen = best_mlen;
  547. opt[cur].off = best_off;
  548. best_mlen = mlen;
  549. best_off = offset;
  550. if (mlen > cur)
  551. break;
  552. cur -= mlen;
  553. }
  554. for (u = 0; u <= last_pos;) {
  555. u += opt[u].mlen;
  556. }
  557. for (cur = 0; cur < last_pos;) {
  558. mlen = opt[cur].mlen;
  559. if (mlen == 1) {
  560. ip++;
  561. cur++;
  562. continue;
  563. }
  564. offset = opt[cur].off;
  565. cur += mlen;
  566. litLength = (U32)(ip - anchor);
  567. if (offset > ZSTD_REP_MOVE_OPT) {
  568. rep[2] = rep[1];
  569. rep[1] = rep[0];
  570. rep[0] = offset - ZSTD_REP_MOVE_OPT;
  571. offset--;
  572. } else {
  573. if (offset != 0) {
  574. best_off = (offset == ZSTD_REP_MOVE_OPT) ? (rep[0] - 1) : (rep[offset]);
  575. if (offset != 1)
  576. rep[2] = rep[1];
  577. rep[1] = rep[0];
  578. rep[0] = best_off;
  579. }
  580. if (litLength == 0)
  581. offset--;
  582. }
  583. ZSTD_updatePrice(seqStorePtr, litLength, anchor, offset, mlen - MINMATCH);
  584. ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset, mlen - MINMATCH);
  585. anchor = ip = ip + mlen;
  586. }
  587. } /* for (cur=0; cur < last_pos; ) */
  588. /* Save reps for next block */
  589. {
  590. int i;
  591. for (i = 0; i < ZSTD_REP_NUM; i++)
  592. ctx->repToConfirm[i] = rep[i];
  593. }
  594. /* Last Literals */
  595. {
  596. size_t const lastLLSize = iend - anchor;
  597. memcpy(seqStorePtr->lit, anchor, lastLLSize);
  598. seqStorePtr->lit += lastLLSize;
  599. }
  600. }
  601. FORCE_INLINE
  602. void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx *ctx, const void *src, size_t srcSize, const int ultra)
  603. {
  604. seqStore_t *seqStorePtr = &(ctx->seqStore);
  605. const BYTE *const istart = (const BYTE *)src;
  606. const BYTE *ip = istart;
  607. const BYTE *anchor = istart;
  608. const BYTE *const iend = istart + srcSize;
  609. const BYTE *const ilimit = iend - 8;
  610. const BYTE *const base = ctx->base;
  611. const U32 lowestIndex = ctx->lowLimit;
  612. const U32 dictLimit = ctx->dictLimit;
  613. const BYTE *const prefixStart = base + dictLimit;
  614. const BYTE *const dictBase = ctx->dictBase;
  615. const BYTE *const dictEnd = dictBase + dictLimit;
  616. const U32 maxSearches = 1U << ctx->params.cParams.searchLog;
  617. const U32 sufficient_len = ctx->params.cParams.targetLength;
  618. const U32 mls = ctx->params.cParams.searchLength;
  619. const U32 minMatch = (ctx->params.cParams.searchLength == 3) ? 3 : 4;
  620. ZSTD_optimal_t *opt = seqStorePtr->priceTable;
  621. ZSTD_match_t *matches = seqStorePtr->matchTable;
  622. const BYTE *inr;
  623. /* init */
  624. U32 offset, rep[ZSTD_REP_NUM];
  625. {
  626. U32 i;
  627. for (i = 0; i < ZSTD_REP_NUM; i++)
  628. rep[i] = ctx->rep[i];
  629. }
  630. ctx->nextToUpdate3 = ctx->nextToUpdate;
  631. ZSTD_rescaleFreqs(seqStorePtr, (const BYTE *)src, srcSize);
  632. ip += (ip == prefixStart);
  633. /* Match Loop */
  634. while (ip < ilimit) {
  635. U32 cur, match_num, last_pos, litlen, price;
  636. U32 u, mlen, best_mlen, best_off, litLength;
  637. U32 curr = (U32)(ip - base);
  638. memset(opt, 0, sizeof(ZSTD_optimal_t));
  639. last_pos = 0;
  640. opt[0].litlen = (U32)(ip - anchor);
  641. /* check repCode */
  642. {
  643. U32 i, last_i = ZSTD_REP_CHECK + (ip == anchor);
  644. for (i = (ip == anchor); i < last_i; i++) {
  645. const S32 repCur = (i == ZSTD_REP_MOVE_OPT) ? (rep[0] - 1) : rep[i];
  646. const U32 repIndex = (U32)(curr - repCur);
  647. const BYTE *const repBase = repIndex < dictLimit ? dictBase : base;
  648. const BYTE *const repMatch = repBase + repIndex;
  649. if ((repCur > 0 && repCur <= (S32)curr) &&
  650. (((U32)((dictLimit - 1) - repIndex) >= 3) & (repIndex > lowestIndex)) /* intentional overflow */
  651. && (ZSTD_readMINMATCH(ip, minMatch) == ZSTD_readMINMATCH(repMatch, minMatch))) {
  652. /* repcode detected we should take it */
  653. const BYTE *const repEnd = repIndex < dictLimit ? dictEnd : iend;
  654. mlen = (U32)ZSTD_count_2segments(ip + minMatch, repMatch + minMatch, iend, repEnd, prefixStart) + minMatch;
  655. if (mlen > sufficient_len || mlen >= ZSTD_OPT_NUM) {
  656. best_mlen = mlen;
  657. best_off = i;
  658. cur = 0;
  659. last_pos = 1;
  660. goto _storeSequence;
  661. }
  662. best_off = i - (ip == anchor);
  663. litlen = opt[0].litlen;
  664. do {
  665. price = ZSTD_getPrice(seqStorePtr, litlen, anchor, best_off, mlen - MINMATCH, ultra);
  666. if (mlen > last_pos || price < opt[mlen].price)
  667. SET_PRICE(mlen, mlen, i, litlen, price); /* note : macro modifies last_pos */
  668. mlen--;
  669. } while (mlen >= minMatch);
  670. }
  671. }
  672. }
  673. match_num = ZSTD_BtGetAllMatches_selectMLS_extDict(ctx, ip, iend, maxSearches, mls, matches, minMatch); /* first search (depth 0) */
  674. if (!last_pos && !match_num) {
  675. ip++;
  676. continue;
  677. }
  678. {
  679. U32 i;
  680. for (i = 0; i < ZSTD_REP_NUM; i++)
  681. opt[0].rep[i] = rep[i];
  682. }
  683. opt[0].mlen = 1;
  684. if (match_num && (matches[match_num - 1].len > sufficient_len || matches[match_num - 1].len >= ZSTD_OPT_NUM)) {
  685. best_mlen = matches[match_num - 1].len;
  686. best_off = matches[match_num - 1].off;
  687. cur = 0;
  688. last_pos = 1;
  689. goto _storeSequence;
  690. }
  691. best_mlen = (last_pos) ? last_pos : minMatch;
  692. /* set prices using matches at position = 0 */
  693. for (u = 0; u < match_num; u++) {
  694. mlen = (u > 0) ? matches[u - 1].len + 1 : best_mlen;
  695. best_mlen = matches[u].len;
  696. litlen = opt[0].litlen;
  697. while (mlen <= best_mlen) {
  698. price = ZSTD_getPrice(seqStorePtr, litlen, anchor, matches[u].off - 1, mlen - MINMATCH, ultra);
  699. if (mlen > last_pos || price < opt[mlen].price)
  700. SET_PRICE(mlen, mlen, matches[u].off, litlen, price);
  701. mlen++;
  702. }
  703. }
  704. if (last_pos < minMatch) {
  705. ip++;
  706. continue;
  707. }
  708. /* check further positions */
  709. for (cur = 1; cur <= last_pos; cur++) {
  710. inr = ip + cur;
  711. if (opt[cur - 1].mlen == 1) {
  712. litlen = opt[cur - 1].litlen + 1;
  713. if (cur > litlen) {
  714. price = opt[cur - litlen].price + ZSTD_getLiteralPrice(seqStorePtr, litlen, inr - litlen);
  715. } else
  716. price = ZSTD_getLiteralPrice(seqStorePtr, litlen, anchor);
  717. } else {
  718. litlen = 1;
  719. price = opt[cur - 1].price + ZSTD_getLiteralPrice(seqStorePtr, litlen, inr - 1);
  720. }
  721. if (cur > last_pos || price <= opt[cur].price)
  722. SET_PRICE(cur, 1, 0, litlen, price);
  723. if (cur == last_pos)
  724. break;
  725. if (inr > ilimit) /* last match must start at a minimum distance of 8 from oend */
  726. continue;
  727. mlen = opt[cur].mlen;
  728. if (opt[cur].off > ZSTD_REP_MOVE_OPT) {
  729. opt[cur].rep[2] = opt[cur - mlen].rep[1];
  730. opt[cur].rep[1] = opt[cur - mlen].rep[0];
  731. opt[cur].rep[0] = opt[cur].off - ZSTD_REP_MOVE_OPT;
  732. } else {
  733. opt[cur].rep[2] = (opt[cur].off > 1) ? opt[cur - mlen].rep[1] : opt[cur - mlen].rep[2];
  734. opt[cur].rep[1] = (opt[cur].off > 0) ? opt[cur - mlen].rep[0] : opt[cur - mlen].rep[1];
  735. opt[cur].rep[0] =
  736. ((opt[cur].off == ZSTD_REP_MOVE_OPT) && (mlen != 1)) ? (opt[cur - mlen].rep[0] - 1) : (opt[cur - mlen].rep[opt[cur].off]);
  737. }
  738. best_mlen = minMatch;
  739. {
  740. U32 i, last_i = ZSTD_REP_CHECK + (mlen != 1);
  741. for (i = (mlen != 1); i < last_i; i++) {
  742. const S32 repCur = (i == ZSTD_REP_MOVE_OPT) ? (opt[cur].rep[0] - 1) : opt[cur].rep[i];
  743. const U32 repIndex = (U32)(curr + cur - repCur);
  744. const BYTE *const repBase = repIndex < dictLimit ? dictBase : base;
  745. const BYTE *const repMatch = repBase + repIndex;
  746. if ((repCur > 0 && repCur <= (S32)(curr + cur)) &&
  747. (((U32)((dictLimit - 1) - repIndex) >= 3) & (repIndex > lowestIndex)) /* intentional overflow */
  748. && (ZSTD_readMINMATCH(inr, minMatch) == ZSTD_readMINMATCH(repMatch, minMatch))) {
  749. /* repcode detected */
  750. const BYTE *const repEnd = repIndex < dictLimit ? dictEnd : iend;
  751. mlen = (U32)ZSTD_count_2segments(inr + minMatch, repMatch + minMatch, iend, repEnd, prefixStart) + minMatch;
  752. if (mlen > sufficient_len || cur + mlen >= ZSTD_OPT_NUM) {
  753. best_mlen = mlen;
  754. best_off = i;
  755. last_pos = cur + 1;
  756. goto _storeSequence;
  757. }
  758. best_off = i - (opt[cur].mlen != 1);
  759. if (mlen > best_mlen)
  760. best_mlen = mlen;
  761. do {
  762. if (opt[cur].mlen == 1) {
  763. litlen = opt[cur].litlen;
  764. if (cur > litlen) {
  765. price = opt[cur - litlen].price + ZSTD_getPrice(seqStorePtr, litlen, inr - litlen,
  766. best_off, mlen - MINMATCH, ultra);
  767. } else
  768. price = ZSTD_getPrice(seqStorePtr, litlen, anchor, best_off, mlen - MINMATCH, ultra);
  769. } else {
  770. litlen = 0;
  771. price = opt[cur].price + ZSTD_getPrice(seqStorePtr, 0, NULL, best_off, mlen - MINMATCH, ultra);
  772. }
  773. if (cur + mlen > last_pos || price <= opt[cur + mlen].price)
  774. SET_PRICE(cur + mlen, mlen, i, litlen, price);
  775. mlen--;
  776. } while (mlen >= minMatch);
  777. }
  778. }
  779. }
  780. match_num = ZSTD_BtGetAllMatches_selectMLS_extDict(ctx, inr, iend, maxSearches, mls, matches, minMatch);
  781. if (match_num > 0 && (matches[match_num - 1].len > sufficient_len || cur + matches[match_num - 1].len >= ZSTD_OPT_NUM)) {
  782. best_mlen = matches[match_num - 1].len;
  783. best_off = matches[match_num - 1].off;
  784. last_pos = cur + 1;
  785. goto _storeSequence;
  786. }
  787. /* set prices using matches at position = cur */
  788. for (u = 0; u < match_num; u++) {
  789. mlen = (u > 0) ? matches[u - 1].len + 1 : best_mlen;
  790. best_mlen = matches[u].len;
  791. while (mlen <= best_mlen) {
  792. if (opt[cur].mlen == 1) {
  793. litlen = opt[cur].litlen;
  794. if (cur > litlen)
  795. price = opt[cur - litlen].price + ZSTD_getPrice(seqStorePtr, litlen, ip + cur - litlen,
  796. matches[u].off - 1, mlen - MINMATCH, ultra);
  797. else
  798. price = ZSTD_getPrice(seqStorePtr, litlen, anchor, matches[u].off - 1, mlen - MINMATCH, ultra);
  799. } else {
  800. litlen = 0;
  801. price = opt[cur].price + ZSTD_getPrice(seqStorePtr, 0, NULL, matches[u].off - 1, mlen - MINMATCH, ultra);
  802. }
  803. if (cur + mlen > last_pos || (price < opt[cur + mlen].price))
  804. SET_PRICE(cur + mlen, mlen, matches[u].off, litlen, price);
  805. mlen++;
  806. }
  807. }
  808. } /* for (cur = 1; cur <= last_pos; cur++) */
  809. best_mlen = opt[last_pos].mlen;
  810. best_off = opt[last_pos].off;
  811. cur = last_pos - best_mlen;
  812. /* store sequence */
  813. _storeSequence: /* cur, last_pos, best_mlen, best_off have to be set */
  814. opt[0].mlen = 1;
  815. while (1) {
  816. mlen = opt[cur].mlen;
  817. offset = opt[cur].off;
  818. opt[cur].mlen = best_mlen;
  819. opt[cur].off = best_off;
  820. best_mlen = mlen;
  821. best_off = offset;
  822. if (mlen > cur)
  823. break;
  824. cur -= mlen;
  825. }
  826. for (u = 0; u <= last_pos;) {
  827. u += opt[u].mlen;
  828. }
  829. for (cur = 0; cur < last_pos;) {
  830. mlen = opt[cur].mlen;
  831. if (mlen == 1) {
  832. ip++;
  833. cur++;
  834. continue;
  835. }
  836. offset = opt[cur].off;
  837. cur += mlen;
  838. litLength = (U32)(ip - anchor);
  839. if (offset > ZSTD_REP_MOVE_OPT) {
  840. rep[2] = rep[1];
  841. rep[1] = rep[0];
  842. rep[0] = offset - ZSTD_REP_MOVE_OPT;
  843. offset--;
  844. } else {
  845. if (offset != 0) {
  846. best_off = (offset == ZSTD_REP_MOVE_OPT) ? (rep[0] - 1) : (rep[offset]);
  847. if (offset != 1)
  848. rep[2] = rep[1];
  849. rep[1] = rep[0];
  850. rep[0] = best_off;
  851. }
  852. if (litLength == 0)
  853. offset--;
  854. }
  855. ZSTD_updatePrice(seqStorePtr, litLength, anchor, offset, mlen - MINMATCH);
  856. ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset, mlen - MINMATCH);
  857. anchor = ip = ip + mlen;
  858. }
  859. } /* for (cur=0; cur < last_pos; ) */
  860. /* Save reps for next block */
  861. {
  862. int i;
  863. for (i = 0; i < ZSTD_REP_NUM; i++)
  864. ctx->repToConfirm[i] = rep[i];
  865. }
  866. /* Last Literals */
  867. {
  868. size_t lastLLSize = iend - anchor;
  869. memcpy(seqStorePtr->lit, anchor, lastLLSize);
  870. seqStorePtr->lit += lastLLSize;
  871. }
  872. }
  873. #endif /* ZSTD_OPT_H_91842398743 */