diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-07 16:22:45 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-07 16:22:45 +0100 |
commit | 2d615fee3879f7eec6fd51c468ce074cc6e7a47c (patch) | |
tree | dbd4e411ee422765d09f748168a46fb8e401d1a0 /miscutils | |
parent | 64074a1767f69b186ce58cafb7eb95bc1aa0dda9 (diff) | |
download | busybox-w32-2d615fee3879f7eec6fd51c468ce074cc6e7a47c.tar.gz busybox-w32-2d615fee3879f7eec6fd51c468ce074cc6e7a47c.tar.bz2 busybox-w32-2d615fee3879f7eec6fd51c468ce074cc6e7a47c.zip |
bc: convert two macros to functions, unwing one complex max(a,min(b,c))
function old new delta
BC_NUM_AREQ - 45 +45
BC_NUM_MREQ - 33 +33
bc_num_rem 104 91 -13
bc_num_divmod 168 155 -13
bc_num_d 584 569 -15
bc_num_mul 80 62 -18
bc_num_mod 80 62 -18
bc_num_div 80 62 -18
bc_num_sub 112 77 -35
bc_num_add 112 77 -35
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/8 up/down: 78/-165) Total: -87 bytes
text data bss dec hex filename
985526 485 7296 993307 f281b busybox_old
985439 485 7296 993220 f27c4 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/bc.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 3da03b437..2cfe87b1e 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -224,14 +224,6 @@ typedef struct BcNum { | |||
224 | 224 | ||
225 | #define BC_NUM_KARATSUBA_LEN (32) | 225 | #define BC_NUM_KARATSUBA_LEN (32) |
226 | 226 | ||
227 | #define BC_NUM_NEG(n, neg) ((((ssize_t)(n)) ^ -((ssize_t)(neg))) + (neg)) | ||
228 | #define BC_NUM_ONE(n) ((n)->len == 1 && (n)->rdx == 0 && (n)->num[0] == 1) | ||
229 | #define BC_NUM_INT(n) ((n)->len - (n)->rdx) | ||
230 | #define BC_NUM_AREQ(a, b) \ | ||
231 | (BC_MAX((a)->rdx, (b)->rdx) + BC_MAX(BC_NUM_INT(a), BC_NUM_INT(b)) + 1) | ||
232 | #define BC_NUM_MREQ(a, b, scale) \ | ||
233 | (BC_NUM_INT(a) + BC_NUM_INT(b) + BC_MAX((scale), (a)->rdx + (b)->rdx) + 1) | ||
234 | |||
235 | typedef BcStatus (*BcNumBinaryOp)(BcNum *, BcNum *, BcNum *, size_t); | 227 | typedef BcStatus (*BcNumBinaryOp)(BcNum *, BcNum *, BcNum *, size_t); |
236 | typedef void (*BcNumDigitOp)(size_t, size_t, bool, size_t *, size_t); | 228 | typedef void (*BcNumDigitOp)(size_t, size_t, bool, size_t *, size_t); |
237 | 229 | ||
@@ -1486,6 +1478,20 @@ static void bc_num_subArrays(BcDig *restrict a, BcDig *restrict b, | |||
1486 | } | 1478 | } |
1487 | } | 1479 | } |
1488 | 1480 | ||
1481 | #define BC_NUM_NEG(n, neg) ((((ssize_t)(n)) ^ -((ssize_t)(neg))) + (neg)) | ||
1482 | #define BC_NUM_ONE(n) ((n)->len == 1 && (n)->rdx == 0 && (n)->num[0] == 1) | ||
1483 | #define BC_NUM_INT(n) ((n)->len - (n)->rdx) | ||
1484 | //#define BC_NUM_AREQ(a, b) (BC_MAX((a)->rdx, (b)->rdx) + BC_MAX(BC_NUM_INT(a), BC_NUM_INT(b)) + 1) | ||
1485 | static /*ALWAYS_INLINE*/ size_t BC_NUM_AREQ(BcNum *a, BcNum *b) | ||
1486 | { | ||
1487 | return BC_MAX(a->rdx, b->rdx) + BC_MAX(BC_NUM_INT(a), BC_NUM_INT(b)) + 1; | ||
1488 | } | ||
1489 | //#define BC_NUM_MREQ(a, b, scale) (BC_NUM_INT(a) + BC_NUM_INT(b) + BC_MAX((scale), (a)->rdx + (b)->rdx) + 1) | ||
1490 | static /*ALWAYS_INLINE*/ size_t BC_NUM_MREQ(BcNum *a, BcNum *b, size_t scale) | ||
1491 | { | ||
1492 | return BC_NUM_INT(a) + BC_NUM_INT(b) + BC_MAX(scale, a->rdx + b->rdx) + 1; | ||
1493 | } | ||
1494 | |||
1489 | static ssize_t bc_num_compare(BcDig *restrict a, BcDig *restrict b, size_t len) | 1495 | static ssize_t bc_num_compare(BcDig *restrict a, BcDig *restrict b, size_t len) |
1490 | { | 1496 | { |
1491 | size_t i; | 1497 | size_t i; |
@@ -2084,7 +2090,12 @@ static BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) | |||
2084 | bc_num_init(©, a->len); | 2090 | bc_num_init(©, a->len); |
2085 | bc_num_copy(©, a); | 2091 | bc_num_copy(©, a); |
2086 | 2092 | ||
2087 | if (!neg) scale = BC_MIN(a->rdx * pow, BC_MAX(scale, a->rdx)); | 2093 | if (!neg) { |
2094 | if (a->rdx > scale) | ||
2095 | scale = a->rdx; | ||
2096 | if (a->rdx * pow < scale) | ||
2097 | scale = a->rdx * pow; | ||
2098 | } | ||
2088 | 2099 | ||
2089 | b->neg = neg; | 2100 | b->neg = neg; |
2090 | 2101 | ||