DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Stefan Kanthak" <stefan.kanthak@nexgo.de>
To: "Pavan Nikhilesh Bhagavatula" <pbhagavatula@marvell.com>, <dev@dpdk.org>
Cc: <hannes@stressinduktion.org>
Subject: Re: [dpdk-dev] [BUG] Maintainer forlib/librte_eal/common/rte_reciprocal.c?
Date: Fri, 5 Apr 2019 21:17:53 +0200	[thread overview]
Message-ID: <992998AF3ADA4F28BBF7D7CC257A2034@H270> (raw)
In-Reply-To: <CY4PR1801MB1863A73B62C8E3F8475A7D0BDE590@CY4PR1801MB1863.namprd18.prod.outlook.com>

"Pavan Nikhilesh Bhagavatula" <pbhagavatula@marvell.com> wrote Thursday, March 28, 2019 6:35 AM:

> Hi Stefan,
>
> Thanks for the heads up, I am planning to use a modified version of
> https://github.com/hcs0/Hackers-Delight/blob/master/divluh.c.txt
> for simplicity as we don't require the remainder.

Why don't you refer to the ORIGINAL source
<https://www.hackersdelight.org/hdcodetxt/divluh.c.txt> instead?

BUT: you also shouldn't use these routines, they too show quite bad
     implementations of a binary division!
     As Don Knuth wrote in volume 2 of TAoCP, hardware implementations
     are most often NOT well-suited for implementation in software.

Take a look at the following STRAIGHTFORWARD implementation, both
in ANSI C and x86 assembly (for Microsoft's Visual C compiler):

unsigned long long divide(unsigned long long dividendlow,
                          unsigned long long dividendhigh,
                          unsigned long long divisor,
                          unsigned long long *remainder)
{
#ifndef _M_IX86
    unsigned int shift = 64;

    do
    {
        if (dividendhigh < divisor)
        {
            dividendhigh <<= 1;
            dividendhigh |= dividendlow >> 63;
            dividendlow <<= 1;
        }
        else
        {
            dividendhigh -= divisor;
            dividendhigh <<= 1;
            dividendhigh |= dividendlow >> 63;
            dividendlow <<= 1;
            dividendlow |= 1;
        }
    } while (--shift != 0);

    if (*remainder != NULL)
        remainder = dividendhigh;

    return dividendlow;
#else
    __asm
    {
        mov    eax, dword ptr dividendlow
        mov    edx, dword ptr dividendlow+4
        mov    ecx, dword ptr dividendhigh
        mov    ebx, dword ptr dividendhigh+4
        mov    edi, dword ptr divisor
        mov    esi, dword ptr divisor+4
        mov    ebp, 64

    NEXT:
        cmp    ebx, esi
        ja     SUBTRACT
        jb     SHIFT
        cmp    ecx, edi
        jb     SHIFT

    SUBTRACT:
        sub    ecx, edi
        sbb    ebx, esi

    SHIFT:
        cmc
        adc    eax, eax
        adc    edx, edx
        adc    ecx, ecx
        adc    ebx, ebx
        dec    ebp
        jnz    NEXT

        or     ebp, remainder
        jz     EXIT

        mov    [ebp], ecx
        mov    [ebp+4], ebx
    EXIT:
    }
#endif
}


> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Stefan Kanthak
> Sent: Tuesday, March 26, 2019 6:41 AM
> To: dev@dpdk.org
> Cc: hannes@stressinduktion.org
> Subject: [dpdk-dev] [BUG] Maintainer for
> lib/librte_eal/common/rte_reciprocal.c?
> 
> Hi @ll,
> 
> <https://git.dpdk.org/dpdk/plain/MAINTAINERS> does NOT list a maintainer
> for lib/librte_eal/common/rte_reciprocal.c
> 
> Whoever it is should take a close look at <https://skanthak.homepage.t-
> online.de/division.html>,
> then fix the most obvious bug plus the many deficiencies of
> divide_128_div_64_to_64().
> 
> regards
> Stefan Kanthak

  parent reply	other threads:[~2019-04-05 19:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-26  1:11 [dpdk-dev] [BUG] Maintainer for lib/librte_eal/common/rte_reciprocal.c? Stefan Kanthak
2019-03-26  1:11 ` Stefan Kanthak
2019-03-28  4:35 ` Pavan Nikhilesh Bhagavatula
2019-03-28  4:35   ` Pavan Nikhilesh Bhagavatula
2019-04-05 19:17   ` Stefan Kanthak [this message]
2019-04-05 19:17     ` [dpdk-dev] [BUG] Maintainer forlib/librte_eal/common/rte_reciprocal.c? Stefan Kanthak

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=992998AF3ADA4F28BBF7D7CC257A2034@H270 \
    --to=stefan.kanthak@nexgo.de \
    --cc=dev@dpdk.org \
    --cc=hannes@stressinduktion.org \
    --cc=pbhagavatula@marvell.com \
    /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).