lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <200807162108.14349.vlobanov@speakeasy.net>
Date:	Wed, 16 Jul 2008 21:08:14 -0700
From:	Vadim Lobanov <vlobanov@...akeasy.net>
To:	Soumyadip Das Mahapatra <soumya.linux@...oo.com>
Cc:	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] : A better approach to compute int_sqrt in lib/int_sqrt.c

On Wednesday 16 July 2008 02:35:56 pm Soumyadip Das Mahapatra wrote:
> > >   */
> > >  unsigned long int_sqrt(unsigned long x)
> > >  {
> > > -    unsigned long op, res, one;
> > > -
> > > -    op = x;
> > > -    res = 0;
> > > -
> > > -    one = 1UL << (BITS_PER_LONG - 2);
> > > -    while (one > op)
> > > -        one >>= 2;
> > > -
> > > -    while (one != 0) {
> > > -        if (op >= res + one) {
> > > -            op = op - (res + one);
> > > -            res = res +  2 * one;
> > > -        }
> > > -        res /= 2;
> > > -        one /= 4;
> > > -    }
> > > -    return res;
> > > +    unsigned long ub, lb, m;
> > > +    lb = 1;                /* lower bound */
> > > +    ub = (x >> 5) + 8;        /* upper bound */
> > > +    do {
> > > +        m = (ub + lb) >>  1;    /* middle value */
> > > +        if((m * m) > x)
> > > +            ub = m - 1;
> > > +        else
> > > +            lb = m + 1;
> > > +    } while(ub >= lb);
> > > +
> > > +    return lb - 1;
> > >  }
> > >  EXPORT_SYMBOL(int_sqrt);
>
> 0 It is better because
>          o contains no division operator (older version has two)
>             which are surely comparatively slow task in computer

Actually, the old version has zero division operators; those are simply 
right-shifts.

-- Vadim Lobanov
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