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>
This commit is contained in:
Denys Vlasenko 2018-12-07 16:22:45 +01:00
parent 64074a1767
commit 2d615fee38

View File

@ -224,14 +224,6 @@ typedef struct BcNum {
#define BC_NUM_KARATSUBA_LEN (32)
#define BC_NUM_NEG(n, neg) ((((ssize_t)(n)) ^ -((ssize_t)(neg))) + (neg))
#define BC_NUM_ONE(n) ((n)->len == 1 && (n)->rdx == 0 && (n)->num[0] == 1)
#define BC_NUM_INT(n) ((n)->len - (n)->rdx)
#define BC_NUM_AREQ(a, b) \
(BC_MAX((a)->rdx, (b)->rdx) + BC_MAX(BC_NUM_INT(a), BC_NUM_INT(b)) + 1)
#define BC_NUM_MREQ(a, b, scale) \
(BC_NUM_INT(a) + BC_NUM_INT(b) + BC_MAX((scale), (a)->rdx + (b)->rdx) + 1)
typedef BcStatus (*BcNumBinaryOp)(BcNum *, BcNum *, BcNum *, size_t);
typedef void (*BcNumDigitOp)(size_t, size_t, bool, size_t *, size_t);
@ -1486,6 +1478,20 @@ static void bc_num_subArrays(BcDig *restrict a, BcDig *restrict b,
}
}
#define BC_NUM_NEG(n, neg) ((((ssize_t)(n)) ^ -((ssize_t)(neg))) + (neg))
#define BC_NUM_ONE(n) ((n)->len == 1 && (n)->rdx == 0 && (n)->num[0] == 1)
#define BC_NUM_INT(n) ((n)->len - (n)->rdx)
//#define BC_NUM_AREQ(a, b) (BC_MAX((a)->rdx, (b)->rdx) + BC_MAX(BC_NUM_INT(a), BC_NUM_INT(b)) + 1)
static /*ALWAYS_INLINE*/ size_t BC_NUM_AREQ(BcNum *a, BcNum *b)
{
return BC_MAX(a->rdx, b->rdx) + BC_MAX(BC_NUM_INT(a), BC_NUM_INT(b)) + 1;
}
//#define BC_NUM_MREQ(a, b, scale) (BC_NUM_INT(a) + BC_NUM_INT(b) + BC_MAX((scale), (a)->rdx + (b)->rdx) + 1)
static /*ALWAYS_INLINE*/ size_t BC_NUM_MREQ(BcNum *a, BcNum *b, size_t scale)
{
return BC_NUM_INT(a) + BC_NUM_INT(b) + BC_MAX(scale, a->rdx + b->rdx) + 1;
}
static ssize_t bc_num_compare(BcDig *restrict a, BcDig *restrict b, size_t len)
{
size_t i;
@ -2084,7 +2090,12 @@ static BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
bc_num_init(&copy, a->len);
bc_num_copy(&copy, a);
if (!neg) scale = BC_MIN(a->rdx * pow, BC_MAX(scale, a->rdx));
if (!neg) {
if (a->rdx > scale)
scale = a->rdx;
if (a->rdx * pow < scale)
scale = a->rdx * pow;
}
b->neg = neg;