Browse Source

Merge pull request #44 from LefterisJP/reintegrating_changes_from_cppethereum

Integrating ethash-cl changes from cppethereum
cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
bf14ab08d1
  1. 22
      ethash.h
  2. 18
      internal.c
  3. 2
      internal.h
  4. 2
      io.c

22
ethash.h

@ -26,17 +26,17 @@
#include <stddef.h>
#include "compiler.h"
#define REVISION 23
#define DATASET_BYTES_INIT 1073741824U // 2**30
#define DATASET_BYTES_GROWTH 8388608U // 2**23
#define CACHE_BYTES_INIT 1073741824U // 2**24
#define CACHE_BYTES_GROWTH 131072U // 2**17
#define EPOCH_LENGTH 30000U
#define MIX_BYTES 128
#define HASH_BYTES 64
#define DATASET_PARENTS 256
#define CACHE_ROUNDS 3
#define ACCESSES 64
#define ETHASH_REVISION 23
#define ETHASH_DATASET_BYTES_INIT 1073741824U // 2**30
#define ETHASH_DATASET_BYTES_GROWTH 8388608U // 2**23
#define ETHASH_CACHE_BYTES_INIT 1073741824U // 2**24
#define ETHASH_CACHE_BYTES_GROWTH 131072U // 2**17
#define ETHASH_EPOCH_LENGTH 30000U
#define ETHASH_MIX_BYTES 128
#define ETHASH_HASH_BYTES 64
#define ETHASH_DATASET_PARENTS 256
#define ETHASH_CACHE_ROUNDS 3
#define ETHASH_ACCESSES 64
#ifdef __cplusplus
extern "C" {

18
internal.c

@ -43,14 +43,14 @@
uint64_t ethash_get_datasize(uint32_t const block_number)
{
assert(block_number / EPOCH_LENGTH < 2048);
return dag_sizes[block_number / EPOCH_LENGTH];
assert(block_number / ETHASH_EPOCH_LENGTH < 2048);
return dag_sizes[block_number / ETHASH_EPOCH_LENGTH];
}
uint64_t ethash_get_cachesize(uint32_t const block_number)
{
assert(block_number / EPOCH_LENGTH < 2048);
return cache_sizes[block_number / EPOCH_LENGTH];
assert(block_number / ETHASH_EPOCH_LENGTH < 2048);
return cache_sizes[block_number / ETHASH_EPOCH_LENGTH];
}
// Follows Sergio's "STRICT MEMORY HARD HASHING FUNCTIONS" (2014)
@ -73,7 +73,7 @@ bool static ethash_compute_cache_nodes(
SHA3_512(nodes[i].bytes, nodes[i - 1].bytes, 64);
}
for (unsigned j = 0; j != CACHE_ROUNDS; j++) {
for (unsigned j = 0; j != ETHASH_CACHE_ROUNDS; j++) {
for (unsigned i = 0; i != num_nodes; i++) {
uint32_t const idx = nodes[i].words[0] % num_nodes;
node data;
@ -142,7 +142,7 @@ void ethash_calculate_dag_item(
__m128i xmm3 = ret->xmm[3];
#endif
for (unsigned i = 0; i != DATASET_PARENTS; ++i) {
for (unsigned i = 0; i != ETHASH_DATASET_PARENTS; ++i) {
uint32_t parent_index = ((node_index ^ i) * FNV_PRIME ^ ret->words[i % NODE_WORDS]) % num_parent_nodes;
node const *parent = &cache_nodes[parent_index];
@ -224,9 +224,9 @@ static bool ethash_hash(
unsigned const page_size = sizeof(uint32_t) * MIX_WORDS;
unsigned const num_full_pages = (unsigned) (params->full_size / page_size);
double const progress_change = 1.0f / ACCESSES / MIX_NODES;
double const progress_change = 1.0f / ETHASH_ACCESSES / MIX_NODES;
double progress = 0.0f;
for (unsigned i = 0; i != ACCESSES; ++i) {
for (unsigned i = 0; i != ETHASH_ACCESSES; ++i) {
uint32_t const index = ((s_mix->words[0] ^ i) * FNV_PRIME ^ mix->words[i % MIX_WORDS]) % num_full_pages;
for (unsigned n = 0; n != MIX_NODES; ++n) {
@ -302,7 +302,7 @@ void ethash_quick_hash(
void ethash_get_seedhash(ethash_h256_t* seedhash, const uint32_t block_number)
{
ethash_h256_reset(seedhash);
const uint32_t epochs = block_number / EPOCH_LENGTH;
const uint32_t epochs = block_number / ETHASH_EPOCH_LENGTH;
for (uint32_t i = 0; i < epochs; ++i)
SHA3_256(seedhash, (uint8_t*)seedhash, 32);
}

2
internal.h

@ -16,7 +16,7 @@ extern "C" {
// compile time settings
#define NODE_WORDS (64/4)
#define MIX_WORDS (MIX_BYTES/4)
#define MIX_WORDS (ETHASH_MIX_BYTES/4)
#define MIX_NODES (MIX_WORDS / NODE_WORDS)
#include <stdint.h>

2
io.c

@ -37,7 +37,7 @@ enum ethash_io_rc ethash_io_prepare(
goto end;
}
ethash_io_mutable_name(REVISION, &seedhash, mutable_name);
ethash_io_mutable_name(ETHASH_REVISION, &seedhash, mutable_name);
char* tmpfile = ethash_io_create_filename(dirname, mutable_name, strlen(mutable_name));
if (!tmpfile) {
goto end;

Loading…
Cancel
Save