aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-02-03 03:12:14 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-02-03 03:14:07 +0100
commit3a2c97bd123477aba8ea5c2d88f374d53f84b3de (patch)
tree1e33458c0d3cd2f8525fd4ed0e84dbe80784a4e7
parent359230da8ea92d980ec2a852754e8e63aa893f73 (diff)
downloadbusybox-w32-3a2c97bd123477aba8ea5c2d88f374d53f84b3de.tar.gz
busybox-w32-3a2c97bd123477aba8ea5c2d88f374d53f84b3de.tar.bz2
busybox-w32-3a2c97bd123477aba8ea5c2d88f374d53f84b3de.zip
bgip2: fewer specifically-sized [u]int32_t's locals in sendMTFValues
Generic ints/unsigneds are usually fine. Yes, really. function old new delta sendMTFValues 2100 2093 -7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/libarchive/bz/compress.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/archival/libarchive/bz/compress.c b/archival/libarchive/bz/compress.c
index 992fd5884..ab0c5d9ec 100644
--- a/archival/libarchive/bz/compress.c
+++ b/archival/libarchive/bz/compress.c
@@ -260,8 +260,11 @@ void generateMTFValues(EState* s)
260static NOINLINE 260static NOINLINE
261void sendMTFValues(EState* s) 261void sendMTFValues(EState* s)
262{ 262{
263 int32_t v, t, i, j, gs, ge, bt, bc, iter; 263 int32_t t, i;
264 int32_t nSelectors, alphaSize, minLen, maxLen, selCtr; 264 unsigned iter;
265 unsigned gs;
266 int32_t alphaSize;
267 unsigned nSelectors, selCtr;
265 int32_t nGroups; 268 int32_t nGroups;
266 269
267 /* 270 /*
@@ -277,15 +280,17 @@ void sendMTFValues(EState* s)
277#define rfreq sendMTFValues__rfreq 280#define rfreq sendMTFValues__rfreq
278#define len_pack sendMTFValues__len_pack 281#define len_pack sendMTFValues__len_pack
279 282
280 uint16_t cost[BZ_N_GROUPS]; 283 unsigned /*uint16_t*/ cost[BZ_N_GROUPS];
281 int32_t fave[BZ_N_GROUPS]; 284 int32_t fave[BZ_N_GROUPS];
282 285
283 uint16_t* mtfv = s->mtfv; 286 uint16_t* mtfv = s->mtfv;
284 287
285 alphaSize = s->nInUse + 2; 288 alphaSize = s->nInUse + 2;
286 for (t = 0; t < BZ_N_GROUPS; t++) 289 for (t = 0; t < BZ_N_GROUPS; t++) {
290 unsigned v;
287 for (v = 0; v < alphaSize; v++) 291 for (v = 0; v < alphaSize; v++)
288 s->len[t][v] = BZ_GREATER_ICOST; 292 s->len[t][v] = BZ_GREATER_ICOST;
293 }
289 294
290 /*--- Decide how many coding tables to use ---*/ 295 /*--- Decide how many coding tables to use ---*/
291 AssertH(s->nMTF > 0, 3001); 296 AssertH(s->nMTF > 0, 3001);
@@ -302,16 +307,20 @@ void sendMTFValues(EState* s)
302 307
303 /*--- Generate an initial set of coding tables ---*/ 308 /*--- Generate an initial set of coding tables ---*/
304 { 309 {
305 int32_t nPart, remF, tFreq, aFreq; 310 unsigned nPart, remF;
306 311
307 nPart = nGroups; 312 nPart = nGroups;
308 remF = s->nMTF; 313 remF = s->nMTF;
309 gs = 0; 314 gs = 0;
310 while (nPart > 0) { 315 while (nPart > 0) {
316 unsigned v;
317 unsigned ge;
318 unsigned tFreq, aFreq;
319
311 tFreq = remF / nPart; 320 tFreq = remF / nPart;
312 ge = gs - 1; 321 ge = gs - 1; //underflows on 1st iteration
313 aFreq = 0; 322 aFreq = 0;
314 while (aFreq < tFreq && ge < alphaSize-1) { 323 while (aFreq < tFreq && (int)ge < (int)alphaSize-1) {
315 ge++; 324 ge++;
316 aFreq += s->mtfFreq[ge]; 325 aFreq += s->mtfFreq[ge];
317 } 326 }
@@ -343,9 +352,11 @@ void sendMTFValues(EState* s)
343 for (t = 0; t < nGroups; t++) 352 for (t = 0; t < nGroups; t++)
344 fave[t] = 0; 353 fave[t] = 0;
345 354
346 for (t = 0; t < nGroups; t++) 355 for (t = 0; t < nGroups; t++) {
356 unsigned v;
347 for (v = 0; v < alphaSize; v++) 357 for (v = 0; v < alphaSize; v++)
348 s->rfreq[t][v] = 0; 358 s->rfreq[t][v] = 0;
359 }
349 360
350#if CONFIG_BZIP2_FAST >= 5 361#if CONFIG_BZIP2_FAST >= 5
351 /* 362 /*
@@ -353,6 +364,7 @@ void sendMTFValues(EState* s)
353 * the common case (nGroups == 6). 364 * the common case (nGroups == 6).
354 */ 365 */
355 if (nGroups == 6) { 366 if (nGroups == 6) {
367 unsigned v;
356 for (v = 0; v < alphaSize; v++) { 368 for (v = 0; v < alphaSize; v++) {
357 s->len_pack[v][0] = (s->len[1][v] << 16) | s->len[0][v]; 369 s->len_pack[v][0] = (s->len[1][v] << 16) | s->len[0][v];
358 s->len_pack[v][1] = (s->len[3][v] << 16) | s->len[2][v]; 370 s->len_pack[v][1] = (s->len[3][v] << 16) | s->len[2][v];
@@ -363,6 +375,9 @@ void sendMTFValues(EState* s)
363 nSelectors = 0; 375 nSelectors = 0;
364 gs = 0; 376 gs = 0;
365 while (1) { 377 while (1) {
378 unsigned ge;
379 unsigned bt, bc;
380
366 /*--- Set group start & end marks. --*/ 381 /*--- Set group start & end marks. --*/
367 if (gs >= s->nMTF) 382 if (gs >= s->nMTF)
368 break; 383 break;
@@ -406,7 +421,7 @@ void sendMTFValues(EState* s)
406 { 421 {
407 /*--- slow version which correctly handles all situations ---*/ 422 /*--- slow version which correctly handles all situations ---*/
408 for (i = gs; i <= ge; i++) { 423 for (i = gs; i <= ge; i++) {
409 uint16_t icv = mtfv[i]; 424 unsigned /*uint16_t*/ icv = mtfv[i];
410 for (t = 0; t < nGroups; t++) 425 for (t = 0; t < nGroups; t++)
411 cost[t] += s->len[t][icv]; 426 cost[t] += s->len[t][icv];
412 } 427 }
@@ -480,6 +495,7 @@ void sendMTFValues(EState* s)
480 for (i = 0; i < nGroups; i++) 495 for (i = 0; i < nGroups; i++)
481 pos[i] = i; 496 pos[i] = i;
482 for (i = 0; i < nSelectors; i++) { 497 for (i = 0; i < nSelectors; i++) {
498 unsigned j;
483 ll_i = s->selector[i]; 499 ll_i = s->selector[i];
484 j = 0; 500 j = 0;
485 tmp = pos[j]; 501 tmp = pos[j];
@@ -496,8 +512,8 @@ void sendMTFValues(EState* s)
496 512
497 /*--- Assign actual codes for the tables. --*/ 513 /*--- Assign actual codes for the tables. --*/
498 for (t = 0; t < nGroups; t++) { 514 for (t = 0; t < nGroups; t++) {
499 minLen = 32; 515 unsigned minLen = 32; //todo: s->len[t][0];
500 maxLen = 0; 516 unsigned maxLen = 0; //todo: s->len[t][0];
501 for (i = 0; i < alphaSize; i++) { 517 for (i = 0; i < alphaSize; i++) {
502 if (s->len[t][i] > maxLen) maxLen = s->len[t][i]; 518 if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
503 if (s->len[t][i] < minLen) minLen = s->len[t][i]; 519 if (s->len[t][i] < minLen) minLen = s->len[t][i];
@@ -531,6 +547,7 @@ void sendMTFValues(EState* s)
531 for (i = 0; i < 16; i++) { 547 for (i = 0; i < 16; i++) {
532 if (inUse16 < 0) { 548 if (inUse16 < 0) {
533 unsigned v16 = 0; 549 unsigned v16 = 0;
550 unsigned j;
534 for (j = 0; j < 16; j++) 551 for (j = 0; j < 16; j++)
535 v16 = v16*2 + s->inUse[i * 16 + j]; 552 v16 = v16*2 + s->inUse[i * 16 + j];
536 bsW16(s, v16); 553 bsW16(s, v16);
@@ -543,6 +560,7 @@ void sendMTFValues(EState* s)
543 bsW(s, 3, nGroups); 560 bsW(s, 3, nGroups);
544 bsW(s, 15, nSelectors); 561 bsW(s, 15, nSelectors);
545 for (i = 0; i < nSelectors; i++) { 562 for (i = 0; i < nSelectors; i++) {
563 unsigned j;
546 for (j = 0; j < s->selectorMtf[i]; j++) 564 for (j = 0; j < s->selectorMtf[i]; j++)
547 bsW(s, 1, 1); 565 bsW(s, 1, 1);
548 bsW(s, 1, 0); 566 bsW(s, 1, 0);
@@ -550,7 +568,7 @@ void sendMTFValues(EState* s)
550 568
551 /*--- Now the coding tables. ---*/ 569 /*--- Now the coding tables. ---*/
552 for (t = 0; t < nGroups; t++) { 570 for (t = 0; t < nGroups; t++) {
553 int32_t curr = s->len[t][0]; 571 unsigned curr = s->len[t][0];
554 bsW(s, 5, curr); 572 bsW(s, 5, curr);
555 for (i = 0; i < alphaSize; i++) { 573 for (i = 0; i < alphaSize; i++) {
556 while (curr < s->len[t][i]) { bsW(s, 2, 2); curr++; /* 10 */ }; 574 while (curr < s->len[t][i]) { bsW(s, 2, 2); curr++; /* 10 */ };
@@ -563,6 +581,8 @@ void sendMTFValues(EState* s)
563 selCtr = 0; 581 selCtr = 0;
564 gs = 0; 582 gs = 0;
565 while (1) { 583 while (1) {
584 unsigned ge;
585
566 if (gs >= s->nMTF) 586 if (gs >= s->nMTF)
567 break; 587 break;
568 ge = gs + BZ_G_SIZE - 1; 588 ge = gs + BZ_G_SIZE - 1;