All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Soete <soete.joel@tiscali.be>
To: Randolph Chung <randolph@tausq.org>
Cc: parisc-linux@lists.parisc-linux.org
Subject: Re: [parisc-linux] Re: teaching the kernel to do division
Date: Sat, 25 Oct 2003 11:13:14 +0000	[thread overview]
Message-ID: <3F9A5ACA.1010403@tiscali.be> (raw)
In-Reply-To: <20031023233935.GZ24406@tausq.org>

Hi Rnadolph and all,

I reach to figure out what your pb is.
This new algo is Ok and the previous formula was definitely wrong (even 
in 2.4 :( ). So it could be interesting to fix it also.

For this I start from basic math:
	Dividend = divisor * quotient + reminder
ie	D = d * q + r (D, d, q, r: being integers)

I can also split D in two 32bits words and write
	D = D1 * 2^32 + D0

But I always have only one equation with two unknown var (q and r).

Is somebody knows where can I find the right solution?
(or should I find it back in objdump from :
uint32_t div64(uint64_t *n, uint32_t base)
{
         uint32_t rem;

         rem = *n % base;
         *n = *n / base;

         return rem;
})

Thanks in advance,
	Joel


Randolph Chung wrote:
>>does anyone want to look into fixing it, and/or writing an optimized
>>version of that function for pa? :-) it needs to do basically this (but
>>be standalone)
> 
> 
> Here's one way to do it, but maybe it can be optimized a bit. Any
> suggestions before i send it upstream?
> 
> randolph
> 
> Index: lib/div64.c
> ===================================================================
> RCS file: /var/cvs/linux-2.6/lib/div64.c,v
> retrieving revision 1.1
> diff -u -p -r1.1 div64.c
> --- lib/div64.c	29 Jul 2003 17:02:19 -0000	1.1
> +++ lib/div64.c	23 Oct 2003 23:36:08 -0000
> @@ -25,26 +25,28 @@
>  
>  uint32_t __div64_32(uint64_t *n, uint32_t base)
>  {
> -	uint32_t low, low2, high, rem;
> +        uint64_t rem = *n;
> +        uint64_t b = base;
> +        uint64_t res = 0, d = 1;
>  
> -	low   = *n   & 0xffffffff;
> -	high  = *n  >> 32;
> -	rem   = high % (uint32_t)base;
> -	high  = high / (uint32_t)base;
> -	low2  = low >> 16;
> -	low2 += rem << 16;
> -	rem   = low2 % (uint32_t)base;
> -	low2  = low2 / (uint32_t)base;
> -	low   = low  & 0xffff;
> -	low  += rem << 16;
> -	rem   = low  % (uint32_t)base;
> -	low   = low  / (uint32_t)base;
> +        if (b > 0) {
> +                while (b < rem) {
> +                        b <<= 1;
> +                        d <<= 1;
> +                }
> +        }
> +        
> +        do {
> +                if (rem >= b) {
> +                        rem -= b;
> +                        res += d;
> +                }
> +                b >>= 1;
> +                d >>= 1;
> +        } while (d);
>  
> -	*n = low +
> -		((uint64_t)low2 << 16) +
> -		((uint64_t)high << 32);
> -
> -	return rem;
> +        *n = res;
> +        return rem;
>  }
>  
>  EXPORT_SYMBOL(__div64_32);
> 

  reply	other threads:[~2003-10-25 11:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-23  7:21 [parisc-linux] teaching the kernel to do division Randolph Chung
2003-10-23 23:39 ` [parisc-linux] " Randolph Chung
2003-10-25 11:13   ` Joel Soete [this message]
2003-10-25 15:42     ` Joel Soete
2003-10-25 16:07     ` Randolph Chung

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=3F9A5ACA.1010403@tiscali.be \
    --to=soete.joel@tiscali.be \
    --cc=parisc-linux@lists.parisc-linux.org \
    --cc=randolph@tausq.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.