Adam Back (aba@dcs.ex.ac.uk)
Sun, 4 Oct 1998 02:55:25 +0100
Scoop writes:
> Many useful crypto algorithms include "rotate-left" and/or
> "rotate-right" steps, and most modern CPUs provide single
> instructions that accomplish these operations. However, the C
> language does NOT include such an operation.
> Can someone tell me how best to write a C function (that can be "inlined")
> that invokes the appropriate assembly language instruction??
>
> The platform I am working on is Sun/64-bit/Ultra/Unix/Solaris 2.6
I think GCC is supposed to be able to recognise the obvious construct :
#define rot_left(x,n) ( ( (x) << (n) ) | ( (x) >> (32-(n)) ) )
though typically x and n involve masses of xors, table lookups and
whatnot so you wonder how well that scales, and whether it will get it
wrong, if the expression macro expands to be too complicated.
try gcc -S :-)
Adam
The following archive was created by hippie-mail 7.98617-22 on Sat Apr 10 1999 - 01:15:19