bc: make all function pointers FAST_FUNC, on i486 this saves ~400 bytes

function                                             old     new   delta
bc_num_rem                                            91      95      +4
bc_num_inv                                            53      56      +3
bc_num_d                                             569     572      +3
bc_num_printDigits                                   136     137      +1
bc_program_assign                                    486     485      -1
dc_lex_token                                         684     682      -2
bc_vec_pop                                            27      25      -2
bc_vec_npop                                           55      53      -2
bc_program_read                                      335     333      -2
bc_program_print                                     713     711      -2
bc_parse_parse                                       462     460      -2
bc_lex_token                                        1280    1278      -2
bc_num_printChar                                      27      24      -3
bc_num_binary                                        150     147      -3
dc_parse_parse                                        59      55      -4
bc_vm_run                                            630     626      -4
bc_num_printHex                                       71      67      -4
bc_num_divmod                                        155     150      -5
bc_vec_free                                           24      18      -6
bc_string_free                                        15       9      -6
bc_num_free                                           15       9      -6
bc_id_free                                            15       9      -6
bc_parse_free                                         53      46      -7
bc_program_scale                                       8       -      -8
bc_num_r                                             245     237      -8
bc_func_free                                          35      27      -8
bc_result_free                                        57      46     -11
bc_num_a                                             454     443     -11
bc_num_sub                                            77      65     -12
bc_num_add                                            77      65     -12
bc_program_modexp                                    736     723     -13
bc_num_s                                             252     239     -13
bc_num_mul                                            62      49     -13
bc_num_mod                                            62      49     -13
bc_num_div                                            62      49     -13
bc_num_pow                                            47      31     -16
bc_program_exec                                     4081    4059     -22
bc_num_printNum                                      514     489     -25
bc_num_p                                             478     445     -33
bc_program_len                                        34       -     -34
bc_program_num                                       963     925     -38
bc_num_k                                             988     944     -44
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 4/36 up/down: 11/-416)         Total: -405 bytes
   text	   data	    bss	    dec	    hex	filename
 984536	    485	   7296	 992317	  f243d	busybox_old
 984131	    485	   7296	 991912	  f22a8	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2018-12-10 15:37:14 +01:00
parent c665c183f1
commit 5ba55f1f35

View File

