linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* do_div vs sector_t
@ 2003-07-11 22:33 Matthew Wilcox
  2003-07-11 22:34 ` Andrew Morton
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Matthew Wilcox @ 2003-07-11 22:33 UTC (permalink / raw)
  To: Bernardo Innocenti; +Cc: Andrew Morton, linux-kernel


# define do_div(n,base) ({                              \
        uint32_t __base = (base);                       \
        uint32_t __rem;                                 \
        if (likely(((n) >> 32) == 0)) {                 \

so if we call do_div() on a u32, the compiler emits nasal daemons.
and we do this -- in the antcipatory scheduler:

                if (aic->seek_samples) {
                        aic->seek_mean = aic->seek_total + 128;
                        do_div(aic->seek_mean, aic->seek_samples);
                }

seek_mean is a sector_t so sometimes it's 64-bit on a 32-bit platform.
so we can't avoid calling do_div().

This almost works (the warning is harmless since gcc optimises away the call)

# define do_div(n,base) ({                                              \
        uint32_t __base = (base);                                       \
        uint32_t __rem;                                                 \
        if ((sizeof(n) < 8) || (likely(((n) >> 32) == 0))) {            \
                __rem = (uint32_t)(n) % __base;                         \
                (n) = (uint32_t)(n) / __base;                           \
        } else                                                          \
                __rem = __div64_32(&(n), __base);                       \
        __rem;                                                          \
 })

Better ideas?

-- 
"It's not Hollywood.  War is real, war is primarily not about defeat or
victory, it is about death.  I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk

^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: do_div vs sector_t
@ 2003-07-13 18:40 linux
  0 siblings, 0 replies; 12+ messages in thread
From: linux @ 2003-07-13 18:40 UTC (permalink / raw)
  To: willy; +Cc: linux-kernel

>        if (likely(((n) >> 32) == 0)) {                 \

if (likely((n) <= 0xffffffff)) {

will work with any unsigned type for n.


GCC knows to only look at the high word to make this test.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2003-07-14  3:53 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-11 22:33 do_div vs sector_t Matthew Wilcox
2003-07-11 22:34 ` Andrew Morton
2003-07-11 22:42 ` Neil Brown
2003-07-12  0:14   ` do_div vs sector_t (patch) Nick Piggin
2003-07-12  6:52 ` do_div vs sector_t Christoph Hellwig
2003-07-12  6:58   ` Andrew Morton
2003-07-13 17:26 ` Richard Henderson
2003-07-13 17:39   ` Russell King
2003-07-13 19:14   ` Bernardo Innocenti
2003-07-13 20:04     ` Matthew Wilcox
2003-07-14  4:07 ` Peter Chubb
2003-07-13 18:40 linux

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).