Skip to content

Commit

Permalink
timetravel: huge optimisation (up to 250x :p)
Browse files Browse the repository at this point in the history
300kH on an i5 4440 (with bmw512 as first algo)
  • Loading branch information
tpruvot committed Jan 26, 2017
1 parent 18cf11a commit 9fff60e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 43 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Algorithms
*__s3__ (OneCoin)
*__sia__ (Reversed Blake2B for SIA [SC])
*__sib__ X11 + gost streebog (SibCoin)
*__timetravel__ Permuted serie of 8 algos (MachineCoin [MAC])
*__vanilla__ (Blake-256 8-rounds - double sha256 [VNL])
*__veltor__ (Veltor [VLT])
*__x11evo__ (Revolver [XRE])
Expand Down
60 changes: 21 additions & 39 deletions algo/timetravel.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,29 @@
#include <sha3/sph_skein.h>
#include <sha3/sph_luffa.h>
#include <sha3/sph_cubehash.h>
#include <sha3/sph_shavite.h>
#include <sha3/sph_simd.h>
#include <sha3/sph_echo.h>

#define HASH_FUNC_BASE_TIMESTAMP 1389040865 // Machinecoin: Genesis Timestamp
#define HASH_FUNC_COUNT 8 // Machinecoin: HASH_FUNC_COUNT of 11
#define HASH_FUNC_COUNT_PERMUTATIONS 40320 // Machinecoin: HASH_FUNC_COUNT!
// Machinecoin Genesis Timestamp
#define HASH_FUNC_BASE_TIMESTAMP 1389040865

#define HASH_FUNC_COUNT 8
#define HASH_FUNC_COUNT_PERMUTATIONS 40320

static __thread uint32_t s_ntime = UINT32_MAX;
static __thread int permutation[HASH_FUNC_COUNT] = { 0 };

// helpers
void swap(int *a, int *b) {
inline void swap(int *a, int *b) {
int c = *a;
*a = *b;
*b = c;
}

void reverse(int *pbegin, int *pend) {
inline void reverse(int *pbegin, int *pend) {
while ( (pbegin != pend) && (pbegin != --pend) )
swap(pbegin++, pend);
}

void next_permutation(int *pbegin, int *pend) {
static void next_permutation(int *pbegin, int *pend) {
if (pbegin == pend)
return;

Expand Down Expand Up @@ -66,7 +68,6 @@ void next_permutation(int *pbegin, int *pend) {
}
}
}
// helpers

void timetravel_hash(void *output, const void *input)
{
Expand All @@ -76,7 +77,6 @@ void timetravel_hash(void *output, const void *input)
uint32_t *work_data = (uint32_t *)input;
const uint32_t timestamp = work_data[17];


sph_blake512_context ctx_blake;
sph_bmw512_context ctx_bmw;
sph_groestl512_context ctx_groestl;
Expand All @@ -85,25 +85,22 @@ void timetravel_hash(void *output, const void *input)
sph_keccak512_context ctx_keccak;
sph_luffa512_context ctx_luffa;
sph_cubehash512_context ctx_cubehash;
sph_shavite512_context ctx_shavite;
sph_simd512_context ctx_simd;
sph_echo512_context ctx_echo;

// We want to permute algorithms. To get started we
// initialize an array with a sorted sequence of unique
// integers where every integer represents its own algorithm.
uint32_t permutation[HASH_FUNC_COUNT];
for (uint32_t i = 0; i < HASH_FUNC_COUNT; i++) {
permutation[i]=i;
}

// Compute the next permuation
uint32_t steps = (timestamp - HASH_FUNC_BASE_TIMESTAMP)%HASH_FUNC_COUNT_PERMUTATIONS;
for (uint32_t i = 0; i < steps; i++) {
next_permutation(permutation, permutation + HASH_FUNC_COUNT);
if (timestamp != s_ntime) {
int steps = (int) (timestamp - HASH_FUNC_BASE_TIMESTAMP) % HASH_FUNC_COUNT_PERMUTATIONS;
for (int i = 0; i < HASH_FUNC_COUNT; i++) {
permutation[i] = i;
}
for (int i = 0; i < steps; i++) {
next_permutation(permutation, permutation + HASH_FUNC_COUNT);
}
s_ntime = timestamp;
}

for (uint32_t i = 0; i < HASH_FUNC_COUNT; i++) {
for (int i = 0; i < HASH_FUNC_COUNT; i++) {
if (i == 0) {
dataLen = 80;
hashA = work_data;
Expand Down Expand Up @@ -154,21 +151,6 @@ void timetravel_hash(void *output, const void *input)
sph_cubehash512 (&ctx_cubehash, hashA, dataLen);
sph_cubehash512_close(&ctx_cubehash, hashB);
break;
case 8:
sph_shavite512_init(&ctx_shavite);
sph_shavite512(&ctx_shavite, hashA, dataLen);
sph_shavite512_close(&ctx_shavite, hashB);
break;
case 9:
sph_simd512_init(&ctx_simd);
sph_simd512 (&ctx_simd, hashA, dataLen);
sph_simd512_close(&ctx_simd, hashB);
break;
case 10:
sph_echo512_init(&ctx_echo);
sph_echo512 (&ctx_echo, hashA, dataLen);
sph_echo512_close(&ctx_echo, hashB);
break;
default:
break;
}
Expand Down
8 changes: 4 additions & 4 deletions res/cpuminer.rc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ IDI_ICON1 ICON "cpuminer.ico"
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,3,0,0
PRODUCTVERSION 1,3,0,0
FILEVERSION 1,3,1,0
PRODUCTVERSION 1,3,1,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x21L
Expand All @@ -76,10 +76,10 @@ BEGIN
BEGIN
BLOCK "040904e4"
BEGIN
VALUE "FileVersion", "1.3"
VALUE "FileVersion", "1.3.1"
VALUE "LegalCopyright", "Copyright (C) 2015"
VALUE "ProductName", "cpuminer-multi"
VALUE "ProductVersion", "1.3"
VALUE "ProductVersion", "1.3.1"
END
END
BLOCK "VarFileInfo"
Expand Down

0 comments on commit 9fff60e

Please sign in to comment.