summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2007-10-13 00:15:42 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2007-10-13 00:15:42 (GMT)
commitc0fc8fefc085ff3a984dc0322af23b2bb38067d2 (patch)
tree0c897706ad8fec68fd5f3f61c8b59aebfc9f61de
parent8f848d2d33b206a521bfaa910fab1f37b0138907 (diff)
downloadpbn-c0fc8fefc085ff3a984dc0322af23b2bb38067d2.zip
pbn-c0fc8fefc085ff3a984dc0322af23b2bb38067d2.tar.gz
pbn-c0fc8fefc085ff3a984dc0322af23b2bb38067d2.tar.bz2
pbn-c0fc8fefc085ff3a984dc0322af23b2bb38067d2.tar.xz
Make pbn_div() slightly faster by avoiding pbn_set_bit()
Don't use pbn_set_bit() inside pbn_div().
-rw-r--r--pbn_div.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/pbn_div.c b/pbn_div.c
index 398c70e..f7b3a56 100644
--- a/pbn_div.c
+++ b/pbn_div.c
@@ -33,6 +33,7 @@ int pbn_div(struct pbn **qp, struct pbn **rp, struct pbn *n, struct pbn *d)
int rv = d->bits == 0 ? -1 : 0;
int cm;
int shift, bits, len, i;
+ pbn_atom_t *qn, qm;
if (rv || (cm = pbn_abscmp(n, d)) < 0) {
/* We either had division by zero, or |n| < |d| */
@@ -79,12 +80,19 @@ int pbn_div(struct pbn **qp, struct pbn **rp, struct pbn *n, struct pbn *d)
q->minus = r->minus ^ d->minus;
r->minus = d->minus; /* Makes our lives easier for now... */
+ qm = (pbn_atom_t)1 << (shift % PBN_ATOM_BITS);
+ qn = &q->num[shift/PBN_ATOM_BITS];
for (i = shift; i >= 0; i--) {
if (pbn_abscmp(r, d) >= 0) {
r = pbn_sub(r, d);
- q = pbn_set_bit(q, i);
+ *qn |= qm;
}
d = pbn_shr(d, 1);
+ qm >>= 1;
+ if (!qm) {
+ qm = (pbn_atom_t)1 << (PBN_ATOM_BITS-1);
+ qn--;
+ }
}
r->minus = q->minus;