[LLVMdev] rotate (original) (raw)

Michael Gottesman mgottesman at apple.com
Sun Jul 29 14:39:01 PDT 2012


After some reflection, I believe the problem was actually with shld/shrd and a similar bit of C code.

On Jul 29, 2012, at 1:02 PM, Andy Gibbs <andyg1001 at hotmail.co.uk> wrote:

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 __builtinclz and builtinctz 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 builtinrotl 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 uint32t ror(uint32t input, sizet rotbits) { return (input >> rotbits) | (input << ((sizeof(input) << 3) - rotbits)); } 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