shithub: blake2

Download patch

ref: 369aa70c0cd68933cfb5c1d253bf10f0aa36f68d
parent: 88df903283b721e5dfcb488331fd90c45f940d25
author: Samuel Neves <sneves@dei.uc.pt>
date: Sun Jun 12 12:37:10 EDT 2016

bench portability

--- a/bench/amd64cpuinfo.c
+++ /dev/null
@@ -1,22 +1,0 @@
-/*
-   BLAKE2 reference source code package - benchmark tool
-  
-   Copyright 2012, Samuel Neves <sneves@dei.uc.pt>.  You may use this under the
-   terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
-   your option.  The terms of these licenses can be found at:
-  
-   - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
-   - OpenSSL license   : https://www.openssl.org/source/license.html
-   - Apache 2.0        : http://www.apache.org/licenses/LICENSE-2.0
-  
-   More information about the BLAKE2 hash function can be found at
-   https://blake2.net.
-*/
-
-unsigned long long cpucycles( void )
-{
-  unsigned long long result;
-  asm volatile( ".byte 15;.byte 49;shlq $32,%%rdx;orq %%rdx,%%rax"
-                : "=a" ( result ) ::  "%rdx" );
-  return result;
-}
--- a/bench/bench.c
+++ b/bench/bench.c
@@ -26,7 +26,26 @@
   return *ix - *iy;
 }
 
-unsigned long long cpucycles( void );
+#if defined(__amd64__) || defined(__x86_64__)
+static unsigned long long cpucycles( void ) {
+  unsigned long long result;
+  __asm__ __volatile__(
+    ".byte 15;.byte 49\n"
+    "shlq $32,%%rdx\n"
+    "orq %%rdx,%%rax\n"
+    : "=a" ( result ) ::  "%rdx"
+  );
+  return result;
+}
+#elif defined(__i386__)
+static unsigned long long cpucycles( void ) {
+  unsigned long long result;
+  __asm__ __volatile__( ".byte 15;.byte 49;" : "=A" ( result ) );
+  return result;
+}
+#else
+#error "Don't know how to count cycles on this platform!"
+#endif
 
 void bench()
 {
--- a/bench/makefile
+++ b/bench/makefile
@@ -1,12 +1,14 @@
 CC=gcc
 # std to gnu99 to support inline asm
 CFLAGS=-std=gnu99 -O3 -march=native -DSUPERCOP # -DHAVE_XOP # uncomment on XOP-enabled CPUs
-FILES=amd64cpuinfo.c bench.c
+FILES=bench.c
 
 all:
 	$(CC) $(FILES) $(CFLAGS) ../sse/blake2b.c -o blake2b
 	$(CC) $(FILES) $(CFLAGS) ../sse/blake2s.c -o blake2s
 	$(CC) $(FILES) $(CFLAGS) md5.c -o md5  -lcrypto -lz
+	
+plot:
 	./blake2b > blake2b.data
 	./blake2s > blake2s.data
 	./md5 > md5.data
--- a/bench/x86cpuinfo.c
+++ /dev/null
@@ -1,21 +1,0 @@
-/*
-   BLAKE2 reference source code package - benchmark tool
-  
-   Copyright 2012, Samuel Neves <sneves@dei.uc.pt>.  You may use this under the
-   terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
-   your option.  The terms of these licenses can be found at:
-  
-   - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
-   - OpenSSL license   : https://www.openssl.org/source/license.html
-   - Apache 2.0        : http://www.apache.org/licenses/LICENSE-2.0
-  
-   More information about the BLAKE2 hash function can be found at
-   https://blake2.net.
-*/
-
-unsigned long long cpucycles( void )
-{
-  unsigned long long result;
-  asm volatile( ".byte 15;.byte 49" : "=A" ( result ) );
-  return result;
-}
--