For performance critical code one should use higher optimization level. With the Sun cc compiler, at -xO5 the compilation of switch statements is optimal (I never looked at other than sparc assembly output, but I would not beleive that it is not the case for x86) and it has been so for ages.
Even more importantly, this particular place in question is in front of a code block (SHA[256,512]Transform) that takes in the order of 1000 cycles to execute. You would not need to worry about a couple of cycles that the difference can be between the if and the switch. The switch is cleaner. Ferenc ----- Original Message ----- From: Bill Sommerfeld <sommerf...@sun.com> Date: Wednesday, January 24, 2007 11:14 pm Subject: Re: [crypto-discuss] adding sha224 without turning sha2.c/sha2.h into hash... To: Garrett D'Amore <garrett_damore at tadpole.com> Cc: crypto-discuss at opensolaris.org > On Wed, 2007-01-24 at 14:02 -0800, Garrett D'Amore wrote: > > > The ones I'm most concerned about are the ones in the middle of > > > SHA2Update, which is a performance-critical path. That is > *not* the > > > place for a switch... > > > > I always thought the compilers were pretty good at optimizing > switch()> into a dispatch table... so much so that switch() was > often faster than > > the corresponding set of if..else..if branches. > > My experience looking at compiler output is that they fall down on the > job more than you'd like if you're trying to shave cycles. > > faster still is not needing the tests at all in the inner loop, > which is > how I think the code ought to be refactored. > > - Bill > > > _______________________________________________ > crypto-discuss mailing list > crypto-discuss at opensolaris.org > http://opensolaris.org/mailman/listinfo/crypto-discuss >