diff options
-rw-r--r-- | test/monniaux/bitsliced-tea/bstea.c | 8 | ||||
-rw-r--r-- | test/monniaux/bitsliced-tea/bstea.h | 14 | ||||
-rwxr-xr-x | test/monniaux/bitsliced-tea/reduce/compare.sh | 20 |
3 files changed, 38 insertions, 4 deletions
diff --git a/test/monniaux/bitsliced-tea/bstea.c b/test/monniaux/bitsliced-tea/bstea.c index c20c169c..43e29d45 100644 --- a/test/monniaux/bitsliced-tea/bstea.c +++ b/test/monniaux/bitsliced-tea/bstea.c @@ -86,7 +86,7 @@ void encrypt(parallel_blocks_t v, const parallel_keys_t k, unsigned int r) * in the expansion of multiples of 32/golden-ratio, * or 32/(1+sqrt(5)/2 */ - ai = (sum & (1<<i)) ? VECTOR_AT_ONE : VECTOR_AT_ZERO; + ai = TERNARY((sum & (1<<i)), VECTOR_AT_ONE, VECTOR_AT_ZERO); bi = v[offset_v1 + i]; aandb = ai & bi; axorb = ai ^ bi; @@ -147,7 +147,7 @@ void encrypt(parallel_blocks_t v, const parallel_keys_t k, unsigned int r) carry = 0; for (i = 0;i < 32;++i) { /* VECTOR_AT_ONE where the ith bit of the sum is set */ - ai = (sum & (1<<i)) ? VECTOR_AT_ONE : VECTOR_AT_ZERO; + ai = TERNARY((sum & (1<<i)), VECTOR_AT_ONE, VECTOR_AT_ZERO); bi = v[offset_v0 + i]; aandb = ai & bi; axorb = ai ^ bi; @@ -261,7 +261,7 @@ void decrypt(parallel_blocks_t v, const parallel_keys_t k, unsigned int r) carry = 0; for (i = 0;i < 32;++i) { /* VECTOR_AT_ONE where the ith bit of the sum is set */ - ai = (sum & (1<<i)) ? VECTOR_AT_ONE : VECTOR_AT_ZERO; + ai = TERNARY((sum & (1<<i)), VECTOR_AT_ONE, VECTOR_AT_ZERO); bi = v[offset_v0 + i]; aandb = ai & bi; axorb = ai ^ bi; @@ -323,7 +323,7 @@ void decrypt(parallel_blocks_t v, const parallel_keys_t k, unsigned int r) carry = 0; for (i = 0;i < 32;++i) { /* VECTOR_AT_ONE where the ith bit of the sum is set */ - ai = (sum & (1<<i)) ? VECTOR_AT_ONE : VECTOR_AT_ZERO; + ai = TERNARY((sum & (1<<i)), VECTOR_AT_ONE, VECTOR_AT_ZERO); bi = v[offset_v1 + i]; aandb = ai & bi; axorb = ai ^ bi; diff --git a/test/monniaux/bitsliced-tea/bstea.h b/test/monniaux/bitsliced-tea/bstea.h index 305bd403..fa767996 100644 --- a/test/monniaux/bitsliced-tea/bstea.h +++ b/test/monniaux/bitsliced-tea/bstea.h @@ -6,6 +6,20 @@ #include "bstea_wordsize.h" +static inline long compcert_ternary_signedl(long x, long v0, long v1) { + return ((-(x==0)) & v0) | ((-(x!=0)) & v1); +} + +static inline uint32_t compcert_ternary(uint32_t x, uint32_t v0, uint32_t v1) { + return compcert_ternary_signedl(x, v0, v1); +} + +#if defined(__K1C__) +#define TERNARY(x, v1, v0) compcert_ternary((x), (v0), (v1)) +#else +#define TERNARY(x, v1, v0) ((x) ? (v1) : (v0)) +#endif + #define TEA_ROUNDS 32 #define TEA_BLOCK_SIZE 64 diff --git a/test/monniaux/bitsliced-tea/reduce/compare.sh b/test/monniaux/bitsliced-tea/reduce/compare.sh new file mode 100755 index 00000000..d9f3cf86 --- /dev/null +++ b/test/monniaux/bitsliced-tea/reduce/compare.sh @@ -0,0 +1,20 @@ +PREFIX=/home/monniaux/work/Kalray/ternary/CompCert +INCLUDES=-I$PREFIX/test/monniaux/bitsliced-tea +CCOMP_K1="$PREFIX/ccomp -fno-unprototyped -O3 $INCLUDES" +GCC_K1="k1-mbr-gcc -Werror=implicit -O3 $INCLUDES" +GCC_HOST="gcc -Werror=implicit -O3 $INCLUDES" +FILE=bstea.c + +OTHERS_K1="$PREFIX/test/monniaux/bitsliced-tea/bstea_run.gcc.k1c.o $PREFIX/test/monniaux/clock.gcc.k1c.o" +OTHERS_HOST="$PREFIX/test/monniaux/bitsliced-tea/bstea_run.gcc.host.o $PREFIX/test/monniaux/clock.gcc.host.o" + +$CCOMP_K1 $FILE $OTHERS_K1 -o bstead.ccomp.k1c && +$GCC_K1 $FILE $OTHERS_K1 -o bstead.gcc.k1c && +$GCC_HOST $FILE $OTHERS_HOST -o bstead.gcc.host && +valgrind -q ./bstead.gcc.host && +k1-cluster --cycle-based -- bstead.ccomp.k1c > bstead.ccomp.k1c.out && +k1-cluster --cycle-based -- bstead.gcc.k1c > bstead.gcc.k1c.out && +grep cycles bstead.ccomp.k1c.out|sed -e 's/cycles: //' > bstead.ccomp.k1c.cycles && +grep cycles bstead.gcc.k1c.out|sed -e 's/cycles: //' > bstead.gcc.k1c.cycles && +test `cat bstead.gcc.k1c.cycles` -gt 100000 && +test `cat bstead.ccomp.k1c.cycles` -gt 200000 |