DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ferruh Yigit <ferruh.yigit@intel.com>
To: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>,
	thomas@monjalon.net, cristian.dumitrescu@intel.com,
	stephen@networkplumber.org
Cc: dev@dpdk.org
Subject: Re: [dpdk-dev] [PATCH v8 2/3] eal: add u64 bit variant for reciprocal
Date: Sun, 28 Oct 2018 01:06:10 +0100	[thread overview]
Message-ID: <7ce0fa65-01ff-4fc3-7714-df0711a0361b@intel.com> (raw)
In-Reply-To: <20180126050451.5953-2-pbhagavatula@caviumnetworks.com>

On 1/26/2018 5:04 AM, Pavan Nikhilesh wrote:
> Currently, rte_reciprocal only supports unsigned 32bit divisors. This
> commit adds support for unsigned 64bit divisors.
> 
> Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>

<...>

> +static uint64_t
> +divide_128_div_64_to_64(uint64_t u1, uint64_t u0, uint64_t v, uint64_t *r)
> +{
> +	const uint64_t b = (1ULL << 32); /* Number base (16 bits). */
> +	uint64_t un1, un0,           /* Norm. dividend LSD's. */
> +		 vn1, vn0,           /* Norm. divisor digits. */
> +		 q1, q0,             /* Quotient digits. */
> +		 un64, un21, un10,   /* Dividend digit pairs. */
> +		 rhat;               /* A remainder. */
> +	int s;                       /* Shift amount for norm. */
> +
> +	/* If overflow, set rem. to an impossible value. */
> +	if (u1 >= v) {
> +		if (r != NULL)
> +			*r = (uint64_t) -1;
> +		return (uint64_t) -1;
> +	}
> +
> +	/* Count leading zeros. */
> +	s = __builtin_clzll(v);
> +	if (s > 0) {
> +		v = v << s;
> +		un64 = (u1 << s) | ((u0 >> (64 - s)) & (-s >> 31));

Hi Pavan,

This is causing a cppcheck warning [1]. s is `int` and we know here s > 0,
so `-s >> 31` should be 0xffffffff right, what is the point of this operation
instead of using hardcoded value?

[1]
(error) Shifting signed 32-bit value by 31 bits is undefined behaviour

  parent reply	other threads:[~2018-10-28  0:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-29 18:46 [dpdk-dev] [PATCH 1/2] eal: introduce integer divide through reciprocal Pavan Nikhilesh
2017-08-29 18:46 ` [dpdk-dev] [PATCH 2/2] eal: add u64 bit variant for reciprocal Pavan Nikhilesh
2017-08-29 19:35   ` Stephen Hemminger
2017-08-29 19:38   ` Stephen Hemminger
2017-08-30  4:05     ` Pavan Nikhilesh Bhagavatula
2017-12-04 13:22 ` [dpdk-dev] [PATCH v7 1/3] eal: introduce integer divide through reciprocal Pavan Nikhilesh
2017-12-04 13:22   ` [dpdk-dev] [PATCH v7 2/3] eal: add u64 bit variant for reciprocal Pavan Nikhilesh
2017-12-04 13:22   ` [dpdk-dev] [PATCH v7 3/3] test: add tests for reciprocal based division Pavan Nikhilesh
2018-01-18 23:49     ` Thomas Monjalon
2018-01-25 22:35       ` Thomas Monjalon
2018-01-11 16:01   ` [dpdk-dev] [PATCH v7 1/3] eal: introduce integer divide through reciprocal Dumitrescu, Cristian
2018-01-26  5:04 ` [dpdk-dev] [PATCH v8 " Pavan Nikhilesh
2018-01-26  5:04   ` [dpdk-dev] [PATCH v8 2/3] eal: add u64 bit variant for reciprocal Pavan Nikhilesh
2018-01-29  6:42     ` Hemant Agrawal
2018-01-29  7:54       ` Pavan Nikhilesh
2018-01-29  8:14         ` Hemant Agrawal
2018-10-28  0:06     ` Ferruh Yigit [this message]
2018-01-26  5:04   ` [dpdk-dev] [PATCH v8 3/3] test: add tests for reciprocal based division Pavan Nikhilesh
2018-01-27 21:39   ` [dpdk-dev] [PATCH v8 1/3] eal: introduce integer divide through reciprocal Thomas Monjalon

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=7ce0fa65-01ff-4fc3-7714-df0711a0361b@intel.com \
    --to=ferruh.yigit@intel.com \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    --cc=pbhagavatula@caviumnetworks.com \
    --cc=stephen@networkplumber.org \
    --cc=thomas@monjalon.net \
    /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).