DPDK patches and discussions
 help / color / mirror / Atom feed
From: <pbhagavatula@marvell.com>
To: <stephen@networkplumber.org>, <jerinj@marvell.com>
Cc: <dev@dpdk.org>, Pavan Nikhilesh <pbhagavatula@marvell.com>,
	<stable@dpdk.org>
Subject: [dpdk-dev] [PATCH] eal/reciprocal: fix off by one when divisor is 32bit
Date: Wed, 4 Sep 2019 00:46:45 +0530	[thread overview]
Message-ID: <20190903191645.1700-1-pbhagavatula@marvell.com> (raw)

From: Pavan Nikhilesh <pbhagavatula@marvell.com>

Fix off by one error in 64bit reciprocal division when divisor is 32bit.

Fixes: 6d45659eacb8 ("eal: add u64-bit variant for reciprocal divide")
Cc: stable@dpdk.org

Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---

Example:
   Division failed, 17358247066007716387/244 =
   		expected 71140356827900476 result 71140356827900477
   Division failed, 17541123788887206374/41475 =
   		expected 422932460250444 result 422932460250445

 lib/librte_eal/common/rte_reciprocal.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/librte_eal/common/rte_reciprocal.c b/lib/librte_eal/common/rte_reciprocal.c
index f017d0c28..1c6d10e73 100644
--- a/lib/librte_eal/common/rte_reciprocal.c
+++ b/lib/librte_eal/common/rte_reciprocal.c
@@ -133,12 +133,15 @@ rte_reciprocal_value_u64(uint64_t d)
 {
 	struct rte_reciprocal_u64 R;
 	uint64_t m;
+	uint64_t r;
 	int l;

 	l = 63 - __builtin_clzll(d);

-	m = divide_128_div_64_to_64((1ULL << l), 0, d, NULL) << 1;
-	m = (1ULL << l) - d ? m + 2 : 1;
+	m = divide_128_div_64_to_64((1ULL << l), 0, d, &r) << 1;
+	if (r << 1 < r || r << 1 >= d)
+		m++;
+	m = (1ULL << l) - d ? m + 1 : 1;
 	R.m = m;

 	R.sh1 = l > 1 ? 1 : l;
--
2.23.0


             reply	other threads:[~2019-09-03 19:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-03 19:16 pbhagavatula [this message]
2019-10-15  8:45 ` David Marchand
2019-10-15  8:56   ` [dpdk-dev] [EXT] " Pavan Nikhilesh Bhagavatula
2019-10-15  9:06     ` David Marchand
2019-10-26 14:33 ` [dpdk-dev] " David Marchand
2019-10-23  8:44 Pavan Nikhilesh Bhagavatula
2019-10-23 14:06 ` Aaron Conole
2019-10-23 15:06 Pavan Nikhilesh Bhagavatula
2019-10-23 15:16 ` Aaron Conole
2019-10-23 15:35 Pavan Nikhilesh Bhagavatula

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190903191645.1700-1-pbhagavatula@marvell.com \
    --to=pbhagavatula@marvell.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=stable@dpdk.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).