Finally, after many failed attempts, I came up with the (currently) correct way of coding "rotate right" in gcc inline (gas) assembly language for i386:
static inline unsigned int ror(unsigned int n, const int count) {
asm volatile(
"rorl %1, %0;"
: "=r" (n)
: "nI" (count), "0" (n)
);
return n;
}
And of course, as with most of my A/L "optimizations", the output runs slower than if I'd just stuck to C. The compiler knows to convert n >> count | n << (32 - count) into rorl %cl, %eax. However, the intrinsic _rotr(n, count) does give a slight performance advantage.
last updated 2013-06-12 09:32:55. served from tektonic.jcomeau.com