Re: [patch v2] epoll use a single inode ...

From: Linus Torvalds
Date: Tue Mar 06 2007 - 12:10:05 EST




On Tue, 6 Mar 2007, H. Peter Anvin wrote:
>
> That's true for *any* sprintf(), though. sprintf() converts all its arguments
> to 64 bits.

Well, it very much uses "do_div()", so that it can do a

64 / 32 -> (div64,mod32)

divide, which is often faster than a full 64:64 divide.

> However, this could be optimized. I think right now sprintf() uses a generic
> divide-by-base, but a divide by 8 and 16 can of course be handled with a
> shift, and divide by 10 can be replaced with a multiplication by
> 0x1999999999999999ULL on most architectures.

Nope. You need both the result of the division *and* the remainder, and
you can't do that with a single multiply.

Also, with modern hardware, divides are usually fairly cheap, with early
exit logic, so that the common case of small integers is fairly cheap.
Yeah, generating a full 64-bit number printout is still expensive, of
course (both because you need to do many divides *and* because only the
last few divides will be able to do any appreciable early exit logic.

Anyway, I think a full integer divide on Core 2 is something like 22
cycles. Yes, the multiply is much fasster (at 4 cycles), but I think that
22 cycles is actually worst-case.

Somebody who has a benchmark could try.

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