Skip to content

Commit 073edce

Browse files
authored
Remove dead code and ineffective optimization path form VpDivd (#379)
* Remove vpdivd optimization which is not frequetly used It only speeds up about 3% in the best case. About 99.98% case running the test, it won't enter to this optimization path. * Remove unused carry logic in vpdivd
1 parent 28903c4 commit 073edce

File tree

2 files changed

+6
-28
lines changed

2 files changed

+6
-28
lines changed

ext/bigdecimal/bigdecimal.c

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6014,7 +6014,7 @@ VpDivd(Real *c, Real *r, Real *a, Real *b)
60146014
size_t i, n, ind_a, ind_b, ind_c, ind_r;
60156015
size_t nLoop;
60166016
DECDIG_DBL q, b1, b1p1, b1b2, b1b2p1, r1r2;
6017-
DECDIG borrow, borrow1, borrow2;
6017+
DECDIG borrow1, borrow2;
60186018
DECDIG_DBL qb;
60196019

60206020
VpSetNaN(r);
@@ -6078,26 +6078,11 @@ VpDivd(Real *c, Real *r, Real *a, Real *b)
60786078
}
60796079
/* The first few word digits of r and b is the same and */
60806080
/* the first different word digit of w is greater than that */
6081-
/* of b, so quotient is 1 and just subtract b from r. */
6082-
borrow = 0; /* quotient=1, then just r-b */
6083-
ind_b = b->Prec - 1;
6084-
ind_r = ind_c + ind_b;
6085-
if (ind_r >= word_r) goto space_error;
6086-
n = ind_b;
6087-
for (i = 0; i <= n; ++i) {
6088-
if (r->frac[ind_r] < b->frac[ind_b] + borrow) {
6089-
r->frac[ind_r] += (BASE - (b->frac[ind_b] + borrow));
6090-
borrow = 1;
6091-
}
6092-
else {
6093-
r->frac[ind_r] = r->frac[ind_r] - b->frac[ind_b] - borrow;
6094-
borrow = 0;
6095-
}
6096-
--ind_r;
6097-
--ind_b;
6098-
}
6081+
/* of b, so quotient is 1. */
6082+
q = 1;
60996083
++c->frac[ind_c];
6100-
goto carry;
6084+
ind_r = b->Prec + ind_c - 1;
6085+
goto sub_mult;
61016086
}
61026087
/* The first two word digits is not the same, */
61036088
/* then compare magnitude, and divide actually. */
@@ -6150,13 +6135,6 @@ VpDivd(Real *c, Real *r, Real *a, Real *b)
61506135
}
61516136

61526137
r->frac[ind_r] -= borrow2;
6153-
carry:
6154-
ind_r = ind_c;
6155-
while (c->frac[ind_r] >= BASE) {
6156-
c->frac[ind_r] -= BASE;
6157-
--ind_r;
6158-
++c->frac[ind_r];
6159-
}
61606138
}
61616139
/* End of operation, now final arrangement */
61626140
out_side:

test/bigdecimal/test_vp_operation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_vpdivd_precisions
8484
end
8585
end
8686

87-
def test_vpdivd_carry_borrow
87+
def test_vpdivd_borrow
8888
y_small = BASE / 7 * BASE ** 4
8989
y_large = (4 * BASE_FIG).times.map {|i| i % 9 + 1 }.join.to_i
9090
[y_large, y_small].each do |y|

0 commit comments

Comments
 (0)