[LLVMdev] rotate

Andy Gibbs andyg1001 at hotmail.co.uk
Sun Jul 29 13:02:17 PDT 2012


> *NOTE* IIRC compiling this with -O0 on x86-64 can yield the wrong result
> since clang will emit shifts and on intel shifts are mod the register
> size [...snip...]

I remember finding the same thing (although I haven't tried it on a recent
clang version) and what I wondered was whether there was mileage in having
an explicit intrinsic for rotation (like there is for bit counting, as in
__builtin_clz and __builtin_ctz and so on).  Microsoft's compiler has an
explicit intrinsic in the form of _rotl8 and _rotl16 (IIRC -- this is from
memory!).  It would be nice to have a __builtin_rotl family in clang, in
my opinion, but it would need back-end support from llvm.  I would expect
it to find use in code relating to hashing and cryptology.  I know that
the compiler *should* optimise

uint32_t ror(uint32_t input, size_t rot_bits) {
  return (input >> rot_bits) | (input << ((sizeof(input) << 3) - rot_bits));
}

and such macros / inline functions are common, but an intrinsic specifies
intent better and could provide for better code optimisation.

Would this be worthwhile pursuing?

Cheers
Andy

 




More information about the llvm-dev mailing list