bc: add and use bc_num_init_DEF_SIZE()

function                                             old     new   delta
bc_num_init_DEF_SIZE                                   -      10     +10
bc_num_binary                                        150     148      -2
bc_program_pushVar                                   208     203      -5
bc_program_modexp                                    741     736      -5
bc_program_copyToVar                                 316     311      -5
bc_program_call                                      352     347      -5
bc_array_expand                                       88      83      -5
bc_program_num                                      1125    1115     -10
bc_vm_init                                           821     786     -35
bc_program_exec                                     4152    4098     -54
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/9 up/down: 10/-126)          Total: -116 bytes
   text	   data	    bss	    dec	    hex	filename
 985988	    477	   7296	 993761	  f29e1	busybox_old
 985872	    477	   7296	 993645	  f296d	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2018-12-09 11:44:20 +01:00
parent 5ec4b49125
commit e20e00de34

View File

@ -1407,6 +1407,11 @@ static void bc_num_init(BcNum *n, size_t req)
n->cap = req; n->cap = req;
} }
static void bc_num_init_DEF_SIZE(BcNum *n)
{
bc_num_init(n, BC_NUM_DEF_SIZE);
}
static void bc_num_expand(BcNum *n, size_t req) static void bc_num_expand(BcNum *n, size_t req)
{ {
req = req >= BC_NUM_DEF_SIZE ? req : BC_NUM_DEF_SIZE; req = req >= BC_NUM_DEF_SIZE ? req : BC_NUM_DEF_SIZE;
@ -2260,8 +2265,8 @@ static void bc_num_parseBase(BcNum *n, const char *val, BcNum *base)
for (i = 0; zero && i < len; ++i) zero = (val[i] == '.' || val[i] == '0'); for (i = 0; zero && i < len; ++i) zero = (val[i] == '.' || val[i] == '0');
if (zero) return; if (zero) return;
bc_num_init(&temp, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&temp);
bc_num_init(&mult, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&mult);
for (i = 0; i < len; ++i) { for (i = 0; i < len; ++i) {
@ -2584,7 +2589,7 @@ static BcStatus bc_num_sqrt(BcNum *a, BcNum *restrict b, size_t scale)
bc_num_init(&num1, len); bc_num_init(&num1, len);
bc_num_init(&num2, len); bc_num_init(&num2, len);
bc_num_init(&half, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&half);
bc_num_one(&half); bc_num_one(&half);
half.num[0] = 5; half.num[0] = 5;
@ -2701,7 +2706,7 @@ static BcStatus bc_num_modexp(BcNum *a, BcNum *b, BcNum *c, BcNum *restrict d)
bc_num_expand(d, c->len); bc_num_expand(d, c->len);
bc_num_init(&base, c->len); bc_num_init(&base, c->len);
bc_num_init(&exp, b->len); bc_num_init(&exp, b->len);
bc_num_init(&two, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&two);
bc_num_init(&temp, b->len); bc_num_init(&temp, b->len);
bc_num_one(&two); bc_num_one(&two);
@ -2792,7 +2797,7 @@ static void bc_array_expand(BcVec *a, size_t len)
if (a->size == sizeof(BcNum) && a->dtor == bc_num_free) { if (a->size == sizeof(BcNum) && a->dtor == bc_num_free) {
while (len > a->len) { while (len > a->len) {
bc_num_init(&data.n, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&data.n);
bc_vec_push(a, &data.n); bc_vec_push(a, &data.n);
} }
} }
@ -5530,7 +5535,7 @@ static BcStatus bc_program_op(char inst)
s = bc_program_binOpPrep(&opd1, &n1, &opd2, &n2, false); s = bc_program_binOpPrep(&opd1, &n1, &opd2, &n2, false);
if (s) return s; if (s) return s;
bc_num_init(&res.d.n, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&res.d.n);
s = bc_program_ops[inst - BC_INST_POWER](n1, n2, &res.d.n, G.prog.scale); s = bc_program_ops[inst - BC_INST_POWER](n1, n2, &res.d.n, G.prog.scale);
if (s) goto err; if (s) goto err;
@ -5784,7 +5789,7 @@ static BcStatus bc_program_logical(char inst)
s = bc_program_binOpPrep(&opd1, &n1, &opd2, &n2, false); s = bc_program_binOpPrep(&opd1, &n1, &opd2, &n2, false);
if (s) return s; if (s) return s;
bc_num_init(&res.d.n, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&res.d.n);
if (inst == BC_INST_BOOL_AND) if (inst == BC_INST_BOOL_AND)
cond = bc_num_cmp(n1, &G.prog.zero) && bc_num_cmp(n2, &G.prog.zero); cond = bc_num_cmp(n1, &G.prog.zero) && bc_num_cmp(n2, &G.prog.zero);
@ -5896,7 +5901,7 @@ static BcStatus bc_program_copyToVar(char *name, bool var)
v = bc_program_search(name, var); v = bc_program_search(name, var);
if (var) { if (var) {
bc_num_init(&r.d.n, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&r.d.n);
bc_num_copy(&r.d.n, n); bc_num_copy(&r.d.n, n);
} }
else { else {
@ -6035,7 +6040,7 @@ static BcStatus bc_program_pushVar(char *code, size_t *bgn,
r.t = BC_RESULT_TEMP; r.t = BC_RESULT_TEMP;
bc_num_init(&r.d.n, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&r.d.n);
bc_num_copy(&r.d.n, num); bc_num_copy(&r.d.n, num);
} }
else { else {
@ -6164,7 +6169,7 @@ static BcStatus bc_program_call(char *code, size_t *idx)
v = bc_program_search(a->name, a->idx); v = bc_program_search(a->name, a->idx);
if (a->idx) { if (a->idx) {
bc_num_init(&param.n, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&param.n);
bc_vec_push(v, &param.n); bc_vec_push(v, &param.n);
} }
else { else {
@ -6203,7 +6208,7 @@ static BcStatus bc_program_return(char inst)
bc_num_copy(&res.d.n, num); bc_num_copy(&res.d.n, num);
} }
else { else {
bc_num_init(&res.d.n, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&res.d.n);
bc_num_zero(&res.d.n); bc_num_zero(&res.d.n);
} }
@ -6261,7 +6266,7 @@ static BcStatus bc_program_builtin(char inst)
return bc_error_variable_is_wrong_type(); return bc_error_variable_is_wrong_type();
#endif #endif
bc_num_init(&res.d.n, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&res.d.n);
if (inst == BC_INST_SQRT) s = bc_num_sqrt(num, &res.d.n, G.prog.scale); if (inst == BC_INST_SQRT) s = bc_num_sqrt(num, &res.d.n, G.prog.scale);
#if ENABLE_BC #if ENABLE_BC
@ -6299,7 +6304,7 @@ static BcStatus bc_program_divmod(void)
s = bc_program_binOpPrep(&opd1, &n1, &opd2, &n2, false); s = bc_program_binOpPrep(&opd1, &n1, &opd2, &n2, false);
if (s) return s; if (s) return s;
bc_num_init(&res.d.n, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&res.d.n);
bc_num_init(&res2.d.n, n2->len); bc_num_init(&res2.d.n, n2->len);
s = bc_num_divmod(n1, n2, &res2.d.n, &res.d.n, G.prog.scale); s = bc_num_divmod(n1, n2, &res2.d.n, &res.d.n, G.prog.scale);
@ -6369,7 +6374,7 @@ static void bc_program_stackLen(void)
res.t = BC_RESULT_TEMP; res.t = BC_RESULT_TEMP;
bc_num_init(&res.d.n, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&res.d.n);
bc_num_ulong2num(&res.d.n, len); bc_num_ulong2num(&res.d.n, len);
bc_vec_push(&G.prog.results, &res); bc_vec_push(&G.prog.results, &res);
} }
@ -6392,7 +6397,7 @@ static BcStatus bc_program_asciify(void)
if (BC_PROG_NUM(r, num)) { if (BC_PROG_NUM(r, num)) {
bc_num_init(&n, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&n);
bc_num_copy(&n, num); bc_num_copy(&n, num);
bc_num_truncate(&n, n.rdx); bc_num_truncate(&n, n.rdx);
@ -6610,7 +6615,7 @@ static void bc_program_pushGlobal(char inst)
else else
val = (unsigned long) G.prog.ob_t; val = (unsigned long) G.prog.ob_t;
bc_num_init(&res.d.n, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&res.d.n);
bc_num_ulong2num(&res.d.n, val); bc_num_ulong2num(&res.d.n, val);
bc_vec_push(&G.prog.results, &res); bc_vec_push(&G.prog.results, &res);
} }
@ -6760,7 +6765,7 @@ static BcStatus bc_program_exec(void)
case BC_INST_BOOL_NOT: case BC_INST_BOOL_NOT:
s = bc_program_prep(&ptr, &num); s = bc_program_prep(&ptr, &num);
if (s) return s; if (s) return s;
bc_num_init(&r.d.n, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&r.d.n);
if (!bc_num_cmp(num, &G.prog.zero)) if (!bc_num_cmp(num, &G.prog.zero))
bc_num_one(&r.d.n); bc_num_one(&r.d.n);
else else
@ -7356,31 +7361,30 @@ static void bc_program_init(void)
memset(&ip, 0, sizeof(BcInstPtr)); memset(&ip, 0, sizeof(BcInstPtr));
/* G.prog.nchars = G.prog.scale = 0; - already is */ /* G.prog.nchars = G.prog.scale = 0; - already is */
bc_num_init_DEF_SIZE(&G.prog.ib);
bc_num_init(&G.prog.ib, BC_NUM_DEF_SIZE);
bc_num_ten(&G.prog.ib); bc_num_ten(&G.prog.ib);
G.prog.ib_t = 10; G.prog.ib_t = 10;
bc_num_init(&G.prog.ob, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&G.prog.ob);
bc_num_ten(&G.prog.ob); bc_num_ten(&G.prog.ob);
G.prog.ob_t = 10; G.prog.ob_t = 10;
bc_num_init(&G.prog.hexb, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&G.prog.hexb);
bc_num_ten(&G.prog.hexb); bc_num_ten(&G.prog.hexb);
G.prog.hexb.num[0] = 6; G.prog.hexb.num[0] = 6;
#if ENABLE_DC #if ENABLE_DC
bc_num_init(&G.prog.strmb, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&G.prog.strmb);
bc_num_ulong2num(&G.prog.strmb, UCHAR_MAX + 1); bc_num_ulong2num(&G.prog.strmb, UCHAR_MAX + 1);
#endif #endif
bc_num_init(&G.prog.last, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&G.prog.last);
bc_num_zero(&G.prog.last); bc_num_zero(&G.prog.last);
bc_num_init(&G.prog.zero, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&G.prog.zero);
bc_num_zero(&G.prog.zero); bc_num_zero(&G.prog.zero);
bc_num_init(&G.prog.one, BC_NUM_DEF_SIZE); bc_num_init_DEF_SIZE(&G.prog.one);
bc_num_one(&G.prog.one); bc_num_one(&G.prog.one);
bc_vec_init(&G.prog.fns, sizeof(BcFunc), bc_func_free); bc_vec_init(&G.prog.fns, sizeof(BcFunc), bc_func_free);