From 73e6d512fe1547292b5df4405a27e2fe727a253b Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Sun, 21 Sep 2014 21:49:41 +0100 Subject: [PATCH] Make digest handling more optimizer save by using a union --- Makefile.am | 9 ++++++++- src/sha1speed.c | 29 ++++++++++++++++------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Makefile.am b/Makefile.am index a7936ed..d5670a9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,5 +16,12 @@ coverage-html: -$(MAKE) -C tests $(AM_MAKEFLAGS) -k $@ endif +REGEX_CCLASS=/^[ \t]*\(TR_CLASS\|TR_INTERFACE\)\(([a-zA-Z0-9_]+)/\2/d,definition/ tags: - ctags -R -V --langdef=cclass --langmap=cclass:.h --regex-cclass='/^[ \t]*\(TR_CLASS\|TR_INTERFACE\)\(([a-zA-Z0-9_]+)/\2/d,definition/' + @ctags -R -V --langdef=cclass --langmap=cclass:.h \ + --regex-cclass='$(REGEX_CCLASS)' + +loc: + @find src/ include/ -not -path testers -and -name "*.[ch]" \ + -exec sed '/\/\*/,/\*\//d;/\/\//d' {} \; | wc -l + diff --git a/src/sha1speed.c b/src/sha1speed.c index b58a641..1579b84 100644 --- a/src/sha1speed.c +++ b/src/sha1speed.c @@ -37,7 +37,10 @@ int main(int argc, char * argv []) { unsigned char data[16384]; - unsigned char digest[20]; + union { + unsigned char bytes[20]; + uint32_t ints[5]; + } digest; size_t got; int i; clock_t start, stop; @@ -56,16 +59,16 @@ main(int argc, char * argv []) SHA1_Init(&ctx); SHA1_Update(&ctx, data, got); - SHA1_Final(digest, &ctx); + SHA1_Final(digest.bytes, &ctx); } stop = clock(); printf( "done\nResult: %08x%08x%08x%08x%08x\n", - htonl(((uint32_t *)&digest)[0]), - htonl(((uint32_t *)&digest)[1]), - htonl(((uint32_t *)&digest)[2]), - htonl(((uint32_t *)&digest)[3]), - htonl(((uint32_t *)&digest)[4])); + htonl(digest.ints[0]), + htonl(digest.ints[1]), + htonl(digest.ints[2]), + htonl(digest.ints[3]), + htonl(digest.ints[4])); printf("CPU time OpenSSL: %f\n", (double)(stop - start) / CLOCKS_PER_SEC); @@ -78,16 +81,16 @@ main(int argc, char * argv []) TR_SHA1_Init(&ctx); TR_SHA1_Update(&ctx, data, got); - TR_SHA1_Final(digest, &ctx); + TR_SHA1_Final(digest.bytes, &ctx); } stop = clock(); printf( "Done\nResult: %08x%08x%08x%08x%08x\n", - htonl(((uint32_t *)&digest)[0]), - htonl(((uint32_t *)&digest)[1]), - htonl(((uint32_t *)&digest)[2]), - htonl(((uint32_t *)&digest)[3]), - htonl(((uint32_t *)&digest)[4])); + htonl(digest.ints[0]), + htonl(digest.ints[1]), + htonl(digest.ints[2]), + htonl(digest.ints[3]), + htonl(digest.ints[4])); printf("CPU time Ours: %f\n", (double)(stop - start) / CLOCKS_PER_SEC); return 0;