aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-06-12 12:35:15 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-06-12 12:35:15 +0200
commite36c39a46d16c080de1034db41b53abf483bdb88 (patch)
tree79940c032de1abbe8a5eef4e9e13f6704763589f
parente5958f7dda4ce962d15950be515284560d6c0275 (diff)
downloadbusybox-w32-e36c39a46d16c080de1034db41b53abf483bdb88.tar.gz
busybox-w32-e36c39a46d16c080de1034db41b53abf483bdb88.tar.bz2
busybox-w32-e36c39a46d16c080de1034db41b53abf483bdb88.zip
bc: code shrink: combine init() and copy() where we can
function old new delta bc_num_init_and_copy - 27 +27 zxc_program_popResultAndCopyToVar 495 483 -12 zxc_num_printNum 518 506 -12 zbc_num_p 518 506 -12 zxc_program_assign 357 341 -16 zbc_num_m 298 267 -31 zxc_vm_process 6498 6412 -86 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/6 up/down: 27/-169) Total: -142 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 930baaaaa..e12a20aec 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -1386,6 +1386,12 @@ static void bc_num_copy(BcNum *d, BcNum *s)
1386 } 1386 }
1387} 1387}
1388 1388
1389static void bc_num_init_and_copy(BcNum *d, BcNum *s)
1390{
1391 bc_num_init(d, s->len);
1392 bc_num_copy(d, s);
1393}
1394
1389static BC_STATUS zbc_num_ulong_abs(BcNum *n, unsigned long *result_p) 1395static BC_STATUS zbc_num_ulong_abs(BcNum *n, unsigned long *result_p)
1390{ 1396{
1391 size_t i; 1397 size_t i;
@@ -1985,11 +1991,8 @@ static FAST_FUNC BC_STATUS zbc_num_m(BcNum *a, BcNum *b, BcNum *restrict c, size
1985 scale = BC_MIN(a->rdx + b->rdx, scale); 1991 scale = BC_MIN(a->rdx + b->rdx, scale);
1986 maxrdx = BC_MAX(maxrdx, scale); 1992 maxrdx = BC_MAX(maxrdx, scale);
1987 1993
1988 bc_num_init(&cpa, a->len); 1994 bc_num_init_and_copy(&cpa, a);
1989 bc_num_init(&cpb, b->len); 1995 bc_num_init_and_copy(&cpb, b);
1990
1991 bc_num_copy(&cpa, a);
1992 bc_num_copy(&cpb, b);
1993 cpa.neg = cpb.neg = false; 1996 cpa.neg = cpb.neg = false;
1994 1997
1995 s = zbc_num_shift(&cpa, maxrdx); 1998 s = zbc_num_shift(&cpa, maxrdx);
@@ -2181,8 +2184,7 @@ static FAST_FUNC BC_STATUS zbc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size
2181 if (s) RETURN_STATUS(s); 2184 if (s) RETURN_STATUS(s);
2182 // b is not used beyond this point 2185 // b is not used beyond this point
2183 2186
2184 bc_num_init(&copy, a->len); 2187 bc_num_init_and_copy(&copy, a);
2185 bc_num_copy(&copy, a);
2186 a_rdx = a->rdx; // pull it into a CPU register (hopefully) 2188 a_rdx = a->rdx; // pull it into a CPU register (hopefully)
2187 // a is not used beyond this point 2189 // a is not used beyond this point
2188 2190
@@ -2508,8 +2510,7 @@ static void bc_array_copy(BcVec *d, const BcVec *s)
2508 dnum = (void*)d->v; 2510 dnum = (void*)d->v;
2509 snum = (void*)s->v; 2511 snum = (void*)s->v;
2510 for (i = 0; i < s->len; i++, dnum++, snum++) { 2512 for (i = 0; i < s->len; i++, dnum++, snum++) {
2511 bc_num_init(dnum, snum->len); 2513 bc_num_init_and_copy(dnum, snum);
2512 bc_num_copy(dnum, snum);
2513 } 2514 }
2514} 2515}
2515 2516
@@ -2523,8 +2524,7 @@ static void dc_result_copy(BcResult *d, BcResult *src)
2523 case XC_RESULT_IBASE: 2524 case XC_RESULT_IBASE:
2524 case XC_RESULT_SCALE: 2525 case XC_RESULT_SCALE:
2525 case XC_RESULT_OBASE: 2526 case XC_RESULT_OBASE:
2526 bc_num_init(&d->d.n, src->d.n.len); 2527 bc_num_init_and_copy(&d->d.n, &src->d.n);
2527 bc_num_copy(&d->d.n, &src->d.n);
2528 break; 2528 break;
2529 case XC_RESULT_VAR: 2529 case XC_RESULT_VAR:
2530 case XC_RESULT_ARRAY: 2530 case XC_RESULT_ARRAY:
@@ -5626,11 +5626,10 @@ static BC_STATUS zxc_num_printNum(BcNum *n, unsigned base_t, size_t width, BcNum
5626 } 5626 }
5627 5627
5628 bc_vec_init(&stack, sizeof(long), NULL); 5628 bc_vec_init(&stack, sizeof(long), NULL);
5629 bc_num_init(&intp, n->len); 5629 bc_num_init_and_copy(&intp, n);
5630 bc_num_init(&fracp, n->rdx); 5630 bc_num_init(&fracp, n->rdx);
5631 bc_num_init(&digit, width); 5631 bc_num_init(&digit, width);
5632 bc_num_init(&frac_len, BC_NUM_INT(n)); 5632 bc_num_init(&frac_len, BC_NUM_INT(n));
5633 bc_num_copy(&intp, n);
5634 bc_num_one(&frac_len); 5633 bc_num_one(&frac_len);
5635 base.cap = ARRAY_SIZE(base_digs); 5634 base.cap = ARRAY_SIZE(base_digs);
5636 base.num = base_digs; 5635 base.num = base_digs;
@@ -5799,8 +5798,7 @@ static BC_STATUS zxc_program_negate(void)
5799 s = zxc_program_prep(&ptr, &num); 5798 s = zxc_program_prep(&ptr, &num);
5800 if (s) RETURN_STATUS(s); 5799 if (s) RETURN_STATUS(s);
5801 5800
5802 bc_num_init(&res.d.n, num->len); 5801 bc_num_init_and_copy(&res.d.n, num);
5803 bc_num_copy(&res.d.n, num);
5804 if (res.d.n.len) res.d.n.neg = !res.d.n.neg; 5802 if (res.d.n.len) res.d.n.neg = !res.d.n.neg;
5805 5803
5806 xc_program_retire(&res, XC_RESULT_TEMP); 5804 xc_program_retire(&res, XC_RESULT_TEMP);
@@ -6039,8 +6037,7 @@ static BC_STATUS zxc_program_assign(char inst)
6039 s = BC_STATUS_SUCCESS; 6037 s = BC_STATUS_SUCCESS;
6040 } 6038 }
6041 6039
6042 bc_num_init(&res.d.n, l->len); 6040 bc_num_init_and_copy(&res.d.n, l);
6043 bc_num_copy(&res.d.n, l);
6044 xc_program_binOpRetire(&res); 6041 xc_program_binOpRetire(&res);
6045 6042
6046 RETURN_STATUS(s); 6043 RETURN_STATUS(s);
@@ -6137,8 +6134,7 @@ static BC_STATUS zbc_program_incdec(char inst)
6137 6134
6138 if (inst == BC_INST_INC_POST || inst == BC_INST_DEC_POST) { 6135 if (inst == BC_INST_INC_POST || inst == BC_INST_DEC_POST) {
6139 copy.t = XC_RESULT_TEMP; 6136 copy.t = XC_RESULT_TEMP;
6140 bc_num_init(&copy.d.n, num->len); 6137 bc_num_init_and_copy(&copy.d.n, num);
6141 bc_num_copy(&copy.d.n, num);
6142 } 6138 }
6143 6139
6144 res.t = BC_RESULT_ONE; 6140 res.t = BC_RESULT_ONE;
@@ -6240,8 +6236,7 @@ static BC_STATUS zbc_program_return(char inst)
6240 6236
6241 s = zxc_program_num(operand, &num); 6237 s = zxc_program_num(operand, &num);
6242 if (s) RETURN_STATUS(s); 6238 if (s) RETURN_STATUS(s);
6243 bc_num_init(&res.d.n, num->len); 6239 bc_num_init_and_copy(&res.d.n, num);
6244 bc_num_copy(&res.d.n, num);
6245 bc_vec_pop(&G.prog.results); 6240 bc_vec_pop(&G.prog.results);
6246 } else { 6241 } else {
6247 if (f->voidfunc) 6242 if (f->voidfunc)