diff options
author | Mattias Andrée <maandree@operamail.com> | 2013-04-16 00:06:18 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2013-04-16 00:06:18 +0200 |
commit | 90258fdadace50db3ef72a46aa84e9004c7cb61a (patch) | |
tree | 4813be3ed649b7bcdb4588aa6cc28613da80576d /java-c-jni | |
parent | whoops, read the filesize instead of the blocksize (diff) | |
download | sha3sum-90258fdadace50db3ef72a46aa84e9004c7cb61a.tar.gz sha3sum-90258fdadace50db3ef72a46aa84e9004c7cb61a.tar.bz2 sha3sum-90258fdadace50db3ef72a46aa84e9004c7cb61a.tar.xz |
fix binary logarithm
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | java-c-jni/SHA3.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/java-c-jni/SHA3.c b/java-c-jni/SHA3.c index 9e93f01..ad01ebc 100644 --- a/java-c-jni/SHA3.c +++ b/java-c-jni/SHA3.c @@ -230,10 +230,18 @@ inline void revarraycopy(byte* src, long soff, byte* dest, long doff, long lengt /** * Binary logarithm * - * @param X:long The value of which to calculate the binary logarithm - * @return :long The binary logarithm + * @param x The value of which to calculate the binary logarithm + * @return The binary logarithm */ -#define lb(X) ((((X & 0xFF00) == 0 ? 0 : 8) + ((X & 0xF0F0) == 0 ? 0 : 4)) + (((X & 0xCCCC) == 0 ? 0 : 2) + ((X & 0xAAAA) == 0 ? 0 : 1))) +static long lb(long x) +{ + long rc = 0; + if ((x & 0xFF00) != 0) { rc += 8; x >>= 8; } + if ((x & 0x00F0) != 0) { rc += 4; x >>= 4; } + if ((x & 0x000C) != 0) { rc += 2; x >>= 2; } + if ((x & 0x0002) != 0) rc += 1; + return rc; +} /** |