Browse Source

Add "memory" as a clobber for bswap inline assembly.

This had been causing Camellia (the only cipher that uses these
macros) to fail when compiling "out-of-the-box" with gcc version
"4.3.3-5ubuntu4".  I think because the compiler had no idea any memory
access was going on in these macros.

Adding "memory" as a clobber solves the problem, but is probably
overkill.  I suspect that if we specify the constraint for y
differently, we could get rid of both "memory" and __volatile__, which
would allow the compiler to optimize much more.

Also, in gcc versions that support it, we should probably use the
bswap builtins instead.
Patrick Pelletier 14 years ago
parent
commit
cefff85550
1 changed files with 2 additions and 2 deletions
  1. 2 2
      src/headers/tomcrypt_macros.h

+ 2 - 2
src/headers/tomcrypt_macros.h

@@ -105,13 +105,13 @@ asm __volatile__ (               \
    "bswapq %0     \n\t"          \
    "bswapq %0     \n\t"          \
    "movq   %0,(%1)\n\t"          \
    "movq   %0,(%1)\n\t"          \
    "bswapq %0     \n\t"          \
    "bswapq %0     \n\t"          \
-      ::"r"(x), "r"(y));
+   ::"r"(x), "r"(y): "memory");
 
 
 #define LOAD64H(x, y)          \
 #define LOAD64H(x, y)          \
 asm __volatile__ (             \
 asm __volatile__ (             \
    "movq (%1),%0\n\t"          \
    "movq (%1),%0\n\t"          \
    "bswapq %0\n\t"             \
    "bswapq %0\n\t"             \
-   :"=r"(x): "r"(y));
+   :"=r"(x): "r"(y): "memory");
 
 
 #else
 #else