32 bit left rotates where n > 1: a hack
johnm at wdi.disney.com
Mon Jan 26 18:18:04 UTC 1998
from Christopher Oliver:
>I found in trying to hack together a quick version of RIPEMD-
>160 that one can actually reduce the execution by about at
>least a quarter and rotate by an arbitrary amount by adding to
>the expression given first a bitAnd: so that the left shift
>stays within four bytes. Hence, my best effort looks like:
> ((a bitAnd: m) bitShift: n) bitOr: (a BitShift: -n)
>where n is a number greater than zero, and m is 2^(32 - n) - 1.
>It seems cheapest when (a bitAnd: m) is a SmallInteger. I
>welcome any improvements to this technique.
This is faster because it minimizes the use of LargeIntegers.
LargeInt arithmetic is pretty fast, but you can't beat small
integers for real speed.
If you have to rotate a lot of words by the same amount, the
BitBlt hack for doing them in bulk (described in a previous
message from Tim Rowledge) might be effective.
One final idea would be to automatically generate a primitive
from your working Smalltalk code using the Smalltalk-to-C
translator. This was done for the sound generation algorithms.
However, you may have a C programming environment available.
More information about the Squeak-dev