aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-10 15:37:14 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-10 15:37:14 +0100
commit5ba55f1f356f3521d2b366d6d7af60c5e05563a8 (patch)
treeb0508c37254dfe7358a19311ca093c074657544e
parentc665c183f15f4246da3d44fba92883ef05fc98af (diff)
downloadbusybox-w32-5ba55f1f356f3521d2b366d6d7af60c5e05563a8.tar.gz
busybox-w32-5ba55f1f356f3521d2b366d6d7af60c5e05563a8.tar.bz2
busybox-w32-5ba55f1f356f3521d2b366d6d7af60c5e05563a8.zip
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>
-rw-r--r--miscutils/bc.c81
1 files changed, 39 insertions, 42 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 9774ac45b..7ed6dd91d 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -193,7 +193,7 @@ typedef enum BcStatus {
193#define BC_VEC_INVALID_IDX ((size_t) -1) 193#define BC_VEC_INVALID_IDX ((size_t) -1)
194#define BC_VEC_START_CAP (1 << 5) 194#define BC_VEC_START_CAP (1 << 5)
195 195
196typedef void (*BcVecFree)(void *); 196typedef void (*BcVecFree)(void *) FAST_FUNC;
197 197
198typedef struct BcVec { 198typedef struct BcVec {
199 char *v; 199 char *v;
@@ -221,16 +221,16 @@ typedef struct BcNum {
221 221
222#define BC_NUM_KARATSUBA_LEN (32) 222#define BC_NUM_KARATSUBA_LEN (32)
223 223
224typedef void (*BcNumDigitOp)(size_t, size_t, bool); 224typedef void (*BcNumDigitOp)(size_t, size_t, bool) FAST_FUNC;
225 225
226typedef BcStatus (*BcNumBinaryOp)(BcNum *, BcNum *, BcNum *, size_t); 226typedef BcStatus (*BcNumBinaryOp)(BcNum *, BcNum *, BcNum *, size_t) FAST_FUNC;
227 227
228static BcStatus bc_num_add(BcNum *a, BcNum *b, BcNum *c, size_t scale); 228static BcStatus bc_num_add(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC;
229static BcStatus bc_num_sub(BcNum *a, BcNum *b, BcNum *c, size_t scale); 229static BcStatus bc_num_sub(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC;
230static BcStatus bc_num_mul(BcNum *a, BcNum *b, BcNum *c, size_t scale); 230static BcStatus bc_num_mul(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC;
231static BcStatus bc_num_div(BcNum *a, BcNum *b, BcNum *c, size_t scale); 231static BcStatus bc_num_div(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC;
232static BcStatus bc_num_mod(BcNum *a, BcNum *b, BcNum *c, size_t scale); 232static BcStatus bc_num_mod(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC;
233static BcStatus bc_num_pow(BcNum *a, BcNum *b, BcNum *c, size_t scale); 233static BcStatus bc_num_pow(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC;
234static BcStatus bc_num_sqrt(BcNum *a, BcNum *b, size_t scale); 234static BcStatus bc_num_sqrt(BcNum *a, BcNum *b, size_t scale);
235static BcStatus bc_num_divmod(BcNum *a, BcNum *b, BcNum *c, BcNum *d, 235static BcStatus bc_num_divmod(BcNum *a, BcNum *b, BcNum *c, BcNum *d,
236 size_t scale); 236 size_t scale);
@@ -559,7 +559,7 @@ enum {
559#endif 559#endif
560 560
561struct BcLex; 561struct BcLex;
562typedef BcStatus (*BcLexNext)(struct BcLex *); 562typedef BcStatus (*BcLexNext)(struct BcLex *) FAST_FUNC;
563 563
564typedef struct BcLex { 564typedef struct BcLex {
565 565
@@ -626,7 +626,7 @@ struct BcParse;
626 626
627struct BcProgram; 627struct BcProgram;
628 628
629typedef BcStatus (*BcParseParse)(struct BcParse *); 629typedef BcStatus (*BcParseParse)(struct BcParse *) FAST_FUNC;
630 630
631typedef struct BcParse { 631typedef struct BcParse {
632 632
@@ -702,8 +702,6 @@ typedef struct BcProgram {
702#define BC_PROG_NUM(r, n) \ 702#define BC_PROG_NUM(r, n) \
703 ((r)->t != BC_RESULT_ARRAY && (r)->t != BC_RESULT_STR && !BC_PROG_STR(n)) 703 ((r)->t != BC_RESULT_ARRAY && (r)->t != BC_RESULT_STR && !BC_PROG_STR(n))
704 704
705typedef unsigned long (*BcProgramBuiltIn)(BcNum *);
706
707#define BC_FLAG_W (1 << 0) 705#define BC_FLAG_W (1 << 0)
708#define BC_FLAG_V (1 << 1) 706#define BC_FLAG_V (1 << 1)
709#define BC_FLAG_S (1 << 2) 707#define BC_FLAG_S (1 << 2)
@@ -1203,7 +1201,7 @@ static void *bc_vec_top(const BcVec *v)
1203 return v->v + v->size * (v->len - 1); 1201 return v->v + v->size * (v->len - 1);
1204} 1202}
1205 1203
1206static void bc_vec_free(void *vec) 1204static FAST_FUNC void bc_vec_free(void *vec)
1207{ 1205{
1208 BcVec *v = (BcVec *) vec; 1206 BcVec *v = (BcVec *) vec;
1209 bc_vec_pop_all(v); 1207 bc_vec_pop_all(v);
@@ -1215,7 +1213,7 @@ static int bc_id_cmp(const void *e1, const void *e2)
1215 return strcmp(((const BcId *) e1)->name, ((const BcId *) e2)->name); 1213 return strcmp(((const BcId *) e1)->name, ((const BcId *) e2)->name);
1216} 1214}
1217 1215
1218static void bc_id_free(void *id) 1216static FAST_FUNC void bc_id_free(void *id)
1219{ 1217{
1220 free(((BcId *) id)->name); 1218 free(((BcId *) id)->name);
1221} 1219}
@@ -1426,7 +1424,7 @@ static void bc_num_expand(BcNum *n, size_t req)
1426 } 1424 }
1427} 1425}
1428 1426
1429static void bc_num_free(void *num) 1427static FAST_FUNC void bc_num_free(void *num)
1430{ 1428{
1431 free(((BcNum *) num)->num); 1429 free(((BcNum *) num)->num);
1432} 1430}
@@ -1675,7 +1673,7 @@ static BcStatus bc_num_inv(BcNum *a, BcNum *b, size_t scale)
1675 return bc_num_div(&one, a, b, scale); 1673 return bc_num_div(&one, a, b, scale);
1676} 1674}
1677 1675
1678static BcStatus bc_num_a(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub) 1676static FAST_FUNC BcStatus bc_num_a(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub)
1679{ 1677{
1680 BcDig *ptr, *ptr_a, *ptr_b, *ptr_c; 1678 BcDig *ptr, *ptr_a, *ptr_b, *ptr_c;
1681 size_t i, max, min_rdx, min_int, diff, a_int, b_int; 1679 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)
1746 return BC_STATUS_SUCCESS; // can't make void, see bc_num_binary() 1744 return BC_STATUS_SUCCESS; // can't make void, see bc_num_binary()
1747} 1745}
1748 1746
1749static BcStatus bc_num_s(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub) 1747static FAST_FUNC BcStatus bc_num_s(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub)
1750{ 1748{
1751 ssize_t cmp; 1749 ssize_t cmp;
1752 BcNum *minuend, *subtrahend; 1750 BcNum *minuend, *subtrahend;
@@ -1808,7 +1806,7 @@ static BcStatus bc_num_s(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub)
1808 return BC_STATUS_SUCCESS; // can't make void, see bc_num_binary() 1806 return BC_STATUS_SUCCESS; // can't make void, see bc_num_binary()
1809} 1807}
1810 1808
1811static BcStatus bc_num_k(BcNum *restrict a, BcNum *restrict b, 1809static FAST_FUNC BcStatus bc_num_k(BcNum *restrict a, BcNum *restrict b,
1812 BcNum *restrict c) 1810 BcNum *restrict c)
1813{ 1811{
1814 BcStatus s; 1812 BcStatus s;
@@ -1914,7 +1912,7 @@ err:
1914 return s; 1912 return s;
1915} 1913}
1916 1914
1917static BcStatus bc_num_m(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) 1915static FAST_FUNC BcStatus bc_num_m(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
1918{ 1916{
1919 BcStatus s; 1917 BcStatus s;
1920 BcNum cpa, cpb; 1918 BcNum cpa, cpb;
@@ -1956,7 +1954,7 @@ err:
1956 return s; 1954 return s;
1957} 1955}
1958 1956
1959static BcStatus bc_num_d(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) 1957static FAST_FUNC BcStatus bc_num_d(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
1960{ 1958{
1961 BcStatus s = BC_STATUS_SUCCESS; 1959 BcStatus s = BC_STATUS_SUCCESS;
1962 BcDig *n, *p, q; 1960 BcDig *n, *p, q;
@@ -2028,7 +2026,7 @@ static BcStatus bc_num_d(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
2028 return s; 2026 return s;
2029} 2027}
2030 2028
2031static BcStatus bc_num_r(BcNum *a, BcNum *b, BcNum *restrict c, 2029static FAST_FUNC BcStatus bc_num_r(BcNum *a, BcNum *b, BcNum *restrict c,
2032 BcNum *restrict d, size_t scale, size_t ts) 2030 BcNum *restrict d, size_t scale, size_t ts)
2033{ 2031{
2034 BcStatus s; 2032 BcStatus s;
@@ -2065,7 +2063,7 @@ err:
2065 return s; 2063 return s;
2066} 2064}
2067 2065
2068static BcStatus bc_num_rem(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) 2066static FAST_FUNC BcStatus bc_num_rem(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
2069{ 2067{
2070 BcStatus s; 2068 BcStatus s;
2071 BcNum c1; 2069 BcNum c1;
@@ -2078,7 +2076,7 @@ static BcStatus bc_num_rem(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
2078 return s; 2076 return s;
2079} 2077}
2080 2078
2081static BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) 2079static FAST_FUNC BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
2082{ 2080{
2083 BcStatus s = BC_STATUS_SUCCESS; 2081 BcStatus s = BC_STATUS_SUCCESS;
2084 BcNum copy; 2082 BcNum copy;
@@ -2216,7 +2214,7 @@ static void bc_num_printNewline(void)
2216} 2214}
2217 2215
2218#if ENABLE_DC 2216#if ENABLE_DC
2219static void bc_num_printChar(size_t num, size_t width, bool radix) 2217static FAST_FUNC void bc_num_printChar(size_t num, size_t width, bool radix)
2220{ 2218{
2221 (void) radix; 2219 (void) radix;
2222 bb_putchar((char) num); 2220 bb_putchar((char) num);
@@ -2224,7 +2222,7 @@ static void bc_num_printChar(size_t num, size_t width, bool radix)
2224} 2222}
2225#endif 2223#endif
2226 2224
2227static void bc_num_printDigits(size_t num, size_t width, bool radix) 2225static FAST_FUNC void bc_num_printDigits(size_t num, size_t width, bool radix)
2228{ 2226{
2229 size_t exp, pow; 2227 size_t exp, pow;
2230 2228
@@ -2245,7 +2243,7 @@ static void bc_num_printDigits(size_t num, size_t width, bool radix)
2245 } 2243 }
2246} 2244}
2247 2245
2248static void bc_num_printHex(size_t num, size_t width, bool radix) 2246static FAST_FUNC void bc_num_printHex(size_t num, size_t width, bool radix)
2249{ 2247{
2250 if (radix) { 2248 if (radix) {
2251 bc_num_printNewline(); 2249 bc_num_printNewline();
@@ -2542,39 +2540,39 @@ static BcStatus bc_num_print(BcNum *n, bool newline)
2542 return s; 2540 return s;
2543} 2541}
2544 2542
2545static BcStatus bc_num_add(BcNum *a, BcNum *b, BcNum *c, size_t scale) 2543static FAST_FUNC BcStatus bc_num_add(BcNum *a, BcNum *b, BcNum *c, size_t scale)
2546{ 2544{
2547 BcNumBinaryOp op = (!a->neg == !b->neg) ? bc_num_a : bc_num_s; 2545 BcNumBinaryOp op = (!a->neg == !b->neg) ? bc_num_a : bc_num_s;
2548 (void) scale; 2546 (void) scale;
2549 return bc_num_binary(a, b, c, false, op, BC_NUM_AREQ(a, b)); 2547 return bc_num_binary(a, b, c, false, op, BC_NUM_AREQ(a, b));
2550} 2548}
2551 2549
2552static BcStatus bc_num_sub(BcNum *a, BcNum *b, BcNum *c, size_t scale) 2550static FAST_FUNC BcStatus bc_num_sub(BcNum *a, BcNum *b, BcNum *c, size_t scale)
2553{ 2551{
2554 BcNumBinaryOp op = (!a->neg == !b->neg) ? bc_num_s : bc_num_a; 2552 BcNumBinaryOp op = (!a->neg == !b->neg) ? bc_num_s : bc_num_a;
2555 (void) scale; 2553 (void) scale;
2556 return bc_num_binary(a, b, c, true, op, BC_NUM_AREQ(a, b)); 2554 return bc_num_binary(a, b, c, true, op, BC_NUM_AREQ(a, b));
2557} 2555}
2558 2556
2559static BcStatus bc_num_mul(BcNum *a, BcNum *b, BcNum *c, size_t scale) 2557static FAST_FUNC BcStatus bc_num_mul(BcNum *a, BcNum *b, BcNum *c, size_t scale)
2560{ 2558{
2561 size_t req = BC_NUM_MREQ(a, b, scale); 2559 size_t req = BC_NUM_MREQ(a, b, scale);
2562 return bc_num_binary(a, b, c, scale, bc_num_m, req); 2560 return bc_num_binary(a, b, c, scale, bc_num_m, req);
2563} 2561}
2564 2562
2565static BcStatus bc_num_div(BcNum *a, BcNum *b, BcNum *c, size_t scale) 2563static FAST_FUNC BcStatus bc_num_div(BcNum *a, BcNum *b, BcNum *c, size_t scale)
2566{ 2564{
2567 size_t req = BC_NUM_MREQ(a, b, scale); 2565 size_t req = BC_NUM_MREQ(a, b, scale);
2568 return bc_num_binary(a, b, c, scale, bc_num_d, req); 2566 return bc_num_binary(a, b, c, scale, bc_num_d, req);
2569} 2567}
2570 2568
2571static BcStatus bc_num_mod(BcNum *a, BcNum *b, BcNum *c, size_t scale) 2569static FAST_FUNC BcStatus bc_num_mod(BcNum *a, BcNum *b, BcNum *c, size_t scale)
2572{ 2570{
2573 size_t req = BC_NUM_MREQ(a, b, scale); 2571 size_t req = BC_NUM_MREQ(a, b, scale);
2574 return bc_num_binary(a, b, c, scale, bc_num_rem, req); 2572 return bc_num_binary(a, b, c, scale, bc_num_rem, req);
2575} 2573}
2576 2574
2577static BcStatus bc_num_pow(BcNum *a, BcNum *b, BcNum *c, size_t scale) 2575static FAST_FUNC BcStatus bc_num_pow(BcNum *a, BcNum *b, BcNum *c, size_t scale)
2578{ 2576{
2579 return bc_num_binary(a, b, c, scale, bc_num_p, a->len * b->len + 1); 2577 return bc_num_binary(a, b, c, scale, bc_num_p, a->len * b->len + 1);
2580} 2578}
@@ -2789,7 +2787,7 @@ static void bc_func_init(BcFunc *f)
2789 f->nparams = 0; 2787 f->nparams = 0;
2790} 2788}
2791 2789
2792static void bc_func_free(void *func) 2790static FAST_FUNC void bc_func_free(void *func)
2793{ 2791{
2794 BcFunc *f = (BcFunc *) func; 2792 BcFunc *f = (BcFunc *) func;
2795 bc_vec_free(&f->code); 2793 bc_vec_free(&f->code);
@@ -2841,7 +2839,7 @@ static void bc_array_copy(BcVec *d, const BcVec *s)
2841 } 2839 }
2842} 2840}
2843 2841
2844static void bc_string_free(void *string) 2842static FAST_FUNC void bc_string_free(void *string)
2845{ 2843{
2846 free(*((char **) string)); 2844 free(*((char **) string));
2847} 2845}
@@ -2883,7 +2881,7 @@ static void bc_result_copy(BcResult *d, BcResult *src)
2883} 2881}
2884#endif // ENABLE_DC 2882#endif // ENABLE_DC
2885 2883
2886static void bc_result_free(void *result) 2884static FAST_FUNC void bc_result_free(void *result)
2887{ 2885{
2888 BcResult *r = (BcResult *) result; 2886 BcResult *r = (BcResult *) result;
2889 2887
@@ -3171,7 +3169,7 @@ static BcStatus bc_lex_comment(BcLex *l)
3171 return BC_STATUS_SUCCESS; 3169 return BC_STATUS_SUCCESS;
3172} 3170}
3173 3171
3174static BcStatus bc_lex_token(BcLex *l) 3172static FAST_FUNC BcStatus bc_lex_token(BcLex *l)
3175{ 3173{
3176 BcStatus s = BC_STATUS_SUCCESS; 3174 BcStatus s = BC_STATUS_SUCCESS;
3177 char c = l->buf[l->i++], c2; 3175 char c = l->buf[l->i++], c2;
@@ -3511,7 +3509,7 @@ static BcStatus dc_lex_string(BcLex *l)
3511 return BC_STATUS_SUCCESS; 3509 return BC_STATUS_SUCCESS;
3512} 3510}
3513 3511
3514static BcStatus dc_lex_token(BcLex *l) 3512static FAST_FUNC BcStatus dc_lex_token(BcLex *l)
3515{ 3513{
3516 BcStatus s = BC_STATUS_SUCCESS; 3514 BcStatus s = BC_STATUS_SUCCESS;
3517 char c = l->buf[l->i++], c2; 3515 char c = l->buf[l->i++], c2;
@@ -4826,7 +4824,7 @@ static BcStatus bc_parse_stmt(BcParse *p)
4826 return s; 4824 return s;
4827} 4825}
4828 4826
4829static BcStatus bc_parse_parse(BcParse *p) 4827static FAST_FUNC BcStatus bc_parse_parse(BcParse *p)
4830{ 4828{
4831 BcStatus s; 4829 BcStatus s;
4832 4830
@@ -5333,7 +5331,7 @@ static BcStatus dc_parse_expr(BcParse *p, uint8_t flags)
5333 return s; 5331 return s;
5334} 5332}
5335 5333
5336static BcStatus dc_parse_parse(BcParse *p) 5334static FAST_FUNC BcStatus dc_parse_parse(BcParse *p)
5337{ 5335{
5338 BcStatus s; 5336 BcStatus s;
5339 5337
@@ -6305,8 +6303,7 @@ static BcStatus bc_program_builtin(char inst)
6305 } 6303 }
6306#endif 6304#endif
6307 else { 6305 else {
6308 BcProgramBuiltIn f = len ? bc_program_len : bc_program_scale; 6306 bc_num_ulong2num(&res.d.n, len ? bc_program_len(num) : bc_program_scale(num));
6309 bc_num_ulong2num(&res.d.n, f(num));
6310 } 6307 }
6311 6308
6312 bc_program_retire(&res, BC_RESULT_TEMP); 6309 bc_program_retire(&res, BC_RESULT_TEMP);