summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2012-03-20 23:20:03 (GMT)
committerH. Peter Anvin <hpa@linux.intel.com>2012-03-20 23:20:03 (GMT)
commit905d22af2aab4c106a0514cc269f3cfc744abe10 (patch)
treedd5bae7838f613a6dd86335d854739dbd71c20d6
parent11bb3f9bfe081ae28f175a50cf848dd82c13023c (diff)
downloadpbn-905d22af2aab4c106a0514cc269f3cfc744abe10.zip
pbn-905d22af2aab4c106a0514cc269f3cfc744abe10.tar.gz
pbn-905d22af2aab4c106a0514cc269f3cfc744abe10.tar.bz2
pbn-905d22af2aab4c106a0514cc269f3cfc744abe10.tar.xz
pbn_muls: Fix pbn_muls() implementation
Fix several bugs in pbn_muls()
-rw-r--r--pbn_muls.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/pbn_muls.c b/pbn_muls.c
index 7a601aa..9a45328 100644
--- a/pbn_muls.c
+++ b/pbn_muls.c
@@ -20,9 +20,8 @@
struct pbn *pbn_muls(struct pbn *s1, pbn_slimb_t s2)
{
- size_t bits, len;
+ size_t i, len;
struct pbn *d;
- int i;
pbn_limb_t s2u, c, *s1p, *dp;
pbn_2limb_t t;
@@ -30,11 +29,9 @@ struct pbn *pbn_muls(struct pbn *s1, pbn_slimb_t s2)
return s1; /* s1 == 0 */
}
- bits = s1->bits + PBN_LIMB_BITS;
- len = (bits+PBN_LIMB_BITS-1)/PBN_LIMB_BITS;
+ len = (s1->bits+PBN_LIMB_BITS-1) >> PBN_LIMB_SHIFT;
- d = pbn_new(len);
- d->bits = bits;
+ d = pbn_new(len+1);
d->minus = s1->minus;
s2u = s2;
@@ -46,7 +43,7 @@ struct pbn *pbn_muls(struct pbn *s1, pbn_slimb_t s2)
c = 0;
s1p = s1->num;
dp = d->num;
- for (i = 0; i < s1->len; i++) {
+ for (i = 0; i < len; i++) {
t = (pbn_2limb_t)*s1p++ * s2u + c;
*dp++ = (pbn_limb_t)t;
c = t >> PBN_LIMB_BITS;