Note that the safer rotate macro can be compiled into a rotate instruction just like the current macro. But LLVM and GCC don't know this. I've made requests to both compiler teams to implement this optimization, but I have no idea if they'll go for it.

http://llvm.org/bugs/show_bug.cgi?id=17904
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59100

John Regehr



On 11/12/2013 08:55 PM, John Regehr wrote:
   #define ROTL32(n,x) (((x)<<(n)) | ((x)>>((-(n)&31))))

The problem is n==0, not n==32.  So this fixes the undefined behavior:

#define ROTL32(n,x) ((n)==0?(x):(((x)<<(n)) | ((x)>>(32-(n)))))

John

_______________________________________________
nettle-bugs mailing list
[email protected]
http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs

_______________________________________________
nettle-bugs mailing list
[email protected]
http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs

Reply via email to