From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 36ECCA2E1B for ; Tue, 3 Sep 2019 21:16:58 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 52ACD1EBFD; Tue, 3 Sep 2019 21:16:57 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id D051D1EBF6; Tue, 3 Sep 2019 21:16:52 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x83JF9ig021694; Tue, 3 Sep 2019 12:16:51 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0818; bh=0d21zKqe6/69gReChlf5OfGjoSSMcAjrVwfpO3aiPPY=; b=wEMT0bx9o4Y1VVifTro3uVhncNjwBqavWZvGAU8NhFSVAXTOiGfCDhnRhVafcQnxVATc DcZXP821wel0MQg/zK3tDaryijyETmq4VvhZWdnDGw8zjT4/DOLV2PIoGqNKQDABuWOV sJRbQ8XtQQqSr68/i4qCxeoXltrY+U8xzI1i5tFxP2B/vD/y/hs6+6WGkEd6J2dqAx6E c9Zz1O3z1M4uA9SjN0F3TS475vNKD4mxKCHDDE0CKWtAV1POV2h/sfGnjvBNrbAmrfRn TCS7S4LxiyIi4zLhK41OPAj7O4xHGQ+G3E8Rc5g0r+BEioODgn9MFMeOm6c2qiE9NXKN BA== Received: from sc-exch01.marvell.com ([199.233.58.181]) by mx0b-0016f401.pphosted.com with ESMTP id 2uqrdmauf4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 03 Sep 2019 12:16:51 -0700 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 3 Sep 2019 12:16:48 -0700 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 3 Sep 2019 12:16:49 -0700 Received: from BG-LT7430.marvell.com (unknown [10.28.17.43]) by maili.marvell.com (Postfix) with ESMTP id D51B53F703F; Tue, 3 Sep 2019 12:16:46 -0700 (PDT) From: To: , CC: , Pavan Nikhilesh , Date: Wed, 4 Sep 2019 00:46:45 +0530 Message-ID: <20190903191645.1700-1-pbhagavatula@marvell.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.70,1.0.8 definitions=2019-09-03_04:2019-09-03,2019-09-03 signatures=0 Subject: [dpdk-dev] [PATCH] eal/reciprocal: fix off by one when divisor is 32bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Pavan Nikhilesh 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 --- 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