From 7510f5b16df9493e24f7ec8291c64e521811c53a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 11 Feb 2014 09:25:11 +0100 Subject: add thread support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 3 +++ c/sha3.c | 36 ++++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index f7180a2..e9130aa 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,9 @@ CFLAGS=-W{all,extra} -pedantic $(C_OPTIMISE) -fPIC ifeq ($(WITH_C99),yes) CFLAGS+=-std=c99 -DWITH_C99 endif +ifeq ($(WITH_THREADLOCAL),yes) + CFLAGS+=-DWITH_THREADLOCAL +endif SOFLAGS=-W{all,extra} -pedantic $(C_OPTIMISE) -shared CPPFLAGS= LDFLAGS= diff --git a/c/sha3.c b/c/sha3.c index 4346a9c..3b0c28e 100644 --- a/c/sha3.c +++ b/c/sha3.c @@ -25,6 +25,14 @@ #define static_inline inline #endif +#ifdef WITH_THREADLOCAL + #define threadlocal __thread + /* This is compiler dependent, if your compiler does + * not support this you need to define __thread yourself. */ +#else + #define threadlocal /* no threading support */ +#endif + #define null 0 #define true 1 #define false 0 @@ -55,74 +63,74 @@ static const llong RC[] = { /** * Keccak-f round temporary */ -static llong B[25]; +static threadlocal llong B[25]; /** * Keccak-f round temporary */ -static llong C[5]; +static threadlocal llong C[5]; /** * The bitrate */ -static long r = 0; +static threadlocal long r = 0; /** * The capacity */ -static long c = 0; +static threadlocal long c = 0; /** * The output size */ -static long n = 0; +static threadlocal long n = 0; /** * The state size */ -static long b = 0; +static threadlocal long b = 0; /** * The word size */ -static long w = 0; +static threadlocal long w = 0; /** * The word mask */ -static llong wmod = 0; +static threadlocal llong wmod = 0; /** * ℓ, the binary logarithm of the word size */ -static long l = 0; +static threadlocal long l = 0; /** * 12 + 2ℓ, the number of rounds */ -static long nr = 0; +static threadlocal long nr = 0; /** * The current state */ -static llong* S = null; +static threadlocal llong* S = null; /** * Left over water to fill the sponge with at next update */ -static byte* M = null; +static threadlocal byte* M = null; /** * Pointer for {@link #M} */ -static long mptr = 0; +static threadlocal long mptr = 0; /** * Size of {@link #M} */ -static long mlen = 0; +static threadlocal long mlen = 0; -- cgit v1.2.3-70-g09d2