Go Back   Velocity Reviews > Newsgroups > C Programming
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

C Programming - Optimization idea: put (y&1) in [] instead of if()

 
Thread Tools Search this Thread
Old 11-06-2009, 03:31 PM   #11
Default Re: Optimization idea: put (y&1) in [] instead of if()


about:
> #ifdef FASTWAY
> p[0] = (p[397] ^ y >> 1) ^ xorer[y & 1];
> #else
> p[0] = y & 1
> ? (p[397] ^ y >> 1) ^ 0x9908b0df
> : (p[397] ^ y >> 1);
> #endif


In article <5180a9bc-db20-4efe-bbf2-> James Dow Allen <> writes:
....
> Thank you. Still, it seemed remarkable that *more than half* the
> time spent by the entire twister (much longer piece of code than
> the posted fragment) was wasted by this "unhoistable" branch,
> especially since the FASTWAY would have been slower, I think,
> on many Jurassic-era processors.


I do not think so. On many early CDC's the first version would be
faster, even if you compiled the code fragment naively to machine
code. The forward branches would kill performance (they would void
the instruction stack leaving a delay comparable to the time for
about 50 instructions, while a load was about 12 instructions worth).

Or do you not think a mainframe from the early 60's is Jurassic-era?

Naive thinking can lead to bad programming and also extrapolating from
past experience to new machines can lead to slow programs. Consider
the relative cost of floating-point multiplication vs floating-point
addition and subtraction. I have seen routines where algorithms using
many multiplications where converted to algorithms using far fewer
multiplications and many more additions, for a total increase in the
number of operations. While this was faster on the first CDC I did
use (addition was 3 cycles, multiplication 57), it failed on later
generations (addition still 3 cycles but multiplication now 4 cycles).
--
dik t. winter, cwi, science park 123, 1098 xg amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/


Dik T. Winter
  Reply With Quote
Old 11-07-2009, 07:35 AM   #12
James Dow Allen
 
Posts: n/a
Default Re: Optimization idea: put (y&1) in [] instead of if()
On Nov 6, 10:31*pm, "Dik T. Winter" <Dik.Win...@cwi.nl> wrote:
> about:
>
> > #ifdef * *FASTWAY
> > * * * * p[0] = (p[397] ^ y >> 1) ^ xorer[y & 1];
> > #else
> > * * * * p[0] = y & 1
> > * * * * * * * * ? (p[397] ^ y >> 1) ^ 0x9908b0df
> > * * * * * * * * : (p[397] ^ y >> 1);
> > #endif

>
> In article <5180a9bc-db20-4efe-bbf2-4b44afe6a...@a37g2000prf.googlegroups..com> James Dow Allen <jdallen2...@yahoo.com> writes:
> ...
> *> Thank you. *Still, it seemed remarkable that *more than half* the
> *> time spent by the entire twister (much longer piece of code than
> *> the posted fragment) was wasted by this "unhoistable" branch,
> *> especially since the FASTWAY would have been slower, I think,
> *> on many Jurassic-era processors.


I did write *many* Jurassic-era processors; I did not write *all*
Jurassic-era processors.

> I do not think so. *On many early CDC's the first version would be
> faster,..


By "many" I think you mean the 6600. They kept that in the Rad Lab
in my day, and we undergrads had to use the 6400 which had no
pipeline. Among IBM mainframes in the mid-1970's, only the
million-dollar-plus models had any real pipeline.

> Or do you not think a mainframe from the early 60's is Jurassic-era?


What I think is that I wrote *many* and you
misinterpreted that to mean *all*.

> Naive thinking can lead to bad programming and also extrapolating from
> past experience to new machines can lead to slow programs.


Everyone seems eager to impugn my optimization talents! For the
first class using the afore-mentioned CDC6400, the Professor gave me
an A+ as my programs outperformed his for speed. I *did* write
the World's Fastest JPEG Compressor. Etc.

I once sat at a desk next to a circuit designer who was, supposedly,
one of only two people in the world to be able to debug the 6600
register-reservation scoreboard (the other was Seymour Cray!)
I did *not* post my message because I wanted someone to explain
pipelining to me! I *did* post, altruistically, because I
thought that the huge performance advantage shown in the fragment
might be of interest to others who seek speed. Perhaps the
post should have been addressed only to "naive thinkers."

James Dow Allen


James Dow Allen
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Search Engine Optimization Guidelines alpha Computer Support 1 02-25-2008 04:28 PM
Web Hosting, Designing, Email Marketing & Search Engine Optimization Packages karen.systems@gmail.com Computer Support 3 07-23-2007 01:38 AM
saraff pravesh pravesh saraff saraff.pravesh.cool@gmail.com Computer Support 31 05-31-2007 01:23 PM
must read content, pravesh saraff saraff.pravesh.cool@gmail.com Computer Support 0 05-30-2007 04:03 PM
BIOS Optimization Guide Rev. 8.21 Silverstrand Front Page News 0 08-24-2005 02:46 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46