diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-05 18:56:14 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-05 18:56:14 +0100 |
commit | b692c2faf1e713fe4ec04d34bd6ad77e02dbb5d6 (patch) | |
tree | 533e5df4cb205d0959991fbee21f25a6d803fbfe | |
parent | 0d7e46b1de8f11ccff9a5efa5d6d6ea6f5bacabf (diff) | |
download | busybox-w32-b692c2faf1e713fe4ec04d34bd6ad77e02dbb5d6.tar.gz busybox-w32-b692c2faf1e713fe4ec04d34bd6ad77e02dbb5d6.tar.bz2 busybox-w32-b692c2faf1e713fe4ec04d34bd6ad77e02dbb5d6.zip |
bc: bc_num_k(): move carry,i,j,len to inner scope
This might help compiler
function old new delta
bc_num_k 957 971 +14
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index a78446d04..ea200ebda 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -1639,16 +1639,16 @@ static BcStatus bc_num_k(BcNum *restrict a, BcNum *restrict b, | |||
1639 | BcNum *restrict c) | 1639 | BcNum *restrict c) |
1640 | { | 1640 | { |
1641 | BcStatus s; | 1641 | BcStatus s; |
1642 | int carry; | 1642 | size_t max = BC_MAX(a->len, b->len), max2 = (max + 1) / 2; |
1643 | size_t i, j, len, max = BC_MAX(a->len, b->len), max2 = (max + 1) / 2; | ||
1644 | BcNum l1, h1, l2, h2, m2, m1, z0, z1, z2, temp; | 1643 | BcNum l1, h1, l2, h2, m2, m1, z0, z1, z2, temp; |
1645 | bool aone = BC_NUM_ONE(a); | 1644 | bool aone; |
1646 | 1645 | ||
1647 | if (a->len == 0 || b->len == 0) { | 1646 | if (a->len == 0 || b->len == 0) { |
1648 | bc_num_zero(c); | 1647 | bc_num_zero(c); |
1649 | return BC_STATUS_SUCCESS; | 1648 | return BC_STATUS_SUCCESS; |
1650 | } | 1649 | } |
1651 | else if (aone || BC_NUM_ONE(b)) { | 1650 | aone = BC_NUM_ONE(a); |
1651 | if (aone || BC_NUM_ONE(b)) { | ||
1652 | bc_num_copy(c, aone ? b : a); | 1652 | bc_num_copy(c, aone ? b : a); |
1653 | return BC_STATUS_SUCCESS; | 1653 | return BC_STATUS_SUCCESS; |
1654 | } | 1654 | } |
@@ -1656,13 +1656,17 @@ static BcStatus bc_num_k(BcNum *restrict a, BcNum *restrict b, | |||
1656 | if (a->len + b->len < BC_NUM_KARATSUBA_LEN || | 1656 | if (a->len + b->len < BC_NUM_KARATSUBA_LEN || |
1657 | a->len < BC_NUM_KARATSUBA_LEN || b->len < BC_NUM_KARATSUBA_LEN) | 1657 | a->len < BC_NUM_KARATSUBA_LEN || b->len < BC_NUM_KARATSUBA_LEN) |
1658 | { | 1658 | { |
1659 | size_t i, j, len; | ||
1660 | int carry; | ||
1661 | |||
1659 | bc_num_expand(c, a->len + b->len + 1); | 1662 | bc_num_expand(c, a->len + b->len + 1); |
1660 | 1663 | ||
1661 | memset(c->num, 0, sizeof(BcDig) * c->cap); | 1664 | memset(c->num, 0, sizeof(BcDig) * c->cap); |
1662 | c->len = carry = len = 0; | 1665 | c->len = len = 0; |
1663 | 1666 | ||
1664 | for (i = 0; i < b->len; ++i) { | 1667 | for (i = 0; i < b->len; ++i) { |
1665 | 1668 | ||
1669 | carry = 0; | ||
1666 | for (j = 0; j < a->len; ++j) { | 1670 | for (j = 0; j < a->len; ++j) { |
1667 | int in = (int) c->num[i + j]; | 1671 | int in = (int) c->num[i + j]; |
1668 | in += ((int) a->num[j]) * ((int) b->num[i]) + carry; | 1672 | in += ((int) a->num[j]) * ((int) b->num[i]) + carry; |
@@ -1672,7 +1676,6 @@ static BcStatus bc_num_k(BcNum *restrict a, BcNum *restrict b, | |||
1672 | 1676 | ||
1673 | c->num[i + j] += (BcDig) carry; | 1677 | c->num[i + j] += (BcDig) carry; |
1674 | len = BC_MAX(len, i + j + !!carry); | 1678 | len = BC_MAX(len, i + j + !!carry); |
1675 | carry = 0; | ||
1676 | } | 1679 | } |
1677 | 1680 | ||
1678 | c->len = len; | 1681 | c->len = len; |