lkml.org 
[lkml]   [2002]   [Feb]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] bring sanity to div64.h and do_div usage
On Fri, 8 Feb 2002, Troy Benjegerdes wrote:

> Several people I have talked to on the issue specifically asked for the
> panic(), as people using do_div() should really know better than to do 64
> bit divides in the kernel.

There are legitimate cases where you cannot avoid a double-precision
division and the inefficiency is negligible. For example for MIPS it's
used in do_*_gettimeoffset() and at most once a jiffy (actually we use
do_div64_32() to reduce work, as we know the quotient will *always* fit in
32 bits).

> The generic C algorithm only handles base < 65536.
>
> I can think of a couple ways around this..
>
> 1) Make the base argument be a 'u16 base', and people with too large a
> base would get compile warnings/errors.
>
> 2) run-time check on base, and panic if too large
>
> 3) run-time check on base, print dmesg warning if too large

4) Use a generic division algorithm using shifts and subtracts such as
one of these described in academic books. You may port the implementation
from include/asm-mips/div64.h. ;-)

Note that in do_*_gettimeoffset() the divisor is an arbitrary 32-bit
number, mostly depending on the uptime.

--
+ Maciej W. Rozycki, Technical University of Gdansk, Poland +
+--------------------------------------------------------------+
+ e-mail: macro@ds2.pg.gda.pl, PGP key available +

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

\
 
 \ /
  Last update: 2005-03-22 13:24    [W:0.085 / U:20.716 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site