Skip to content

Commit

Permalink
supercop-20110617
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel J. Bernstein authored and floodyberry committed Jun 17, 2011
1 parent b2e9861 commit 3cb0d50
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 4 deletions.
43 changes: 43 additions & 0 deletions cpucycles/apple.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <mach/mach_time.h>
#include "osfreq.c"

#define timebase mach_absolute_time

static int tbmib[2] = { CTL_HW, HW_TB_FREQ } ;

static long myround(double u)
{
long result = u;
while (result + 0.5 < u) result += 1;
while (result - 0.5 > u) result -= 1;
return result;
}

static long long cpufrequency = 0;
static long tbcycles = 0;

static void init(void)
{
unsigned int tbfrequency = 0; size_t tbfrequencylen = sizeof(unsigned int);
cpufrequency = osfreq();
sysctl(tbmib,2,&tbfrequency,&tbfrequencylen,0,0);
if (tbfrequency > 0)
tbcycles = myround(64 * (double) (unsigned long long) cpufrequency
/ (double) (unsigned long long) tbfrequency);
}

long long cpucycles_apple(void)
{
if (!cpufrequency) init();
return (timebase() * tbcycles) >> 6;
}

long long cpucycles_apple_persecond(void)
{
if (!cpufrequency) init();
return cpufrequency;
}
27 changes: 27 additions & 0 deletions cpucycles/apple.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
cpucycles apple.h version 20110616
D. J. Bernstein
Public domain.
*/

#ifndef CPUCYCLES_apple_h
#define CPUCYCLES_apple_h

#ifdef __cplusplus
extern "C" {
#endif

extern long long cpucycles_apple(void);
extern long long cpucycles_apple_persecond(void);

#ifdef __cplusplus
}
#endif

#ifndef cpucycles_implementation
#define cpucycles_implementation "apple"
#define cpucycles cpucycles_apple
#define cpucycles_persecond cpucycles_apple_persecond
#endif

#endif
3 changes: 2 additions & 1 deletion cpucycles/do
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ okabi | (
;;
esac

echo apple
echo amd64tscfreq
echo amd64cpuinfo
echo amd64cpuspeed
Expand Down Expand Up @@ -82,7 +83,7 @@ okabi | (
cp $n.h cpucycles-impl.h || continue
$c -c cpucycles-impl.c || continue
$c -o test test.c cpucycles-impl.o || continue
./test || continue
killafter 300 ./test || continue
echo "=== `date` === Success. Using $n.c." >&2
mkdir -p lib/$abi
mv cpucycles-impl.o lib/$abi/cpucycles.o
Expand Down
14 changes: 14 additions & 0 deletions cpucycles/osfreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ static double osfreq(void)
double result;
int s;

f = fopen("/etc/cpucyclespersecond", "r");
if (f) {
s = fscanf(f,"%lf",&result);
fclose(f);
if (s > 0) return result;
}

f = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq", "r");
if (f) {
s = fscanf(f,"%lf",&result);
Expand Down Expand Up @@ -42,6 +49,13 @@ static double osfreq(void)
if (result) return 1000000.0 * result;
}

f = popen("sysctl hw.cpufrequency 2>/dev/null","r");
if (f) {
s = fscanf(f,"hw.cpufrequency: %lf",&result);
pclose(f);
if (s > 0) if (result > 0) return result;
}

f = popen("/usr/sbin/lsattr -E -l proc0 -a frequency 2>/dev/null","r");
if (f) {
s = fscanf(f,"frequency %lf",&result);
Expand Down
1 change: 1 addition & 0 deletions crypto_hash/fugue384/description
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fugue with 384-bit output
3 changes: 3 additions & 0 deletions crypto_hash/fugue384/designers
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Charanjit Jutla
Shai Halevi
Eric Hall
1 change: 1 addition & 0 deletions crypto_hash/sha256/sphlib-small/implementors
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Thomas Pornin
1 change: 1 addition & 0 deletions crypto_hash/sha256/sphlib/implementors
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Thomas Pornin
1 change: 1 addition & 0 deletions crypto_hash/sha512/sphlib-small/implementors
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Thomas Pornin
1 change: 1 addition & 0 deletions crypto_hash/sha512/sphlib/implementors
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Thomas Pornin
2 changes: 1 addition & 1 deletion data-vars
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
version=`cat version`

project=supercop
shorthostname=`hostname | sed 's/\..*//' | tr -cd '[a-z][A-Z][0-9]'`
shorthostname=`hostname | sed 's/\..*//' | tr -cd '[a-z][A-Z][0-9]' | tr '[A-Z]' '[a-z]'`

top="`pwd`/supercop-data/$shorthostname"

Expand Down
2 changes: 1 addition & 1 deletion do
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

version=`cat version`
project=supercop
shorthostname=`hostname | sed 's/\..*//' | tr -cd '[a-z][A-Z][0-9]'`
shorthostname=`hostname | sed 's/\..*//' | tr -cd '[a-z][A-Z][0-9]' | tr '[A-Z]' '[a-z]'`

top="`pwd`/bench/$shorthostname"
bin="$top/bin"
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20110609
20110617

0 comments on commit 3cb0d50

Please sign in to comment.