Re: Unsigned Long Long
Re: Unsigned Long Long
- Subject: Re: Unsigned Long Long
- From: Sherm Pendley <email@hidden>
- Date: Wed, 12 May 2004 23:00:13 -0400
On May 12, 2004, at 10:05 PM, Clark Cox wrote:
On May 12, 2004, at 21:15, Sherm Pendley wrote:
Bit-shifting is faster than division:
...but then you make a statement that is also not supported by the
standard.
I didn't say it was. Nor did I state or imply that it should it be -
it's an implementation detail, not part of the language definition.
Regardless, any introductory programming text or class will tell you
the same thing. If you're multiplying or dividing by a power of two,
bit-shifting is always faster than integer division.
long long kb = b >> 10;
It is far less clear what the actual intent here is
It's clear to anyone who's spent at least a week programming in C. But
if you're concerned about beginners being able to grok it, just use
longer variable names, and add a comment:
// Divide by 1024 to get KB - use >> for speed
long long kilobytes = bytes >> 10;
Assuming of course that GCC doesn't optimize division by a constant
power of 2 into a bit-shift on its own.
That is a bad assumption to make, for something so easily testable,
there is no need to assume.
What are you suggesting, that I benchmark the bit-shift operators
and/or examine the assembly code produced by every compiler available?
Is that your idea of "easily testable?" Why would I go to such absurd
lengths, when there's a trivially simple alternative that's guaranteed
to produce optimal code with any C compiler for any modern CPU?
sherm--
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.