@ -193,7 +193,7 @@ typedef enum BcStatus {
#define BC_VEC_INVALID_IDX ((size_t) -1)
#define BC_VEC_START_CAP (1 << 5)
typedef void (*BcVecFree)(void *);
typedef void (*BcVecFree)(void *) FAST_FUNC;
typedef struct BcVec {
char *v;
@ -221,16 +221,16 @@ typedef struct BcNum {
#define BC_NUM_KARATSUBA_LEN (32)
typedef void (*BcNumDigitOp)(size_t, size_t, bool);
typedef void (*BcNumDigitOp)(size_t, size_t, bool) FAST_FUNC;
typedef BcStatus (*BcNumBinaryOp)(BcNum *, BcNum *, BcNum *, size_t);
typedef BcStatus (*BcNumBinaryOp)(BcNum *, BcNum *, BcNum *, size_t) FAST_FUNC;
static BcStatus bc_num_add(BcNum *a, BcNum *b, BcNum *c, size_t scale);
static BcStatus bc_num_sub(BcNum *a, BcNum *b, BcNum *c, size_t scale);
static BcStatus bc_num_mul(BcNum *a, BcNum *b, BcNum *c, size_t scale);
static BcStatus bc_num_div(BcNum *a, BcNum *b, BcNum *c, size_t scale);
static BcStatus bc_num_mod(BcNum *a, BcNum *b, BcNum *c, size_t scale);
static BcStatus bc_num_pow(BcNum *a, BcNum *b, BcNum *c, size_t scale);
static BcStatus bc_num_add(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC;
static BcStatus bc_num_sub(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC;
static BcStatus bc_num_mul(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC;
static BcStatus bc_num_div(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC;
static BcStatus bc_num_mod(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC;
static BcStatus bc_num_pow(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC;
static BcStatus bc_num_sqrt(BcNum *a, BcNum *b, size_t scale);
static BcStatus bc_num_divmod(BcNum *a, BcNum *b, BcNum *c, BcNum *d,
size_t scale);
@ -559,7 +559,7 @@ enum {
#endif
struct BcLex;
typedef BcStatus (*BcLexNext)(struct BcLex *);
typedef BcStatus (*BcLexNext)(struct BcLex *) FAST_FUNC;
typedef struct BcLex {
@ -626,7 +626,7 @@ struct BcParse;
struct BcProgram;
typedef BcStatus (*BcParseParse)(struct BcParse *);
typedef BcStatus (*BcParseParse)(struct BcParse *) FAST_FUNC;
typedef struct BcParse {
@ -702,8 +702,6 @@ typedef struct BcProgram {
#define BC_PROG_NUM(r, n) \
((r)->t != BC_RESULT_ARRAY && (r)->t != BC_RESULT_STR && !BC_PROG_STR(n))
typedef unsigned long (*BcProgramBuiltIn)(BcNum *);
#define BC_FLAG_W (1 << 0)
#define BC_FLAG_V (1 << 1)
#define BC_FLAG_S (1 << 2)
@ -1203,7 +1201,7 @@ static void *bc_vec_top(const BcVec *v)
return v->v + v->size * (v->len - 1);
}
static void bc_vec_free(void *vec)
static FAST_FUNC void bc_vec_free(void *vec)
{
BcVec *v = (BcVec *) vec;
bc_vec_pop_all(v);
@ -1215,7 +1213,7 @@ static int bc_id_cmp(const void *e1, const void *e2)
return strcmp(((const BcId *) e1)->name, ((const BcId *) e2)->name);
}
static void bc_id_free(void *id)
static FAST_FUNC void bc_id_free(void *id)
{
free(((BcId *) id)->name);
}
@ -1426,7 +1424,7 @@ static void bc_num_expand(BcNum *n, size_t req)
}
}
static void bc_num_free(void *num)
static FAST_FUNC void bc_num_free(void *num)
{
free(((BcNum *) num)->num);
}
@ -1675,7 +1673,7 @@ static BcStatus bc_num_inv(BcNum *a, BcNum *b, size_t scale)
return bc_num_div(&one, a, b, scale);
}
static BcStatus bc_num_a(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub)
static FAST_FUNC BcStatus bc_num_a(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub)
{
BcDig *ptr, *ptr_a, *ptr_b, *ptr_c;
size_t i, max, min_rdx, min_int, diff, a_int, b_int;
@ -1746,7 +1744,7 @@ static BcStatus bc_num_a(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub)
return BC_STATUS_SUCCESS; // can't make void, see bc_num_binary()
}
static BcStatus bc_num_s(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub)
static FAST_FUNC BcStatus bc_num_s(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub)
{
ssize_t cmp;
BcNum *minuend, *subtrahend;
@ -1808,7 +1806,7 @@ static BcStatus bc_num_s(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub)
return BC_STATUS_SUCCESS; // can't make void, see bc_num_binary()
}
static BcStatus bc_num_k(BcNum *restrict a, BcNum *restrict b,
static FAST_FUNC BcStatus bc_num_k(BcNum *restrict a, BcNum *restrict b,
BcNum *restrict c)
{
BcStatus s;
@ -1914,7 +1912,7 @@ err:
return s;
}
static BcStatus bc_num_m(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
static FAST_FUNC BcStatus bc_num_m(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
{
BcStatus s;
BcNum cpa, cpb;
@ -1956,7 +1954,7 @@ err:
return s;
}
static BcStatus bc_num_d(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
static FAST_FUNC BcStatus bc_num_d(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
{
BcStatus s = BC_STATUS_SUCCESS;
BcDig *n, *p, q;
@ -2028,7 +2026,7 @@ static BcStatus bc_num_d(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
return s;
}
static BcStatus bc_num_r(BcNum *a, BcNum *b, BcNum *restrict c,
static FAST_FUNC BcStatus bc_num_r(BcNum *a, BcNum *b, BcNum *restrict c,
BcNum *restrict d, size_t scale, size_t ts)
{
BcStatus s;
@ -2065,7 +2063,7 @@ err:
return s;
}
static BcStatus bc_num_rem(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
static FAST_FUNC BcStatus bc_num_rem(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
{
BcStatus s;
BcNum c1;
@ -2078,7 +2076,7 @@ static BcStatus bc_num_rem(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
return s;
}
static BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
static FAST_FUNC BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
{
BcStatus s = BC_STATUS_SUCCESS;
BcNum copy;
@ -2216,7 +2214,7 @@ static void bc_num_printNewline(void)
}
#if ENABLE_DC
static void bc_num_printChar(size_t num, size_t width, bool radix)
static FAST_FUNC void bc_num_printChar(size_t num, size_t width, bool radix)
{
(void) radix;
bb_putchar((char) num);
@ -2224,7 +2222,7 @@ static void bc_num_printChar(size_t num, size_t width, bool radix)
}
#endif
static void bc_num_printDigits(size_t num, size_t width, bool radix)
static FAST_FUNC void bc_num_printDigits(size_t num, size_t width, bool radix)
{
size_t exp, pow;
@ -2245,7 +2243,7 @@ static void bc_num_printDigits(size_t num, size_t width, bool radix)
}
}
static void bc_num_printHex(size_t num, size_t width, bool radix)
static FAST_FUNC void bc_num_printHex(size_t num, size_t width, bool radix)
{
if (radix) {
bc_num_printNewline();
@ -2542,39 +2540,39 @@ static BcStatus bc_num_print(BcNum *n, bool newline)
return s;
}
static BcStatus bc_num_add(BcNum *a, BcNum *b, BcNum *c, size_t scale)
static FAST_FUNC BcStatus bc_num_add(BcNum *a, BcNum *b, BcNum *c, size_t scale)
{
BcNumBinaryOp op = (!a->neg == !b->neg) ? bc_num_a : bc_num_s;
(void) scale;
return bc_num_binary(a, b, c, false, op, BC_NUM_AREQ(a, b));
}
static BcStatus bc_num_sub(BcNum *a, BcNum *b, BcNum *c, size_t scale)
static FAST_FUNC BcStatus bc_num_sub(BcNum *a, BcNum *b, BcNum *c, size_t scale)
{
BcNumBinaryOp op = (!a->neg == !b->neg) ? bc_num_s : bc_num_a;
(void) scale;
return bc_num_binary(a, b, c, true, op, BC_NUM_AREQ(a, b));
}
static BcStatus bc_num_mul(BcNum *a, BcNum *b, BcNum *c, size_t scale)
static FAST_FUNC BcStatus bc_num_mul(BcNum *a, BcNum *b, BcNum *c, size_t scale)
{
size_t req = BC_NUM_MREQ(a, b, scale);
return bc_num_binary(a, b, c, scale, bc_num_m, req);
}
static BcStatus bc_num_div(BcNum *a, BcNum *b, BcNum *c, size_t scale)
static FAST_FUNC BcStatus bc_num_div(BcNum *a, BcNum *b, BcNum *c, size_t scale)
{
size_t req = BC_NUM_MREQ(a, b, scale);
return bc_num_binary(a, b, c, scale, bc_num_d, req);
}
static BcStatus bc_num_mod(BcNum *a, BcNum *b, BcNum *c, size_t scale)
static FAST_FUNC BcStatus bc_num_mod(BcNum *a, BcNum *b, BcNum *c, size_t scale)
{
size_t req = BC_NUM_MREQ(a, b, scale);
return bc_num_binary(a, b, c, scale, bc_num_rem, req);
}
static BcStatus bc_num_pow(BcNum *a, BcNum *b, BcNum *c, size_t scale)
static FAST_FUNC BcStatus bc_num_pow(BcNum *a, BcNum *b, BcNum *c, size_t scale)
{
return bc_num_binary(a, b, c, scale, bc_num_p, a->len * b->len + 1);
}
@ -2789,7 +2787,7 @@ static void bc_func_init(BcFunc *f)
f->nparams = 0;
}
static void bc_func_free(void *func)
static FAST_FUNC void bc_func_free(void *func)
{
BcFunc *f = (BcFunc *) func;
bc_vec_free(&f->code);
@ -2841,7 +2839,7 @@ static void bc_array_copy(BcVec *d, const BcVec *s)
}
}
static void bc_string_free(void *string)
static FAST_FUNC void bc_string_free(void *string)
{
free(*((char **) string));
}
@ -2883,7 +2881,7 @@ static void bc_result_copy(BcResult *d, BcResult *src)
}
#endif // ENABLE_DC
static void bc_result_free(void *result)
static FAST_FUNC void bc_result_free(void *result)
{
BcResult *r = (BcResult *) result;
@ -3171,7 +3169,7 @@ static BcStatus bc_lex_comment(BcLex *l)
return BC_STATUS_SUCCESS;
}
static BcStatus bc_lex_token(BcLex *l)
static FAST_FUNC BcStatus bc_lex_token(BcLex *l)
{
BcStatus s = BC_STATUS_SUCCESS;
char c = l->buf[l->i++], c2;
@ -3511,7 +3509,7 @@ static BcStatus dc_lex_string(BcLex *l)
return BC_STATUS_SUCCESS;
}
static BcStatus dc_lex_token(BcLex *l)
static FAST_FUNC BcStatus dc_lex_token(BcLex *l)
{
BcStatus s = BC_STATUS_SUCCESS;
char c = l->buf[l->i++], c2;
@ -4826,7 +4824,7 @@ static BcStatus bc_parse_stmt(BcParse *p)
return s;
}
static BcStatus bc_parse_parse(BcParse *p)
static FAST_FUNC BcStatus bc_parse_parse(BcParse *p)
{
BcStatus s;
@ -5333,7 +5331,7 @@ static BcStatus dc_parse_expr(BcParse *p, uint8_t flags)
return s;
}
static BcStatus dc_parse_parse(BcParse *p)
static FAST_FUNC BcStatus dc_parse_parse(BcParse *p)
{
BcStatus s;
@ -6305,8 +6303,7 @@ static BcStatus bc_program_builtin(char inst)
}
#endif
else {
BcProgramBuiltIn f = len ? bc_program_len : bc_program_scale;
bc_num_ulong2num(&res.d.n, f(num));
bc_num_ulong2num(&res.d.n, len ? bc_program_len(num) : bc_program_scale(num));
}
bc_program_retire(&res, BC_RESULT_TEMP);