Re: The performance of all kinds of C operations



Nick Keighley wrote:
websnarf@xxxxxxxxx wrote:
Nick Keighley wrote:
websnarf@xxxxxxxxx wrote:
Eric Sosman wrote:
websnarf@xxxxxxxxx wrote:
spibou@xxxxxxxxx wrote:
I didn't read your whole page but had a look at the table in the
section "Strictly for beginners". Can you explain why would
"x = y << 3" be faster than "x = y * 8" ? [...]

I was using a compiler in the '80s that was smart enough to replace * 8
with << 3. Stuff like this in the source just obscures the intent.

Explain how it obscures the intent.

obviously we are not on the same wavelength. If I want to multiply by 8
I write *8. Why would I do anything else? (unless measurement showed
<<3 was faster *and* this line of code needed to be faster).

If shifting by 3 is the *same* as multiplying by 8, then how is
shifting by 8 "doing something else" other than multiplying by 8? Tell
me, why do you think C includes a << operation?

What about *10 would you replace that with two shifts and an add?

That's a different question. Doing so involves a dependency chain of
operations, and there are alternative platform specific tricks for
this. So it doesn't belong in the "beginners section".

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/

.



Relevant Pages

  • Re: The performance of all kinds of C operations
    ... section "Strictly for beginners". ... I was using a compiler in the '80s that was smart enough to replace * 8 ... If shifting by 3 is the *same* as multiplying by 8, ... If I want to shift the bits of an object left by 3 positions I'll use ...
    (comp.lang.c)
  • Re: The performance of all kinds of C operations
    ... section "Strictly for beginners". ... I was using a compiler in the '80s that was smart enough to replace * 8 ... If shifting by 3 is the *same* as multiplying by 8, ... If I want to shift the bits of an object left by 3 positions I'll use ...
    (comp.lang.c)
  • Re: How many mathematicians ...
    ... be divided by 7 before multiplying by 6. ... why many beginners make the mistake of believing the crank Einstein, ... and you sure are a beginner, Bonehead. ...
    (sci.physics.relativity)
  • Re: The performance of all kinds of C operations
    ... section "Strictly for beginners". ... I was using a compiler in the '80s that was smart enough to replace * 8 ... Stuff like this in the source just obscures the intent. ...
    (comp.lang.c)
  • Re: Beginners Group
    ... RMCG is mostly beginners and frauds. ... The intent of the group is to get beginners together to improve our CG ... Membership is wide open right now, ...
    (rec.music.classical.guitar)