X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftally%2Ftally.c;h=5602e75017055ae5ce20f71deaf4c80f2db55784;hp=a6d66b6688dc5d6940bfc75596e20d866a098ebd;hb=63a3c0f3a8cf34e64f8ba9ba426537133fa71b2b;hpb=137c60bf9e4aa3160fbd44b99e54bcb0df5d6cbf diff --git a/ccan/tally/tally.c b/ccan/tally/tally.c index a6d66b66..5602e750 100644 --- a/ccan/tally/tally.c +++ b/ccan/tally/tally.c @@ -231,8 +231,9 @@ static uint64_t divlu64(uint64_t u1, uint64_t u0, uint64_t v) uint64_t p; /* Product of two digits. */ int64_t s, i, j, t, k; - if (u1 >= v) /* If overflow, return the largest */ + if (u1 >= v) { /* If overflow, return the largest */ return (uint64_t)-1; /* possible quotient. */ + } s = 64 - fls64(v); /* 0 <= s <= 63. */ vn0 = v << s; /* Normalize divisor. */ @@ -255,7 +256,9 @@ static uint64_t divlu64(uint64_t u1, uint64_t u0, uint64_t v) if (qhat >= b || qhat*vn[0] > b*rhat + un[j]) { qhat = qhat - 1; rhat = rhat + vn[1]; - if (rhat < b) goto again; + if (rhat < b) { + goto again; + } } /* Multiply and subtract. */ @@ -289,26 +292,28 @@ static int64_t divls64(int64_t u1, uint64_t u0, int64_t v) { int64_t q, uneg, vneg, diff, borrow; - uneg = u1 >> 63; // -1 if u < 0. - if (uneg) { // Compute the absolute - u0 = -u0; // value of the dividend u. + uneg = u1 >> 63; /* -1 if u < 0. */ + if (uneg) { /* Compute the absolute */ + u0 = -u0; /* value of the dividend u. */ borrow = (u0 != 0); u1 = -u1 - borrow; } - vneg = v >> 63; // -1 if v < 0. - v = (v ^ vneg) - vneg; // Absolute value of v. + vneg = v >> 63; /* -1 if v < 0. */ + v = (v ^ vneg) - vneg; /* Absolute value of v. */ - if ((uint64_t)u1 >= (uint64_t)v) + if ((uint64_t)u1 >= (uint64_t)v) { goto overflow; + } q = divlu64(u1, u0, v); - diff = uneg ^ vneg; // Negate q if signs of - q = (q ^ diff) - diff; // u and v differed. + diff = uneg ^ vneg; /* Negate q if signs of */ + q = (q ^ diff) - diff; /* u and v differed. */ - if ((diff ^ q) < 0 && q != 0) { // If overflow, return the largest - overflow: // possible neg. quotient. + if ((diff ^ q) < 0 && q != 0) { /* If overflow, return the + largest */ + overflow: /* possible neg. quotient. */ q = 0x8000000000000000ULL; } return q;